Skip to content

Add dialBest to the API #376

Closed
Closed
@vasco-santos

Description

@vasco-santos

Type: Feature

Severity: N/A

Description:

There are use cases where we want to leverage libp2p to dial other peers using a specific protocol, but fallback to another one if that peer does not support the initial attempt. With the current API we need to do a cascade of dials, in order to do this, while libp2p could offer this in its API.

One example of this is in the Gossipsub implementation ChainSafe/gossipsub-js#34, where we intend to fallback to floodsubs if the peer does not support gossipsub.

We should have a utility to handle multi protocol negotiation, receiving a list of protocols and trying to dial by its order. An example could be:

const protocolPreferences = [gossipsubMulticodec, floodsubMulticodec]
libp2p.newStream(peerInfo, protocolPreferences, callback)
// or
libp2p.dialBest(peerInfo, protocolPreferences, callback)

This was discussed with @jacobheun in the Gossipsub PR

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