// VpnCloud - Peer-to-Peer VPN // Copyright (C) 2015-2019 Dennis Schwerdel // This software is licensed under GPL-3 or newer (see LICENSE.md) #[macro_use] mod helper; mod nat; mod payload; mod peers; use std::{ io::Write, net::{IpAddr, Ipv6Addr, SocketAddr}, sync::{ atomic::{AtomicUsize, Ordering}, Once } }; pub use super::{ cloud::GenericCloud, config::Config, crypto::Crypto, device::MockDevice, ethernet::{self, SwitchTable}, ip::{self, RoutingTable}, net::MockSocket, types::{Protocol, Range, Table}, udpmessage::Message, util::MockTimeSource }; static INIT_LOGGER: Once = Once::new(); pub fn init_debug_logger() { INIT_LOGGER.call_once(|| { log::set_boxed_logger(Box::new(DebugLogger)).unwrap(); log::set_max_level(log::LevelFilter::Debug); }) } struct DebugLogger; impl log::Log for DebugLogger { #[inline] fn enabled(&self, _metadata: &log::Metadata) -> bool { true } #[inline] fn log(&self, record: &log::Record) { if self.enabled(record.metadata()) { eprintln!("{} - {}", record.level(), record.args()); } } #[inline] fn flush(&self) { std::io::stderr().flush().expect("Failed to flush") } } type TestNode
= GenericCloud ) -> (SocketAddr, Vec , from: SocketAddr, msg: Vec , SocketAddr)]) {
for (ref mut node, ref _from_addr) in nodes.iter_mut() {
while node.device().has_inbound() {
node.trigger_device_event();
}
}
let mut clean = false;
while !clean {
clean = true;
let mut msgs = Vec::new();
for (ref mut node, ref from_addr) in nodes.iter_mut() {
while let Some((to_addr, msg)) = node.socket().pop_outbound() {
msgs.push((msg, *from_addr, to_addr));
}
}
clean &= msgs.is_empty();
for (msg, from_addr, to_addr) in msgs {
for (ref mut node, ref addr) in nodes.iter_mut() {
if *addr == to_addr {
msg_put(node, from_addr, msg);
break
}
}
}
}
}