You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

peer-info

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

peer-info

IPFS Peer abstraction JavaScript implementation


Version published
Weekly downloads
4.3K
decreased by-46.81%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

0.7.1 (2016-09-07)

Bug Fixes

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

<a name="0.7.0"></a>

Readme

Source

peer-info JavaScript implementation

Build Status Coverage Status Dependency Status js-standard-style

A PeerInfo object contains information about a PeerID and its multiaddrs. This module is used by IPFS and libp2p.

Example

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

const peer = new PeerInfo()

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

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

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

API

const PeerInfo = require('peer-info')

const peer = new PeerInfo()

Creates a new PeerInfo instance and also generates a new underlying PeerID for it.

const peer = new PeerInfo(peerId)

Creates a new PeerInfo instance from an existing PeerID.

peer.multiaddrs

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

peer.multiaddr.add(addr)

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

peer.multiaddr.addSafe(addr)

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).

peer.multiaddr.rm(addr)

Removes a multiaddress instance addr from peer.

peer.multiaddr.replace(existing, fresh)

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

Installation

npm

> npm i peer-info

Node.JS, Browserify, Webpack

var 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://npmcdn.com/peer-info/dist/index.min.js"></script>
<!-- OR -->
<script src="https://npmcdn.com/peer-info/dist/index.js"></script>

License

MIT

Keywords

FAQs

Package last updated on 07 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc