-
Notifications
You must be signed in to change notification settings - Fork 1.2k
litep2p/discovery: Publish authority records with external addresses only #5176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2d0893b
b24c9d3
251c2c8
7b92b57
fd5d697
5efd51b
15c056b
0630bd0
e339df3
f17a08c
8367766
331b006
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,12 +66,18 @@ const KADEMLIA_QUERY_INTERVAL: Duration = Duration::from_secs(5); | |
| /// mDNS query interval. | ||
| const MDNS_QUERY_INTERVAL: Duration = Duration::from_secs(30); | ||
|
|
||
| /// Minimum number of confirmations received before an address is verified. | ||
| const MIN_ADDRESS_CONFIRMATIONS: usize = 5; | ||
|
|
||
| // The minimum number of peers we expect an answer before we terminate the request. | ||
| /// The minimum number of peers we expect an answer before we terminate the request. | ||
| const GET_RECORD_REDUNDANCY_FACTOR: usize = 4; | ||
|
|
||
| /// The maximum number of tracked external addresses we allow. | ||
| const MAX_EXTERNAL_ADDRESSES: u32 = 32; | ||
|
|
||
| /// Minimum number of confirmations received before an address is verified. | ||
| /// | ||
| /// Note: all addresses are confirmed by libp2p on the first encounter. This aims to make | ||
| /// addresses a bit more robust. | ||
| const MIN_ADDRESS_CONFIRMATIONS: usize = 2; | ||
|
|
||
| /// Discovery events. | ||
| #[derive(Debug)] | ||
| pub enum DiscoveryEvent { | ||
|
|
@@ -195,7 +201,7 @@ pub struct Discovery { | |
| listen_addresses: Arc<RwLock<HashSet<Multiaddr>>>, | ||
|
|
||
| /// External address confirmations. | ||
| address_confirmations: LruMap<Multiaddr, usize>, | ||
| address_confirmations: LruMap<Multiaddr, HashSet<PeerId>>, | ||
|
|
||
| /// Delay to next `FIND_NODE` query. | ||
| duration_to_next_find_query: Duration, | ||
|
|
@@ -278,7 +284,7 @@ impl Discovery { | |
| find_node_query_id: None, | ||
| pending_events: VecDeque::new(), | ||
| duration_to_next_find_query: Duration::from_secs(1), | ||
| address_confirmations: LruMap::new(ByLength::new(8)), | ||
| address_confirmations: LruMap::new(ByLength::new(MAX_EXTERNAL_ADDRESSES)), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do we ensure that nodes do not report junk addresses to us?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally I don't get why we not bootstrap it with the addresses of our interfaces? If these addresses are global, the likelihood that the node is reachable via them should be quite big?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep that could also work, we can check our interfaces and iff we find a global, we'll propagate that. I think this wasn't considered before because it was assumed that most nodes are under nat / firewall. Another approach for this would be to use a distributed address lookup service (instead of curl centralized.service.ip).
I don't think anything is protecting either libp2p or litep2p here. Litep2p ran into this error because it was waiting for 5 confirmations, instead of eagerly accepting all reported addresses 🤔 |
||
| allow_non_global_addresses: config.allow_non_globals_in_dht, | ||
| public_addresses: config.public_addresses.iter().cloned().map(Into::into).collect(), | ||
| next_kad_query: Some(Delay::new(KADEMLIA_QUERY_INTERVAL)), | ||
|
|
@@ -428,7 +434,7 @@ impl Discovery { | |
| } | ||
|
|
||
| /// Check if `address` can be considered a new external address. | ||
| fn is_new_external_address(&mut self, address: &Multiaddr) -> bool { | ||
| fn is_new_external_address(&mut self, address: &Multiaddr, peer: PeerId) -> bool { | ||
| log::trace!(target: LOG_TARGET, "verify new external address: {address}"); | ||
|
|
||
| // is the address one of our known addresses | ||
|
|
@@ -444,14 +450,14 @@ impl Discovery { | |
|
|
||
| match self.address_confirmations.get(address) { | ||
| Some(confirmations) => { | ||
| *confirmations += 1usize; | ||
| confirmations.insert(peer); | ||
|
|
||
| if *confirmations >= MIN_ADDRESS_CONFIRMATIONS { | ||
| if confirmations.len() >= MIN_ADDRESS_CONFIRMATIONS { | ||
| return true | ||
| } | ||
| }, | ||
| None => { | ||
| self.address_confirmations.insert(address.clone(), 1usize); | ||
| self.address_confirmations.insert(address.clone(), Default::default()); | ||
| }, | ||
| } | ||
|
|
||
|
|
@@ -563,7 +569,7 @@ impl Stream for Discovery { | |
| supported_protocols, | ||
| observed_address, | ||
| })) => { | ||
| if this.is_new_external_address(&observed_address) { | ||
| if this.is_new_external_address(&observed_address, peer) { | ||
| this.pending_events.push_back(DiscoveryEvent::ExternalAddressDiscovered { | ||
| address: observed_address.clone(), | ||
| }); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.