Created
February 26, 2019 20:45
-
-
Save rsbondi/655801272818c1593535fb65c24ce9cd to your computer and use it in GitHub Desktop.
Generate random graph dot file for lnet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const args = process.argv.reduce((o, a) => { | |
if(~a.indexOf('=')) { | |
const kv = a.split('=') | |
o[kv[0]] = kv[1] | |
} | |
return o | |
}, {}) | |
let nodes = [] | |
for(let i=0; i<args.count; i++) { | |
nodes.push(Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)) | |
} | |
let graph = '' | |
let cons = {} | |
for (let i=0; i < nodes.length; i++) { | |
const node = nodes[i] | |
const peers = Math.floor(Math.random() * (args.maxchannels || 3)) + 1 | |
cons[node] = [] | |
for(let p = 0; p < peers; p++) { | |
const d = Math.floor(Math.random() * args.count) | |
if(d === i) { p--; continue } // con't connect to self, try again | |
const src = nodes[d] | |
if(~cons[node].indexOf(src)) { p--; continue } // only one connection | |
if(cons[src] && ~cons[src].indexOf(node)) { p--; continue } // the other way | |
cons[node].push(src) | |
const cap = Math.floor(Math.random() * (10000000 - 500000 + 1) + 500000) | |
graph += ` "${src}" -- "${node}" [capacity="${cap}"];\n` | |
} | |
} | |
fs.writeFileSync(args.out, Buffer.from(`graph g {\n${graph}}`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For creating a random configuration of lightning nodes for use with lnet
usage