forked from bbossola/sysdist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp2p.js
36 lines (28 loc) · 720 Bytes
/
p2p.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var peers = []
host_by_port = function(port) {
return "127.0.0." + (port - 3000);
};
var current_port;
exports.init = function(localport) {
for (port = 3001; port <= 3004; port++) {
if (port != localport) {
host = host_by_port(port);
peers.push({
port: port,
host: host
})
}
}
current_port = localport;
console.log("Expected peers:",peers.length)
};
exports.peers = function() {
return peers;
};
exports.localAddress = function() {
return host_by_port(current_port);
};
exports.httpurl = function(port) {
return 'http://' + host_by_port(port) + ":" + port;
};
exports.host_by_port = host_by_port;