p2p-graph live demo, made with esnextbin
-
-
Save jimpick/f1e393d91a80e8015d8e51acc8ec4f0e to your computer and use it in GitHub Desktop.
p2p-graph esnextbin sketch
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
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>ESNextbin Sketch</title> | |
<!-- put additional styles and scripts here --> | |
<style> | |
body{ | |
background-color: #7f7a7a; | |
}; | |
</style> | |
</head> | |
<body> | |
<!-- put markup and other contents here --> | |
<div class="root"> | |
</div> | |
</body> | |
</html> |
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
// Press "Execute" to run your program | |
var faker = require('faker') | |
var Graph = require('p2p-graph') | |
var graph = new Graph('.root') | |
// select event | |
graph.on('select', function (id) { | |
console.log(id + ' selected!') | |
}) | |
// Add main peer | |
/* | |
graph.add({ | |
id: 'me', | |
me: true, | |
name: 'You' | |
}) | |
*/ | |
const num = 10 | |
for (let i = 0; i<num; i++){ | |
// add peers | |
graph.add({ | |
id: 'peer'+i, | |
name: faker.internet.ip() | |
}) | |
// connect them | |
// graph.connect('me', 'peer'+i) | |
} | |
for (let i = 0; i < 60; i++) { | |
try { | |
graph.connect( | |
'peer' + Math.floor(Math.random() * num), | |
'peer' + Math.floor(Math.random() * num) | |
) | |
} catch (e) {} | |
} | |
for (let i = 0; i < 10; i++) { | |
try { | |
graph.rate( | |
'peer' + Math.floor(Math.random() * num), | |
'peer' + Math.floor(Math.random() * num), | |
Math.random() * 2097152 | |
) | |
} catch (e) {} | |
} | |
graph.seed('peer0', true) |
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
{ | |
"name": "p2p-graph-example", | |
"version": "0.0.1", | |
"dependencies": { | |
"faker": "4.1.0", | |
"p2p-graph": "1.2.1" | |
} | |
} |
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
'use strict'; | |
// Press "Execute" to run your program | |
var faker = require('faker'); | |
var Graph = require('p2p-graph'); | |
var graph = new Graph('.root'); | |
// on click event listener | |
graph.on('select', function (id) { | |
console.log(id + ' selected!') | |
}) | |
// Add main peer | |
graph.add({ | |
id: 'me', | |
me: true, | |
name: 'You' | |
}); | |
for (var i = 0; i < 10; i++) { | |
// add peers | |
graph.add({ | |
id: 'peer' + i, | |
name: faker.internet.ip() | |
}); | |
// connect them | |
graph.connect('me', 'peer' + i); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment