Simplify bootstrap node declarations
This commit is contained in:
parent
c4abe4cd52
commit
cd89b6ca9e
2 changed files with 82 additions and 70 deletions
|
@ -38,27 +38,17 @@ if __name__ == '__main__':
|
|||
# extract relevant values from node dictionaries
|
||||
addresses = [node['ipv4'] for node in nodes]
|
||||
ports = [node['port'] for node in nodes]
|
||||
pubkeys = [node['public_key'] for node in nodes]
|
||||
keys = [node['public_key'] for node in nodes]
|
||||
comments = ['Maintainer: {}, location: {}'.format(
|
||||
node['maintainer'], node['location']) for node in nodes]
|
||||
|
||||
# format data as C literals
|
||||
addresses_c = ', '.join('"{}"'.format(address) for address in addresses)
|
||||
ports_c = ', '.join('{}'.format(port) for port in ports)
|
||||
pubkeys_c = ',\n '.join('/* {} */\n "{}"'.format(
|
||||
comment, key) for comment, key in zip(comments, pubkeys))
|
||||
|
||||
# word-wrap and indent addresses and ports
|
||||
addresses_c = textwrap.fill(addresses_c).replace('\n', '\n ')
|
||||
ports_c = textwrap.fill(ports_c).replace('\n', '\n ')
|
||||
|
||||
# emit C code
|
||||
print('/* bootstrap nodes generated by {}, do not modify'.format(__file__))
|
||||
print(' * last generated', datetime.datetime.now().isoformat())
|
||||
print(' */')
|
||||
print('char *twc_bootstrap_keys[] = {')
|
||||
print(' '*3, pubkeys_c, ' };\n')
|
||||
print('char *twc_bootstrap_addresses[] = {')
|
||||
print(' '*3, addresses_c, ' };\n')
|
||||
print('uint16_t twc_bootstrap_ports[] = {')
|
||||
print(' '*3, ports_c, ' };')
|
||||
print('/* bootstrap nodes generated by', __file__)
|
||||
print(' * last generated', datetime.datetime.now().isoformat(), '*/')
|
||||
|
||||
print('static struct t_twc_bootstrap_node const twc_bootstrap_nodes[] = {')
|
||||
for key, address, port, comment in zip(keys, addresses, ports, comments):
|
||||
print(' /* {} */'.format(comment))
|
||||
print(' {{"{}",'.format(key))
|
||||
print(' "{}", {}}},'.format(address, port))
|
||||
print('};')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue