Limit peer lists to 20 peers

This commit is contained in:
Dennis Schwerdel 2017-01-11 14:31:28 +01:00
parent e68ff2ba6a
commit b248e50672
2 changed files with 10 additions and 13 deletions

View File

@ -11,7 +11,7 @@ use std::os::unix::io::AsRawFd;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::hash::BuildHasherDefault; use std::hash::BuildHasherDefault;
use std::time::Instant; use std::time::Instant;
use std::cmp::{min, max}; use std::cmp::min;
use fnv::FnvHasher; use fnv::FnvHasher;
use libc::{SIGTERM, SIGQUIT, SIGINT}; use libc::{SIGTERM, SIGQUIT, SIGINT};
@ -376,11 +376,8 @@ impl<P: Protocol> GenericCloud<P> {
debug!("Send peer list to all peers"); debug!("Send peer list to all peers");
let mut peer_num = self.peers.len(); let mut peer_num = self.peers.len();
// If the number of peers is high, send only a fraction of the full peer list to // If the number of peers is high, send only a fraction of the full peer list to
// reduce the management traffic. The number of peers to send is the square root of the // reduce the management traffic. The number of peers to send is limited by 20.
// total number of peers. peer_num = min(peer_num, 20);
if peer_num > 10 {
peer_num = max(10, min(255, (peer_num as f32).sqrt().ceil() as usize));
}
// Select that many peers... // Select that many peers...
let peers = self.peers.subset(peer_num); let peers = self.peers.subset(peer_num);
// ...and send them to all peers // ...and send them to all peers

View File

@ -397,17 +397,17 @@ will follow:
* **Closing message** (message type 3): * **Closing message** (message type 3):
This packet does not contain any more data. This packet does not contain any more data.
Nodes are expected to send an **initial message** whenever they connect to a Nodes are expected to send an **initial message** with stage 0 whenever they
node they were not connected to before. As a reply to this message, another connect to a node they were not connected to before. As a reply to this message,
initial should be sent with stage 2. Also a **peer list** message should be another initial should be sent with stage 1. Also a **peer list** message should
sent as a reply. be sent as a reply.
When connected, nodes should periodically send their **peer list** to all When connected, nodes should periodically send their **peer list** to all
of their peers to spread this information and to avoid peer timeouts. of their peers to spread this information and to avoid peer timeouts.
To avoid the cubic growth of management traffic, nodes should at a certain To avoid the cubic growth of management traffic, nodes should at a certain
network size start sending partial peer lists instead of the full list. network size start sending partial peer lists instead of the full list. A
A reasonable number would be the square root of the number of peers. reasonable number would be about 20 peers. The subsets should be selected
The subsets should be selected randomly. randomly.
Nodes should remove peers from their peer list after a certain period of Nodes should remove peers from their peer list after a certain period of
inactivity or when receiving a **closing message**. Before shutting down, nodes inactivity or when receiving a **closing message**. Before shutting down, nodes