Просмотр исходного кода

net: add `getaddrs_max` setting

epiphany 10 месяцев назад
Родитель
Сommit
6b7e1cf7ca

+ 2 - 1
src/net/protocol/protocol_address.rs

@@ -279,6 +279,7 @@ impl ProtocolBase for ProtocolAddress {
 
         let settings = self.settings.read().await;
         let outbound_connections = settings.outbound_connections;
+        let getaddrs_max = settings.getaddrs_max;
         let allowed_transports = settings.allowed_transports.clone();
         drop(settings);
 
@@ -293,7 +294,7 @@ impl ProtocolBase for ProtocolAddress {
         // Send get_address message.
         // We ask for a maximum of u8::MAX addresses from a single node
         let get_addrs = GetAddrsMessage {
-            max: outbound_connections.min(u8::MAX as usize) as u32,
+            max: getaddrs_max.unwrap_or(outbound_connections).min(u8::MAX as usize) as u32,
             transports: allowed_transports,
         };
         self.channel.send(&get_addrs).await?;

+ 2 - 1
src/net/protocol/protocol_seed.rs

@@ -110,13 +110,14 @@ impl ProtocolBase for ProtocolSeed {
 
         let settings = self.settings.read().await;
         let outbound_connections = settings.outbound_connections;
+        let getaddrs_max = settings.getaddrs_max;
         let allowed_transports = settings.allowed_transports.clone();
         drop(settings);
 
         // Send get address message
         // We ask for a maximum of u8::MAX addresses from a single node
         let get_addr = GetAddrsMessage {
-            max: outbound_connections.min(u8::MAX as usize) as u32,
+            max: getaddrs_max.unwrap_or(outbound_connections).min(u8::MAX as usize) as u32,
             transports: allowed_transports,
         };
         self.channel.send(&get_addr).await?;

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

@@ -524,6 +524,7 @@ impl PeerDiscoveryBase for PeerDiscovery {
             let outbound_peer_discovery_attempt_time =
                 settings.outbound_peer_discovery_attempt_time;
             let outbound_connections = settings.outbound_connections;
+            let getaddrs_max = settings.getaddrs_max;
             let allowed_transports = settings.allowed_transports.clone();
             let seeds = settings.seeds.clone();
             drop(settings);
@@ -567,7 +568,7 @@ impl PeerDiscoveryBase for PeerDiscovery {
                 });
 
                 let get_addrs = GetAddrsMessage {
-                    max: outbound_connections as u32,
+                    max: getaddrs_max.unwrap_or(outbound_connections).min(u8::MAX as usize) as u32,
                     transports: allowed_transports,
                 };
 

+ 12 - 0
src/net/settings.rs

@@ -100,6 +100,10 @@ pub struct Settings {
     pub outbound_peer_discovery_cooloff_time: u64,
     /// Time between peer discovery attempts
     pub outbound_peer_discovery_attempt_time: u64,
+    /// Maximum number of addresses (with preferred transports) to receive from
+    /// seeds and peers.
+    /// If undefined, `outbound_connections` will be used instead.
+    pub getaddrs_max: Option<usize>,
     /// P2P datastore path
     pub p2p_datastore: Option<String>,
     /// Hostlist storage path
@@ -153,6 +157,7 @@ impl Default for Settings {
             localnet: false,
             outbound_peer_discovery_cooloff_time: 30,
             outbound_peer_discovery_attempt_time: 5,
+            getaddrs_max: None,
             p2p_datastore: None,
             hostlist: None,
             greylist_refinery_interval: 15,
@@ -286,6 +291,12 @@ pub struct SettingsOpt {
     #[structopt(skip)]
     pub outbound_peer_discovery_attempt_time: Option<u64>,
 
+    /// Maximum number of addresses (with preferred transports) to receive from
+    /// seeds and peers.
+    /// If undefined, `outbound_connections` will be used instead.
+    #[structopt(skip)]
+    pub getaddrs_max: Option<usize>,
+
     /// P2P datastore path
     #[serde(default)]
     #[structopt(long)]
@@ -368,6 +379,7 @@ impl From<SettingsOpt> for Settings {
             outbound_peer_discovery_attempt_time: opt
                 .outbound_peer_discovery_attempt_time
                 .unwrap_or(def.outbound_peer_discovery_attempt_time),
+            getaddrs_max: opt.getaddrs_max,
             p2p_datastore: opt.p2p_datastore,
             hostlist: opt.hostlist,
             greylist_refinery_interval: opt