diff --git a/package.json b/package.json index 9cd6b7c..754a876 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/index.js b/src/index.js index 57f64e7..e4b980f 100644 --- a/src/index.js +++ b/src/index.js @@ -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) @@ -63,6 +65,12 @@ 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) => { + let pRa = a.priority || DEFAULT_TRANSPORT_PRIORITY + let pRb = b.priority || DEFAULT_TRANSPORT_PRIORITY + + return pRa - pRb + }) } // higher level (public) API