From 3c84e11f94a9a123de035e2e8b807a8cade63846 Mon Sep 17 00:00:00 2001 From: ennucore Date: Tue, 19 May 2020 13:53:14 +0300 Subject: [PATCH] Formatting --- src/ironforce.rs | 4 ++-- src/lib.rs | 2 +- src/message.rs | 24 ++++++++++++++---------- src/transport.rs | 9 +++++---- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/ironforce.rs b/src/ironforce.rs index 796c5f5..8e8fcbe 100644 --- a/src/ironforce.rs +++ b/src/ironforce.rs @@ -46,7 +46,7 @@ impl IronForce { self.send_through_tunnel_to(msg, tunnel, &node) } if count == MULTICAST_TUNNELS { - break; + break } } count @@ -82,7 +82,7 @@ impl IronForce { let tunnel = match &msg.tunnel { crate::message::MsgTunnel::Tunnel(t) => t, crate::message::MsgTunnel::NoTunnel => panic!() - } ; + }; self.send_through_tunnel_to(msg, tunnel, target) } } diff --git a/src/lib.rs b/src/lib.rs index 0f0f9d7..e393392 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,7 @@ mod tests { let mut iforce = IronForce::new(); assert_eq!( iforce.new_message( - MsgType::Service, &Vec::::new() + MsgType::Service, &Vec::::new(), ), Message::new(MsgType::Service, Vec::::new(), &iforce.key_pack) ); diff --git a/src/message.rs b/src/message.rs index 01b65c8..e29ba57 100644 --- a/src/message.rs +++ b/src/message.rs @@ -15,21 +15,23 @@ fn get_hash(b: &Vec) -> Vec { #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] pub enum MsgType { - MultiCast, // No source, sign and tunnel - UniCast(PublicKey /* destination */), // has source, sign and tunnel + MultiCast, + // No source, sign and tunnel + UniCast(PublicKey /* destination */), + // has source, sign and tunnel Service, // Has source and sign but no tunnel } #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] pub enum Sign { NoSign, - Signed(PublicKey /* source */, Vec /* sign */) + Signed(PublicKey /* source */, Vec /* sign */), } #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] pub enum MsgTunnel { NoTunnel, - Tunnel(Tunnel) + Tunnel(Tunnel), } #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] @@ -60,10 +62,12 @@ impl MessageContent { #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] pub struct Message { pub content: MessageContent, - pub content_hash: Vec, // hash for signing - pub hash: Vec, // hash for checking integrity + pub content_hash: Vec, + // hash for signing + pub hash: Vec, + // hash for checking integrity pub sign: Sign, - pub tunnel: MsgTunnel + pub tunnel: MsgTunnel, } impl Message { @@ -74,19 +78,19 @@ impl Message { } pub fn new(msg_type: MsgType, body: Vec, key_pack: &Keys) -> Message { - let content= MessageContent::new(msg_type.clone(), body); + let content = MessageContent::new(msg_type.clone(), body); let content_hash = content.get_hash(); let mut msg = Message { content, content_hash, hash: Vec::::new(), sign: Sign::NoSign, - tunnel: MsgTunnel::NoTunnel + tunnel: MsgTunnel::NoTunnel, }; msg.sign = match msg_type { MsgType::UniCast(_) | MsgType::Service => { Sign::Signed(key_pack.get_public(), key_pack.sign(&msg.content_hash)) - }, + } MsgType::MultiCast => { Sign::NoSign } }; msg.hash = msg.get_hash(); diff --git a/src/transport.rs b/src/transport.rs index 6f6150e..d68ee5f 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -42,11 +42,13 @@ impl Transport { } pub fn send_service(&self, msg: &Message) { - + // todo + // send message through radio (using pins) } 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(); return msg; } - return self.receive(); // recursion: infinite loop - // until we get a message (see exit condition above) + return self.receive(); // recursion: infinite loop until we get a message (see exit condition above) } fn way_receiving_loop(&mut self, i: i32) {