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

Triggering protocol once identify is done #908

Closed
D4nte opened this issue Apr 14, 2021 · 2 comments
Closed

Triggering protocol once identify is done #908

D4nte opened this issue Apr 14, 2021 · 2 comments

Comments

@D4nte
Copy link
Contributor

D4nte commented Apr 14, 2021

Type: Question/Feature

Severity: Medium

Description:

When Alice connects to a peer that support protocol /foo/1.0.0, Alice wants to automatically initiate the message request for said protocol.

Alice dials Bob, once done, Alice triggers the identify protocol with Bob.
Until the identify protocol is done, Alice does not know what protocol Bob implements.
On Alice side, there is no event emitted once the identify protocol is done.
All we can do is check that Alice's peerStore now contains Bob's protocols.

I would like to propose emitting an event peer:identify once the identify protocol is done and the peer's protocols are now.

Please let me know your thought, am I missing a more obvious solution to my issue?

@vasco-santos vasco-santos added the need/author-input Needs input from the original author label Apr 14, 2021
@vasco-santos
Copy link
Member

vasco-santos commented Apr 14, 2021

Hello @D4nte
Once your peer establishes a connection with another peer and the identify protocol finishes, the peer protocols are stored in the Protobook. You can listen for these changes:

libp2p.peerStore.on('change:protocols', ({ peerId, protocols}) => {
  if (protocols.includes('/foo/1.0.0') { }
})

I believe this solves your solution. Please let me know

@D4nte
Copy link
Contributor Author

D4nte commented Apr 15, 2021

Indeed, I missed this one. Thanks!

@D4nte D4nte closed this as completed Apr 15, 2021
@vasco-santos vasco-santos removed the need/author-input Needs input from the original author label Apr 16, 2021
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

2 participants