contrib: parse I2P addresses in generate-seeds.py

This commit is contained in:
Jon Atack 2021-05-01 20:50:01 +02:00
parent d22e7ee933
commit ea269c7ef1
No known key found for this signature in database
GPG key ID: 4F5721B3D0E3921D

View file

@ -16,6 +16,7 @@ These files must consist of lines in the format
<ip>:<port>
[<ipv6>]:<port>
<onion>.onion:<port>
<i2p>.b32.i2p:<port>
The output will be two data structures with the peers in binary format:
@ -52,6 +53,12 @@ def name_to_bip155(addr):
return (BIP155Network.TORV3, vchAddr[:32])
else:
raise ValueError('Invalid onion %s' % vchAddr)
elif addr.endswith('.b32.i2p'):
vchAddr = b32decode(addr[0:-8] + '====', True)
if len(vchAddr) == 32:
return (BIP155Network.I2P, vchAddr)
else:
raise ValueError(f'Invalid I2P {vchAddr}')
elif '.' in addr: # IPv4
return (BIP155Network.IPV4, bytes((int(x) for x in addr.split('.'))))
elif ':' in addr: # IPv6