Browse Source

threads

master
ennucore 5 years ago
parent
commit
38caf33138
  1. 2
      src/ironforce.rs
  2. 2
      src/lib.rs
  3. 47
      src/transport.rs
  4. 11
      src/tunnel.rs

2
src/ironforce.rs

@ -45,7 +45,7 @@ impl IronForce {
MsgType::MultiCast => { MsgType::MultiCast => {
}, },
MsgType::UniCast(Target) => { MsgType::UniCast(target) => {
} }
} }

2
src/lib.rs

@ -1,6 +1,8 @@
#![no_std] #![no_std]
extern crate alloc; extern crate alloc;
#[cfg(feature = "std")]
extern crate std;
mod ironforce; mod ironforce;

47
src/transport.rs

@ -1,41 +1,43 @@
use crate::message::{Message, MsgType}; use crate::message::{Message, MsgType};
use crate::crypto::PublicKey;
#[cfg(feature = "std")]
use crate::way::Way; use crate::way::Way;
#[cfg(feature = "std")]
use std::thread;
use alloc::vec::Vec; use alloc::vec::Vec;
use alloc::boxed::Box; use alloc::boxed::Box;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
pub struct Transport { pub struct Transport {}
id: [u8; 64]
}
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub struct Transport { pub struct Transport {
ways: Vec<Box<dyn Way>>, ways: Vec<Box<dyn Way + Send>>,
id: [u8; 64] msg_pool: Vec<Message>,
} }
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
impl Transport { impl Transport {
pub fn new() -> Self { 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, PublicKey) {
(Message::new(MsgType::Service,
pub fn receive(&self) -> Message {
Message::new(MsgType::Service,
Vec::<u8>::new(), Vec::<u8>::new(),
&crate::crypto::Keys::gen()) &crate::crypto::Keys::gen()), PublicKey { key: [0u8; 32] })
} }
} }
#[cfg(feature = "std")] #[cfg(feature = "std")]
impl Transport { impl Transport {
pub fn new() -> Self { pub fn new() -> Self {
Self {ways: Vec::<Box<dyn Way>>::new(), id: [0; 64]} let transport = Self { ways: Vec::<Box<dyn Way + Send>>::new(), msg_pool: Vec::<Message>::new() };
transport
} }
pub fn send(&self, msg: &Message) { pub fn send(&self, msg: &Message) {
@ -44,9 +46,22 @@ impl Transport {
} }
} }
pub fn receive(&self) -> Message { pub fn receive(&self) -> (Message, PublicKey) {
Message::new(MsgType::Service, (Message::new(MsgType::MultiCast,
Vec::<u8>::new(), Vec::<u8>::new(),
&crate::crypto::Keys::gen()) &crate::crypto::Keys::gen()), PublicKey { key: [1u8; 32] })
}
fn receive_through_way_in_loop_and_add_in_pool(&mut self, way: &mut Box<dyn Way + Send>) {
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]);
});
} }
} }

11
src/tunnel.rs

@ -1,4 +1,5 @@
use crate::crypto::PublicKey; use crate::crypto::PublicKey;
use alloc::vec::Vec; use alloc::vec::Vec;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
@ -6,3 +7,13 @@ use serde::{Serialize, Deserialize};
pub struct Tunnel { pub struct Tunnel {
nodes: Vec<PublicKey> nodes: Vec<PublicKey>
} }
impl Tunnel {
pub fn tunnel_to(&self, me: &PublicKey, to: &PublicKey) -> Option<Tunnel> {
None
}
pub fn next(&self, to: &PublicKey) -> PublicKey {
PublicKey { key: [0u8; 32] }
}
}

Loading…
Cancel
Save