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

View File

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