diff --git a/src/crypto.rs b/src/crypto.rs index 21e0cca..0901a78 100644 --- a/src/crypto.rs +++ b/src/crypto.rs @@ -1,5 +1,5 @@ extern crate rand; -extern crate rand_os; + extern crate rand_os; extern crate ed25519_dalek; use ed25519_dalek::{PublicKey as PK, Keypair, Signature}; diff --git a/src/ironforce.rs b/src/ironforce.rs index 87642af..b246bbf 100644 --- a/src/ironforce.rs +++ b/src/ironforce.rs @@ -45,7 +45,7 @@ impl IronForce { MsgType::MultiCast => { }, - MsgType::UniCast(Target) => { + MsgType::UniCast(target) => { } } diff --git a/src/lib.rs b/src/lib.rs index f5d2c54..1ca6b28 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,8 @@ #![no_std] extern crate alloc; +#[cfg(feature = "std")] +extern crate std; mod ironforce; diff --git a/src/transport.rs b/src/transport.rs index 8cebb08..2550660 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -1,41 +1,43 @@ use crate::message::{Message, MsgType}; +use crate::crypto::PublicKey; + +#[cfg(feature = "std")] use crate::way::Way; +#[cfg(feature = "std")] +use std::thread; use alloc::vec::Vec; use alloc::boxed::Box; #[cfg(not(feature = "std"))] -pub struct Transport { - id: [u8; 64] -} +pub struct Transport {} #[cfg(feature = "std")] pub struct Transport { - ways: Vec>, - id: [u8; 64] + ways: Vec>, + msg_pool: Vec, } #[cfg(not(feature = "std"))] impl Transport { pub fn new() -> Self { - Self {id: [0; 64]} + Self {} } - pub fn send(&self, msg: &Message) { + pub fn send(&self, msg: &Message) {} - } - - pub fn receive(&self) -> Message { - Message::new(MsgType::Service, - Vec::::new(), - &crate::crypto::Keys::gen()) + pub fn receive(&self) -> (Message, PublicKey) { + (Message::new(MsgType::Service, + Vec::::new(), + &crate::crypto::Keys::gen()), PublicKey { key: [0u8; 32] }) } } #[cfg(feature = "std")] impl Transport { pub fn new() -> Self { - Self {ways: Vec::>::new(), id: [0; 64]} + let transport = Self { ways: Vec::>::new(), msg_pool: Vec::::new() }; + transport } pub fn send(&self, msg: &Message) { @@ -44,9 +46,22 @@ impl Transport { } } - pub fn receive(&self) -> Message { - Message::new(MsgType::Service, - Vec::::new(), - &crate::crypto::Keys::gen()) + pub fn receive(&self) -> (Message, PublicKey) { + (Message::new(MsgType::MultiCast, + Vec::::new(), + &crate::crypto::Keys::gen()), PublicKey { key: [1u8; 32] }) + } + + fn receive_through_way_in_loop_and_add_in_pool(&mut self, way: &mut Box) { + loop { + let mut msg = way.receive(); + self.msg_pool.push(msg); + } + } + + fn start_receiving_thread(&'static mut self) { + thread::spawn(|| { + self.receive_through_way_in_loop_and_add_in_pool(&mut self.ways[0]); + }); } } diff --git a/src/tunnel.rs b/src/tunnel.rs index 2c58cb0..94494d3 100644 --- a/src/tunnel.rs +++ b/src/tunnel.rs @@ -1,4 +1,5 @@ use crate::crypto::PublicKey; + use alloc::vec::Vec; use serde::{Serialize, Deserialize}; @@ -6,3 +7,13 @@ use serde::{Serialize, Deserialize}; pub struct Tunnel { nodes: Vec } + +impl Tunnel { + pub fn tunnel_to(&self, me: &PublicKey, to: &PublicKey) -> Option { + None + } + + pub fn next(&self, to: &PublicKey) -> PublicKey { + PublicKey { key: [0u8; 32] } + } +}