# js-peer-info
**Repository Path**: mirrors_libp2p/js-peer-info
## Basic Information
- **Project Name**: js-peer-info
- **Description**: libp2p Peer abstraction Node.js implementation
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-08-09
- **Last Updated**: 2026-01-03
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
⛔️ DEPRECATED: peer-info is not used anymore in favour of storing this data in the [PeerStore](https://github.com/libp2p/js-libp2p/tree/master/src/peer-store) from [libp2p@0.28.0](https://github.com/libp2p/js-libp2p/releases/tag/v0.28.0).
======
# js-peer-info
[](http://protocol.ai)
[](http://libp2p.io/)
[](http://webchat.freenode.net/?channels=%23libp2p)
[](https://discuss.libp2p.io)
[](https://codecov.io/gh/libp2p/js-peer-info)
[](https://travis-ci.com/libp2p/js-peer-info)
[](https://david-dm.org/libp2p/js-peer-info)
[](https://github.com/feross/standard)


## Lead Maintainer
[Vasco Santos](https://github.com/vasco-santos)
## Table of Contents
- [js-peer-info](#js-peer-info)
- [Lead Maintainer](#lead-maintainer)
- [Table of Contents](#table-of-contents)
- [Installation](#installation)
- [npm](#npm)
- [Node.JS, Browserify, Webpack](#nodejs-browserify-webpack)
- [Browser: `
```
## Usage
```js
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
```js
const PeerInfo = require('peer-info')
```
### `PeerInfo.create([id])`
- `id` optional - can be a PeerId or a JSON object(will be parsed with https://github.com/libp2p/js-peer-id#createfromjsonobj)
Creates a new PeerInfo instance and if no `id` is passed it
generates a new underlying [PeerID](https://github.com/libp2p/js-peer-id)
for it.
Returns `Promise`.
### `new PeerInfo(id)`
- `id: PeerId` - instance of PeerId (optional)
Creates a new PeerInfo instance from an existing PeerId.
### `.id`
The [PeerId](https://github.com/libp2p/js-peer-id) 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](https://github.com/multiformats/js-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](https://github.com/RichardLitt/standard-readme) specification.
## License
[MIT © David Dias](LICENSE)