@@ -9,6 +9,12 @@ dependencies = [ | |||||
"winapi 0.3.8", | "winapi 0.3.8", | ||||
] | ] | ||||
[[package]] | |||||
name = "anyhow" | |||||
version = "1.0.31" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "85bb70cc08ec97ca5450e6eba421deeea5f172c0fc61f78b5357b2a8e8be195f" | |||||
[[package]] | [[package]] | ||||
name = "async-attributes" | name = "async-attributes" | ||||
version = "1.1.1" | version = "1.1.1" | ||||
@@ -122,6 +128,15 @@ dependencies = [ | |||||
"vec_map", | "vec_map", | ||||
] | ] | ||||
[[package]] | |||||
name = "crc32fast" | |||||
version = "1.2.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" | |||||
dependencies = [ | |||||
"cfg-if", | |||||
] | |||||
[[package]] | [[package]] | ||||
name = "crossbeam-channel" | name = "crossbeam-channel" | ||||
version = "0.4.2" | version = "0.4.2" | ||||
@@ -318,14 +333,16 @@ dependencies = [ | |||||
[[package]] | [[package]] | ||||
name = "ilmp" | name = "ilmp" | ||||
version = "0.1.0" | version = "0.1.0" | ||||
source = "git+https://github.com/izzabelle/ilmp#cb0257e9665b6fc9f0004c928ec043662ea275e0" | |||||
dependencies = [ | dependencies = [ | ||||
"anyhow", | |||||
"chrono", | "chrono", | ||||
"crc32fast", | |||||
"futures", | "futures", | ||||
"futures-util", | "futures-util", | ||||
"ring", | "ring", | ||||
"serde", | "serde", | ||||
"serde_json", | "serde_json", | ||||
"thiserror", | |||||
"uuid", | "uuid", | ||||
] | ] | ||||
@@ -460,6 +477,7 @@ dependencies = [ | |||||
name = "msg" | name = "msg" | ||||
version = "0.1.0" | version = "0.1.0" | ||||
dependencies = [ | dependencies = [ | ||||
"anyhow", | |||||
"async-std", | "async-std", | ||||
"chrono", | "chrono", | ||||
"futures", | "futures", | ||||
@@ -786,6 +804,26 @@ dependencies = [ | |||||
"unicode-width", | "unicode-width", | ||||
] | ] | ||||
[[package]] | |||||
name = "thiserror" | |||||
version = "1.0.18" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "5976891d6950b4f68477850b5b9e5aa64d955961466f9e174363f573e54e8ca7" | |||||
dependencies = [ | |||||
"thiserror-impl", | |||||
] | |||||
[[package]] | |||||
name = "thiserror-impl" | |||||
version = "1.0.18" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "ab81dbd1cd69cd2ce22ecfbdd3bdb73334ba25350649408cc6c085f46d89573d" | |||||
dependencies = [ | |||||
"proc-macro2", | |||||
"quote", | |||||
"syn", | |||||
] | |||||
[[package]] | [[package]] | ||||
name = "time" | name = "time" | ||||
version = "0.1.43" | version = "0.1.43" | ||||
@@ -15,5 +15,7 @@ structopt = "0.3.14" | |||||
chrono = "0.4.11" | chrono = "0.4.11" | ||||
futures = "0.3.5" | futures = "0.3.5" | ||||
toml = "0.5.6" | toml = "0.5.6" | ||||
ilmp = { git = "https://github.com/izzabelle/ilmp" } | |||||
# ilmp = { git = "https://github.com/izzabelle/ilmp" } | |||||
ilmp = { path = "../ilmp"} | |||||
ring = "0.16.13" | ring = "0.16.13" | ||||
anyhow = "1.0.31" |
@@ -2,19 +2,19 @@ | |||||
use crate::config::ClientConfig as Config; | use crate::config::ClientConfig as Config; | ||||
use crate::Result; | use crate::Result; | ||||
use async_std::net::TcpStream; | use async_std::net::TcpStream; | ||||
use futures_util::io::AsyncReadExt; | |||||
/// wraps the client | /// wraps the client | ||||
pub async fn client(port: u16) -> Result<()> { | pub async fn client(port: u16) -> Result<()> { | ||||
let config = Config::load()?; | |||||
let _config = Config::load()?; | |||||
let stream = TcpStream::connect(format!("127.0.0.1:{}", &port)).await?; | |||||
println!( | |||||
"connection established to: {}:{}", | |||||
stream.peer_addr()?.ip(), | |||||
port | |||||
); | |||||
let (_read, mut write) = stream.split(); | |||||
let mut stream = TcpStream::connect(format!("127.0.0.1:{}", &port)).await?; | |||||
println!("connection established to: {}:{}", stream.peer_addr()?.ip(), port); | |||||
/*let (_read, mut write) = stream.split();*/ | |||||
let message = | |||||
ilmp::Message::new("Isabelle".to_string(), "new message protocol working".to_string()); | |||||
ilmp::write(&mut stream, message).await?; | |||||
loop {} | loop {} | ||||
} | } |
@@ -8,5 +8,4 @@ pub use client::client; | |||||
pub use server::server; | pub use server::server; | ||||
// lazy idiot error/result type | // lazy idiot error/result type | ||||
pub type Error = std::io::Error; | |||||
pub type Result<T> = std::result::Result<T, Error>; | |||||
pub type Result<T> = anyhow::Result<T>; |
@@ -6,6 +6,7 @@ use async_std::{ | |||||
}; | }; | ||||
use futures::io::{ReadHalf, WriteHalf}; | use futures::io::{ReadHalf, WriteHalf}; | ||||
use futures_util::{io::AsyncReadExt, stream::StreamExt}; | use futures_util::{io::AsyncReadExt, stream::StreamExt}; | ||||
use ilmp::Sendable; | |||||
use lazy_static::lazy_static; | use lazy_static::lazy_static; | ||||
use std::{collections::HashMap, sync::Mutex}; | use std::{collections::HashMap, sync::Mutex}; | ||||
use uuid::Uuid; | use uuid::Uuid; | ||||
@@ -18,11 +19,7 @@ lazy_static! { | |||||
/// wraps the server | /// wraps the server | ||||
pub async fn server(port: u16) -> Result<()> { | pub async fn server(port: u16) -> Result<()> { | ||||
let listener = TcpListener::bind(format!("127.0.0.1:{}", &port)).await?; | let listener = TcpListener::bind(format!("127.0.0.1:{}", &port)).await?; | ||||
println!( | |||||
"online as server at: {}:{}", | |||||
listener.local_addr()?.ip(), | |||||
port | |||||
); | |||||
println!("online as server at: {}:{}", listener.local_addr()?.ip(), port); | |||||
let mut incoming = listener.incoming(); | let mut incoming = listener.incoming(); | ||||
while let Some(stream) = incoming.next().await { | while let Some(stream) = incoming.next().await { | ||||
@@ -34,26 +31,28 @@ pub async fn server(port: u16) -> Result<()> { | |||||
let (read, write) = stream.split(); | let (read, write) = stream.split(); | ||||
let stream_id = Uuid::new_v4(); | let stream_id = Uuid::new_v4(); | ||||
WRITE_STREAMS | |||||
.lock() | |||||
.expect("could not aqcuire lock") | |||||
.insert(stream_id.clone(), write); | |||||
WRITE_STREAMS.lock().expect("could not aqcuire lock").insert(stream_id.clone(), write); | |||||
task::spawn(handle_stream(read, stream_id)); | task::spawn(handle_stream(read, stream_id)); | ||||
} | } | ||||
Ok(()) | Ok(()) | ||||
} | } | ||||
async fn handle_stream(mut stream: ReadHalf<TcpStream>, stream_id: Uuid) -> Result<()> { | |||||
loop {} | |||||
println!("disconnecting"); | |||||
async fn handle_stream(mut stream: ReadHalf<TcpStream>, _stream_id: Uuid) -> Result<()> { | |||||
loop { | |||||
let packet = ilmp::read(&mut stream).await?; | |||||
if let Some(packet) = packet { | |||||
let res = match packet.kind { | |||||
ilmp::PacketKind::Message => ilmp::Message::from_packet(packet), | |||||
}; | |||||
println!("{:?}", res); | |||||
} | |||||
} | |||||
/* println!("disconnecting"); | |||||
WRITE_STREAMS | |||||
.lock() | |||||
.expect("failed to aqcuire lock") | |||||
.remove(&stream_id); | |||||
WRITE_STREAMS.lock().expect("failed to aqcuire lock").remove(&stream_id); | |||||
Ok(()) | |||||
Ok(())*/ | |||||
} | } | ||||
/*async fn relay_packet<T: Clone + Sendable>(packet: T) -> Result<()> { | /*async fn relay_packet<T: Clone + Sendable>(packet: T) -> Result<()> { | ||||