some little updates with database
This commit is contained in:
parent
1ddc42721c
commit
acd8be2628
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1 +1,4 @@
|
||||||
/target
|
/target
|
||||||
|
./hole.db
|
||||||
|
hole.db
|
||||||
|
*.db
|
||||||
|
|
105
Cargo.lock
generated
105
Cargo.lock
generated
|
@ -182,6 +182,17 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a"
|
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]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
|
@ -283,6 +294,30 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
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]]
|
[[package]]
|
||||||
name = "concurrent-queue"
|
name = "concurrent-queue"
|
||||||
version = "1.2.2"
|
version = "1.2.2"
|
||||||
|
@ -325,6 +360,16 @@ dependencies = [
|
||||||
"lazy_static",
|
"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]]
|
[[package]]
|
||||||
name = "digest"
|
name = "digest"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
|
@ -594,6 +639,7 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"simple_logger",
|
||||||
"tokio 0.3.6",
|
"tokio 0.3.6",
|
||||||
"toml",
|
"toml",
|
||||||
"tungstenite 0.12.0",
|
"tungstenite 0.12.0",
|
||||||
|
@ -711,11 +757,12 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.4.11"
|
version = "0.4.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
|
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 0.1.10",
|
"cfg-if 1.0.0",
|
||||||
|
"value-bag",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -800,6 +847,25 @@ dependencies = [
|
||||||
"libc",
|
"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]]
|
[[package]]
|
||||||
name = "num_cpus"
|
name = "num_cpus"
|
||||||
version = "1.13.0"
|
version = "1.13.0"
|
||||||
|
@ -1281,6 +1347,19 @@ dependencies = [
|
||||||
"libc",
|
"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]]
|
[[package]]
|
||||||
name = "slab"
|
name = "slab"
|
||||||
version = "0.4.2"
|
version = "0.4.2"
|
||||||
|
@ -1344,6 +1423,17 @@ dependencies = [
|
||||||
"once_cell",
|
"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]]
|
[[package]]
|
||||||
name = "tinyvec"
|
name = "tinyvec"
|
||||||
version = "0.3.4"
|
version = "0.3.4"
|
||||||
|
@ -1507,6 +1597,15 @@ version = "0.7.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7"
|
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]]
|
[[package]]
|
||||||
name = "vcpkg"
|
name = "vcpkg"
|
||||||
version = "0.2.10"
|
version = "0.2.10"
|
||||||
|
|
|
@ -12,7 +12,7 @@ rusqlite = "0.24.2"
|
||||||
toml = "0.5.6"
|
toml = "0.5.6"
|
||||||
tungstenite = "0.12.0"
|
tungstenite = "0.12.0"
|
||||||
tokio = { version = "0.3.3", features = ["full"] }
|
tokio = { version = "0.3.3", features = ["full"] }
|
||||||
log = "0.4.11"
|
log = "0.4.14"
|
||||||
futures = "0.3.6"
|
futures = "0.3.6"
|
||||||
async-std = "1.6.5"
|
async-std = "1.6.5"
|
||||||
async-tls = "0.10.0"
|
async-tls = "0.10.0"
|
||||||
|
@ -21,6 +21,7 @@ serde_json = "1.0.59"
|
||||||
serde = "1.0.116"
|
serde = "1.0.116"
|
||||||
serde_derive = "1.0.116"
|
serde_derive = "1.0.116"
|
||||||
async-trait = "0.1.42"
|
async-trait = "0.1.42"
|
||||||
|
simple_logger = "1.11.0"
|
||||||
|
|
||||||
[dependencies.fcpv2]
|
[dependencies.fcpv2]
|
||||||
path = "../FCPv2"
|
path = "../FCPv2"
|
||||||
|
|
|
@ -1,22 +1,28 @@
|
||||||
use crate::chat::types::PackedMessage;
|
use crate::chat::types::PackedMessage;
|
||||||
use async_std::io;
|
use async_std::io;
|
||||||
|
use fcpv2::client::fcp_types::{ClientGet, SSK};
|
||||||
|
use fcpv2::client::types::{FcpRequest, ReturnType};
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
type SP = Sender<PackedMessage>;
|
type SP = Sender<PackedMessage>;
|
||||||
|
|
||||||
pub async fn request_repeater(ss: SP) -> io::Result<()> {
|
pub async fn request_repeater(ss: SP) -> io::Result<()> {
|
||||||
loop {
|
loop {
|
||||||
|
//TODO create a field with tracked users
|
||||||
let time = std::time::Duration::from_millis(1000);
|
let time = std::time::Duration::from_millis(1000);
|
||||||
std::thread::sleep(time);
|
std::thread::sleep(time);
|
||||||
match ss.send(PackedMessage {
|
match ss.send(PackedMessage{
|
||||||
message: format!(
|
message: ClientGet::new_default(SSK{sign_key: "9Zq-H7vg1iN6852rcL3mQQaIfPZODnIJnKyIy1dE6mk".to_string(), decrypt_key: "n-vQibdLXPDMtW7k5ftbR9HVz4Tb184lUc~MiUGHWAM".to_string(),settings: Some("AQACAAE".to_string())},
|
||||||
"ClientGet\n\
|
"check",
|
||||||
URI=KSK@msg23.txt\n\
|
ReturnType::Direct).convert()
|
||||||
Identifier=doesnt_matter?\n\
|
// message: format!(
|
||||||
Verbosity=0\n\
|
// "ClientGet\n\
|
||||||
ReturnType=direct\n\
|
// URI=KSK@msg23.txt\n\
|
||||||
EndMessage\n\n"
|
// Identifier=doesnt_matter?\n\
|
||||||
),
|
// Verbosity=0\n\
|
||||||
|
// ReturnType=direct\n\
|
||||||
|
// EndMessage\n\n"
|
||||||
|
// ),
|
||||||
}) {
|
}) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => println!("{:?}", e),
|
Err(e) => println!("{:?}", e),
|
||||||
|
|
|
@ -5,43 +5,52 @@ pub mod messaging;
|
||||||
pub struct Person {
|
pub struct Person {
|
||||||
id: i32,
|
id: i32,
|
||||||
name: String,
|
name: String,
|
||||||
data: Option<Vec<u8>>,
|
key: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_db() -> Result<()> {
|
fn create_db(conn: &Connection) -> Result<()> {
|
||||||
let conn = Connection::open("../hole.db")?;
|
|
||||||
println!("{}", conn.is_autocommit());
|
|
||||||
|
|
||||||
match conn.execute(
|
match conn.execute(
|
||||||
"CREATE TABLE person (
|
"CREATE TABLE users (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
data BLOB
|
key BLOB
|
||||||
)",
|
)",
|
||||||
params![],
|
params![],
|
||||||
) {
|
) {
|
||||||
Ok(_) => {}
|
Ok(_) => {log::info!("USER table created successfully!")},
|
||||||
Err(e) => println!("{:?}", e),
|
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 {
|
let me = Person {
|
||||||
id: 0,
|
id: 0,
|
||||||
name: "Steven".to_string(),
|
name: "Steven".to_string(),
|
||||||
data: None,
|
key: "SSK@OolaRmEpOc1q0JF9iypUHZTlNNIqstOnScyb15SUr6k,MgxYrnex5LfvW-pRwMINs~d4nE2mYKjW1AE1U9vIPUM,AQECAAE".to_string(),
|
||||||
};
|
};
|
||||||
conn.execute(
|
conn.execute(
|
||||||
"INSERT INTO person (name, data) VALUES (?1, ?2)",
|
"INSERT INTO users (name, key) VALUES (?1, ?2)",
|
||||||
params![me.name, me.data],
|
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| {
|
let person_iter = stmt.query_map(params![], |row| {
|
||||||
Ok(Person {
|
Ok(Person {
|
||||||
id: row.get(0)?,
|
id: row.get(0)?,
|
||||||
name: row.get(1)?,
|
name: row.get(1)?,
|
||||||
data: row.get(2)?,
|
key: row.get(2)?,
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|
||||||
for person in person_iter {
|
for person in person_iter {
|
||||||
println!("Found person {:?}", person.unwrap());
|
println!("Found person {:?}", person.unwrap());
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use async_std::io;
|
||||||
use chat::front_conn::listen_client;
|
use chat::front_conn::listen_client;
|
||||||
use chat::serv_conn::listen_server;
|
use chat::serv_conn::listen_server;
|
||||||
use chat::types::PackedMessage;
|
use chat::types::PackedMessage;
|
||||||
|
use log;
|
||||||
use std::{
|
use std::{
|
||||||
sync::{
|
sync::{
|
||||||
mpsc,
|
mpsc,
|
||||||
|
@ -14,6 +14,7 @@ use std::{
|
||||||
},
|
},
|
||||||
thread,
|
thread,
|
||||||
};
|
};
|
||||||
|
use simple_logger::SimpleLogger;
|
||||||
/*
|
/*
|
||||||
+-----------------------------------------------------------------------------------+
|
+-----------------------------------------------------------------------------------+
|
||||||
| Client |
|
| Client |
|
||||||
|
@ -43,6 +44,7 @@ use std::{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fn main() -> io::Result<()> {
|
fn main() -> io::Result<()> {
|
||||||
|
SimpleLogger::new().init().unwrap();
|
||||||
db::start_db().unwrap();
|
db::start_db().unwrap();
|
||||||
|
|
||||||
let (to_server_sender, server_receiver): (Sender<PackedMessage>, Receiver<PackedMessage>) =
|
let (to_server_sender, server_receiver): (Sender<PackedMessage>, Receiver<PackedMessage>) =
|
||||||
|
|
Loading…
Reference in a new issue