Преглед изворни кода

outbound_session: fix bug in Slot white_count calculations

settings.white_count was 90 by default (a percentage) but was being
treated as an absolute value in outbound session.

we fix this and simplify the types to avoid excessive conversions.
draoi пре 2 година
родитељ
комит
3bf9c67e77
2 измењених фајлова са 8 додато и 8 уклоњено
  1. 2 2
      src/net/session/outbound_session.rs
  2. 6 6
      src/net/settings.rs

+ 2 - 2
src/net/session/outbound_session.rs

@@ -225,11 +225,11 @@ impl Slot {
     /// connections. A network that purely favors uptime over unreliable
     /// connections may be vulnerable to sybil by attackers with good uptime.
     async fn fetch_addrs_with_preference(&self, preference: SlotPreference) -> Vec<(Url, u64)> {
-        let slot = self.slot;
+        let slot = self.slot as usize;
         let settings = self.p2p().settings();
         let hosts = &self.p2p().hosts().container;
 
-        let white_count = settings.white_connect_count;
+        let white_count = (settings.white_connect_percent * settings.outbound_connections) / 100;
         let gold_count = settings.gold_connect_count;
 
         let transports = &settings.allowed_transports;

+ 6 - 6
src/net/settings.rs

@@ -69,9 +69,9 @@ pub struct Settings {
     /// Pause interval within greylist refinery process
     pub greylist_refinery_interval: u64,
     /// Percent of connections to come from the whitelist
-    pub white_connect_count: u32,
+    pub white_connect_percent: usize,
     /// Number of goldlist connections
-    pub gold_connect_count: u32,
+    pub gold_connect_count: usize,
     /// Number of seconds with no connections after which refinery
     /// process is paused.
     pub time_with_no_connections: u64,
@@ -104,7 +104,7 @@ impl Default for Settings {
             outbound_peer_discovery_attempt_time: 5,
             hostlist: "/dev/null".to_string(),
             greylist_refinery_interval: 15,
-            white_connect_count: 90,
+            white_connect_percent: 90,
             gold_connect_count: 2,
             time_with_no_connections: 30,
             blacklist: vec![],
@@ -200,11 +200,11 @@ pub struct SettingsOpt {
 
     /// Number of whitelist connections
     #[structopt(skip)]
-    pub white_connect_count: Option<u32>,
+    pub white_connect_percent: Option<usize>,
 
     /// Number of goldlist connections
     #[structopt(skip)]
-    pub gold_connect_count: Option<u32>,
+    pub gold_connect_count: Option<usize>,
 
     /// Number of seconds with no connections after which refinery
     /// process is paused.
@@ -253,7 +253,7 @@ impl From<SettingsOpt> for Settings {
             greylist_refinery_interval: opt
                 .greylist_refinery_interval
                 .unwrap_or(def.greylist_refinery_interval),
-            white_connect_count: opt.white_connect_count.unwrap_or(def.white_connect_count),
+            white_connect_percent: opt.white_connect_percent.unwrap_or(def.white_connect_percent),
             gold_connect_count: opt.gold_connect_count.unwrap_or(def.gold_connect_count),
             time_with_no_connections: opt
                 .time_with_no_connections