fix: address clippy warnings and reselection bug
This commit is contained in:
1 parent
3b5b124f8e
commit
cf2936700e
5 files changed
+15
-22
No files matched your search
+2
-2
@@ -43,13 +43,13 @@ impl FromStr for MeasurementType {
|
||||
type Err = ConfigError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
return match s.to_lowercase().as_str() {
|
||||
match s.to_lowercase().as_str() {
|
||||
"icmp" => Ok(MeasurementType::Icmp),
|
||||
"icmp-timestamps" => Ok(MeasurementType::IcmpTimestamps),
|
||||
"ntp" => Ok(MeasurementType::Ntp),
|
||||
"tcp-timestamps" => Ok(MeasurementType::TcpTimestamps),
|
||||
&_ => Err(ConfigError::InvalidMeasurementType(s.to_string())),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -226,7 +226,7 @@ impl Netlink {
|
||||
|
||||
if _type.eq(type_to_look_for) {
|
||||
let qdisc = Qdisc {
|
||||
ifindex: p.tcm_ifindex as i32,
|
||||
ifindex: p.tcm_ifindex,
|
||||
parent: p.tcm_parent,
|
||||
};
|
||||
|
||||
|
||||
+2
-2
@@ -133,12 +133,12 @@ pub trait PingSender {
|
||||
for reflector in reflectors.iter() {
|
||||
let addr: SockAddr = match reflector.is_ipv4() {
|
||||
true => {
|
||||
let ip4 = Ipv4Addr::from_str(&*reflector.to_string()).unwrap();
|
||||
let ip4 = Ipv4Addr::from_str(&reflector.to_string()).unwrap();
|
||||
let sock4 = SocketAddrV4::new(ip4, 0);
|
||||
sock4.into()
|
||||
}
|
||||
false => {
|
||||
let ip6 = Ipv6Addr::from_str(&*reflector.to_string()).unwrap();
|
||||
let ip6 = Ipv6Addr::from_str(&reflector.to_string()).unwrap();
|
||||
let sock6 = SocketAddrV6::new(ip6, 0, 0, 0);
|
||||
sock6.into()
|
||||
}
|
||||
|
||||
@@ -318,6 +318,7 @@ impl Ratecontroller {
|
||||
speed_hist_fd_inner = File::options()
|
||||
.create(true)
|
||||
.write(true)
|
||||
.truncate(true)
|
||||
.open(self.config.speed_hist_file.as_str())?;
|
||||
|
||||
speed_hist_fd_inner.write_all("time,counter,upspeed,downspeed\n".as_bytes())?;
|
||||
@@ -328,6 +329,7 @@ impl Ratecontroller {
|
||||
stats_fd_inner = File::options()
|
||||
.create(true)
|
||||
.write(true)
|
||||
.truncate(true)
|
||||
.open(self.config.stats_file.as_str())?;
|
||||
|
||||
stats_fd_inner.write_all(
|
||||
@@ -348,11 +350,6 @@ impl Ratecontroller {
|
||||
|
||||
(self.state_dl.current_bytes, self.state_ul.current_bytes) =
|
||||
get_interface_stats(&self.config, self.down_direction, self.up_direction)?;
|
||||
if self.state_dl.current_bytes == -1 || self.state_ul.current_bytes == -1 {
|
||||
warn!(
|
||||
"One or both Netlink stats could not be read. Skipping rate control algorithm");
|
||||
continue;
|
||||
}
|
||||
|
||||
self.update_deltas();
|
||||
self.calculate_rate(Direction::Down)?;
|
||||
|
||||
@@ -52,13 +52,13 @@ impl ReflectorSelector {
|
||||
|
||||
// Include all current peers
|
||||
for reflector in reflectors_peers.iter() {
|
||||
debug!("Current peer: {}", reflector.to_string());
|
||||
debug!("Current peer: {}", reflector);
|
||||
next_peers.push(*reflector);
|
||||
}
|
||||
|
||||
for _ in 1..20 {
|
||||
let next_candidate = self.reflector_pool.choose(&mut rng).unwrap();
|
||||
debug!("Next candidate: {}", next_candidate.to_string());
|
||||
debug!("Next candidate: {}", next_candidate);
|
||||
next_peers.push(*next_candidate);
|
||||
}
|
||||
|
||||
@@ -84,12 +84,9 @@ impl ReflectorSelector {
|
||||
if owd_recent.contains_key(&peer) {
|
||||
let rtt = (owd_recent[&peer].down_ewma + owd_recent[&peer].up_ewma) as u64;
|
||||
candidates.push((peer, rtt));
|
||||
info!("Candidate reflector: {} RTT: {}", peer.to_string(), rtt);
|
||||
info!("Candidate reflector: {} RTT: {}", peer, rtt);
|
||||
} else {
|
||||
info!(
|
||||
"No data found from candidate reflector: {} - skipping",
|
||||
peer.to_string()
|
||||
);
|
||||
info!("No data found from candidate reflector: {} - skipping", peer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +96,9 @@ impl ReflectorSelector {
|
||||
// Now we will just limit the candidates down to 2 * num_reflectors
|
||||
let mut num_reflectors = self.config.num_reflectors;
|
||||
let candidate_pool_num = (2 * num_reflectors) as usize;
|
||||
candidates = candidates[0..candidate_pool_num - 1].to_vec();
|
||||
if candidates.len() > candidate_pool_num {
|
||||
candidates.truncate(candidate_pool_num);
|
||||
}
|
||||
|
||||
for (candidate, rtt) in candidates.iter() {
|
||||
info!("Fastest candidate {}: {}", candidate, rtt);
|
||||
@@ -118,10 +117,7 @@ impl ReflectorSelector {
|
||||
let mut new_peers = Vec::new();
|
||||
for i in 0..num_reflectors {
|
||||
new_peers.push(candidates[i as usize].0);
|
||||
info!(
|
||||
"New selected peer: {}",
|
||||
candidates[i as usize].0.to_string()
|
||||
);
|
||||
info!("New selected peer: {}", candidates[i as usize].0);
|
||||
}
|
||||
|
||||
*reflectors_peers = new_peers;
|
||||
|
||||
Reference in new issue
Block a user