diff options
Diffstat (limited to 'lib/app.js')
-rw-r--r-- | lib/app.js | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -157,3 +157,31 @@ App.prototype.createLogStream = function (opts) { ? this.sbot.createFeedStream(opts) : this.sbot.createLogStream(opts) } + +var stateVals = { + connected: 3, + connecting: 2, + disconnecting: 1, +} + +function comparePeers(a, b) { + var aState = stateVals[a.state] || 0 + var bState = stateVals[b.state] || 0 + return bState > aState ? 1 : bState < aState ? -1 : + b.stateChange - a.stateChange +} + +App.prototype.streamPeers = function (opts) { + var gossip = this.sbot.gossip + return u.readNext(function (cb) { + gossip.peers(function (err, peers) { + if (err) return cb(err) + if (opts) peers = peers.filter(function (peer) { + for (var k in opts) if (opts[k] !== peer[k]) return false + return true + }) + peers.sort(comparePeers) + cb(null, pull.values(peers)) + }) + }) +} |