Skip to content

Commit

Permalink
Adapt libp2p-relay.
Browse files Browse the repository at this point in the history
  • Loading branch information
romanb committed Mar 16, 2021
1 parent b0b9a93 commit efe0960
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 2 additions & 4 deletions protocols/relay/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,12 @@ impl<T: Transport> Stream for RelayListener<T> {
Poll::Ready(Some(BehaviourToListenerMsg::IncomingRelayedConnection {
stream,
src_peer_id,
relay_peer_id,
relay_addr,
relay_peer_id: _
})) => {
return Poll::Ready(Some(Ok(ListenerEvent::Upgrade {
upgrade: RelayedListenerUpgrade::Relayed(Some(stream)),
local_addr: relay_addr
.with(Protocol::P2p(relay_peer_id.into()))
.with(Protocol::P2pCircuit),
local_addr: relay_addr.with(Protocol::P2pCircuit),
remote_addr: Protocol::P2p(src_peer_id.into()).into(),
})));
}
Expand Down
18 changes: 13 additions & 5 deletions protocols/relay/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,10 @@ fn src_try_connect_to_offline_dst() {

loop {
match src_swarm.next_event().await {
SwarmEvent::UnknownPeerUnreachableAddr { address, .. }
SwarmEvent::UnreachableAddr { address, peer_id, .. }
if address == dst_addr_via_relay =>
{
assert_eq!(peer_id, dst_peer_id);
break;
}
SwarmEvent::Behaviour(CombinedEvent::Ping(_)) => {}
Expand Down Expand Up @@ -437,9 +438,10 @@ fn src_try_connect_to_unsupported_dst() {

loop {
match src_swarm.next_event().await {
SwarmEvent::UnknownPeerUnreachableAddr { address, .. }
SwarmEvent::UnreachableAddr { address, peer_id, .. }
if address == dst_addr_via_relay =>
{
assert_eq!(peer_id, dst_peer_id);
break;
}
SwarmEvent::ConnectionClosed { peer_id, .. } if peer_id == relay_peer_id => {}
Expand Down Expand Up @@ -486,8 +488,10 @@ fn src_try_connect_to_offline_dst_via_offline_relay() {

// Source Node fail to reach Destination Node due to failure reaching Relay.
match src_swarm.next_event().await {
SwarmEvent::UnknownPeerUnreachableAddr { address, .. }
if address == dst_addr_via_relay => {}
SwarmEvent::UnreachableAddr { address, peer_id, .. }
if address == dst_addr_via_relay => {
assert_eq!(peer_id, dst_peer_id);
}
e => panic!("{:?}", e),
}
});
Expand Down Expand Up @@ -573,6 +577,9 @@ fn firewalled_src_discover_firewalled_dst_via_kad_and_connect_to_dst_via_routabl
}
}
SwarmEvent::Behaviour(CombinedEvent::Ping(_)) => {}
SwarmEvent::Behaviour(CombinedEvent::Kad(KademliaEvent::RoutingUpdated {
..
})) => {}
e => panic!("{:?}", e),
}
}
Expand Down Expand Up @@ -1005,9 +1012,10 @@ fn yield_incoming_connection_through_correct_listener() {
}

match src_3_swarm.next_event().boxed().poll_unpin(cx) {
Poll::Ready(SwarmEvent::UnknownPeerUnreachableAddr { address, .. })
Poll::Ready(SwarmEvent::UnreachableAddr { address, peer_id, .. })
if address == dst_addr_via_relay_3 =>
{
assert_eq!(peer_id, dst_peer_id);
return Poll::Ready(());
}
Poll::Ready(SwarmEvent::Dialing { .. }) => {}
Expand Down

0 comments on commit efe0960

Please sign in to comment.