Skip to content

Commit

Permalink
fix(iroh-net): reduce noise in swarm discovery due to republish (#2685)
Browse files Browse the repository at this point in the history
## Description

Since republish occurs more or less every second, for every peer in the
local network, every second we insert it in the node_map (which includes
locking), print a debug line, and for requesters, re-send a value that
was previously sent (since every time a new sender is added we
immediately send known values). This pr makes it so that we do all this
only when new values are found.

## Breaking Changes

- swarm discovery will no longer send consecutive repeated values

## Notes & open questions

the typo is unrelated to the pr but was flagged by ci

## Change checklist

- [x] Self-review.
- [ ] ~~Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.~~
- [ ] ~~Tests if relevant.~~
- [x] All breaking changes documented.
  • Loading branch information
divagant-martian authored Sep 2, 2024
1 parent 6296964 commit fd56763
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion iroh-blobs/src/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ impl Downloader {
}
}

/// Declare that certains nodes can be used to download a hash.
/// Declare that certain nodes can be used to download a hash.
///
/// Note that this does not start a download, but only provides new nodes to already queued
/// downloads. Use [`Self::queue`] to queue a download.
Expand Down
21 changes: 15 additions & 6 deletions iroh-net/src/discovery/local_swarm_discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,28 @@ impl LocalSwarmDiscovery {
continue;
}

if let Some(senders) = senders.get(&discovered_node_id) {
for sender in senders.values() {
let item: DiscoveryItem = (&peer_info).into();
trace!(?item, "sending DiscoveryItem");
sender.send(Ok(item)).await.ok();
let entry = node_addrs.entry(discovered_node_id);
if let std::collections::hash_map::Entry::Occupied(ref entry) = entry {
if entry.get() == &peer_info {
// this is a republish we already know about
continue;
}
}

debug!(
?discovered_node_id,
?peer_info,
"adding node to LocalSwarmDiscovery address book"
);
node_addrs.insert(discovered_node_id, peer_info);

if let Some(senders) = senders.get(&discovered_node_id) {
let item: DiscoveryItem = (&peer_info).into();
trace!(?item, senders = senders.len(), "sending DiscoveryItem");
for sender in senders.values() {
sender.send(Ok(item.clone())).await.ok();
}
}
entry.or_insert(peer_info);
}
Message::SendAddrs(node_id, sender) => {
let id = last_id + 1;
Expand Down

0 comments on commit fd56763

Please sign in to comment.