Skip to content

Commit 420695c

Browse files
committed
contrib: recognize CJDNS seeds as such
An IPv6 address from fc00::/8 could be either from the CJDNS network or from a private-unroutable-reserved segment of IPv6. A seed node with such an address must be from the CJDNS network, otherwise other peers will not be able to connect to it.
1 parent f9c2833 commit 420695c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

contrib/seeds/generate-seeds.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def name_to_bip155(addr):
6161
raise ValueError(f'Invalid I2P {vchAddr}')
6262
elif '.' in addr: # IPv4
6363
return (BIP155Network.IPV4, bytes((int(x) for x in addr.split('.'))))
64-
elif ':' in addr: # IPv6
64+
elif ':' in addr: # IPv6 or CJDNS
6565
sub = [[], []] # prefix, suffix
6666
x = 0
6767
addr = addr.split(':')
@@ -77,7 +77,14 @@ def name_to_bip155(addr):
7777
sub[x].append(val & 0xff)
7878
nullbytes = 16 - len(sub[0]) - len(sub[1])
7979
assert((x == 0 and nullbytes == 0) or (x == 1 and nullbytes > 0))
80-
return (BIP155Network.IPV6, bytes(sub[0] + ([0] * nullbytes) + sub[1]))
80+
addr_bytes = bytes(sub[0] + ([0] * nullbytes) + sub[1])
81+
if addr_bytes[0] == 0xfc:
82+
# Assume that seeds with fc00::/8 addresses belong to CJDNS,
83+
# not to the publicly unroutable "Unique Local Unicast" network, see
84+
# RFC4193: https://datatracker.ietf.org/doc/html/rfc4193#section-8
85+
return (BIP155Network.CJDNS, addr_bytes)
86+
else:
87+
return (BIP155Network.IPV6, addr_bytes)
8188
else:
8289
raise ValueError('Could not parse address %s' % addr)
8390

0 commit comments

Comments
 (0)