This repository was archived by the owner on Oct 3, 2023. It is now read-only.
File tree 4 files changed +43
-17
lines changed
4 files changed +43
-17
lines changed Original file line number Diff line number Diff line change 30
30
"devDependencies" : {
31
31
"aegir" : " ^21.2.0" ,
32
32
"chai" : " ^4.2.0" ,
33
- "dirty-chai" : " ^2.0.1"
33
+ "dirty-chai" : " ^2.0.1" ,
34
+ "libp2p-interfaces" : " ^0.3.0"
34
35
},
35
36
"dependencies" : {
36
37
"debug" : " ^4.1.1" ,
37
38
"mafmt" : " ^7.0.0" ,
38
39
"multiaddr" : " ^7.2.1" ,
39
- "peer-id" : " ^0.13.5" ,
40
- "peer-info" : " ^0.17.0"
40
+ "peer-id" : " ^0.13.5"
41
41
},
42
42
"pre-push" : [
43
43
" lint" ,
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
const PeerId = require ( 'peer-id' )
4
- const PeerInfo = require ( 'peer-info' )
5
4
const multiaddr = require ( 'multiaddr' )
6
5
const mafmt = require ( 'mafmt' )
7
6
const { EventEmitter } = require ( 'events' )
@@ -50,7 +49,11 @@ class Bootstrap extends EventEmitter {
50
49
* Emit each address in the list as a PeerInfo.
51
50
*/
52
51
_discoverBootstrapPeers ( ) {
53
- this . _list . forEach ( async ( candidate ) => {
52
+ if ( ! this . _timer ) {
53
+ return
54
+ }
55
+
56
+ this . _list . forEach ( ( candidate ) => {
54
57
if ( ! mafmt . P2P . matches ( candidate ) ) {
55
58
return log . error ( 'Invalid multiaddr' )
56
59
}
@@ -60,9 +63,10 @@ class Bootstrap extends EventEmitter {
60
63
const peerId = PeerId . createFromB58String ( ma . getPeerId ( ) )
61
64
62
65
try {
63
- const peerInfo = await PeerInfo . create ( peerId )
64
- peerInfo . multiaddrs . add ( ma )
65
- this . emit ( 'peer' , peerInfo )
66
+ this . emit ( 'peer' , {
67
+ id : peerId ,
68
+ multiaddrs : [ ma ]
69
+ } )
66
70
} catch ( err ) {
67
71
log . error ( 'Invalid bootstrap peer id' , err )
68
72
}
@@ -73,10 +77,8 @@ class Bootstrap extends EventEmitter {
73
77
* Stop emitting events.
74
78
*/
75
79
stop ( ) {
76
- if ( this . _timer ) {
77
- clearInterval ( this . _timer )
78
- this . _timer = null
79
- }
80
+ clearInterval ( this . _timer )
81
+ this . _timer = null
80
82
}
81
83
}
82
84
Original file line number Diff line number Diff line change @@ -5,10 +5,12 @@ const chai = require('chai')
5
5
chai . use ( require ( 'dirty-chai' ) )
6
6
const { expect } = chai
7
7
8
+ const mafmt = require ( 'mafmt' )
9
+ const PeerId = require ( 'peer-id' )
10
+
8
11
const Bootstrap = require ( '../src' )
9
12
const peerList = require ( './default-peers' )
10
13
const partialValidPeerList = require ( './some-invalid-peers' )
11
- const mafmt = require ( 'mafmt' )
12
14
13
15
describe ( 'bootstrap' , ( ) => {
14
16
it ( 'should throw if no peer list is provided' , ( ) => {
@@ -42,10 +44,11 @@ describe('bootstrap', () => {
42
44
} )
43
45
44
46
const p = new Promise ( ( resolve ) => {
45
- r . once ( 'peer' , ( peer ) => {
46
- const peerList = peer . multiaddrs . toArray ( )
47
- expect ( peerList . length ) . to . eq ( 1 )
48
- expect ( mafmt . IPFS . matches ( peerList [ 0 ] . toString ( ) ) ) . equals ( true )
47
+ r . once ( 'peer' , ( { id, multiaddrs } ) => {
48
+ expect ( id ) . to . exist ( )
49
+ expect ( PeerId . isPeerId ( id ) ) . to . eql ( true )
50
+ expect ( multiaddrs . length ) . to . eq ( 1 )
51
+ expect ( mafmt . IPFS . matches ( multiaddrs [ 0 ] . toString ( ) ) ) . equals ( true )
49
52
resolve ( )
50
53
} )
51
54
} )
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ /* eslint-env mocha */
4
+
5
+ const tests = require ( 'libp2p-interfaces/src/peer-discovery/tests' )
6
+
7
+ const Bootstrap = require ( '../src' )
8
+ const peerList = require ( './default-peers' )
9
+
10
+ describe ( 'compliance tests' , ( ) => {
11
+ tests ( {
12
+ setup ( ) {
13
+ const bootstrap = new Bootstrap ( {
14
+ list : peerList ,
15
+ interval : 2000
16
+ } )
17
+
18
+ return bootstrap
19
+ }
20
+ } )
21
+ } )
You can’t perform that action at this time.
0 commit comments