Skip to content

Commit

Permalink
chore: use newest libp2p release
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Jul 31, 2019
2 parents 1ae0a19 + 46d0c18 commit 8acc4bd
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 57 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"cids": "~0.6.0",
"debug": "^4.1.1",
"length-prefixed-stream": "github:jacobheun/length-prefixed-stream#v2.0.0-rc.1",
"libp2p": "~0.26.0-rc.0",
"libp2p": "~0.26.0-rc.1",
"libp2p-bootstrap": "~0.9.7",
"libp2p-floodsub": "~0.17.0",
"libp2p-gossipsub": "~0.0.4",
Expand Down
6 changes: 3 additions & 3 deletions src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class Daemon {
async handlePubsubRequest ({ pubsub }, enc) {
switch (pubsub.type) {
case PSRequest.Type.GET_TOPICS: {
const topics = await this.libp2p.pubsub.getTopics()
const topics = await this.libp2p.pubsub.ls()

await new Promise((resolve) => {
enc.write(
Expand All @@ -283,7 +283,7 @@ class Daemon {
case PSRequest.Type.SUBSCRIBE: {
const topic = pubsub.topic

await this.libp2p.pubsub.subscribe(topic, {}, async (msg) => {
await this.libp2p.pubsub.subscribe(topic, async (msg) => {
await new Promise((resolve) => {
enc.write(PSMessage.encode({
from: msg.from && Buffer.from(msg.from),
Expand All @@ -294,7 +294,7 @@ class Daemon {
key: msg.key
}), resolve)
})
})
}, {})

await new Promise((resolve) => {
enc.write(OkResponse(), resolve)
Expand Down
51 changes: 0 additions & 51 deletions src/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,52 +107,6 @@ class ContentRouting {
}
}

class Pubsub {
/**
* @param {Libp2p} libp2p The libp2p instance to use
*/
constructor (libp2p) {
this.libp2p = libp2p
}

/**
* Subscribe to a pubsub topic
* @param {string} topic
* @param {Object} options
* @param {function(msg)} handler handle received messages
* @returns { Promise<void>}
*/
subscribe (topic, options, handler) {
return this.libp2p._pubsub.subscribe(topic, handler, options)
}

/**
* Publish data in the context of a topic
* @param {string} topic
* @param {Buffer} data
* @returns {Promise<void>}
*/
publish (topic, data) {
return this.libp2p._pubsub.publish(topic, data)
}

/**
* Get the list of subscriptions the peer is subscribed to.
* @returns {Promise<Array<string>>}
*/
getTopics () {
return this.libp2p._pubsub.ls()
}

start (cb) {
this.libp2p._pubsub.start(cb)
}

stop (cb) {
this.libp2p._pubsub.stop(cb)
}
}

class DHT {
/**
* @param {Libp2p} libp2p The libp2p instance to use
Expand Down Expand Up @@ -249,11 +203,6 @@ class DaemonLibp2p extends Libp2p {
super(libp2pOpts)
this.announceAddrs = announceAddrs
this.needsPullStream = libp2pOpts.config.pubsub.enabled

if (libp2pOpts.config.pubsub.enabled) {
this._pubsub = this.pubsub
this.pubsub = new Pubsub(this)
}
}
get contentRouting () {
return this._contentRouting
Expand Down
4 changes: 2 additions & 2 deletions test/daemon/pubsub.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ const testPubsub = (router) => {
stream.end()

// subscribe topic
await libp2pPeer.pubsub.subscribe(topic, {}, (msg) => {
await libp2pPeer.pubsub.subscribe(topic, (msg) => {
expect(msg.data).to.equalBytes(data)
resolve()
})
}, {})

// wait to pubsub to propagate messages
await new Promise(resolve => setTimeout(resolve, 1000))
Expand Down

0 comments on commit 8acc4bd

Please sign in to comment.