Skip to content

Instantly share code, notes, and snippets.

@jimpick
Forked from roccomuso/index.html
Last active April 10, 2018 18:48
Show Gist options
  • Save jimpick/f1e393d91a80e8015d8e51acc8ec4f0e to your computer and use it in GitHub Desktop.
Save jimpick/f1e393d91a80e8015d8e51acc8ec4f0e to your computer and use it in GitHub Desktop.
p2p-graph esnextbin sketch
<!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>
// 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)
{
"name": "p2p-graph-example",
"version": "0.0.1",
"dependencies": {
"faker": "4.1.0",
"p2p-graph": "1.2.1"
}
}
'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