# eth-peer-info

> IPFS Peer abstraction JavaScript implementation

Latest version **0.0.2** (published 2019-05-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install eth-peer-info
pnpm add eth-peer-info
yarn add eth-peer-info
bun add eth-peer-info
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2019-05-03 |
| First published | 2019-05-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10.0.0 |
| Dependencies | 4 |
| Unpacked size | 17.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | d1ll0n |
| Keywords | IPFS |

## Links

- npm: https://www.npmjs.com/package/eth-peer-info
- Repository: https://github.com/d1ll0n/eth-peer-info
- Issues: https://github.com/d1ll0n/eth-peer-info/issues
- npm.io page: https://npm.io/package/eth-peer-info

## Dependencies (4)

- [mafmt](https://npm.io/package/mafmt.md) ^6.0.7
- [multiaddr](https://npm.io/package/multiaddr.md) ^6.0.6
- [unique-by](https://npm.io/package/unique-by.md) ^1.0.0
- [eth-peer-id](https://npm.io/package/eth-peer-id.md) 0.0.2

## Recent versions

- 0.0.2 (latest) — 2019-05-03
- 0.0.1 — 2019-05-03

## README

# js-peer-info

> Fork of [peer-info](https://github.com/libp2p/js-peer-info/) using eth-peer-id.

## Lead Maintainer

[Dillon Kellar](https://github.com/d1ll0n)

## 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: `<script>` Tag](#browser-script-tag)
  - [Usage](#usage)
  - [API](#api)
    - [`PeerInfo.create([id, ] callback)`](#peerinfocreateid--callback)
    - [`new PeerInfo(id)`](#new-peerinfoid)
    - [`protocols`](#protocols)
    - [`.protocols.add(protocol)`](#protocolsaddprotocol)
    - [`.protocols.delete(protocol)`](#protocolsdeleteprotocol)
    - [`multiaddrs`](#multiaddrs)
    - [`.multiaddrs.add(addr)`](#multiaddrsaddaddr)
    - [`.multiaddrs.addSafe(addr)`](#multiaddrsaddsafeaddr)
    - [`.multiaddrs.delete(addr)`](#multiaddrsdeleteaddr)
    - [`.multiaddrs.replace(existing, fresh)`](#multiaddrsreplaceexisting-fresh)
  - [Contribute](#contribute)
  - [License](#license)

## Installation

### npm

```sh
> npm i peer-info
```

### Node.JS, Browserify, Webpack

```js
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.

```html
<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

```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, ] callback)`

- `id` optional - can be a PeerId or a JSON object(will be parsed with https://github.com/libp2p/js-peer-id#createfromjsonobj) 
- `callback: Function` with signature `function (err, peerInfo) {}`

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.

### `new PeerInfo(id)`

- `id: PeerId` - instance of PeerId (optional)

Creates a new PeerInfo instance from an existing PeerId.

### `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`.

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

---
_Source: https://npm.io/package/eth-peer-info · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
