pull/34/head
Dennis Schwerdel 2019-03-01 23:25:42 +01:00
parent 706d205ff1
commit f2e6a1ef7b
6 changed files with 29 additions and 29 deletions

View File

@ -31,7 +31,7 @@ fn base_62_sanitize(data: &str) -> String {
}
fn sha512(data: &[u8]) -> Vec<u8> {
digest::digest(&digest::SHA512, data).as_ref().iter().map(|b| *b).collect()
digest::digest(&digest::SHA512, data).as_ref().to_vec()
}
struct FutureResult<T> {
@ -72,6 +72,7 @@ impl<TS: TimeSource> BeaconSerializer<TS> {
sha512(&data)
}
#[allow(clippy::needless_range_loop)]
fn mask_with_keystream(&self, data: &mut [u8], type_: u8, seed: u8) {
let mut iter = 0;
let mut mask = self.get_keystream(type_, seed, iter);

View File

@ -143,7 +143,7 @@ impl<TS: TimeSource> PeerList<TS> {
#[inline]
pub fn get_node_id(&self, addr: &SocketAddr) -> Option<NodeId> {
self.addresses.get(addr).map(|n| *n)
self.addresses.get(addr).cloned()
}
#[inline]
@ -230,6 +230,7 @@ pub struct GenericCloud<D: Device, P: Protocol, T: Table, S: Socket, TS: TimeSou
}
impl<D: Device, P: Protocol, T: Table, S: Socket, TS: TimeSource> GenericCloud<D, P, T, S, TS> {
#[allow(clippy::too_many_arguments)]
pub fn new(config: &Config, device: D, table: T,
learning: bool, broadcast: bool, addresses: Vec<Range>,
crypto: Crypto, port_forwarding: Option<PortForwarding>
@ -271,7 +272,7 @@ impl<D: Device, P: Protocol, T: Table, S: Socket, TS: TimeSource> GenericCloud<D
_dummy_ts: PhantomData
};
res.initialize();
return res
res
}
#[inline]
@ -292,7 +293,7 @@ impl<D: Device, P: Protocol, T: Table, S: Socket, TS: TimeSource> GenericCloud<D
let msg_data = encode(msg, &mut self.buffer_out, self.magic, &mut self.crypto);
for addr in self.peers.peers.keys() {
self.traffic.count_out_traffic(*addr, msg_data.len());
let mut socket = match *addr {
let socket = match *addr {
SocketAddr::V4(_) => &mut self.socket4,
SocketAddr::V6(_) => &mut self.socket6
};
@ -715,7 +716,7 @@ impl<D: Device, P: Protocol, T: Table, S: Socket, TS: TimeSource> GenericCloud<D
fn handle_socket_data(&mut self, src: SocketAddr, data: &mut [u8]) {
let size = data.len();
if let Err(e) = decode(data, self.magic, &mut self.crypto).and_then(|msg| {
if let Err(e) = decode(data, self.magic, &self.crypto).and_then(|msg| {
self.traffic.count_in_traffic(src, size);
self.handle_net_message(src, msg)
}) {

View File

@ -248,7 +248,7 @@ pub struct MockDevice {
impl MockDevice {
pub fn new() -> Self {
Self { outbound: VecDeque::new(), inbound: VecDeque::new() }
Default::default()
}
pub fn put_inbound(&mut self, data: Vec<u8>) {
@ -288,6 +288,12 @@ impl Device for MockDevice {
}
}
impl Default for MockDevice {
fn default() -> Self {
Self { outbound: VecDeque::new(), inbound: VecDeque::new() }
}
}
impl AsRawFd for MockDevice {
#[inline]
fn as_raw_fd(&self) -> RawFd {

View File

@ -5,22 +5,8 @@
#![cfg_attr(feature = "bench", feature(test))]
#[macro_use] extern crate log;
extern crate time;
extern crate docopt;
#[macro_use] extern crate serde_derive;
extern crate serde;
extern crate serde_yaml;
extern crate signal;
extern crate libc;
extern crate rand;
extern crate fnv;
extern crate net2;
extern crate yaml_rust;
extern crate igd;
extern crate siphasher;
extern crate daemonize;
extern crate ring;
extern crate base_62;
#[cfg(test)] extern crate tempfile;
#[cfg(feature = "bench")] extern crate test;

View File

@ -273,17 +273,17 @@ pub fn encode<'a>(msg: &'a mut Message, mut buf: &'a mut [u8], magic: HeaderMagi
impl<'a> PartialEq for Message<'a> {
fn eq(&self, other: &Message) -> bool {
match self {
&Message::Data(ref data1, start1, end1) => if let &Message::Data(ref data2, start2, end2) = other {
match *self {
Message::Data(ref data1, start1, end1) => if let Message::Data(ref data2, start2, end2) = *other {
data1[start1..end1] == data2[start2..end2]
} else { false },
&Message::Peers(ref peers1) => if let &Message::Peers(ref peers2) = other {
Message::Peers(ref peers1) => if let Message::Peers(ref peers2) = *other {
peers1 == peers2
} else { false },
&Message::Init(step1, node_id1, ref ranges1) => if let &Message::Init(step2, node_id2, ref ranges2) = other {
Message::Init(step1, node_id1, ref ranges1) => if let Message::Init(step2, node_id2, ref ranges2) = *other {
step1 == step2 && node_id1 == node_id2 && ranges1 == ranges2
} else { false },
&Message::Close => if let &Message::Close = other {
Message::Close => if let Message::Close = *other {
true
} else { false }
}

View File

@ -177,9 +177,7 @@ pub struct CtrlC {
impl CtrlC {
pub fn new() -> Self {
let dummy_time = Instant::now();
let trap = Trap::trap(&[Signal::SIGINT, Signal::SIGTERM, Signal::SIGQUIT]);
Self { dummy_time, trap }
Default::default()
}
pub fn was_pressed(&self) -> bool {
@ -187,6 +185,14 @@ impl CtrlC {
}
}
impl Default for CtrlC {
fn default() -> Self {
let dummy_time = Instant::now();
let trap = Trap::trap(&[Signal::SIGINT, Signal::SIGTERM, Signal::SIGQUIT]);
Self { dummy_time, trap }
}
}
pub trait TimeSource: Sync + Copy + Send + 'static {
fn now() -> Time;