-
Notifications
You must be signed in to change notification settings - Fork 4
/
gen_readme.php
executable file
·150 lines (111 loc) · 3.41 KB
/
gen_readme.php
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env php
<?php
/**
* This script queries lightning-cli listnodes and formats
* the response into a markdown file
*/
/* sample listnodes response JSON
"nodes": [
{
"nodeid": "0297bab0d86a08db807102f4e79e5639eb44dcfc914476051fb3e4057ae6772d00",
"alias": "Bitonic",
"color": "192171",
"last_timestamp": 1532588756,
"addresses": [
{
"type": "ipv4",
"address": "92.111.70.106",
"port": 9735
}
]
},
...
]
*/
exec($_SERVER['HOME'] . '/bin/lightning-cli listnodes', $output, $rc );
if( $rc != 0 ) {
echo "lightning-cli failed with code $rc\n\n";
exit($rc);
}
$buf = implode("\n", $output);
$data = json_decode($buf, true);
$rows = [];
$totals = [
'nodes' => 0,
'nodes_with_address' => 0,
'addresses' => 0,
'torv3' => 0,
'torv2' => 0,
'ipv6' => 0,
'ipv4' => 0,
];
$bytype = [ 'torv3' => [], 'torv2' => [], 'ipv6' => [], 'ipv4' => [] ];
foreach($data['nodes'] as $node ) {
$totals['nodes'] ++;
if( !@$node['addresses'] ) {
continue;
}
$found_addr = false;
foreach($node['addresses'] as $addr) {
if(!@$addr['type'] ) { // some are empty. bug in lightningd?
continue;
}
$found_addr = true;
$row = $node;
unset($row['addresses']);
$rows[] = array_merge($row, $addr);
$bytype[ $addr['type'] ][] = array_merge($row, $addr);
$totals['addresses'] ++;
$totals[ $addr['type'] ] ++;
}
if( $found_addr ) {
$totals['nodes_with_address'] ++;
}
}
usort( $rows, 'tscmp' );
function tscmp($a, $b) {
return -($a['last_timestamp'] - $b['last_timestamp']);
}
foreach( $bytype as &$list ) {
usort( $list, 'tscmp' );
}
file_put_contents(__DIR__ . '/nodes-by-addr-type.json', json_encode($bytype, JSON_PRETTY_PRINT));
function print_node_table($rows, $addrtype) {
$buf = <<< END
|alias|last seen|address|port|id|
|-----|---------|-------|----|--|
END;
foreach($rows as $row) {
if($row['type'] == $addrtype) {
$buf .= sprintf('|%s|%s|%s|%s|%s|' . "\n", e($row['alias']), nbr(gmdate('Y.m.d H:i', $row['last_timestamp'])), e($row['address']), e($row['port']), e($row['nodeid']));
}
}
echo $buf;
}
function nbr($b) {return str_replace(' ', ' ', $b);}
// we quote strings with backtick only if string includes a colon. because markdown
// interprets certain colon delimited strings as emoji chars with no way to escape properly.
// for our purposes mostly it means that ipv6 addrs will be in backticks, which will format them
// evenly anyway.
function e($b) { $quote = strstr($b, ':') ? "`" : ''; return $quote . htmlentities($b) . $quote;}
?>
# lightning-nodes
A historical list of lightning nodes, including .onion, updated daily.
Data obtained from [c-lightning](https://github.com/ElementsProject/lightning) listnodes API. [json](https://raw.githubusercontent.com/dan-da/lightning-nodes/master/nodes-by-addr-type.json) also available.
Last updated: <?= gmdate('Y-m-d H:i:s e' ); ?>
## Stats
|Desc|count|
|----|----|
<?php
foreach( $totals as $k => $t ) {
echo sprintf("|%s|%s|\n", ucfirst($k), $t);
}
?>
## Lightning Tor v3 onion:
<?php print_node_table($rows, 'torv3'); ?>
## Lightning Tor v2 onion:
<?php print_node_table($rows, 'torv2'); ?>
## IPV6:
<?php print_node_table($rows, 'ipv6'); ?>
## IPV4:
<?php print_node_table($rows, 'ipv4'); ?>