Skip to content

feat(relay): implement autorelay#6156

Open
dariusc93 wants to merge 55 commits into
libp2p:masterfrom
dariusc93:feat/autorelay
Open

feat(relay): implement autorelay#6156
dariusc93 wants to merge 55 commits into
libp2p:masterfrom
dariusc93:feat/autorelay

Conversation

@dariusc93

@dariusc93 dariusc93 commented Sep 2, 2025

Copy link
Copy Markdown
Member

Description

This PR implements a basic autorelay system that would automatically make reservation as soon as it is discovered that the connected node supports HOP protocol.

resolves #4651.

Notes & open questions

Currently, this PR is a PoC, but ideally would be the initial foundation for autorelay implementation. Currently, we will only support making reservation as we discover them, but ideally, we should implement events to notify swarm about no relays available, which would allow the node to perform its own discovery of relays (ie walking DHT, etc), as well as supporting static relays that would have priority or be used in the event of no relays being discovered, although it is all up for discussion to determine what is needed vs wants.

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

Comment thread protocols/relay/CHANGELOG.md Outdated
Comment thread protocols/relay/src/autorelay/handler.rs Outdated
@dariusc93 dariusc93 requested review from elenaf9 and jxs May 17, 2026 00:04
@@ -0,0 +1,135 @@
use std::{error::Error, num::NonZeroU8};

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Wasnt sure if I shouldve added this to dcutr example or have it as a separate example, but I decided to have it separate for now.

Comment thread protocols/relay/src/autorelay.rs Outdated
};
self.events.push_back(ToSwarm::NotifyHandler {
peer_id,
handler: NotifyHandler::One(connection_id),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Only "blacklisting" a single connection instead of multiple connections made to the peer. Open to changing it though.

Comment thread protocols/relay/src/autorelay.rs Outdated
return;
}

if let Some((peer_id, connection_id)) = self.reservations.get(&listener_id).copied()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I wonder if we should also store any new reservation that been established outside of auto relay. Thoughts?

Comment thread protocols/relay/CHANGELOG.md Outdated
@dariusc93 dariusc93 marked this pull request as draft May 21, 2026 12:49
@dariusc93 dariusc93 marked this pull request as ready for review June 4, 2026 13:19
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.

auto-relay: automatically make reservations on relays as we discover them

1 participant