Skip to content
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

feat(dcutr): add ConnectionId to upgrade success/failed events #4558

Merged
merged 15 commits into from
Oct 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions misc/metrics/src/dcutr.rs
Original file line number Diff line number Diff line change
@@ -66,11 +66,13 @@ impl From<&libp2p_dcutr::Event> for EventType {
remote_peer_id: _,
remote_relayed_addr: _,
} => EventType::RemoteInitiatedDirectConnectionUpgrade,
libp2p_dcutr::Event::DirectConnectionUpgradeSucceeded { remote_peer_id: _ } => {
EventType::DirectConnectionUpgradeSucceeded
}
libp2p_dcutr::Event::DirectConnectionUpgradeSucceeded {
remote_peer_id: _,
connection_id: _,
} => EventType::DirectConnectionUpgradeSucceeded,
libp2p_dcutr::Event::DirectConnectionUpgradeFailed {
remote_peer_id: _,
connection_id: _,
error: _,
} => EventType::DirectConnectionUpgradeFailed,
}
4 changes: 4 additions & 0 deletions protocols/dcutr/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 0.11.0 - unreleased

- Add `ConnectionId` to `Event::DirectConnectionUpgradeSucceeded` and `Event::DirectConnectionUpgradeFailed`.
See [PR 4558].

[PR 4558]: https://github.com/libp2p/rust-libp2p/pull/4558

## 0.10.0

6 changes: 6 additions & 0 deletions protocols/dcutr/src/behaviour_impl.rs
Original file line number Diff line number Diff line change
@@ -55,9 +55,11 @@ pub enum Event {
},
DirectConnectionUpgradeSucceeded {
remote_peer_id: PeerId,
connection_id: ConnectionId,
},
DirectConnectionUpgradeFailed {
remote_peer_id: PeerId,
connection_id: ConnectionId,
error: Error,
},
}
@@ -151,6 +153,7 @@ impl Behaviour {
self.queued_events.extend([ToSwarm::GenerateEvent(
Event::DirectConnectionUpgradeFailed {
remote_peer_id: peer_id,
connection_id: failed_direct_connection,
error: Error::Dial,
},
)]);
@@ -263,6 +266,7 @@ impl NetworkBehaviour for Behaviour {
self.queued_events.extend([ToSwarm::GenerateEvent(
Event::DirectConnectionUpgradeSucceeded {
remote_peer_id: peer,
connection_id,
},
)]);
}
@@ -300,6 +304,7 @@ impl NetworkBehaviour for Behaviour {
self.queued_events.push_back(ToSwarm::GenerateEvent(
Event::DirectConnectionUpgradeFailed {
remote_peer_id: event_source,
connection_id,
error: Error::Handler(error),
},
));
@@ -320,6 +325,7 @@ impl NetworkBehaviour for Behaviour {
self.queued_events.push_back(ToSwarm::GenerateEvent(
Event::DirectConnectionUpgradeFailed {
remote_peer_id: event_source,
connection_id: relayed_connection_id,
error: Error::Handler(error),
},
));
28 changes: 21 additions & 7 deletions protocols/dcutr/tests/lib.rs
Original file line number Diff line number Diff line change
@@ -86,13 +86,27 @@ async fn connect() {

let dst_addr = dst_addr.with(Protocol::P2p(dst_peer_id));

src.wait(move |e| match e {
SwarmEvent::ConnectionEstablished { endpoint, .. } => {
(*endpoint.get_remote_address() == dst_addr).then_some(())
}
_ => None,
})
.await;
let established_conn_id = src
.wait(move |e| match e {
SwarmEvent::ConnectionEstablished {
endpoint,
connection_id,
..
} => (*endpoint.get_remote_address() == dst_addr).then_some(connection_id),
_ => None,
})
.await;

let reported_conn_id = src
.wait(move |e| match e {
SwarmEvent::Behaviour(ClientEvent::Dcutr(
dcutr::Event::DirectConnectionUpgradeSucceeded { connection_id, .. },
)) => Some(connection_id),
_ => None,
})
.await;

assert_eq!(established_conn_id, reported_conn_id);
}

fn build_relay() -> Swarm<relay::Behaviour> {