Skip to content

libp2p-stream: open a stream with an explict connection_id #6358

@Heap-Hop

Description

@Heap-Hop

Description

Currently, the stream is opened randomly on connections.

It would be great to allow callers to open a stream on an explicit connection ID.

Motivation

For instance, when opening a stream, you can choose to prefer direct connections or relay connections.

Requirements

Add a method like

pub async fn open_stream_on_connection(
        &mut self,
        peer: PeerId,
        connection: ConnectionId,
        protocol: StreamProtocol,
    ) -> Result<Stream, OpenStreamError>

ConnectionId is enough because the caller can maintain a ConnectionId <-> Connection state map of its own.

Open questions

Actually, I’ve implemented one for my project (with AI):

Heap-Hop@b5c6bd0

It works fine on my project fungi.

I'm not sure it is a necessary feature for rust-libp2p.

If it’s done correctly, I’d love to open a PR.
If not, and there’s a better way to achieve the same result, please let me know.

Furthermore, it would be great if the listener side could add a method like accept_with_id that also provides the connection ID for new streams.

Are you planning to do it yourself in a pull request?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions