some little updates with database

This commit is contained in:
Horhik 2021-03-11 09:53:47 +03:00
parent 1ddc42721c
commit acd8be2628
6 changed files with 151 additions and 31 deletions

3
.gitignore vendored
View file

@ -1 +1,4 @@
/target
./hole.db
hole.db
*.db

105
Cargo.lock generated
View file

@ -182,6 +182,17 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a"
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.0.1"
@ -283,6 +294,30 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
"libc",
"num-integer",
"num-traits",
"time",
"winapi",
]
[[package]]
name = "colored"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59"
dependencies = [
"atty",
"lazy_static",
"winapi",
]
[[package]]
name = "concurrent-queue"
version = "1.2.2"
@ -325,6 +360,16 @@ dependencies = [
"lazy_static",
]
[[package]]
name = "ctor"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fbaabec2c953050352311293be5c6aba8e141ba19d6811862b232d6fd020484"
dependencies = [
"quote",
"syn",
]
[[package]]
name = "digest"
version = "0.9.0"
@ -594,6 +639,7 @@ dependencies = [
"serde",
"serde_derive",
"serde_json",
"simple_logger",
"tokio 0.3.6",
"toml",
"tungstenite 0.12.0",
@ -711,11 +757,12 @@ dependencies = [
[[package]]
name = "log"
version = "0.4.11"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
dependencies = [
"cfg-if 0.1.10",
"cfg-if 1.0.0",
"value-bag",
]
[[package]]
@ -800,6 +847,25 @@ dependencies = [
"libc",
]
[[package]]
name = "num-integer"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.13.0"
@ -1281,6 +1347,19 @@ dependencies = [
"libc",
]
[[package]]
name = "simple_logger"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd57f17c093ead1d4a1499dc9acaafdd71240908d64775465543b8d9a9f1d198"
dependencies = [
"atty",
"chrono",
"colored",
"log",
"winapi",
]
[[package]]
name = "slab"
version = "0.4.2"
@ -1344,6 +1423,17 @@ dependencies = [
"once_cell",
]
[[package]]
name = "time"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"winapi",
]
[[package]]
name = "tinyvec"
version = "0.3.4"
@ -1507,6 +1597,15 @@ version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7"
[[package]]
name = "value-bag"
version = "1.0.0-alpha.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b676010e055c99033117c2343b33a40a30b91fecd6c49055ac9cd2d6c305ab1"
dependencies = [
"ctor",
]
[[package]]
name = "vcpkg"
version = "0.2.10"

View file

@ -12,7 +12,7 @@ rusqlite = "0.24.2"
toml = "0.5.6"
tungstenite = "0.12.0"
tokio = { version = "0.3.3", features = ["full"] }
log = "0.4.11"
log = "0.4.14"
futures = "0.3.6"
async-std = "1.6.5"
async-tls = "0.10.0"
@ -21,6 +21,7 @@ serde_json = "1.0.59"
serde = "1.0.116"
serde_derive = "1.0.116"
async-trait = "0.1.42"
simple_logger = "1.11.0"
[dependencies.fcpv2]
path = "../FCPv2"

View file

@ -1,22 +1,28 @@
use crate::chat::types::PackedMessage;
use async_std::io;
use fcpv2::client::fcp_types::{ClientGet, SSK};
use fcpv2::client::types::{FcpRequest, ReturnType};
use std::sync::mpsc::Sender;
type SP = Sender<PackedMessage>;
pub async fn request_repeater(ss: SP) -> io::Result<()> {
loop {
//TODO create a field with tracked users
let time = std::time::Duration::from_millis(1000);
std::thread::sleep(time);
match ss.send(PackedMessage {
message: format!(
"ClientGet\n\
URI=KSK@msg23.txt\n\
Identifier=doesnt_matter?\n\
Verbosity=0\n\
ReturnType=direct\n\
EndMessage\n\n"
),
match ss.send(PackedMessage{
message: ClientGet::new_default(SSK{sign_key: "9Zq-H7vg1iN6852rcL3mQQaIfPZODnIJnKyIy1dE6mk".to_string(), decrypt_key: "n-vQibdLXPDMtW7k5ftbR9HVz4Tb184lUc~MiUGHWAM".to_string(),settings: Some("AQACAAE".to_string())},
"check",
ReturnType::Direct).convert()
// message: format!(
// "ClientGet\n\
// URI=KSK@msg23.txt\n\
// Identifier=doesnt_matter?\n\
// Verbosity=0\n\
// ReturnType=direct\n\
// EndMessage\n\n"
// ),
}) {
Ok(_) => {}
Err(e) => println!("{:?}", e),

View file

@ -5,43 +5,52 @@ pub mod messaging;
pub struct Person {
id: i32,
name: String,
data: Option<Vec<u8>>,
key: String,
}
pub fn start_db() -> Result<()> {
let conn = Connection::open("../hole.db")?;
println!("{}", conn.is_autocommit());
match conn.execute(
"CREATE TABLE person (
fn create_db(conn: &Connection) -> Result<()> {
match conn.execute(
"CREATE TABLE users (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
data BLOB
key BLOB
)",
params![],
) {
Ok(_) => {}
Err(e) => println!("{:?}", e),
params![],
) {
Ok(_) => {log::info!("USER table created successfully!")},
Err(e) => log::error!("failed to create USER table {:?}", e),
}
Ok(())
}
pub fn start_db() -> Result<()> {
let conn = Connection::open("hole.db")?;
println!("{}", conn.is_autocommit());
match create_db(&conn) {
Ok(_) => log::info!("Successfully created DB!"),
Err(e) => log::error!("Failed to create DB: {:?}", e)
}
let me = Person {
id: 0,
name: "Steven".to_string(),
data: None,
key: "SSK@OolaRmEpOc1q0JF9iypUHZTlNNIqstOnScyb15SUr6k,MgxYrnex5LfvW-pRwMINs~d4nE2mYKjW1AE1U9vIPUM,AQECAAE".to_string(),
};
conn.execute(
"INSERT INTO person (name, data) VALUES (?1, ?2)",
params![me.name, me.data],
"INSERT INTO users (name, key) VALUES (?1, ?2)",
params![me.name, me.key],
)?;
let mut stmt = conn.prepare("SELECT id, name, data FROM person")?;
let mut stmt = conn.prepare("SELECT id, name, key FROM users")?;
let person_iter = stmt.query_map(params![], |row| {
Ok(Person {
id: row.get(0)?,
name: row.get(1)?,
data: row.get(2)?,
key: row.get(2)?,
})
})?;
for person in person_iter {
println!("Found person {:?}", person.unwrap());
}

View file

@ -6,7 +6,7 @@ use async_std::io;
use chat::front_conn::listen_client;
use chat::serv_conn::listen_server;
use chat::types::PackedMessage;
use log;
use std::{
sync::{
mpsc,
@ -14,6 +14,7 @@ use std::{
},
thread,
};
use simple_logger::SimpleLogger;
/*
+-----------------------------------------------------------------------------------+
| Client |
@ -43,6 +44,7 @@ use std::{
*/
fn main() -> io::Result<()> {
SimpleLogger::new().init().unwrap();
db::start_db().unwrap();
let (to_server_sender, server_receiver): (Sender<PackedMessage>, Receiver<PackedMessage>) =