-
Notifications
You must be signed in to change notification settings - Fork 454
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
libp2p events #1574
Comments
Great idea @achingbrain this would be very helpful, I would also add the following to this list:
@wemeetagain can you think of other events that might be useful? |
We may not need a |
More events would definitely be nice. Would be nice for the success events to include as much relevant data as possible. Eg: have identify:success also emit the As far as being a substitute to access to the underlying implementation, I disagree that it works for all cases. For example, Lodestar currently inspects the dialer to avoid redialing peers with pending dials. This ensures we dial enough peers with the right properties and don't underdial. We could track the libp2p dial/dial:success/dial:error events and build our own map of pending dials. For us, the tradeoffs pretty clearly point to us doing something like this: function isPending(libp2p: Libp2p, peerIdStr: string): boolean {
return (libp2p as unknown as {dialer: DefaultDialer}).dialer.pendingDials.has(peerIdStr);
} rather than something like this: class PendingDialTracker {
public pendingDials = new Set<string>()
libp2p: Libp2p
constructor(libp2p: Libp2p) {
this.libp2p = libp2p
this.libp2p.addEventListener('peer:dial', this.onPeerDial)
this.libp2p.addEventListener('peer:dial:success', this.onPeerDialFinish)
this.libp2p.addEventListener('peer:dial:error', this.onPeerDialFinish)
}
close() {
this.libp2p.removeEventListener('peer:dial', this.onPeerDial)
this.libp2p.removeEventListener('peer:dial:success', this.onPeerDialFinish)
this.libp2p.removeEventListener('peer:dial:error', this.onPeerDialFinish)
}
onPeerDial = (peerId: PeerId) => {
this.pendingDials.add(peerId.toString())
}
onPeerDialFinish = (peerId: PeerId) => {
this.pendingDials.delete(peerId.toString())
}
} |
As discussed with @achingbrain we could structure these events as Progress Events which would allow us to create union types that represent a variety of custom events that are emitted from a particular Libp2p process at various stages in it's progress. We can begin working on this once ipfs/helia-ipns#1 is merged and we see how performant this is. |
The problem with that particular The properties, things like The progress events used by |
Adds an event emitter as a libp2p component that will echo every emitted event on the main libp2p object. Fixes #1574
Send DHT query events to the onProgress callback if one is passed to allow operation-specific progress events to pass up the stack. Refs: libp2p/js-libp2p#1574
Send DHT query events to the onProgress callback if one is passed to allow operation-specific progress events to pass up the stack. Refs: libp2p/js-libp2p#1574
Allow passing an `onProgress` callback to the peer/content routers that can receive DHT query events. Refs #1574
Allow passing an `onProgress` callback to the peer/content routers that can receive DHT query events. Refs #1574
The
libp2p
object returned from createLibp2p is an EventTarget that emits a few different events.These events are really useful for observing the inner workings of libp2p without having to tie your code to the internal structure of libp2p.
They also open the door to real-time monitoring of libp2p with better observability and debugging possibilities.
The event list should be expanded to encompass more events. Some (non-exhausive) suggestions:
peer:dial
- when we dial a peer, the event should hold the peer id and which multiaddrs are being dialledpeer:dial:success
- the event should hold the peer id and the multiaddr that succeededpeer:dial:error
- the event should hold the peer id and the multiaddr that failed and anError
objectidentify:success
- the identify protocol competed for a peer - the event should hold the peer ididentify:error
- the identify protocol failed for a peer - the event should hold the peer id and anError
objectidentify:push:success
- the identify push protocol competed for a peer - the event should hold the peer ididentify:push:error
- the identify push protocol failed for a peer - the event should hold the peer id and anError
objectconnection:prune
- we pruned a connection, the event should have the peer id of the connection that was closedconnection:upgrade
- a connection was upgraded, the event should have the connection that was upgradedIt would be good to establish a naming convention for events, the above hasn't had a whole lot of thought applied to it.
The text was updated successfully, but these errors were encountered: