Changeset View
Changeset View
Standalone View
Standalone View
contrib/seeds/generate-seeds.py
Show All 16 Lines | These files must consist of lines in the format | ||||
<ip>:<port> | <ip>:<port> | ||||
[<ipv6>] | [<ipv6>] | ||||
[<ipv6>]:<port> | [<ipv6>]:<port> | ||||
<onion>.onion | <onion>.onion | ||||
0xDDBBCCAA (IPv4 little-endian old pnSeeds format) | 0xDDBBCCAA (IPv4 little-endian old pnSeeds format) | ||||
The output will be two data structures with the peers in binary format: | The output will be two data structures with the peers in binary format: | ||||
static SeedSpec6 pnSeed6_main[]={ | SeedSpec6 pnSeed6_main[]={ | ||||
... | ... | ||||
} | } | ||||
static SeedSpec6 pnSeed6_test[]={ | SeedSpec6 pnSeed6_test[]={ | ||||
... | ... | ||||
} | } | ||||
These should be pasted into `src/chainparamsseeds.h`. | These should be pasted into `src/chainparamsseeds.h`. | ||||
''' | ''' | ||||
from base64 import b32decode | from base64 import b32decode | ||||
from binascii import a2b_hex | from binascii import a2b_hex | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | else: | ||||
port = int(port) | port = int(port) | ||||
host = name_to_ipv6(host) | host = name_to_ipv6(host) | ||||
return (host, port) | return (host, port) | ||||
def process_nodes(g, f, structname, defaultport): | def process_nodes(g, f, structname, defaultport): | ||||
g.write('static SeedSpec6 {}[] = {{\n'.format(structname)) | g.write('SeedSpec6 {}[] = {{\n'.format(structname)) | ||||
first = True | first = True | ||||
for line in f: | for line in f: | ||||
comment = line.find('#') | comment = line.find('#') | ||||
if comment != -1: | if comment != -1: | ||||
line = line[0:comment] | line = line[0:comment] | ||||
line = line.strip() | line = line.strip() | ||||
if not line: | if not line: | ||||
continue | continue | ||||
if not first: | if not first: | ||||
g.write(',\n') | g.write(',\n') | ||||
first = False | first = False | ||||
(host, port) = parse_spec(line, defaultport) | (host, port) = parse_spec(line, defaultport) | ||||
hoststr = ','.join(('0x{:02x}'.format(b)) for b in host) | hoststr = ','.join(('0x{:02x}'.format(b)) for b in host) | ||||
g.write(' {{{{{}}}, {}}}'.format(hoststr, port)) | g.write(' {{{{{}}}, {}}}'.format(hoststr, port)) | ||||
g.write('\n};\n') | g.write('\n};\n') | ||||
g.write('uint16_t {}_len = ARRAYLEN({});\n'.format(structname, structname)) | |||||
def main(): | def main(): | ||||
if len(sys.argv) < 2: | if len(sys.argv) < 2: | ||||
print( | print( | ||||
'Usage: {} <path_to_nodes_txt>'.format( | 'Usage: {} <path_to_nodes_txt>'.format( | ||||
sys.argv[0]), | sys.argv[0]), | ||||
file=sys.stderr) | file=sys.stderr) | ||||
sys.exit(1) | sys.exit(1) | ||||
g = sys.stdout | g = sys.stdout | ||||
indir = sys.argv[1] | indir = sys.argv[1] | ||||
g.write('#ifndef BITCOIN_CHAINPARAMSSEEDS_H\n') | g.write('#include <chainparams.h>\n') | ||||
g.write('#define BITCOIN_CHAINPARAMSSEEDS_H\n') | g.write('#include <util/strencodings.h>\n') | ||||
g.write('/**\n') | g.write('/**\n') | ||||
g.write(' * List of fixed seed nodes for the bitcoin network\n') | g.write(' * List of fixed seed nodes for the bitcoin network\n') | ||||
g.write(' * @{} by contrib/seeds/generate-seeds.py\n'.format('generated')) | g.write(' * @{} by contrib/seeds/generate-seeds.py\n'.format('generated')) | ||||
g.write(' *\n') | g.write(' *\n') | ||||
g.write(' * Each line contains a 16-byte IPv6 address and a port.\n') | g.write(' * Each line contains a 16-byte IPv6 address and a port.\n') | ||||
g.write( | g.write( | ||||
' * IPv4 as well as onion addresses are wrapped inside an IPv6 address accordingly.\n') | ' * IPv4 as well as onion addresses are wrapped inside an IPv6 address accordingly.\n') | ||||
g.write(' */\n') | g.write(' */\n') | ||||
with open(os.path.join(indir, 'nodes_main.txt'), 'r', encoding="utf8") as f: | with open(os.path.join(indir, 'nodes_main.txt'), 'r', encoding="utf8") as f: | ||||
process_nodes(g, f, 'pnSeed6_main', 8333) | process_nodes(g, f, 'pnSeed6_main', 8333) | ||||
g.write('\n') | g.write('\n') | ||||
with open(os.path.join(indir, 'nodes_test.txt'), 'r', encoding="utf8") as f: | with open(os.path.join(indir, 'nodes_test.txt'), 'r', encoding="utf8") as f: | ||||
process_nodes(g, f, 'pnSeed6_test', 18333) | process_nodes(g, f, 'pnSeed6_test', 18333) | ||||
g.write('#endif // BITCOIN_CHAINPARAMSSEEDS_H\n') | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
main() | main() |