Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"dependencies": {
"libp2p-ping": "~0.3.1",
"libp2p-swarm": "~0.26.17",
"libp2p-circuit": "~0.0.1",
"mafmt": "^2.1.6",
"multiaddr": "^2.2.1",
"peer-book": "~0.3.1",
Expand All @@ -54,4 +55,4 @@
"greenkeeperio-bot <[email protected]>",
"mayerwin <[email protected]>"
]
}
}
16 changes: 12 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const EE = require('events').EventEmitter
const assert = require('assert')
const Ping = require('libp2p-ping')
const setImmediate = require('async/setImmediate')
const series = require('async/series')

exports = module.exports

Expand Down Expand Up @@ -41,6 +42,9 @@ class Node {
// If muxer exists, we can use Identify
this.swarm.connection.reuse()

// If muxer exists, we can use Relay
this.swarm.connection.relay()

// Received incommind dial and muxer upgrade happened, reuse this
// muxed connection
this.swarm.on('peer-mux-established', (peerInfo) => {
Expand Down Expand Up @@ -100,7 +104,7 @@ class Node {
this.swarm.transport.add(
transport.tag || transport.constructor.name, transport)
} else if (transport.constructor &&
transport.constructor.name === 'WebSockets') {
transport.constructor.name === 'WebSockets') {
// TODO find a cleaner way to signal that a transport is always
// used for dialing, even if no listener
ws = transport
Expand All @@ -119,7 +123,8 @@ class Node {

if (this.modules.discovery) {
this.modules.discovery.forEach((discovery) => {
setImmediate(() => discovery.start(() => {}))
setImmediate(() => discovery.start(() => {
}))
})
}

Expand All @@ -135,11 +140,14 @@ class Node {

if (this.modules.discovery) {
this.modules.discovery.forEach((discovery) => {
setImmediate(() => discovery.stop(() => {}))
setImmediate(() => discovery.stop(() => {
}))
})
}

this.swarm.close(callback)
series([
(cb) => this.swarm.close(cb)
], callback)
}

//
Expand Down