Bleeding edge discovery (#2435)

* Update discovery banning logic and tokio

* Update to latest discovery

* Shift to latest discovery

* Fmt
This commit is contained in:
Age Manning
2021-07-07 18:18:44 +10:00
parent f4bc9db16d
commit c1d2e35c9e
28 changed files with 50 additions and 33 deletions

View File

@@ -151,6 +151,16 @@ impl Default for Config {
.build()
.expect("valid gossipsub configuration");
// Discv5 Unsolicited Packet Rate Limiter
let filter_rate_limiter = Some(
discv5::RateLimiterBuilder::new()
.total_n_every(10, Duration::from_secs(1)) // Allow bursts, average 10 per second
.ip_n_every(9, Duration::from_secs(1)) // Allow bursts, average 9 per second
.node_n_every(8, Duration::from_secs(1)) // Allow bursts, average 8 per second
.build()
.expect("The total rate limit has been specified"),
);
// discv5 configuration
let discv5_config = Discv5ConfigBuilder::new()
.enable_packet_filter()
@@ -164,6 +174,10 @@ impl Default for Config {
.disable_report_discovered_peers()
.ip_limit() // limits /24 IP's in buckets.
.incoming_bucket_limit(8) // half the bucket size
.filter_rate_limiter(filter_rate_limiter)
.filter_max_bans_per_ip(Some(5))
.filter_max_nodes_per_ip(Some(10))
.ban_duration(Some(Duration::from_secs(3600)))
.ping_interval(Duration::from_secs(300))
.build();

View File

@@ -497,13 +497,13 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
// first try and convert the peer_id to a node_id.
if let Ok(node_id) = peer_id_to_node_id(peer_id) {
// If we could convert this peer id, remove it from the DHT and ban it from discovery.
self.discv5.ban_node(&node_id);
self.discv5.ban_node(&node_id, None);
// Remove the node from the routing table.
self.discv5.remove_node(&node_id);
}
for ip_address in ip_addresses {
self.discv5.ban_ip(ip_address);
self.discv5.ban_ip(ip_address, None);
}
}
@@ -512,11 +512,11 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
// first try and convert the peer_id to a node_id.
if let Ok(node_id) = peer_id_to_node_id(peer_id) {
// If we could convert this peer id, remove it from the DHT and ban it from discovery.
self.discv5.permit_node(&node_id);
self.discv5.ban_node_remove(&node_id);
}
for ip_address in ip_addresses {
self.discv5.permit_ip(ip_address);
self.discv5.ban_ip_remove(&ip_address);
}
}
@@ -944,7 +944,9 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
*self.network_globals.local_enr.write() = enr;
return Poll::Ready(DiscoveryEvent::SocketUpdated(socket));
}
_ => {} // Ignore all other discv5 server events
Discv5Event::EnrAdded { .. }
| Discv5Event::TalkRequest(_)
| Discv5Event::NodeInserted { .. } => {} // Ignore all other discv5 server events
}
}
}