Skip to content

Commit

Permalink
feat: resolve relayed dial on the first connection
Browse files Browse the repository at this point in the history
  • Loading branch information
fbozic committed May 17, 2024
1 parent e65ea66 commit 50835d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions examples/chat/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl EventLoop {
let _ = sender.send(Ok(None));
}
hash_map::Entry::Vacant(entry) => {
match self.swarm.dial(peer_addr.clone()) {
match self.swarm.dial(peer_addr) {
Ok(_) => {
entry.insert(sender);
}
Expand Down Expand Up @@ -392,12 +392,13 @@ impl TryFrom<&Multiaddr> for MultiaddrMeta {
}
}

match peer_ids.len() {
0 => Err("expected at least one p2p proto"),
_ => Ok(Self {
peer_id: peer_ids[peer_ids.len() - 1],
relay_peer_ids: peer_ids[0..peer_ids.len() - 1].to_vec(),
}),
if let Some(peer_id) = peer_ids.pop() {
Ok(Self {
peer_id,
relay_peer_ids: peer_ids,
})
} else {
Err("expected at least one p2p proto")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/chat/src/network/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl EventLoop {
SwarmEvent::ConnectionEstablished {
peer_id, endpoint, ..
} => {
debug!(peer=%peer_id, ?endpoint, "Connection established");
debug!(%peer_id, ?endpoint, "Connection established");
match endpoint {
libp2p::core::ConnectedPoint::Dialer { address, .. } => {
let addr_meta = match MultiaddrMeta::try_from(&address) {
Expand All @@ -56,7 +56,7 @@ impl EventLoop {
};

if addr_meta.is_relayed() {
return;
debug!("Connection established via relay");
}

if let Some(sender) = self.pending_dial.remove(&peer_id) {
Expand Down

0 comments on commit 50835d3

Please sign in to comment.