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
1 parent aaee3ec commit 1ae0a19
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Daemon {
let successfulProto
for (const protocol of proto) {
try {
connection = await this.libp2p.dial(peerInfo, protocol)
connection = await this.libp2p._dial(peerInfo, protocol)
successfulProto = protocol
break
} catch (err) {
Expand Down Expand Up @@ -186,7 +186,7 @@ class Daemon {
* @returns {Promise<void>}
*/
async start () {
await this.libp2p.start()
await this.libp2p._start()
return new Promise((resolve, reject) => {
const options = multiaddrToNetConfig(this.multiaddr)
this.server.listen(options, (err) => {
Expand Down
41 changes: 6 additions & 35 deletions src/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,7 @@ class Pubsub {
* @returns { Promise<void>}
*/
subscribe (topic, options, handler) {
return new Promise((resolve, reject) => {
this.libp2p._pubsub.subscribe(topic, options, handler, (err) => {
if (err) return reject(err)
resolve()
})
})
return this.libp2p._pubsub.subscribe(topic, handler, options)
}

/**
Expand All @@ -138,25 +133,15 @@ class Pubsub {
* @returns {Promise<void>}
*/
publish (topic, data) {
return new Promise((resolve, reject) => {
this.libp2p._pubsub.publish(topic, data, (err) => {
if (err) return reject(err)
resolve()
})
})
return this.libp2p._pubsub.publish(topic, data)
}

/**
* Get the list of subscriptions the peer is subscribed to.
* @returns {Promise<Array<string>>}
*/
getTopics () {
return new Promise((resolve, reject) => {
this.libp2p._pubsub.ls((err, topics) => {
if (err) return reject(err)
resolve(topics)
})
})
return this.libp2p._pubsub.ls()
}

start (cb) {
Expand Down Expand Up @@ -294,7 +279,7 @@ class DaemonLibp2p extends Libp2p {
*
* @returns {Promise<void>}
*/
start () {
_start () {
return new Promise((resolve, reject) => {
super.start((err) => {
if (err) return reject(err)
Expand Down Expand Up @@ -325,28 +310,14 @@ class DaemonLibp2p extends Libp2p {
})
}

/**
* Stops the libp2p node
*
* @returns {Promise<void>}
*/
stop () {
return new Promise((resolve, reject) => {
super.stop((err) => {
if (err) return reject(err)
resolve()
})
})
}

/**
* Dials the given peer on protocol. The promise will resolve with the connection
*
* @param {PeerInfo} peerInfo
* @param {string} protocol
* @returns {Promise<Connection>}
*/
dial (peerInfo, protocol) {
_dial (peerInfo, protocol) {
return new Promise((resolve, reject) => {
this.dialProtocol(peerInfo, protocol, (err, conn) => {
if (err) return reject(err)
Expand Down Expand Up @@ -469,7 +440,7 @@ const createLibp2p = async ({
kBucketSize: 20
},
pubsub: {
enabled: pubsub
enabled: Boolean(pubsub)
}
}
}, {
Expand Down
1 change: 1 addition & 0 deletions test/daemon/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('configuration', () => {
})

await daemon.start()

const addrs = daemon.libp2p.peerInfo.multiaddrs.toArray()
expect(addrs).to.eql([
ma('/dns/ipfs.io')
Expand Down
2 changes: 1 addition & 1 deletion test/daemon/streams.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ describe('streams', function () {

// Open a connection between the peer and our daemon
// Then send hello from the peer to the daemon
const connection = await libp2pPeer.dial(daemon.libp2p.peerInfo, '/echo/1.0.0')
const connection = await libp2pPeer._dial(daemon.libp2p.peerInfo, '/echo/1.0.0')
const hello = Buffer.from('hello, peer')
connection.write(hello)

Expand Down

0 comments on commit 1ae0a19

Please sign in to comment.