Skip to content

Commit

Permalink
fix(iroh-docs): do not dial invalid peers (#2470)
Browse files Browse the repository at this point in the history
## Description

<!-- A summary of what this pull request achieves and a rough list of
changes. -->

## Breaking Changes

<!-- Optional, if there are any breaking changes document them,
including how to migrate older code. -->

## Notes & open questions

<!-- Any notes, remarks or open questions you have to make about the PR.
-->

## Change checklist

- [ ] 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.
- [ ] All breaking changes documented.

---------

Co-authored-by: Franz Heinzmann (Frando) <[email protected]>
  • Loading branch information
dignifiedquire and Frando authored Jul 15, 2024
1 parent ecfbed3 commit 7579caa
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions iroh-docs/src/engine/live.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,24 @@ impl<B: iroh_blobs::store::Store> LiveActor<B> {
namespace: NamespaceId,
peers: Vec<NodeAddr>,
) -> anyhow::Result<()> {
let peer_ids: Vec<PublicKey> = peers.iter().map(|p| p.node_id).collect();
let mut peer_ids = Vec::new();

// add addresses of peers to our endpoint address book
for peer in peers.into_iter() {
let peer_id = peer.node_id;
if let Err(err) = self.endpoint.add_node_addr_with_source(peer, SOURCE_NAME) {
warn!(peer = %peer_id.fmt_short(), "failed to add known addrs: {err:?}");
// adding a node address without any addressing info fails with an error,
// but we still want to include those peers because node discovery might find addresses for them
if peer.info.is_empty() {
peer_ids.push(peer_id)
} else {
match self.endpoint.add_node_addr_with_source(peer, SOURCE_NAME) {
Ok(()) => {
peer_ids.push(peer_id);
}
Err(err) => {
warn!(peer = %peer_id.fmt_short(), "failed to add known addrs: {err:?}");
}
}
}
}

Expand All @@ -465,9 +476,11 @@ impl<B: iroh_blobs::store::Store> LiveActor<B> {
})
.await?;

// trigger initial sync with initial peers
for peer in peer_ids {
self.sync_with_peer(namespace, peer, SyncReason::DirectJoin);
if !peer_ids.is_empty() {
// trigger initial sync with initial peers
for peer in peer_ids {
self.sync_with_peer(namespace, peer, SyncReason::DirectJoin);
}
}
Ok(())
}
Expand Down

0 comments on commit 7579caa

Please sign in to comment.