Browse Source

Formatting

master
Lev 5 years ago
parent
commit
3c84e11f94
  1. 2
      src/ironforce.rs
  2. 2
      src/lib.rs
  3. 22
      src/message.rs
  4. 9
      src/transport.rs

2
src/ironforce.rs

@ -46,7 +46,7 @@ impl IronForce {
self.send_through_tunnel_to(msg, tunnel, &node) self.send_through_tunnel_to(msg, tunnel, &node)
} }
if count == MULTICAST_TUNNELS { if count == MULTICAST_TUNNELS {
break; break
} }
} }
count count

2
src/lib.rs

@ -33,7 +33,7 @@ mod tests {
let mut iforce = IronForce::new(); let mut iforce = IronForce::new();
assert_eq!( assert_eq!(
iforce.new_message( iforce.new_message(
MsgType::Service, &Vec::<u8>::new() MsgType::Service, &Vec::<u8>::new(),
), ),
Message::new(MsgType::Service, Vec::<u8>::new(), &iforce.key_pack) Message::new(MsgType::Service, Vec::<u8>::new(), &iforce.key_pack)
); );

22
src/message.rs

@ -15,21 +15,23 @@ fn get_hash(b: &Vec<u8>) -> Vec<u8> {
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub enum MsgType { pub enum MsgType {
MultiCast, // No source, sign and tunnel MultiCast,
UniCast(PublicKey /* destination */), // has source, sign and tunnel // No source, sign and tunnel
UniCast(PublicKey /* destination */),
// has source, sign and tunnel
Service, // Has source and sign but no tunnel Service, // Has source and sign but no tunnel
} }
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub enum Sign { pub enum Sign {
NoSign, NoSign,
Signed(PublicKey /* source */, Vec<u8> /* sign */) Signed(PublicKey /* source */, Vec<u8> /* sign */),
} }
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub enum MsgTunnel { pub enum MsgTunnel {
NoTunnel, NoTunnel,
Tunnel(Tunnel) Tunnel(Tunnel),
} }
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
@ -60,10 +62,12 @@ impl MessageContent {
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct Message { pub struct Message {
pub content: MessageContent, pub content: MessageContent,
pub content_hash: Vec<u8>, // hash for signing pub content_hash: Vec<u8>,
pub hash: Vec<u8>, // hash for checking integrity // hash for signing
pub hash: Vec<u8>,
// hash for checking integrity
pub sign: Sign, pub sign: Sign,
pub tunnel: MsgTunnel pub tunnel: MsgTunnel,
} }
impl Message { impl Message {
@ -81,12 +85,12 @@ impl Message {
content_hash, content_hash,
hash: Vec::<u8>::new(), hash: Vec::<u8>::new(),
sign: Sign::NoSign, sign: Sign::NoSign,
tunnel: MsgTunnel::NoTunnel tunnel: MsgTunnel::NoTunnel,
}; };
msg.sign = match msg_type { msg.sign = match msg_type {
MsgType::UniCast(_) | MsgType::Service => { MsgType::UniCast(_) | MsgType::Service => {
Sign::Signed(key_pack.get_public(), key_pack.sign(&msg.content_hash)) Sign::Signed(key_pack.get_public(), key_pack.sign(&msg.content_hash))
}, }
MsgType::MultiCast => { Sign::NoSign } MsgType::MultiCast => { Sign::NoSign }
}; };
msg.hash = msg.get_hash(); msg.hash = msg.get_hash();

9
src/transport.rs

@ -42,11 +42,13 @@ impl Transport {
} }
pub fn send_service(&self, msg: &Message) { pub fn send_service(&self, msg: &Message) {
// todo
// send message through radio (using pins)
} }
pub fn send_to(&self, msg: &Message, to: &PublicKey) { pub fn send_to(&self, msg: &Message, to: &PublicKey) {
// todo
// send message through radio (using pins)
} }
} }
@ -75,8 +77,7 @@ impl Transport {
self.msg_pool = self.msg_pool[1..].to_vec(); self.msg_pool = self.msg_pool[1..].to_vec();
return msg; return msg;
} }
return self.receive(); // recursion: infinite loop return self.receive(); // recursion: infinite loop until we get a message (see exit condition above)
// until we get a message (see exit condition above)
} }
fn way_receiving_loop(&mut self, i: i32) { fn way_receiving_loop(&mut self, i: i32) {

Loading…
Cancel
Save