Skip to content

Instantly share code, notes, and snippets.

@dominictarr
Last active July 22, 2024 00:14
Show Gist options
  • Save dominictarr/37abe288664b6b0d3b4f349637db820f to your computer and use it in GitHub Desktop.
Save dominictarr/37abe288664b6b0d3b4f349637db820f to your computer and use it in GitHub Desktop.
var pull = require('pull-stream')
var paramap = require('pull-paramap')
var createClient = require('ssb-client')
function toAddress (peer) {
return [peer.host, peer.port, peer.key].join(':')
}
createClient(function (err, sbot) {
if(err) throw err
var found = {}, c = 0
sbot.gossip.peers(function (err, peers) {
if(err) throw err
console.log(peers.length)
pull(
pull.values(peers),
paramap(function (peer, cb) {
console.error('attempt', toAddress(peer))
createClient(null, {key:peer.key, host: peer.host, port: peer.port, timeout: 1000}, function (err, sbot) {
if(err) {
console.error('-', toAddress(peer))
cb()
}
else {
console.error('+', c++, toAddress(peer))
sbot.close(true, function () {
found[sbot.id] = toAddress(peer)
cb(null, sbot.id)
})
}
})
}),
pull.filter(),
pull.drain(console.log, function () {
console.log(found)
sbot.close(true)
})
)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment