{
next_housekeep: now(),
next_stats_out: now() + STATS_INTERVAL,
port_forwarding,
- traffic: TrafficStats::new(),
+ traffic: TrafficStats::default(),
stats_file: config.stats_file.clone(),
_dummy_p: PhantomData,
}
@@ -474,6 +480,7 @@ impl {
try!(writeln!(&mut f));
try!(self.traffic.write_out(&mut f));
try!(writeln!(&mut f));
+ try!(fs::set_permissions(self.stats_file.as_ref().unwrap(), Permissions::from_mode(0o644)));
Ok(())
}
@@ -595,8 +602,7 @@ impl {
}
// Add sender as peer or as alternative address to existing peer
if self.peers.contains_node(&node_id) {
- //TODO: make this address primary
- self.peers.add_alt_addr(node_id, peer);
+ self.peers.make_primary(node_id, peer);
} else {
self.peers.add(node_id, peer);
for range in ranges {
diff --git a/src/traffic.rs b/src/traffic.rs
index 8d8bffd..2fcc406 100644
--- a/src/traffic.rs
+++ b/src/traffic.rs
@@ -7,6 +7,7 @@ use super::cloud::Hash;
use super::util::Bytes;
+#[derive(Default)]
pub struct TrafficEntry {
pub out_bytes_total: u64,
pub out_packets_total: usize,
@@ -20,20 +21,6 @@ pub struct TrafficEntry {
}
impl TrafficEntry {
- pub fn new() -> Self {
- TrafficEntry {
- out_bytes_total: 0,
- out_packets_total: 0,
- out_bytes: 0,
- out_packets: 0,
- in_bytes_total: 0,
- in_packets_total: 0,
- in_bytes: 0,
- in_packets: 0,
- idle_periods: 0
- }
- }
-
#[inline]
fn count_out(&mut self, bytes: usize) {
self.out_packets += 1;
@@ -63,34 +50,32 @@ impl TrafficEntry {
}
}
+
+#[derive(Default)]
pub struct TrafficStats {
peers: HashMap