Browse Source

threads

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

2
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};

2
src/ironforce.rs

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

2
src/lib.rs

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

47
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<Box<dyn Way>>,
id: [u8; 64]
ways: Vec<Box<dyn Way + Send>>,
msg_pool: Vec<Message>,
}
#[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,
pub fn receive(&self) -> (Message, PublicKey) {
(Message::new(MsgType::Service,
Vec::<u8>::new(),
&crate::crypto::Keys::gen())
&crate::crypto::Keys::gen()), PublicKey { key: [0u8; 32] })
}
}
#[cfg(feature = "std")]
impl Transport {
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) {
@ -44,9 +46,22 @@ impl Transport {
}
}
pub fn receive(&self) -> Message {
Message::new(MsgType::Service,
pub fn receive(&self) -> (Message, PublicKey) {
(Message::new(MsgType::MultiCast,
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 alloc::vec::Vec;
use serde::{Serialize, Deserialize};
@ -6,3 +7,13 @@ use serde::{Serialize, Deserialize};
pub struct Tunnel {
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