libp2p / js-peer-info

libp2p Peer abstraction Node.js implementation
https://libp2p.io
MIT License
37 stars 28 forks source link

feat: add support for multiaddrs on create #76

Closed jacobheun closed 4 years ago

jacobheun commented 5 years ago

This backwards compatible change allows users to seed the multiaddr set with known multiaddrs on PeerInfo creation. This prevents the need to do .add for known addresses.

const peerInfo = new PeerInfo(id)
knownAddrs.forEach((addr) => peerInfo.multiaddrs.add(addr))

and you can instead just do:

const peerInfo = new PeerInfo(id, knownAddrs)

Since the multiaddrs are verified as multiaddrs on creation you can also use an array of strings or buffers.

new PeerInfo(id, [
  '/ip4/0.0.0.0/tcp/0',
  '/ip4/0.0.0.0/tcp/0/ws'
])

Other things