aboutsummaryrefslogtreecommitdiffstats
path: root/src/transport/libp2p
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/libp2p')
-rw-r--r--src/transport/libp2p/book.rs4
-rw-r--r--src/transport/libp2p/mod.rs15
2 files changed, 14 insertions, 5 deletions
diff --git a/src/transport/libp2p/book.rs b/src/transport/libp2p/book.rs
index b2ce7bb..02a6b49 100644
--- a/src/transport/libp2p/book.rs
+++ b/src/transport/libp2p/book.rs
@@ -267,8 +267,8 @@ impl Book {
let address = without_peer(address.clone());
(!address.is_empty() && !is_relayed(&address)).then_some(address)
});
- // First: the member list keeps only so many (`members::MAX_ADDRESSES`), and a
- // node listening everywhere has many.
+ // First: only so many are published (`PUBLISHED_DIRECT`), and a node listening
+ // everywhere has many.
let mut first: Vec<Multiaddr> = Vec::new();
for address in self.mapped.iter().cloned().chain(confirmed) {
if !first.contains(&address) {
diff --git a/src/transport/libp2p/mod.rs b/src/transport/libp2p/mod.rs
index 6032891..2ad07e5 100644
--- a/src/transport/libp2p/mod.rs
+++ b/src/transport/libp2p/mod.rs
@@ -145,6 +145,11 @@ const MIN_RATE: u64 = 1 << 20;
const READS: usize = 32;
/// Addresses kept per peer, and peers with addresses at most.
const ADDRESSES_PER_PEER: usize = 8;
+/// Of this node's own, the direct ones (the best first) and those through relays it
+/// publishes at most (`local_addresses`): a node listening everywhere has many direct
+/// ones, and those through a relay are what reaches it from behind a NAT.
+const PUBLISHED_DIRECT: usize = 4;
+const PUBLISHED_RELAYED: usize = 2;
const MAX_PEERS: usize = 4096;
/// A relayed connection (circuit) through this node lasts at most this long and carries
@@ -363,20 +368,24 @@ impl Transport for Libp2pTransport {
}
/// Where we can be reached, each with our peer ID: the announced addresses, or else
- /// those we listen on (`published`), and those through relays. A relay adds each
- /// direct one again, ending in `/p2p-circuit`: where to reserve a slot.
+ /// those we listen on (`published`), and those through relays; at most
+ /// `PUBLISHED_DIRECT` and `PUBLISHED_RELAYED` of them, so the direct ones never
+ /// crowd out the relayed ones. A relay adds each direct one again, ending in
+ /// `/p2p-circuit`: where to reserve a slot.
fn local_addresses(&self) -> Vec<String> {
let book = lock(&self.book);
let direct: Vec<Multiaddr> = book
.direct()
.into_iter()
.filter_map(|address| address.with_p2p(self.peer_id).ok())
+ .take(PUBLISHED_DIRECT)
.collect();
let relayed = book
.listening
.iter()
.filter(|address| is_relayed(address))
- .filter_map(|address| address.clone().with_p2p(self.peer_id).ok());
+ .filter_map(|address| address.clone().with_p2p(self.peer_id).ok())
+ .take(PUBLISHED_RELAYED);
let offers: Vec<Multiaddr> = if book.serving {
direct
.iter()