-
Notifications
You must be signed in to change notification settings - Fork 0
/
peerStats
executable file
·54 lines (50 loc) · 2.1 KB
/
peerStats
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env node
/* -*- Mode:Js */
/* vim: set expandtab ts=4 sw=4: */
/*
* You may redistribute this program and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
var Cjdns = require('./cjdns/tools/lib/cjdnsadmin/cjdnsadmin');
var PublicToIp6 = require('./cjdns/tools/lib/publicToIp6');
var Peers = require('hyperboria-peers');
console.log("## Peer availability table\n");
console.log("\nTable was last generated on: **"+(new Date()).toString()+"**\n\n");
console.log("| Peer path | Public key | Status |\n|-------|------|-------|");
handlePeers = function (peers) {
Peers.filter(function (creds, path) {
for (const peer in creds)
if (creds.hasOwnProperty(peer))
if (peer.indexOf('[') === -1) {
if (typeof(peers[creds[peer].publicKey]) !== 'undefined')
console.log("| ["+ path.join('/')+"](https://github.com/hyperboria/peers/tree/master/"+path.join('/')+") | "+creds[peer].publicKey+" | "+peers[creds[peer].publicKey]+" | ");
}
});
}
Cjdns.connectAsAnon(function (cjdns) {
var peers = {};
var again = function (i) {
cjdns.InterfaceController_peerStats(i, function (err, ret) {
if (err) { throw err; }
ret.peers.forEach(function (peer) {
peers[peer['addr'].split('.').slice(-2).join('.')] = peer['state'];
});
if (typeof(ret.more) !== 'undefined') {
again(i+1);
} else {
cjdns.disconnect();
handlePeers(peers);
}
});
};
again(0);
});