Skip to content
This repository was archived by the owner on Aug 23, 2019. It is now read-only.

Commit 0423744

Browse files
committed
feat: adding default priority for transports
1 parent 8bbaf7a commit 0423744

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@
5151
"libp2p-tcp": "~0.10.0",
5252
"libp2p-webrtc-star": "~0.9.0",
5353
"libp2p-websockets": "~0.10.0",
54+
"peer-book": "~0.4.0",
5455
"pre-commit": "^1.2.2",
5556
"pull-goodbye": "0.0.1",
56-
"peer-book": "~0.4.0",
5757
"pull-stream": "^3.5.0",
58+
"sinon": "^2.1.0",
5859
"webrtcsupport": "^2.2.0"
5960
},
6061
"dependencies": {

src/index.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const protocolMuxer = require('./protocol-muxer')
1111
const plaintext = require('./plaintext')
1212
const assert = require('assert')
1313

14+
const DEFAULT_TRANSPORT_PRIORITY = 1
15+
1416
exports = module.exports = Swarm
1517

1618
util.inherits(Swarm, EE)
@@ -64,14 +66,11 @@ function Swarm (peerInfo, peerBook) {
6466
// Only listen on transports we actually have addresses for
6567
return myTransports.filter((ts) => this.transports[ts].filter(myAddrs).length > 0)
6668
.sort((a, b) => {
67-
if ((this.transports[a] && this.transports[b]) &&
68-
(this.transports[a].priority && this.transports[b].priority)) {
69-
return this.transports[a].priority - this.transports[b].priority
70-
}
69+
let pRa = a.priority || DEFAULT_TRANSPORT_PRIORITY
70+
let pRb = b.priority || DEFAULT_TRANSPORT_PRIORITY
7171

72-
return 0
72+
return pRa - pRb
7373
})
74-
7574
}
7675

7776
// higher level (public) API

0 commit comments

Comments
 (0)