This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree 3 files changed +31
-13
lines changed
3 files changed +31
-13
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const EventEmitter = require ( 'events' )
4
+
5
+ function fail ( ) {
6
+ throw new Error ( 'The daemon must be run with \'--enable-pubsub-experiment\'' )
7
+ }
8
+
9
+ class NoFloodSub extends EventEmitter {
10
+ constructor ( ) {
11
+ super ( )
12
+
13
+ this . peers = new Map ( )
14
+ this . subscriptions = new Set ( )
15
+ }
16
+
17
+ start ( callback ) { callback ( ) }
18
+ stop ( callback ) { callback ( ) }
19
+ publish ( ) { fail ( ) }
20
+ subscribe ( ) { fail ( ) }
21
+ unsubscribe ( ) { fail ( ) }
22
+
23
+ }
24
+
25
+ module . exports = NoFloodSub
Original file line number Diff line number Diff line change 3
3
const series = require ( 'async/series' )
4
4
const Bitswap = require ( 'ipfs-bitswap' )
5
5
const FloodSub = require ( 'libp2p-floodsub' )
6
+ const NoFloodSub = require ( './no-floodsub' )
6
7
const setImmediate = require ( 'async/setImmediate' )
7
8
const promisify = require ( 'promisify-es6' )
8
9
@@ -50,12 +51,10 @@ module.exports = (self) => {
50
51
self . _bitswap . start ( )
51
52
self . _blockService . setExchange ( self . _bitswap )
52
53
53
- if ( self . _options . EXPERIMENTAL . pubsub ) {
54
- self . _pubsub = new FloodSub ( self . _libp2pNode )
55
- self . _pubsub . start ( done )
56
- } else {
57
- done ( )
58
- }
54
+ self . _pubsub = self . _options . EXPERIMENTAL . pubsub
55
+ ? new FloodSub ( self . _libp2pNode )
56
+ : new NoFloodSub ( )
57
+ self . _pubsub . start ( done )
59
58
} )
60
59
} )
61
60
}
Original file line number Diff line number Diff line change @@ -31,13 +31,7 @@ module.exports = (self) => {
31
31
self . _bitswap . stop ( )
32
32
33
33
series ( [
34
- ( cb ) => {
35
- if ( self . _options . EXPERIMENTAL . pubsub ) {
36
- self . _pubsub . stop ( cb )
37
- } else {
38
- cb ( )
39
- }
40
- } ,
34
+ ( cb ) => self . _pubsub . stop ( cb ) ,
41
35
( cb ) => self . libp2p . stop ( cb ) ,
42
36
( cb ) => self . _repo . close ( cb )
43
37
] , done )
You can’t perform that action at this time.
0 commit comments