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

feat: add getAddresses function to return detailed address info #387

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
44 changes: 44 additions & 0 deletions packages/interface-libp2p/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,34 @@ export interface PeerUpdate {
previous?: Peer
}

/**
* A address this node knows about
*/
export interface NodeAddress {
/**
* This address as a multiaddr
*/
multiaddr: Multiaddr

/**
* If `true`, this address is advertised to the network via peer records and the
* Identify protocols
*/
announce?: boolean

/**
* If `true`, this address was observed by remote peers and communicated back to
* this node via the AutoNAT protocol
*/
observed?: boolean

/**
* Only set on `observed` addresses - if `true` the node has confidence that this
* address is publicly routable and remote peers can dial it
*/
confidence?: boolean
}

/**
* 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 @@ -404,6 +432,22 @@ export interface Libp2p extends Startable, EventEmitter<Libp2pEvents> {
*/
getMultiaddrs: () => Multiaddr[]

/**
* Returns a list of address this node is listening on and the status
* of those addresses
*
* @example
*
* ```js
* const listenMa = libp2p.getAddresses()
* // [{
* // multiaddr: <Multiaddr 047f00000106f9ba - /ip4/127.0.0.1/tcp/63930>
* // announce: true
* // }]
* ```
*/
getAddresses: () => NodeAddress[]

/**
* Returns a list of supported protocols
*
Expand Down