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