Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

peer-info

libp2p38.7kMITdeprecated0.17.5TypeScript support: included

No longer supported for js-libp2p0.28.0 or later

IPFS Peer abstraction JavaScript implementation

IPFS

readme

js-peer-info

Discourse posts Dependency Status js-standard-style

Lead Maintainer

Vasco Santos

Table of Contents

Installation

npm

> npm i peer-info

Node.JS, Browserify, Webpack

const PeerInfo = require('peer-info')

Browser: <script> Tag

Loading this module through a script tag will make the PeerInfo obj available in the global namespace.

<script src="https://unpkg.com/peer-info/dist/index.min.js"></script>
<!-- OR -->
<script src="https://unpkg.com/peer-info/dist/index.js"></script>

Usage

const PeerInfo = require('peer-info')
const peer = new PeerInfo()

// TCP port 5001
peer.multiaddrs.add('/ip4/1.2.3.4/tcp/5001')

// UDP port 8001
peer.multiaddrs.add('/ip4/1.2.3.4/udp/8001')

// mic/speaker soundwaves using frequencies 697 and 1209
peer.multiaddrs.add('/sonic/bfsk/697/1209')

API

const PeerInfo = require('peer-info')

PeerInfo.create([id])

Creates a new PeerInfo instance and if no id is passed it generates a new underlying PeerID for it.

Returns Promise<PeerInfo>.

new PeerInfo(id)

  • id: PeerId - instance of PeerId (optional)

Creates a new PeerInfo instance from an existing PeerId.

.id

The PeerId of the peer this info relates to.

protocols

A list of protocols that peer supports.

.protocols.add(protocol)

Adds a protocol that peer can support. protocol is a string.

.protocols.delete(protocol)

Removes a protocol that peer no longer supports. protocol is a string.

.multiaddrs

A list of multiaddresses instances that peer can be reached at.

.multiaddrs.add(addr)

  • addr: Multiaddr

Adds a new multiaddress that peer can be reached at. addr is an instance of a multiaddr.

.multiaddrs.addSafe(addr)

  • addr: Multiaddr

The addSafe call, in comparison to add, will only add the multiaddr to multiaddrs if the same multiaddr tries to be added twice.

This is a simple mechanism to prevent multiaddrs from becoming bloated with unusable addresses, which happens when we exchange observed multiaddrs with peers which will not provide a useful multiaddr to be shared to the rest of the network (e.g. a multiaddr referring to a peer inside a LAN being shared to the outside world).

.multiaddrs.delete(addr)

  • addr: Multiaddr

Removes a multiaddress instance addr from peer.

.multiaddrs.replace(existing, fresh)

  • existing: Multiaddr
  • fresh: Multiaddr

Removes the array of multiaddresses existing from peer, and adds the array of multiaddresses fresh.

.connect(ma)

Records the given multiaddr, ma as the active multiaddr of the peer.

  • ma: Multiaddr

.disconnect()

Removes the existing connected Multiaddr from tracking.

.isConnected()

Returns true if a connected Multiaddr exists, otherwise returns false.

Contribute

PRs accepted.

Small note: If editing the Readme, please conform to the standard-readme specification.

License

MIT © David Dias

changelog

0.17.5 (2020-02-19)

0.17.4 (2020-02-17)

0.17.3 (2020-02-13)

Bug Fixes

0.17.2 (2020-02-11)

0.17.1 (2020-01-02)

0.17.0 (2019-09-19)

0.16.2 (2019-09-19)

0.16.1 (2019-09-11)

Features

BREAKING CHANGES

  • API refactored to use async/await

chore: update node version fix: better verifications on create() chore: deps and linting

0.16.0 (2019-07-12)

Features

BREAKING CHANGES

  • API refactored to use async/await

chore: update node version fix: better verifications on create() chore: deps and linting

0.15.1 (2019-01-09)

Features

  • clean repo and bundle size reduction (350103f)

0.15.0 (2018-11-29)

0.14.1 (2018-04-09)

Features

  • add filter functionality for multiaddr (#63) (0dc8e03)

0.14.0 (2018-04-05)

0.13.0 (2018-04-05)

0.12.0 (2018-04-05)

0.11.6 (2018-01-28)

0.11.5 (2018-01-28)

0.11.4 (2017-12-14)

Features

  • support PeerInfo.create(IdJSON, cb) as well (#61) (5b8b160)

0.11.3 (2017-12-01)

0.11.2 (2017-12-01)

0.11.1 (2017-11-09)

0.11.0 (2017-09-03)

Features

0.10.0 (2017-07-22)

0.9.4 (2017-07-21)

0.9.3 (2017-07-09)

0.9.2 (2017-03-31)

Features

  • loose connect a bit for websockets in the browser (c4e9902)

0.9.1 (2017-03-31)

Features

  • return the multiaddr in isConnected - usefulness (a0a06d1)

0.9.0 (2017-03-30)

Features

0.8.5 (2017-03-27)

0.8.4 (2017-03-16)

0.8.3 (2017-02-09)

0.8.2 (2016-12-25)

Bug Fixes

  • package: add missing lodash.uniqby dependency. (9304328)

0.8.1 (2016-11-22)

0.8.0 (2016-11-03)

0.7.1 (2016-09-07)

Bug Fixes

  • ensure all addresses are multiaddr (2cfac63)
  • deps: remove superfluous multiaddr dependency, update it to latest (2a27346)

0.7.0 (2016-05-26)

Bug Fixes

  • use forge bundle for libp2p-crypto (76c3495)

0.6.2 (2016-04-19)

Bug Fixes

0.6.1 (2016-04-12)

0.6.0 (2016-03-10)

0.5.2 (2016-03-04)

0.5.1 (2016-03-04)

0.5.0 (2016-03-04)

0.4.0 (2015-11-06)

0.3.3 (2015-10-28)

0.3.2 (2015-09-15)

0.3.1 (2015-09-14)

0.3.0 (2015-07-19)

0.2.0 (2015-07-19)

0.1.0 (2015-07-08)