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

Add dialBest to the API #376

Closed
vasco-santos opened this issue Jul 10, 2019 · 3 comments
Closed

Add dialBest to the API #376

vasco-santos opened this issue Jul 10, 2019 · 3 comments

Comments

@vasco-santos
Copy link
Member

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

@dirkmc
Copy link
Contributor

dirkmc commented Jul 10, 2019

Sounds like a good improvement to me 👍

Should this just be an option on the dialProtocol() method? ie clients would specify either a string or an array as the second argument

@vasco-santos
Copy link
Member Author

vasco-santos commented Jul 10, 2019

We could support an array of protocols, but in these type of APIs I usually prefer to be more specific. The naming would not suit greatly receiving an array.

Unless we add an option for fallbackProtocols

@wemeetagain
Copy link
Member

dialProtocol accepts an array of protocols

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

No branches or pull requests

3 participants