Skip to content

Commit

Permalink
feat(relay): emit ReservationClosed event when all the client connect…
Browse files Browse the repository at this point in the history
…ions are dropped
  • Loading branch information
RolandSherwin committed Feb 25, 2025
1 parent 1c9b3ca commit 8fc7efe
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ libp2p-ping = { version = "0.46.0", path = "protocols/ping" }
libp2p-plaintext = { version = "0.43.0", path = "transports/plaintext" }
libp2p-pnet = { version = "0.26.0", path = "transports/pnet" }
libp2p-quic = { version = "0.12.0", path = "transports/quic" }
libp2p-relay = { version = "0.19.1", path = "protocols/relay" }
libp2p-relay = { version = "0.20.0", path = "protocols/relay" }
libp2p-rendezvous = { version = "0.16.0", path = "protocols/rendezvous" }
libp2p-request-response = { version = "0.28.1", path = "protocols/request-response" }
libp2p-server = { version = "0.12.6", path = "misc/server" }
Expand Down
2 changes: 2 additions & 0 deletions misc/metrics/src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ enum EventType {
ReservationReqAcceptFailed,
ReservationReqDenied,
ReservationReqDenyFailed,
ReservationClosed,
ReservationTimedOut,
CircuitReqDenied,
CircuitReqDenyFailed,
Expand All @@ -76,6 +77,7 @@ impl From<&libp2p_relay::Event> for EventType {
libp2p_relay::Event::ReservationReqDenyFailed { .. } => {
EventType::ReservationReqDenyFailed
}
libp2p_relay::Event::ReservationClosed { .. } => EventType::ReservationClosed,
libp2p_relay::Event::ReservationTimedOut { .. } => EventType::ReservationTimedOut,
libp2p_relay::Event::CircuitReqDenied { .. } => EventType::CircuitReqDenied,
#[allow(deprecated)]
Expand Down
4 changes: 4 additions & 0 deletions protocols/relay/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.20.0

- Emit `relay::Event::ReservationClosed` when an active reservation is dropped due to the connection closing.

## 0.19.1

- Remove duplicated forwarding of pending events to connection handler.
Expand Down
2 changes: 1 addition & 1 deletion protocols/relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-relay"
edition = "2021"
rust-version = { workspace = true }
description = "Communications relaying for libp2p"
version = "0.19.1"
version = "0.20.0"
authors = ["Parity Technologies <admin@parity.io>", "Max Inden <mail@max-inden.de>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
9 changes: 8 additions & 1 deletion protocols/relay/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ pub enum Event {
src_peer_id: PeerId,
error: inbound_hop::Error,
},
/// A reservation has been closed.
ReservationClosed { src_peer_id: PeerId },
/// An inbound reservation has timed out.
ReservationTimedOut { src_peer_id: PeerId },
/// An inbound circuit request has been denied.
Expand Down Expand Up @@ -277,7 +279,12 @@ impl Behaviour {
}: ConnectionClosed,
) {
if let hash_map::Entry::Occupied(mut peer) = self.reservations.entry(peer_id) {
peer.get_mut().remove(&connection_id);
if peer.get_mut().remove(&connection_id) {
self.queued_actions
.push_back(ToSwarm::GenerateEvent(Event::ReservationClosed {
src_peer_id: peer_id,
}));
}
if peer.get().is_empty() {
peer.remove();
}
Expand Down

0 comments on commit 8fc7efe

Please sign in to comment.