Making clippy happy

This commit is contained in:
Dennis Schwerdel 2017-05-04 07:26:21 +02:00
parent 21837abf68
commit 2d11454316
8 changed files with 14 additions and 13 deletions

View File

@ -5,7 +5,7 @@ This project follows [semantic versioning](http://semver.org).
### UNRELEASED ### UNRELEASED
- [added] Added more tests - [added] Added more tests
- [changed] Updated dependencies - [changed] Updated dependencies and libsodium
### v0.8.0 (2016-11-25) ### v0.8.0 (2016-11-25)

View File

@ -78,7 +78,7 @@ impl PeerList {
#[inline] #[inline]
fn is_connected<Addr: ToSocketAddrs+fmt::Debug>(&self, addr: Addr) -> Result<bool, Error> { fn is_connected<Addr: ToSocketAddrs+fmt::Debug>(&self, addr: Addr) -> Result<bool, Error> {
for addr in try!(resolve(addr)) { for addr in try!(resolve(&addr)) {
if self.contains_addr(&addr) { if self.contains_addr(&addr) {
return Ok(true); return Ok(true);
} }
@ -319,7 +319,7 @@ impl<P: Protocol> GenericCloud<P> {
/// Returns an `Error::SocketError` if the given address is a name that failed to resolve to /// Returns an `Error::SocketError` if the given address is a name that failed to resolve to
/// actual addresses. /// actual addresses.
fn is_blacklisted<Addr: ToSocketAddrs+fmt::Debug>(&self, addr: Addr) -> Result<bool, Error> { fn is_blacklisted<Addr: ToSocketAddrs+fmt::Debug>(&self, addr: Addr) -> Result<bool, Error> {
for addr in try!(resolve(addr)) { for addr in try!(resolve(&addr)) {
if self.blacklist_peers.contains(&addr) { if self.blacklist_peers.contains(&addr) {
return Ok(true); return Ok(true);
} }
@ -343,7 +343,7 @@ impl<P: Protocol> GenericCloud<P> {
let subnets = self.addresses.clone(); let subnets = self.addresses.clone();
let node_id = self.node_id; let node_id = self.node_id;
// Send a message to each resolved address // Send a message to each resolved address
for a in try!(resolve(addr)) { for a in try!(resolve(&addr)) {
// Ignore error this time // Ignore error this time
let mut msg = Message::Init(0, node_id, subnets.clone()); let mut msg = Message::Init(0, node_id, subnets.clone());
self.send_msg(a, &mut msg).ok(); self.send_msg(a, &mut msg).ok();

View File

@ -171,7 +171,7 @@ impl Config {
Encoder::write_u32((s.finish() & 0xffffffff) as u32, &mut data); Encoder::write_u32((s.finish() & 0xffffffff) as u32, &mut data);
data data
} else { } else {
let num = try_fail!(u32::from_str_radix(&name, 16), "Failed to parse header magic: {}"); let num = try_fail!(u32::from_str_radix(name, 16), "Failed to parse header magic: {}");
let mut data = [0; 4]; let mut data = [0; 4];
Encoder::write_u32(num, &mut data); Encoder::write_u32(num, &mut data);
data data

View File

@ -289,7 +289,7 @@ impl Crypto {
Crypto::ChaCha20Poly1305{ref key, ref mut nonce} => { Crypto::ChaCha20Poly1305{ref key, ref mut nonce} => {
inc_nonce_12(nonce); inc_nonce_12(nonce);
let mut clen: u64 = buf.len() as u64; let mut clen: u64 = buf.len() as u64;
assert!(nonce_bytes.len() == nonce.len()); assert_eq!(nonce_bytes.len(), nonce.len());
assert!(clen as usize >= mlen + crypto_aead_chacha20poly1305_ietf_ABYTES); assert!(clen as usize >= mlen + crypto_aead_chacha20poly1305_ietf_ABYTES);
let res = unsafe { crypto_aead_chacha20poly1305_ietf_encrypt( let res = unsafe { crypto_aead_chacha20poly1305_ietf_encrypt(
buf.as_mut_ptr(), // Base pointer to buffer buf.as_mut_ptr(), // Base pointer to buffer
@ -311,7 +311,7 @@ impl Crypto {
Crypto::AES256GCM{ref state, ref mut nonce} => { Crypto::AES256GCM{ref state, ref mut nonce} => {
inc_nonce_12(nonce); inc_nonce_12(nonce);
let mut clen: u64 = buf.len() as u64; let mut clen: u64 = buf.len() as u64;
assert!(nonce_bytes.len() == nonce.len()); assert_eq!(nonce_bytes.len(), nonce.len());
assert!(clen as usize >= mlen + crypto_aead_aes256gcm_ABYTES); assert!(clen as usize >= mlen + crypto_aead_aes256gcm_ABYTES);
let res = unsafe { crypto_aead_aes256gcm_encrypt_afternm( let res = unsafe { crypto_aead_aes256gcm_encrypt_afternm(
buf.as_mut_ptr(), // Base pointer to buffer buf.as_mut_ptr(), // Base pointer to buffer

View File

@ -47,8 +47,8 @@ impl Protocol for Frame {
dst[2..8].copy_from_slice(dst_data); dst[2..8].copy_from_slice(dst_data);
Ok((Address{data: src, len: 8}, Address{data: dst, len: 8})) Ok((Address{data: src, len: 8}, Address{data: dst, len: 8}))
} else { } else {
let src = try!(Address::read_from_fixed(&src_data, 6)); let src = try!(Address::read_from_fixed(src_data, 6));
let dst = try!(Address::read_from_fixed(&dst_data, 6)); let dst = try!(Address::read_from_fixed(dst_data, 6));
Ok((src, dst)) Ok((src, dst))
} }
} }

View File

@ -124,7 +124,7 @@ impl log::Log for DualLogger {
} }
} }
fn run_script(script: String, ifname: &str) { fn run_script(script: &str, ifname: &str) {
let mut cmd = Command::new("sh"); let mut cmd = Command::new("sh");
cmd.arg("-c").arg(&script).env("IFNAME", ifname); cmd.arg("-c").arg(&script).env("IFNAME", ifname);
debug!("Running script: {:?}", cmd); debug!("Running script: {:?}", cmd);
@ -170,7 +170,7 @@ fn run<T: Protocol> (config: Config) {
}; };
let mut cloud = GenericCloud::<T>::new(magic, device, config.port, table, peer_timeout, learning, broadcasting, ranges, crypto, port_forwarding); let mut cloud = GenericCloud::<T>::new(magic, device, config.port, table, peer_timeout, learning, broadcasting, ranges, crypto, port_forwarding);
if let Some(script) = config.ifup { if let Some(script) = config.ifup {
run_script(script, cloud.ifname()); run_script(&script, cloud.ifname());
} }
for addr in config.peers { for addr in config.peers {
try_fail!(cloud.connect(&addr as &str), "Failed to send message to {}: {}", &addr); try_fail!(cloud.connect(&addr as &str), "Failed to send message to {}: {}", &addr);
@ -192,7 +192,7 @@ fn run<T: Protocol> (config: Config) {
} }
cloud.run(); cloud.run();
if let Some(script) = config.ifdown { if let Some(script) = config.ifdown {
run_script(script, cloud.ifname()); run_script(&script, cloud.ifname());
} }
} }

View File

@ -122,7 +122,7 @@ impl FromStr for Address {
if parts.len() == 6 { if parts.len() == 6 {
let mut bytes = [0; 16]; let mut bytes = [0; 16];
for i in 0..6 { 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] = try!(u8::from_str_radix(parts[i], 16).map_err(|_| Error::Parse("Failed to parse mac")));
} }
return Ok(Address{data: bytes, len: 6}); return Ok(Address{data: bytes, len: 6});
} }

View File

@ -123,6 +123,7 @@ macro_rules! try_fail {
} }
#[allow(unknown_lints,needless_pass_by_value)]
pub fn resolve<Addr: ToSocketAddrs+fmt::Debug>(addr: Addr) -> Result<Vec<SocketAddr>, Error> { pub fn resolve<Addr: ToSocketAddrs+fmt::Debug>(addr: Addr) -> Result<Vec<SocketAddr>, Error> {
let addrs = try!(addr.to_socket_addrs().map_err(|_| Error::Name(format!("{:?}", addr)))); let addrs = try!(addr.to_socket_addrs().map_err(|_| Error::Name(format!("{:?}", addr))));
// Remove duplicates in addrs (why are there duplicates???) // Remove duplicates in addrs (why are there duplicates???)