Skip to content

Instantly share code, notes, and snippets.

@wanderer
Last active February 8, 2019 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wanderer/ec4a6001afad08d4ba5dfd7a7ac69ee7 to your computer and use it in GitHub Desktop.
Save wanderer/ec4a6001afad08d4ba5dfd7a7ac69ee7 to your computer and use it in GitHub Desktop.
var ssbClient = require('ssb-client')
ssbClient(function (err, sbot) {
sbot.friends.getGraph((err, g) => {
// returns a list of pubs
sbot.analysis.get(async (err, pubs) => {
// remove the pubs from the social graph b/c pubs are not humans
pubs.forEach(pub => delete g[pub])
for (const key in g) {
const id = g[key]
// remove the the pubs links from the ids
pubs.forEach(pub => delete id[pub])
for (const subkey in id) {
// remove the links that are blocks
if (id[subkey] < 0) {
delete id[subkey]
}
}
}
console.log(JSON.stringify(pubs, null, 2))
sbot.close()
})
})
})
const FlumeReduce = require('flumeview-reduce')
exports.name = 'analysis'
exports.version = require('./package.json').version
exports.manifest = {
stream: 'source',
get: 'async'
}
const initialState = []
exports.init = function (ssb, config) {
const view = ssb._flumeUse('identifyPubs', FlumeReduce(3, reduce, map, null, initialState))
return view
}
function reduce (result, [id, pub]) {
const r = new Set(result)
if (pub) {
r.add(id)
} else {
r.delete(id)
}
return [...r]
}
function isPub (msg) {
return msg.value.content && msg.value.content.pub && msg.value.content.scope !== 'ferment'
}
function map (msg) {
// finds all the links in the socail graph
if (msg.value.content && msg.value.content.type === 'contact') {
return [msg.value.author, isPub(msg)]
}
}
function dfs (graph, startID) {
const vistedIDs = new Set()
function _dfs (graph, startID) {
vistedIDs.add(startID)
const follows = graph[startID]
for (const id in follows) {
if (!vistedIDs.has(id)) {
_dfs(graph, id)
}
}
}
_dfs(graph, startID)
return vistedIDs
}
function prune (graph, startId) {
const ids = dfs(graph, startId)
const prunedGraph = {}
ids.forEach(id => {
prunedGraph[id] = graph[id]
})
return prunedGraph
}
function createList (graph) {
const keys = Object.keys(graph)
const pubs = require('./pubs.json')
const all = keys.concat(pubs)
all.forEach(id => console.log(id))
}
let graph = require('./out.json')
// uikkwUQU4dcd/ZrHU7JstnkTgncxQB2A8PDLHV9wDAs is just my identiy but you can use any id that is connected to the "strongset" to start the dfs from
graph = prune(graph, '@uikkwUQU4dcd/ZrHU7JstnkTgncxQB2A8PDLHV9wDAs=.ed25519')
createList(graph)
@wanderer
Copy link
Author

wanderer commented Feb 7, 2019

install plugin.js as a scuttlebutt plugin. Then start scuttlebut scuttlebot server and run the client node ./client.js > out.json then run node prune.js > final.txt

@sdtsui
Copy link

sdtsui commented Feb 8, 2019

Note:

  • server was also modified to replicate everyone (including non-friends/follows). This is so the whole network can be seen.
  • L18 of prune.js uses a depth-first search to 'remove' all islands, in effect creating an ssb strongset.

Thus, in order to recreate the generated list, all you'll need to do to join the strongset is join ssb through a pub, and follow someone popular (like staltz or tarr). Let me know if you need any help with this, but it might be simplest to just ping someone you know on the team that also uses ssb. Thanks!!

@wanderer
Copy link
Author

wanderer commented Feb 8, 2019

server was also modified to replicate everyone (including non-friends/follows). This is so the whole network can be seen.

todo this you can just sets the hops and dunbar number really high in ~/.ssb/config
like so
"friends": { "dunbar": 10000, "hops": 10000 }
or just set this callback to always return true https://github.com/ssbc/ssb-friends/blob/master/index.js#L33

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment