Skip to content

Commit 5680050

Browse files
committed
chore: use topology interface
1 parent 5e45409 commit 5680050

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"it-length-prefixed": "^2.0.0",
3838
"it-pipe": "^1.0.1",
3939
"libp2p-floodsub": "libp2p/js-libp2p-floodsub#refactor/async",
40-
"libp2p-pubsub": "libp2p/js-libp2p-pubsub#refactor/async",
40+
"libp2p-pubsub": "~0.3.0",
4141
"p-map": "^3.0.0",
4242
"peer-id": "~0.13.3",
4343
"peer-info": "~0.17.0",

src/index.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ class GossipSub extends BasicPubsub {
2828
constructor (peerInfo, registrar, options = {}) {
2929
assert(PeerInfo.isPeerInfo(peerInfo), 'peer info must be an instance of `peer-info`')
3030

31-
// registrar handling
32-
assert(registrar && typeof registrar.handle === 'function', 'a handle function must be provided in registrar')
33-
assert(registrar && typeof registrar.register === 'function', 'a register function must be provided in registrar')
34-
assert(registrar && typeof registrar.unregister === 'function', 'a unregister function must be provided in registrar')
35-
3631
super({
3732
debugName: 'libp2p:gossipsub',
3833
multicodec: constants.GossipSubID,

src/pubsub.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
'use strict'
22

33
const assert = require('assert')
4-
const debug = require('debug')
5-
const debugName = 'libp2p:gossipsub'
6-
const log = debug(debugName)
7-
log.error = debug(`${debugName}:error`)
84
const errcode = require('err-code')
95

106
const TimeCache = require('time-cache')
@@ -76,6 +72,7 @@ class BasicPubSub extends Pubsub {
7672
this._options = _options
7773

7874
this._onRpc = this._onRpc.bind(this)
75+
this.log = this.log.bind(this)
7976
}
8077

8178
/**
@@ -142,7 +139,7 @@ class BasicPubSub extends Pubsub {
142139
return
143140
}
144141

145-
log('rpc from', idB58Str)
142+
this.log('rpc from', idB58Str)
146143
const subs = rpc.subscriptions
147144
const msgs = rpc.msgs
148145

@@ -191,7 +188,7 @@ class BasicPubSub extends Pubsub {
191188
}
192189

193190
if (error || !isValid) {
194-
log('Message could not be validated, dropping it. isValid=%s', isValid, error)
191+
this.log('Message could not be validated, dropping it. isValid=%s', isValid, error)
195192
return
196193
}
197194

@@ -352,7 +349,7 @@ class BasicPubSub extends Pubsub {
352349
async publish (topics, messages) {
353350
assert(this.started, 'Pubsub has not started')
354351

355-
log('publish', topics, messages)
352+
this.log('publish', topics, messages)
356353

357354
topics = utils.ensureArray(topics)
358355
messages = utils.ensureArray(messages)

test/utils/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,14 @@ const createMockRegistrar = (registrarRecord) => ({
117117
}
118118
})
119119
},
120-
register: ({ multicodecs, handlers }) => {
120+
register: ({ multicodecs, _onConnect, _onDisconnect }) => {
121121
multicodecs.forEach((multicodec) => {
122122
const rec = registrarRecord[multicodec] || {}
123123

124124
registrarRecord[multicodec] = {
125125
...rec,
126-
...handlers
126+
onConnect: _onConnect,
127+
onDisconnect: _onDisconnect
127128
}
128129
})
129130
return multicodecs[0]

0 commit comments

Comments
 (0)