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

Commit

Permalink
feat: adding default priority for transports
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov committed Apr 13, 2017
1 parent 8bbaf7a commit 0423744
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@
"libp2p-tcp": "~0.10.0",
"libp2p-webrtc-star": "~0.9.0",
"libp2p-websockets": "~0.10.0",
"peer-book": "~0.4.0",
"pre-commit": "^1.2.2",
"pull-goodbye": "0.0.1",
"peer-book": "~0.4.0",
"pull-stream": "^3.5.0",
"sinon": "^2.1.0",
"webrtcsupport": "^2.2.0"
},
"dependencies": {
Expand Down
11 changes: 5 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const protocolMuxer = require('./protocol-muxer')
const plaintext = require('./plaintext')
const assert = require('assert')

const DEFAULT_TRANSPORT_PRIORITY = 1

exports = module.exports = Swarm

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

return 0
return pRa - pRb
})

}

// higher level (public) API
Expand Down

0 comments on commit 0423744

Please sign in to comment.