0.17.5 • Published 4 years ago

peer-info v0.17.5

Weekly downloads
7,735
License
MIT
Repository
github
Last release
4 years ago

js-peer-info

npm.io npm.io npm.io Discourse posts npm.io npm.io Dependency Status js-standard-style npm.io npm.io

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

@apato/tupelo-wasm-sdkcyber-baseenigma-p2p@daocasino/mock-ipfs@everything-registry/sub-chunk-2423@dtubenetwork/cmdsignal@dstack-js/transporttupelo-wasm-sdkzero-sdkzeronet-nodetrustzeronet-relayzeronet-swarmzeronet-ziteutquosvitaerecusandaezeroflash-protocol@haad/ipfs-api@infinitebrahmanuniverse/nolb-pee@gny/cliocrio-ipfs-http-clientdoloremquiarepudiandaedoloressimiliquedolorumsinteumsitaperiam@casto/sdk@gnyio/climurmur-clientmoonshard_corenode-red-contrib-ipfsapinode-red-ipfstestpangea-clipeer-star-apppeer-basepeer-bookdisco-serverpulsarcastpeersafe-ipfspeersafe-pdfsperferendisautem@michaelmure/ipfs-api@nger/magnus@pintswap/sdk@ocario/ipfs-http-client@polkadot/client-p2pethereumjs-clientjanus-betaipfs-vueipfs-ci-testipfs-apiipfs-api-with-timeoutsipfs-postmsg-proxyipfs-hd@idn/util-peer@idn/identity@idn/libp2p-webrtc-star@jimpick/peer-star-app@jimpick/peer-star-app-staging@jimpick/ipfs@jimpick/is-peer-pad-fast-yet-pinner@jimpick/libp2p@metabin/shareds2ims-p2peaquererumims-cliinciduntlaboriosamjs-libp2p-pstn-node@0confirmation/p2p@0confirmation/sdkleofcoinlibp2p-railinglibp2p-rpclibp2p-signalhublibp2p-simplelibp2p-stardustlibp2p-swarmlibp2p-switchlibp2p-circuitlibp2p-gossip-discoverylibp2p-identifylibp2p-ipfslibp2p-mdns-discoverylibp2p-pstn-nodelibp2p-pstnlibp2p-websocket-starlibp2p-websocket-star-rendezvouslibp2p-websocket-star-signallibp2p-ipfs-browserlibp2p-ipfs-nodejsaegir-test-repo@arve.knudsen/libp2p-daemon-clientaleph@zerodao/keeper@zerodao/p2p@zerodao/protocol@zippie/ipfs-postmsg-proxygossip-cyclon
0.17.5

4 years ago

0.17.4

4 years ago

0.17.3

4 years ago

0.17.2

4 years ago

0.17.1

4 years ago

0.17.0

5 years ago

0.16.2

5 years ago

0.16.1

5 years ago

0.16.0

5 years ago

0.15.1

5 years ago

0.15.0

5 years ago

0.14.1

6 years ago

0.14.0

6 years ago

0.11.6

6 years ago

0.11.4

6 years ago

0.11.3

6 years ago

0.11.1

6 years ago

0.11.0

7 years ago

0.10.0

7 years ago

0.9.4

7 years ago

0.9.3

7 years ago

0.9.2

7 years ago

0.9.1

7 years ago

0.9.0

7 years ago

0.8.5

7 years ago

0.8.4

7 years ago

0.8.3

7 years ago

0.8.2

7 years ago

0.8.1

7 years ago

0.8.0

7 years ago

0.7.1

8 years ago

0.7.0

8 years ago

0.6.2

8 years ago

0.6.1

8 years ago

0.6.0

8 years ago

0.5.2

8 years ago

0.5.1

8 years ago

0.5.0

8 years ago

0.4.0

8 years ago

0.3.3

9 years ago

0.3.2

9 years ago