From 706d205ff1c145f244630b2b2723b73fa239d9d4 Mon Sep 17 00:00:00 2001 From: Dennis Schwerdel Date: Fri, 1 Mar 2019 23:12:19 +0100 Subject: [PATCH 1/3] Edition 2018 --- Cargo.toml | 1 + src/beacon.rs | 20 ++++++------- src/cloud.rs | 76 +++++++++++++++++++++++------------------------ src/device.rs | 6 ++-- src/ethernet.rs | 8 ++--- src/ip.rs | 12 ++++---- src/main.rs | 20 ++++++------- src/poll/epoll.rs | 6 ++-- src/tests/mod.rs | 2 +- src/traffic.rs | 10 +++---- src/types.rs | 30 +++++++++---------- src/udpmessage.rs | 12 ++++---- src/util.rs | 2 +- 13 files changed, 103 insertions(+), 102 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7d8d21b..36183f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ homepage = "https://vpncloud.ddswd.de" repository = "https://github.com/dswd/vpncloud" keywords = ["vpn", "p2p", "tun", "tap", "network"] readme = "README.md" +edition = "2018" [dependencies] time = "0.1" diff --git a/src/beacon.rs b/src/beacon.rs index 191256a..7b3903d 100644 --- a/src/beacon.rs +++ b/src/beacon.rs @@ -209,9 +209,9 @@ impl BeaconSerializer { pub fn write_to_file>(&self, peers: &[SocketAddr], path: P) -> Result<(), io::Error> { let beacon = self.encode(peers); debug!("Beacon: {}", beacon); - let mut f = try!(File::create(&path)); - try!(writeln!(&mut f, "{}", beacon)); - try!(fs::set_permissions(&path, Permissions::from_mode(0o644))); + let mut f = File::create(&path)?; + writeln!(&mut f, "{}", beacon)?; + fs::set_permissions(&path, Permissions::from_mode(0o644))?; Ok(()) } @@ -221,9 +221,9 @@ impl BeaconSerializer { let end = self.end(); let beacon = format!("{}{}{}", begin, data, end); debug!("Calling beacon command: {}", cmd); - let process = try!(Command::new("sh").args(&["-c", cmd]) + let process = Command::new("sh").args(&["-c", cmd]) .env("begin", begin).env("data", data).env("end", end).env("beacon", beacon) - .stdout(Stdio::piped()).stderr(Stdio::piped()).spawn()); + .stdout(Stdio::piped()).stderr(Stdio::piped()).spawn()?; thread::spawn(move || { let output = process.wait_with_output().expect("Failed to wait on child"); if !output.status.success() { @@ -256,9 +256,9 @@ impl BeaconSerializer { } pub fn read_from_file>(&self, path: P, ttl_hours: Option) -> Result, io::Error> { - let mut f = try!(File::open(&path)); + let mut f = File::open(&path)?; let mut contents = String::new(); - try!(f.read_to_string(&mut contents)); + f.read_to_string(&mut contents)?; Ok(self.decode(&contents, ttl_hours)) } @@ -266,9 +266,9 @@ impl BeaconSerializer { let begin = self.begin(); let end = self.end(); debug!("Calling beacon command: {}", cmd); - let process = try!(Command::new("sh").args(&["-c", cmd]) + let process = Command::new("sh").args(&["-c", cmd]) .env("begin", begin).env("end", end) - .stdout(Stdio::piped()).stderr(Stdio::piped()).spawn()); + .stdout(Stdio::piped()).stderr(Stdio::piped()).spawn()?; let this = self.clone(); thread::spawn(move || { let output = process.wait_with_output().expect("Failed to wait on child"); @@ -301,7 +301,7 @@ impl BeaconSerializer { #[cfg(test)] use std::str::FromStr; #[cfg(test)] use std::time::Duration; #[cfg(test)] use tempfile; -#[cfg(test)] use ::util::MockTimeSource; +#[cfg(test)] use crate::util::MockTimeSource; #[test] fn encode() { diff --git a/src/cloud.rs b/src/cloud.rs index f80f1ec..fc42d0e 100644 --- a/src/cloud.rs +++ b/src/cloud.rs @@ -87,7 +87,7 @@ impl PeerList { #[inline] pub fn is_connected(&self, addr: Addr) -> Result { - for addr in try!(resolve(&addr)) { + for addr in resolve(&addr)? { if self.contains_addr(&addr) { return Ok(true); } @@ -181,10 +181,10 @@ impl PeerList { #[inline] fn write_out(&self, out: &mut W) -> Result<(), io::Error> { - try!(writeln!(out, "Peers:")); + writeln!(out, "Peers:")?; let now = TS::now(); for (addr, data) in &self.peers { - try!(writeln!(out, " - {} (ttl: {} s)", addr, data.timeout-now)); + writeln!(out, " - {} (ttl: {} s)", addr, data.timeout-now)?; } Ok(()) } @@ -296,11 +296,11 @@ impl GenericCloud &mut self.socket4, SocketAddr::V6(_) => &mut self.socket6 }; - try!(match socket.send(msg_data, *addr) { + match socket.send(msg_data, *addr) { Ok(written) if written == msg_data.len() => Ok(()), Ok(_) => Err(Error::Socket("Sent out truncated packet", io::Error::new(io::ErrorKind::Other, "truncated"))), Err(e) => Err(Error::Socket("IOError when sending", e)) - }) + }? } Ok(()) } @@ -336,7 +336,7 @@ impl GenericCloud io::Result<(SocketAddr, SocketAddr)> { - Ok((try!(self.socket4.address()), try!(self.socket6.address()))) + Ok((self.socket4.address()?, self.socket6.address()?)) } /// Returns the number of peers @@ -367,7 +367,7 @@ impl GenericCloud(&self, addr: Addr) -> Result { - for addr in try!(resolve(&addr)) { + for addr in resolve(&addr)? { if self.own_addresses.contains(&addr) { return Ok(true); } @@ -384,14 +384,14 @@ impl GenericCloud(&mut self, addr: Addr) -> Result<(), Error> { - if try!(self.peers.is_connected(addr.clone())) || try!(self.is_own_address(addr.clone())) { + if self.peers.is_connected(addr.clone())? || self.is_own_address(addr.clone())? { return Ok(()) } debug!("Connecting to {:?}", addr); let subnets = self.addresses.clone(); let node_id = self.node_id; // Send a message to each resolved address - for a in try!(resolve(&addr)) { + for a in resolve(&addr)? { // Ignore error this time let mut msg = Message::Init(0, node_id, subnets.clone()); self.send_msg(a, &mut msg).ok(); @@ -449,7 +449,7 @@ impl GenericCloud GenericCloud now { continue } - try!(self.connect(&entry.resolved as &[SocketAddr])); + self.connect(&entry.resolved as &[SocketAddr])?; } for entry in &mut self.reconnect_peers { // Schedule for next second if node is connected - if try!(self.peers.is_connected(&entry.resolved as &[SocketAddr])) { + if self.peers.is_connected(&entry.resolved as &[SocketAddr])? { entry.tries = 0; entry.timeout = 1; entry.next = now + 1; @@ -494,19 +494,19 @@ impl GenericCloud GenericCloud = self.own_addresses.choose_multiple(&mut thread_rng(),3).cloned().collect(); if path.starts_with('|') { - try!(self.beacon_serializer.write_to_cmd(&peers, &path[1..]).map_err(|e| Error::Beacon("Failed to call beacon command", e))); + self.beacon_serializer.write_to_cmd(&peers, &path[1..]).map_err(|e| Error::Beacon("Failed to call beacon command", e))?; } else { - try!(self.beacon_serializer.write_to_file(&peers, &path).map_err(|e| Error::Beacon("Failed to write beacon to file", e))); + self.beacon_serializer.write_to_file(&peers, &path).map_err(|e| Error::Beacon("Failed to write beacon to file", e))?; } } Ok(()) @@ -530,17 +530,17 @@ impl GenericCloud GenericCloud Result<(), io::Error> { if self.config.stats_file.is_none() { return Ok(()) } debug!("Writing out stats"); - let mut f = try!(File::create(self.config.stats_file.as_ref().unwrap())); - try!(self.peers.write_out(&mut f)); - try!(writeln!(&mut f)); - try!(self.table.write_out(&mut f)); - try!(writeln!(&mut f)); - try!(self.traffic.write_out(&mut f)); - try!(writeln!(&mut f)); - try!(fs::set_permissions(self.config.stats_file.as_ref().unwrap(), Permissions::from_mode(0o644))); + let mut f = File::create(self.config.stats_file.as_ref().unwrap())?; + self.peers.write_out(&mut f)?; + writeln!(&mut f)?; + self.table.write_out(&mut f)?; + writeln!(&mut f)?; + self.traffic.write_out(&mut f)?; + writeln!(&mut f)?; + fs::set_permissions(self.config.stats_file.as_ref().unwrap(), Permissions::from_mode(0o644))?; Ok(()) } @@ -577,26 +577,26 @@ impl GenericCloud Result<(), Error> { - let (src, dst) = try!(P::parse(&payload[start..end])); + let (src, dst) = P::parse(&payload[start..end])?; debug!("Read data from interface: src: {}, dst: {}, {} bytes", src, dst, end-start); self.traffic.count_out_payload(dst, src, end-start); match self.table.lookup(&dst) { Some(addr) => { // Peer found for destination debug!("Found destination for {} => {}", dst, addr); - try!(self.send_msg(addr, &mut Message::Data(payload, start, end))); + self.send_msg(addr, &mut Message::Data(payload, start, end))?; if !self.peers.contains_addr(&addr) { // If the peer is not actually connected, remove the entry in the table and try // to reconnect. warn!("Destination for {} not found in peers: {}", dst, addr); self.table.remove(&dst); - try!(self.connect_sock(addr)); + self.connect_sock(addr)?; } }, None => { if self.broadcast { debug!("No destination for {} found, broadcasting", dst); let mut msg = Message::Data(payload, start, end); - try!(self.broadcast_msg(&mut msg)); + self.broadcast_msg(&mut msg)?; } else { debug!("No destination for {} found, dropping", dst); } @@ -642,7 +642,7 @@ impl GenericCloud { - let (src, dst) = try!(P::parse(&payload[start..end])); + let (src, dst) = P::parse(&payload[start..end])?; debug!("Writing data to device: {} bytes", end-start); self.traffic.count_in_payload(src, dst, end-start); if let Err(e) = self.device.write(&mut payload[..end], start) { @@ -658,14 +658,14 @@ impl GenericCloud { // Connect to sender if not connected if !self.peers.contains_addr(&peer) { - try!(self.connect_sock(peer)); + self.connect_sock(peer)?; } if let Some(node_id) = self.peers.get_node_id(&peer) { self.peers.make_primary(node_id, peer); } // Connect to all peers in the message for p in &peers { - try!(self.connect_sock(*p)); + self.connect_sock(*p)?; } // Refresh peer self.peers.refresh(&peer); @@ -689,11 +689,11 @@ impl GenericCloud { self.peers.remove(&peer); diff --git a/src/device.rs b/src/device.rs index 87b6ff8..e4bdee6 100644 --- a/src/device.rs +++ b/src/device.rs @@ -107,7 +107,7 @@ impl TunTapDevice { if type_ == Type::Dummy { return Self::dummy(ifname, path, type_); } - let fd = try!(fs::OpenOptions::new().read(true).write(true).open(path)); + let fd = fs::OpenOptions::new().read(true).write(true).open(path)?; // Add trailing \0 to interface name let mut ifname_string = String::with_capacity(32); ifname_string.push_str(ifname); @@ -156,7 +156,7 @@ impl TunTapDevice { #[allow(dead_code)] pub fn dummy(ifname: &str, path: &str, type_: Type) -> io::Result { Ok(TunTapDevice{ - fd: try!(fs::OpenOptions::new().create(true).read(true).write(true).open(path)), + fd: fs::OpenOptions::new().create(true).read(true).write(true).open(path)?, ifname: ifname.to_string(), type_ }) @@ -218,7 +218,7 @@ impl Device for TunTapDevice { } fn read(&mut self, mut buffer: &mut [u8]) -> Result<(usize, usize), Error> { - let read = try!(self.fd.read(&mut buffer).map_err(|e| Error::TunTapDev("Read error", e))); + let read = self.fd.read(&mut buffer).map_err(|e| Error::TunTapDev("Read error", e))?; let (start, read) = self.correct_data_after_read(&mut buffer, 0, read); Ok((start, read)) } diff --git a/src/ethernet.rs b/src/ethernet.rs index be11906..f4f9993 100644 --- a/src/ethernet.rs +++ b/src/ethernet.rs @@ -49,8 +49,8 @@ impl Protocol for Frame { dst[2..8].copy_from_slice(dst_data); Ok((Address{data: src, len: 8}, Address{data: dst, len: 8})) } else { - let src = try!(Address::read_from_fixed(src_data, 6)); - let dst = try!(Address::read_from_fixed(dst_data, 6)); + let src = Address::read_from_fixed(src_data, 6)?; + let dst = Address::read_from_fixed(dst_data, 6)?; Ok((src, dst)) } } @@ -105,9 +105,9 @@ impl Table for SwitchTable { /// Write out the table fn write_out(&self, out: &mut W) -> Result<(), io::Error> { let now = TS::now(); - try!(writeln!(out, "Switch table:")); + writeln!(out, "Switch table:")?; for (addr, val) in &self.table { - try!(writeln!(out, " - {} => {} (ttl: {} s)", addr, val.address, val.timeout - now)); + writeln!(out, " - {} => {} (ttl: {} s)", addr, val.address, val.timeout - now)?; } Ok(()) } diff --git a/src/ip.rs b/src/ip.rs index ddd2518..6d9570b 100644 --- a/src/ip.rs +++ b/src/ip.rs @@ -34,16 +34,16 @@ impl Protocol for Packet { if data.len() < 20 { return Err(Error::Parse("Truncated IPv4 header")); } - let src = try!(Address::read_from_fixed(&data[12..], 4)); - let dst = try!(Address::read_from_fixed(&data[16..], 4)); + let src = Address::read_from_fixed(&data[12..], 4)?; + let dst = Address::read_from_fixed(&data[16..], 4)?; Ok((src, dst)) }, 6 => { if data.len() < 40 { return Err(Error::Parse("Truncated IPv6 header")); } - let src = try!(Address::read_from_fixed(&data[8..], 16)); - let dst = try!(Address::read_from_fixed(&data[24..], 16)); + let src = Address::read_from_fixed(&data[8..], 16)?; + let dst = Address::read_from_fixed(&data[24..], 16)?; Ok((src, dst)) }, _ => Err(Error::Parse("Invalid version")) @@ -149,10 +149,10 @@ impl Table for RoutingTable { /// Write out the table fn write_out(&self, out: &mut W) -> Result<(), io::Error> { - try!(writeln!(out, "Routing table:")); + writeln!(out, "Routing table:")?; for entries in self.0.values() { for entry in entries { - try!(writeln!(out, " - {}/{} => {}", entry.bytes, entry.prefix_len, entry.address)); + writeln!(out, " - {}/{} => {}", entry.bytes, entry.prefix_len, entry.address)?; } } Ok(()) diff --git a/src/main.rs b/src/main.rs index 41755ed..f3acc8d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,15 +51,15 @@ use std::path::Path; use std::io::{self, Write}; use std::net::UdpSocket; -use device::{TunTapDevice, Device, Type}; -use ethernet::SwitchTable; -use ip::RoutingTable; -use types::{Mode, Range, Protocol, HeaderMagic, Error}; -use cloud::GenericCloud; -use crypto::{Crypto, CryptoMethod}; -use port_forwarding::PortForwarding; -use util::{Duration, SystemTimeSource}; -use config::Config; +use crate::device::{TunTapDevice, Device, Type}; +use crate::ethernet::SwitchTable; +use crate::ip::RoutingTable; +use crate::types::{Mode, Range, Protocol, HeaderMagic, Error}; +use crate::cloud::GenericCloud; +use crate::crypto::{Crypto, CryptoMethod}; +use crate::port_forwarding::PortForwarding; +use crate::util::{Duration, SystemTimeSource}; +use crate::config::Config; const VERSION: u8 = 1; @@ -109,7 +109,7 @@ struct DualLogger { impl DualLogger { pub fn new>(path: Option

) -> Result { if let Some(path) = path { - let file = try!(File::create(path)); + let file = File::create(path)?; Ok(DualLogger{file: Mutex::new(Some(file))}) } else { Ok(DualLogger{file: Mutex::new(None)}) diff --git a/src/poll/epoll.rs b/src/poll/epoll.rs index 226b14c..6e94d24 100644 --- a/src/poll/epoll.rs +++ b/src/poll/epoll.rs @@ -6,11 +6,11 @@ use libc; use std::os::unix::io::RawFd; use std::io; -use device::Device; +use crate::device::Device; use super::WaitResult; -use ::device::Type; -use net::Socket; +use crate::device::Type; +use crate::net::Socket; pub struct EpollWait { poll_fd: RawFd, diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 2d851b7..bb35588 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -73,7 +73,7 @@ fn msg6_put(node: &mut TestNode, from: SocketAddr, } fn simulate(nodes: &mut [(&mut TestNode, SocketAddr)]) { - for (ref mut node, ref from_addr) in nodes.iter_mut() { + for (ref mut node, ref _from_addr) in nodes.iter_mut() { while node.device().has_inbound() { node.trigger_device_event(); } diff --git a/src/traffic.rs b/src/traffic.rs index 4d30353..3f58b4c 100644 --- a/src/traffic.rs +++ b/src/traffic.rs @@ -105,18 +105,18 @@ impl TrafficStats { #[inline] pub fn write_out(&self, out: &mut W) -> Result<(), io::Error> { - try!(writeln!(out, "Peer traffic:")); + writeln!(out, "Peer traffic:")?; let mut peers: Vec<_> = self.get_peer_traffic().collect(); peers.sort_unstable_by_key(|(_, data)| (data.out_bytes + data.in_bytes)); for (addr, data) in peers.iter().rev() { - try!(writeln!(out, " - {}: in={}/s, out={}/s", addr, Bytes(data.in_bytes/60), Bytes(data.out_bytes/60))); + writeln!(out, " - {}: in={}/s, out={}/s", addr, Bytes(data.in_bytes/60), Bytes(data.out_bytes/60))?; } - try!(writeln!(out)); - try!(writeln!(out, "Payload traffic:")); + writeln!(out)?; + writeln!(out, "Payload traffic:")?; let mut payload: Vec<_> = self.get_payload_traffic().collect(); payload.sort_unstable_by_key(|(_, data)| (data.out_bytes + data.in_bytes)); for ((remote, local), data) in payload.iter().rev() { - try!(writeln!(out, " - {} <-> {}: in={}/s, out={}/s", remote, local, Bytes(data.in_bytes/60), Bytes(data.out_bytes/60))); + writeln!(out, " - {} <-> {}: in={}/s, out={}/s", remote, local, Bytes(data.in_bytes/60), Bytes(data.out_bytes/60))?; } Ok(()) } diff --git a/src/types.rs b/src/types.rs index 6ac1ac1..8c65abf 100644 --- a/src/types.rs +++ b/src/types.rs @@ -29,7 +29,7 @@ impl Address { return Err(Error::Parse("Address too short")); } let len = data[0] as usize; - let addr = try!(Address::read_from_fixed(&data[1..], len)); + let addr = Address::read_from_fixed(&data[1..], len)?; Ok((addr, len + 1)) } @@ -121,7 +121,7 @@ impl FromStr for Address { if parts.len() == 6 { let mut bytes = [0; 16]; for i in 0..6 { - bytes[i] = try!(u8::from_str_radix(parts[i], 16).map_err(|_| Error::Parse("Failed to parse mac"))); + bytes[i] = u8::from_str_radix(parts[i], 16).map_err(|_| Error::Parse("Failed to parse mac"))?; } return Ok(Address{data: bytes, len: 6}); } @@ -139,7 +139,7 @@ pub struct Range { impl Range { #[inline] pub fn read_from(data: &[u8]) -> Result<(Range, usize), Error> { - let (address, read) = try!(Address::read_from(data)); + let (address, read) = Address::read_from(data)?; if data.len() < read + 1 { return Err(Error::Parse("Range too short")); } @@ -164,9 +164,9 @@ impl FromStr for Range { Some(pos) => pos, None => return Err(Error::Parse("Invalid range format")) }; - let prefix_len = try!(u8::from_str(&text[pos+1..]) - .map_err(|_| Error::Parse("Failed to parse prefix length"))); - let base = try!(Address::from_str(&text[..pos])); + let prefix_len = u8::from_str(&text[pos+1..]) + .map_err(|_| Error::Parse("Failed to parse prefix length"))?; + let base = Address::from_str(&text[..pos])?; Ok(Range{base, prefix_len}) } } @@ -207,16 +207,16 @@ impl fmt::Display for Mode { } pub trait Table { - fn learn(&mut self, Address, Option, SocketAddr); - fn lookup(&mut self, &Address) -> Option; + fn learn(&mut self, _: Address, _: Option, _: SocketAddr); + fn lookup(&mut self, _: &Address) -> Option; fn housekeep(&mut self); fn write_out(&self, out: &mut W) -> Result<(), io::Error>; - fn remove(&mut self, &Address) -> bool; - fn remove_all(&mut self, &SocketAddr); + fn remove(&mut self, _: &Address) -> bool; + fn remove_all(&mut self, _: &SocketAddr); } pub trait Protocol: Sized { - fn parse(&[u8]) -> Result<(Address, Address), Error>; + fn parse(_: &[u8]) -> Result<(Address, Address), Error>; } #[derive(Debug)] @@ -278,10 +278,10 @@ fn address_decode_encode() { #[test] fn address_eq() { - assert!(Address::read_from_fixed(&[1,2,3,4], 4).unwrap() == Address::read_from_fixed(&[1,2,3,4], 4).unwrap()); - assert!(Address::read_from_fixed(&[1,2,3,4], 4).unwrap() != Address::read_from_fixed(&[1,2,3,5], 4).unwrap()); - assert!(Address::read_from_fixed(&[1,2,3,4], 3).unwrap() == Address::read_from_fixed(&[1,2,3,5], 3).unwrap()); - assert!(Address::read_from_fixed(&[1,2,3,4], 3).unwrap() != Address::read_from_fixed(&[1,2,3,4], 4).unwrap()); + assert_eq!(Address::read_from_fixed(&[1,2,3,4], 4).unwrap(), Address::read_from_fixed(&[1,2,3,4], 4).unwrap()); + assert_ne!(Address::read_from_fixed(&[1,2,3,4], 4).unwrap(), Address::read_from_fixed(&[1,2,3,5], 4).unwrap()); + assert_eq!(Address::read_from_fixed(&[1,2,3,4], 3).unwrap(), Address::read_from_fixed(&[1,2,3,5], 3).unwrap()); + assert_ne!(Address::read_from_fixed(&[1,2,3,4], 3).unwrap(), Address::read_from_fixed(&[1,2,3,4], 4).unwrap()); } #[test] diff --git a/src/udpmessage.rs b/src/udpmessage.rs index f6f9b71..8c66dec 100644 --- a/src/udpmessage.rs +++ b/src/udpmessage.rs @@ -71,14 +71,14 @@ impl<'a> fmt::Debug for Message<'a> { match *self { Message::Data(_, start, end) => write!(formatter, "Data({} bytes)", end-start), Message::Peers(ref peers) => { - try!(write!(formatter, "Peers [")); + write!(formatter, "Peers [")?; let mut first = true; for p in peers { if !first { - try!(write!(formatter, ", ")); + write!(formatter, ", ")?; } first = false; - try!(write!(formatter, "{}", p)); + write!(formatter, "{}", p)?; } write!(formatter, "]") }, @@ -91,7 +91,7 @@ impl<'a> fmt::Debug for Message<'a> { #[allow(unknown_lints,clippy::needless_range_loop)] pub fn decode<'a>(data: &'a mut [u8], magic: HeaderMagic, crypto: &Crypto) -> Result, Error> { let mut end = data.len(); - let (header, mut pos) = try!(TopHeader::read_from(&data[..end])); + let (header, mut pos) = TopHeader::read_from(&data[..end])?; if header.magic != magic { return Err(Error::WrongHeaderMagic(header.magic)); } @@ -107,7 +107,7 @@ pub fn decode<'a>(data: &'a mut [u8], magic: HeaderMagic, crypto: &Crypto) -> Re let (before, after) = data.split_at_mut(pos); let (nonce, crypto_data) = after.split_at_mut(len); pos += len; - end = try!(crypto.decrypt(crypto_data, nonce, &before[..TopHeader::size()])) + pos; + end = crypto.decrypt(crypto_data, nonce, &before[..TopHeader::size()])? + pos; } assert_eq!(end, data.len()-crypto.additional_bytes()); } @@ -169,7 +169,7 @@ pub fn decode<'a>(data: &'a mut [u8], magic: HeaderMagic, crypto: &Crypto) -> Re pos += 1; let mut addrs = Vec::with_capacity(count); for _ in 0..count { - let (range, read) = try!(Range::read_from(&data[pos..end])); + let (range, read) = Range::read_from(&data[pos..end])?; pos += read; addrs.push(range); } diff --git a/src/util.rs b/src/util.rs index 927289c..c8d3499 100644 --- a/src/util.rs +++ b/src/util.rs @@ -117,7 +117,7 @@ macro_rules! try_fail { #[allow(unknown_lints,clippy::needless_pass_by_value)] pub fn resolve(addr: Addr) -> Result, Error> { - let addrs = try!(addr.to_socket_addrs().map_err(|_| Error::Name(format!("{:?}", addr)))); + let addrs = addr.to_socket_addrs().map_err(|_| Error::Name(format!("{:?}", addr)))?; // Remove duplicates in addrs (why are there duplicates???) let mut addrs = addrs.collect::>(); // Try IPv4 first as it usually is faster From f2e6a1ef7b22f027ce2619edc0b5f91b25fb81d5 Mon Sep 17 00:00:00 2001 From: Dennis Schwerdel Date: Fri, 1 Mar 2019 23:25:42 +0100 Subject: [PATCH 2/3] Clippy --- src/beacon.rs | 3 ++- src/cloud.rs | 9 +++++---- src/device.rs | 8 +++++++- src/main.rs | 16 +--------------- src/udpmessage.rs | 10 +++++----- src/util.rs | 12 +++++++++--- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/beacon.rs b/src/beacon.rs index 7b3903d..c5cca5b 100644 --- a/src/beacon.rs +++ b/src/beacon.rs @@ -31,7 +31,7 @@ fn base_62_sanitize(data: &str) -> String { } fn sha512(data: &[u8]) -> Vec { - digest::digest(&digest::SHA512, data).as_ref().iter().map(|b| *b).collect() + digest::digest(&digest::SHA512, data).as_ref().to_vec() } struct FutureResult { @@ -72,6 +72,7 @@ impl BeaconSerializer { 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); diff --git a/src/cloud.rs b/src/cloud.rs index fc42d0e..845babd 100644 --- a/src/cloud.rs +++ b/src/cloud.rs @@ -143,7 +143,7 @@ impl PeerList { #[inline] pub fn get_node_id(&self, addr: &SocketAddr) -> Option { - self.addresses.get(addr).map(|n| *n) + self.addresses.get(addr).cloned() } #[inline] @@ -230,6 +230,7 @@ pub struct GenericCloud GenericCloud { + #[allow(clippy::too_many_arguments)] pub fn new(config: &Config, device: D, table: T, learning: bool, broadcast: bool, addresses: Vec, crypto: Crypto, port_forwarding: Option @@ -271,7 +272,7 @@ impl GenericCloud GenericCloud &mut self.socket4, SocketAddr::V6(_) => &mut self.socket6 }; @@ -715,7 +716,7 @@ impl GenericCloud Self { - Self { outbound: VecDeque::new(), inbound: VecDeque::new() } + Default::default() } pub fn put_inbound(&mut self, data: Vec) { @@ -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 { diff --git a/src/main.rs b/src/main.rs index f3acc8d..c3ed39d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; diff --git a/src/udpmessage.rs b/src/udpmessage.rs index 8c66dec..1625376 100644 --- a/src/udpmessage.rs +++ b/src/udpmessage.rs @@ -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 } } diff --git a/src/util.rs b/src/util.rs index c8d3499..3b9e872 100644 --- a/src/util.rs +++ b/src/util.rs @@ -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; From 3cc40ff8d1baa8168e61c76a976b707aa2f27d3a Mon Sep 17 00:00:00 2001 From: Dennis Schwerdel Date: Sat, 2 Mar 2019 00:50:55 +0100 Subject: [PATCH 3/3] Updates --- CHANGELOG.md | 5 ++ Cargo.lock | 158 ++++++++++++++++------------------------- builder/Dockerfile-deb | 2 +- src/udpmessage.rs | 13 ++-- 4 files changed, 74 insertions(+), 104 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50a38d9..4e52fa9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,12 @@ This project follows [semantic versioning](http://semver.org). ### UNRELEASED - [added] Added ability to publish small beacons for rendezvous +- [added] Added build chain for pacakges +- [added] Added more tests - [changed] Allow to build binary without manpage +- [changed] Rust edition 2018 +- [changed] Rust version 1.33.0 +- [changed] Updated dependencies - [fixed] Fixed bug that could cause repeated initialization messages ### v0.9.1 (2019-02-16) diff --git a/Cargo.lock b/Cargo.lock index 8ee1531..97c710d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ [[package]] name = "aho-corasick" -version = "0.6.9" +version = "0.6.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -13,13 +13,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "backtrace" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -29,8 +29,8 @@ name = "backtrace-sys" version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -70,7 +70,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cc" -version = "1.0.29" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -91,7 +91,7 @@ name = "daemonize" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -99,10 +99,10 @@ name = "docopt" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -116,7 +116,7 @@ name = "failure" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -127,7 +127,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -193,12 +193,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lazy_static" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.48" +version = "0.2.49" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -246,7 +246,7 @@ version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -256,9 +256,9 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -289,7 +289,7 @@ name = "num_cpus" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -323,7 +323,7 @@ name = "rand" version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -333,7 +333,7 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -345,14 +345,14 @@ version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_jitter 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand_os 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -400,7 +400,7 @@ name = "rand_jitter" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -412,7 +412,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -420,11 +420,11 @@ dependencies = [ [[package]] name = "rand_pcg" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -453,7 +453,7 @@ name = "regex" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -462,10 +462,10 @@ dependencies = [ [[package]] name = "regex" -version = "1.1.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -501,9 +501,9 @@ name = "ring" version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -514,45 +514,24 @@ name = "rustc-demangle" version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "safemem" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "serde" -version = "1.0.87" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde_derive" -version = "1.0.87" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -562,7 +541,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "linked-hash-map 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "yaml-rust 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -571,7 +550,7 @@ name = "signal" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -582,11 +561,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smallvec" -version = "0.6.8" +version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "spin" @@ -600,7 +576,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "syn" -version = "0.15.26" +version = "0.15.27" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", @@ -615,7 +591,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -625,7 +601,7 @@ version = "3.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", "remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -637,7 +613,7 @@ name = "thread_local" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -645,7 +621,7 @@ name = "time" version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -686,7 +662,7 @@ name = "unicode-normalization" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -694,14 +670,6 @@ name = "unicode-xid" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "unreachable" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "untrusted" version = "0.6.2" @@ -737,19 +705,19 @@ name = "vpncloud" version = "0.9.1" dependencies = [ "base-62 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)", "daemonize 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "docopt 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "igd 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_yaml 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", "signal 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "siphasher 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -802,16 +770,16 @@ dependencies = [ ] [metadata] -"checksum aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1e9a933f4e58658d7b12defcf96dc5c720f20832deebe3e0a19efd3b6aaeeb9e" +"checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5" "checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799" -"checksum backtrace 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "b5b493b66e03090ebc4343eb02f94ff944e0cbc9ac6571491d170ba026741eb5" +"checksum backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "cd5a90e2b463010cd0e0ce9a11d4a9d5d58d9f41d4a6ba3dcaf9e68b466e88b4" "checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6" "checksum base-62 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f28ebd71b3e708e895b83ec2d35c6e2ef96e34945706bf4d73826354e84f89b2" "checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" -"checksum cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)" = "4390a3b5f4f6bce9c1d0c00128379df433e53777fdd30e92f16a529332baec4e" +"checksum cc 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)" = "d01c69d08ff207f231f07196e30f84c70f1c815b04f980f8b7b01ff01f05eb92" "checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum daemonize 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4093d27eb267d617f03c2ee25d4c3ca525b89a76154001954a11984508ffbde5" @@ -826,8 +794,8 @@ dependencies = [ "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum igd 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "356a0dc23a4fa0f8ce4777258085d00a01ea4923b2efd93538fc44bf5e1bda76" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" -"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" -"checksum libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)" = "e962c7641008ac010fa60a7dfdc1712449f29c44ef2d4702394aea943ee75047" +"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" +"checksum libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)" = "413f3dfc802c5dc91dc570b05125b6cda9855edfaa9825c9849807876376e70e" "checksum linked-hash-map 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "70fb39025bc7cdd76305867c4eccf2f2dcf6e9a57f5b21a93e1c2d86cd03ec9e" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" @@ -854,30 +822,27 @@ dependencies = [ "checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" "checksum rand_jitter 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b9ea758282efe12823e0d952ddb269d2e1897227e464919a554f2a03ef1b832" "checksum rand_os 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b7c690732391ae0abafced5015ffb53656abfaec61b342290e5eb56b286a679d" -"checksum rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "086bd09a33c7044e56bb44d5bdde5a60e7f119a9e95b0775f545de759a32fe05" +"checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85" "checksum regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384" -"checksum regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37e7cbbd370869ce2e8dff25c7018702d10b21a20ef7135316f8daecd6c25b7f" +"checksum regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53ee8cfdddb2e0291adfb9f13d31d3bbe0a03c9a402c01b1e24188d86c35b24f" "checksum regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7" "checksum regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8c2f35eedad5295fdf00a63d7d4b238135723f92b434ec06774dad15c7ab0861" "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" "checksum ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)" = "426bc186e3e95cac1e4a4be125a4aca7e84c2d616ffc02244eef36e2a60a093c" "checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" -"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" -"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)" = "2e20fde37801e83c891a2dc4ebd3b81f0da4d1fb67a9e0a2a3b921e2536a58ee" -"checksum serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)" = "633e97856567e518b59ffb2ad7c7a4fd4c5d91d9c7f32dd38a27b2bf7e8114ea" +"checksum serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "92514fb95f900c9b5126e32d020f5c6d40564c27a5ea6d1d7d9f157a96623560" +"checksum serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6eabf4b5914e88e24eea240bb7c9f9a2cbc1bbbe8d961d381975ec3c6b806c" "checksum serde_yaml 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)" = "0887a8e097a69559b56aa2526bf7aff7c3048cf627dff781f0b56a6001534593" "checksum signal 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "106428d9d96840ecdec5208c13ab8a4e28c38da1e0ccf2909fb44e41b992f897" "checksum siphasher 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9913c75df657d84a03fa689c016b0bb2863ff0b497b26a8d6e9703f8d5df03a8" -"checksum smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "88aea073965ab29f6edb5493faf96ad662fb18aa9eeb186a3b7057951605ed15" +"checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" "checksum spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44363f6f51401c34e7be73db0db371c04705d35efbe9f7d6082e03a921a32c55" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" -"checksum syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)" = "f92e629aa1d9c827b2bb8297046c1ccffc57c99b947a680d3ccff1f136a3bee9" +"checksum syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)" = "525bd55255f03c816e5d7f615587bd13030c7103354fadb104993dcee6a788ec" "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" "checksum tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b86c784c88d98c801132806dadd3819ed29d8600836c4088e855cdf3e178ed8a" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" @@ -889,7 +854,6 @@ dependencies = [ "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" -"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" "checksum untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" "checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" diff --git a/builder/Dockerfile-deb b/builder/Dockerfile-deb index b1e1edf..86930cc 100644 --- a/builder/Dockerfile-deb +++ b/builder/Dockerfile-deb @@ -9,7 +9,7 @@ RUN useradd -ms /bin/bash user USER user WORKDIR /home/user -ENV RUST=1.32.0 +ENV RUST=1.33.0 RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain ${RUST} diff --git a/src/udpmessage.rs b/src/udpmessage.rs index 1625376..b974f1b 100644 --- a/src/udpmessage.rs +++ b/src/udpmessage.rs @@ -183,6 +183,12 @@ pub fn decode<'a>(data: &'a mut [u8], magic: HeaderMagic, crypto: &Crypto) -> Re #[allow(unknown_lints,clippy::needless_range_loop)] pub fn encode<'a>(msg: &'a mut Message, mut buf: &'a mut [u8], magic: HeaderMagic, crypto: &mut Crypto) -> &'a mut [u8] { + let header_type = match msg { + Message::Data(_, _, _) => 0, + Message::Peers(_) => 1, + Message::Init(_, _, _) => 2, + Message::Close => 3 + }; let mut start = 64; let mut end = 64; match *msg { @@ -250,12 +256,7 @@ pub fn encode<'a>(msg: &'a mut Message, mut buf: &'a mut [u8], magic: HeaderMagi start -= crypto.nonce_bytes(); let mut header = TopHeader::default(); header.magic = magic; - header.msgtype = match *msg { - Message::Data(_, _, _) => 0, - Message::Peers(_) => 1, - Message::Init(_, _, _) => 2, - Message::Close => 3 - }; + header.msgtype = header_type; header.crypto_method = crypto.method(); start -= TopHeader::size(); header.write_to(&mut buf[start..]);