This event notifies listeners when incoming or outgoing connections are closed.
This event notifies listeners when new incoming or outgoing connections are opened.
This event is dispatched when the connection manager has more than the configured allowable max connections and has closed some connections to bring the node back under the limit.
This event will be triggered any time a new peer connects.
libp2p.addEventListener('peer:connect', (event) => {
const peerId = event.detail
// ...
})
This event will be triggered any time we are disconnected from another peer, regardless of the circumstances of that disconnection. If we happen to have multiple connections to a peer, this event will only be triggered when the last connection is closed.
libp2p.addEventListener('peer:disconnect', (event) => {
const peerId = event.detail
// ...
})
This event is dispatched when a new network peer is discovered.
libp2p.addEventListener('peer:discovery', (event) => {
const peerInfo = event.detail
// ...
})
This event is dispatched after a remote peer has successfully responded to the identify protocol. Note that for this to be emitted, both peers must have an identify service configured.
libp2p.addEventListener('peer:identify', (event) => {
const identifyResult = event.detail
// ...
})
When a peer tagged with keep-alive
disconnects, we will make multiple
attempts to reconnect to it with a backoff factor (see the connection
manager settings for details). If these all fail, the keep-alive
tag will
be removed and this event will be emitted.
libp2p.addEventListener('peer:reconnect-failure', (event) => {
const peerId = event.detail
// ...
})
This event is dispatched when the peer store data for a peer has been updated - e.g. their multiaddrs, protocols etc have changed.
If they were previously known to this node, the old peer data will be
set in the previous
field.
This may be in response to the identify protocol running, a manual update or some other event.
This event is dispatched when the current node's peer record changes - for example a transport started listening on a new address or a new protocol handler was registered.
libp2p.addEventListener('self:peer:update', (event) => {
const { peer } = event.detail
// ...
})
This event notifies listeners that the node has started
libp2p.addEventListener('start', (event) => {
console.info(libp2p.isStarted()) // true
})
This event notifies listeners that the node has stopped
libp2p.addEventListener('stop', (event) => {
console.info(libp2p.isStarted()) // false
})
This event is dispatched when a transport stops listening on an address
This event is dispatched when a transport begins listening on a new address
Once you have a libp2p instance, you can listen to several events it emits, so that you can be notified of relevant network events.
Event names are
noun:verb
so the first part is the name of the object being acted on and the second is the action.