Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

feat: add peer:identify event to libp2p #395

Merged
merged 2 commits into from
May 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 75 additions & 2 deletions packages/interface-libp2p/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,63 @@ export interface PeerUpdate {
previous?: Peer
}

/**
* Peer data signed by the remote Peer's public key
*/
export interface SignedPeerRecord {
addresses: Multiaddr[]
seq: bigint
}

/**
* Data returned from a successful identify response
*/
export interface IdentifyResult {
/**
* The remote Peer's PeerId
*/
peerId: PeerId

/**
* The unsigned addresses they are listening on. Note - any multiaddrs present
* in the signed peer record should be preferred to the value here.
*/
listenAddrs: Multiaddr[]

/**
* The protocols the remote peer supports
*/
protocols: string[]

/**
* The remote protocol version
*/
protocolVersion?: string

/**
* The remote agent version
*/
agentVersion?: string

/**
* The public key part of the remote PeerId - this is only useful for older
* RSA-based PeerIds, the more modern Ed25519 and secp256k1 types have the
* public key embedded in them
*/
publicKey?: Uint8Array

/**
* If set this is the address that the remote peer saw the identify request
* originate from
*/
observedAddr?: Multiaddr

/**
* If sent by the remote peer this is the deserialized signed peer record
*/
signedPeerRecord?: SignedPeerRecord
}

/**
* Once you have a libp2p instance, you can listen to several events it emits,
* so that you can be notified of relevant network events.
Expand Down Expand Up @@ -72,7 +129,7 @@ export interface Libp2pEvents {
* @example
*
* ```js
* libp2p.connectionManager.addEventListener('peer:connect', (event) => {
* libp2p.addEventListener('peer:connect', (event) => {
* const peerId = event.detail
* // ...
* })
Expand All @@ -88,14 +145,30 @@ export interface Libp2pEvents {
* @example
*
* ```js
* libp2p.connectionManager.addEventListener('peer:disconnect', (event) => {
* libp2p.addEventListener('peer:disconnect', (event) => {
* const peerId = event.detail
* // ...
* })
* ```
*/
'peer:disconnect': CustomEvent<PeerId>

/**
* 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.
*
* @example
*
* ```js
* libp2p.addEventListener('peer:identify', (event) => {
* const identifyResult = event.detail
* // ...
* })
* ```
*/
'peer:identify': CustomEvent<IdentifyResult>

/**
* This event is dispatched when the peer store data for a peer has been
* updated - e.g. their multiaddrs, protocols etc have changed.
Expand Down