From 86ad317084ba00dc0945affa647680fa3cb5134d Mon Sep 17 00:00:00 2001 From: ennucore Date: Sat, 28 Mar 2020 22:15:28 +0300 Subject: [PATCH] Some methods and tests for IronForce --- src/crypto.rs | 3 +-- src/ironforce.rs | 12 ++++++++---- src/lib.rs | 17 ++++++++++++++++- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/crypto.rs b/src/crypto.rs index 70f87f1..0f6f2cd 100644 --- a/src/crypto.rs +++ b/src/crypto.rs @@ -32,8 +32,7 @@ pub struct Keys { impl Keys { pub fn gen() -> Keys { - let mut osrng = OsRng {}; - Keys { pair: Keypair::generate(&mut osrng) } + Keys { pair: Keypair::generate(&mut OsRng {}) } } } diff --git a/src/ironforce.rs b/src/ironforce.rs index 3f29ed9..796c5f5 100644 --- a/src/ironforce.rs +++ b/src/ironforce.rs @@ -13,7 +13,7 @@ const MULTICAST_TUNNELS: u32 = 5; pub struct IronForce { transport: Transport, tunnels: Vec, - key_pack: Keys, + pub key_pack: Keys, } impl IronForce { @@ -26,7 +26,7 @@ impl IronForce { msg.verify() } - fn new_message(&self, msg_type: MsgType, body: &Vec) -> Message { + pub fn new_message(&self, msg_type: MsgType, body: &Vec) -> Message { Message::new(msg_type, body.clone(), &self.key_pack) } @@ -76,10 +76,14 @@ impl IronForce { self.service_msg(&msg.content.body) } MsgType::MultiCast => { - // todo + self.multicast(msg); } MsgType::UniCast(target) => { - // todo + 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 bea47d6..8681890 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,11 +17,26 @@ mod tunnel; #[cfg(test)] mod tests { mod iron_force { + use crate::ironforce::IronForce; + use crate::message::{Message, MsgType}; + + use alloc::vec::Vec; + #[test] fn creation() { - use crate::ironforce::IronForce; IronForce::new(); } + + #[test] + fn new_message() { + let mut iforce = IronForce::new(); + assert_eq!( + iforce.new_message( + MsgType::Service, &Vec::::new() + ), + Message::new(MsgType::Service, Vec::::new(), &iforce.key_pack) + ); + } } mod crypto {