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(relay): emit event when all client connections are dropped #5869

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

RolandSherwin
Copy link

Description

When a relay server has no more connection with a reserved client, it would remove the reservation and the drop the circuits without any information passed to the server. It will be useful to for a server to track all its reservations and to know when they're removed (without keeping track of the connections themselves).

This PR aims to notify the server when a reservation closes, with the emission of the following event

    /// A reservation has been closed.
    ReservationClosed { src_peer_id: PeerId },

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

@RolandSherwin RolandSherwin force-pushed the close_reservation_on_zero_conn branch from 61d5841 to 7f11002 Compare February 18, 2025 14:38
@RolandSherwin RolandSherwin force-pushed the close_reservation_on_zero_conn branch from 7f11002 to 1664632 Compare February 18, 2025 14:39
Comment on lines 282 to 289
peer.get_mut().remove(&connection_id);
if peer.get().is_empty() {
peer.remove();
self.queued_actions
.push_back(ToSwarm::GenerateEvent(Event::ReservationClosed {
src_peer_id: peer_id,
}));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
peer.get_mut().remove(&connection_id);
if peer.get().is_empty() {
peer.remove();
self.queued_actions
.push_back(ToSwarm::GenerateEvent(Event::ReservationClosed {
src_peer_id: peer_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();
}

We may have multiple connections to a peer, so we should emit the event when a connection closes for which we have an active reservation.

Maybe it also makes sense to include the connection id in the event?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Additionally, we should also include the connection id of which we had the reservation since there may be multiple reservation to a peer with different connections.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it complete, the other events should also have connection IDs: ReservationReqAccepted, ReservationReqDenied and ReservationTimedOut.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we keep the ReservationClosed variant without the connection-id in this PR, and do a separate one that adds it for all of the mentioned variants (and discuss there if we want to in the first place)? That way it's consistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants