Browse Source

Some methods and tests for IronForce

master
ennucore 5 years ago
parent
commit
86ad317084
  1. 3
      src/crypto.rs
  2. 12
      src/ironforce.rs
  3. 17
      src/lib.rs

3
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 {}) }
}
}

12
src/ironforce.rs

@ -13,7 +13,7 @@ const MULTICAST_TUNNELS: u32 = 5;
pub struct IronForce {
transport: Transport,
tunnels: Vec<Tunnel>,
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<u8>) -> Message {
pub fn new_message(&self, msg_type: MsgType, body: &Vec<u8>) -> 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)
}
}
}

17
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::<u8>::new()
),
Message::new(MsgType::Service, Vec::<u8>::new(), &iforce.key_pack)
);
}
}
mod crypto {

Loading…
Cancel
Save