1
- peer-info JavaScript implementation
2
- ===================================
1
+ # js-peer-info
3
2
4
3
[ ![ ] ( https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square )] ( http://ipn.io )
5
4
[ ![ ] ( https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square )] ( http://webchat.freenode.net/?channels=%23ipfs )
6
- [ ![ Build Status] ( https://travis-ci.org/diasdavid /js-peer-info.svg?style=flat-square )] ( https://travis-ci.org/diasdavid /js-peer-info )
7
- [ ![ Coverage Status] ( https://coveralls.io/repos/github/diasdavid /js-peer-info/badge.svg?branch=master )] ( https://coveralls.io/github/diasdavid /js-peer-info?branch=master )
8
- [ ![ Dependency Status] ( https://david-dm.org/diasdavid /js-peer-info.svg?style=flat-square )] ( https://david-dm.org/diasdavid /js-peer-info )
5
+ [ ![ Build Status] ( https://travis-ci.org/libp2p /js-peer-info.svg?style=flat-square )] ( https://travis-ci.org/libp2p /js-peer-info )
6
+ [ ![ Coverage Status] ( https://coveralls.io/repos/github/libp2p /js-peer-info/badge.svg?branch=master )] ( https://coveralls.io/github/libp2p /js-peer-info?branch=master )
7
+ [ ![ Dependency Status] ( https://david-dm.org/libp2p /js-peer-info.svg?style=flat-square )] ( https://david-dm.org/libp2p /js-peer-info )
9
8
[ ![ js-standard-style] ( https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square )] ( https://github.com/feross/standard )
9
+ [ ![ standard-readme compliant] ( https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square )] ( https://github.com/RichardLitt/standard-readme )
10
+ ![ ] ( https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square )
11
+ ![ ] ( https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square )
12
+
13
+ [ ![ Sauce Test Status] ( https://saucelabs.com/browser-matrix/ipfs-js-peer-info.svg )] ( https://saucelabs.com/u/ipfs-js-peer-info )
10
14
11
15
> A PeerInfo object contains information about a
12
16
> [ PeerID] ( https://github.com/libp2p/js-peer-id ) and its
13
17
> [ multiaddrs] ( https://github.com/libp2p/js-multiaddr ) . This module is used by
14
18
> [ IPFS] ( https://github.com/ipfs/ipfs ) and
15
19
> [ libp2p] ( https://github.com/libp2p/js-libp2p ) .
16
20
17
- # Example
21
+ ## Table of Contents
22
+
23
+ - [ Installation] ( #installation )
24
+ - [ npm] ( #npm )
25
+ - [ Node.JS, Browserify, Webpack] ( #nodejs-browserify-webpack )
26
+ - [ Browser: ` <script> ` Tag] ( #browser-script-tag )
27
+ - [ Usage] ( #usage )
28
+ - [ API] ( #api )
29
+ - [ ` PeerInfo.create([id, ] callback) ` ] ( #peerinfocreateid-callback )
30
+ - [ ` new PeerInfo(id) ` ] ( #new-peerinfoid )
31
+ - [ ` multiaddrs ` ] ( #multiaddrs )
32
+ - [ ` multiaddr.add(addr) ` ] ( #multiaddraddaddr )
33
+ - [ ` multiaddr.addSafe(addr) ` ] ( #multiaddraddsafeaddr )
34
+ - [ ` multiaddr.rm(addr) ` ] ( #multiaddrrmaddr )
35
+ - [ ` multiaddr.replace(existing, fresh) ` ] ( #multiaddrreplaceexisting-fresh )
36
+ - [ Contribute] ( #contribute )
37
+ - [ License] ( #license )
38
+
39
+ ## Installation
40
+
41
+ ### npm
42
+
43
+ ``` sh
44
+ > npm i peer-info
45
+ ```
46
+
47
+ ### Node.JS, Browserify, Webpack
48
+
49
+ ``` js
50
+ const PeerInfo = require (' peer-info' )
51
+ ```
52
+
53
+ ### Browser: ` <script> ` Tag
54
+
55
+ Loading this module through a script tag will make the ` PeerInfo ` obj available in the global namespace.
56
+
57
+ ``` html
58
+ <script src =" https://unpkg.com/peer-info/dist/index.min.js" ></script >
59
+ <!-- OR -->
60
+ <script src =" https://unpkg.com/peer-info/dist/index.js" ></script >
61
+ ```
62
+
63
+ ## Usage
18
64
19
65
``` js
20
66
const PeerInfo = require (' peer-info' )
@@ -32,31 +78,41 @@ peer.multiaddr.add(multiaddr('/ip4/1.2.3.4/udp/8001'))
32
78
peer .multiaddr .add (multiaddr (' /sonic/bfsk/697/1209' ))
33
79
```
34
80
35
- # API
81
+ ## API
36
82
37
83
``` js
38
84
const PeerInfo = require (' peer-info' )
39
85
```
40
86
41
- ## const peer = new PeerInfo()
87
+ ### ` PeerInfo.create([id, ] callback) `
42
88
43
- Creates a new PeerInfo instance and also generates a new underlying
44
- [ PeerID ] ( https://github.com/libp2p/js-peer-id ) for it.
89
+ - ` id: PeerID ` , optional
90
+ - ` callback: Function `
45
91
46
- ## const peer = new PeerInfo(peerId)
92
+ Creates a new PeerInfo instance and if no ` id ` is passed it
93
+ generates a new underlying [ PeerID] ( https://github.com/libp2p/js-peer-id )
94
+ for it.
95
+
96
+ ### ` new PeerInfo(id) `
97
+
98
+ - ` id: PeerID `
47
99
48
100
Creates a new PeerInfo instance from an existing PeerID.
49
101
50
- ## peer. multiaddrs
102
+ ### ` multiaddrs `
51
103
52
104
A list of multiaddresses instances that ` peer ` can be reached at.
53
105
54
- ## peer.multiaddr.add(addr)
106
+ ### ` multiaddr.add(addr) `
107
+
108
+ - ` addr: Multiaddr `
55
109
56
110
Adds a new multiaddress that ` peer ` can be reached at. ` addr ` is an instance of
57
111
a [ multiaddr] ( https://github.com/libp2p/js-multiaddr ) .
58
112
59
- ## peer.multiaddr.addSafe(addr)
113
+ ### ` multiaddr.addSafe(addr) `
114
+
115
+ - ` addr: Multiaddr `
60
116
61
117
The ` addSafe ` call, in comparison to ` add ` , will only add the multiaddr to
62
118
` multiaddrs ` if the same multiaddr tries to be added twice.
@@ -67,40 +123,26 @@ peers which will not provide a useful multiaddr to be shared to the rest of the
67
123
network (e.g. a multiaddr referring to a peer inside a LAN being shared to the
68
124
outside world).
69
125
70
- ## peer.multiaddr.rm(addr)
126
+ ### ` multiaddr.rm(addr) `
127
+
128
+ - ` addr: Multiaddr `
71
129
72
130
Removes a multiaddress instance ` addr ` from ` peer ` .
73
131
74
- ## peer.multiaddr.replace(existing, fresh)
132
+ ### ` multiaddr.replace(existing, fresh) `
133
+
134
+ - ` existing: Multiaddr `
135
+ - ` fresh: Multiaddr `
75
136
76
137
Removes the array of multiaddresses ` existing ` from ` peer ` , and adds the array
77
138
of multiaddresses ` fresh ` .
78
139
140
+ ## Contribute
79
141
80
- # Installation
81
-
82
- ## npm
83
-
84
- ``` sh
85
- > npm i peer-info
86
- ```
87
-
88
- ## Node.JS, Browserify, Webpack
89
-
90
- ``` JavaScript
91
- var PeerInfo = require (' peer-info' )
92
- ```
93
-
94
- ## Browser: ` <script> ` Tag
95
-
96
- Loading this module through a script tag will make the ` PeerInfo ` obj available in the global namespace.
142
+ PRs accepted.
97
143
98
- ``` html
99
- <script src =" https://unpkg.com/peer-info/dist/index.min.js" ></script >
100
- <!-- OR -->
101
- <script src =" https://unpkg.com/peer-info/dist/index.js" ></script >
102
- ```
144
+ Small note: If editing the Readme, please conform to the [ standard-readme] ( https://github.com/RichardLitt/standard-readme ) specification.
103
145
104
- # License
146
+ ## License
105
147
106
- MIT
148
+ [ MIT © David Dias ] ( LICENSE )
0 commit comments