Skip to content

Commit af550b3

Browse files
committed
makeseeds: Support CJDNS
1 parent d5a8c4c commit af550b3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

contrib/seeds/makeseeds.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ def parseline(line: str) -> Union[dict, None]:
8888
if m.group(1) in ['::']: # Not interested in localhost
8989
return None
9090
ipstr = m.group(1)
91+
if ipstr.startswith("fc"): # cjdns looks like ipv6 but always begins with fc
92+
net = "cjdns"
9193
sortkey = ipstr # XXX parse IPv6 into number, could use name_to_ipv6 from generate-seeds
9294
port = int(m.group(2))
9395
else:
@@ -154,6 +156,7 @@ def filterbyasn(asmap: ASMap, ips: list[dict], max_per_asn: dict, max_per_net: i
154156
ips_ipv46 = [ip for ip in ips if ip['net'] in ['ipv4', 'ipv6']]
155157
ips_onion = [ip for ip in ips if ip['net'] == 'onion']
156158
ips_i2p = [ip for ip in ips if ip['net'] == 'i2p']
159+
ips_cjdns = [ip for ip in ips if ip["net"] == "cjdns"]
157160

158161
# Filter IPv46 by ASN, and limit to max_per_net per network
159162
result = []
@@ -178,6 +181,7 @@ def filterbyasn(asmap: ASMap, ips: list[dict], max_per_asn: dict, max_per_net: i
178181
# Add back Onions (up to max_per_net)
179182
result.extend(ips_onion[0:max_per_net])
180183
result.extend(ips_i2p[0:max_per_net])
184+
result.extend(ips_cjdns[0:max_per_net])
181185
return result
182186

183187
def ip_stats(ips: list[dict]) -> str:
@@ -187,7 +191,7 @@ def ip_stats(ips: list[dict]) -> str:
187191
if ip is not None:
188192
hist[ip['net']] += 1
189193

190-
return f"{hist['ipv4']:6d} {hist['ipv6']:6d} {hist['onion']:6d} {hist['i2p']:6d}"
194+
return f"{hist['ipv4']:6d} {hist['ipv6']:6d} {hist['onion']:6d} {hist['i2p']:6d} {hist['cjdns']:6d}"
191195

192196
def parse_args():
193197
argparser = argparse.ArgumentParser(description='Generate a list of bitcoin node seed ip addresses.')
@@ -209,7 +213,7 @@ def main():
209213
ips = [parseline(line) for line in lines]
210214
print('Done.', file=sys.stderr)
211215

212-
print('\x1b[7m IPv4 IPv6 Onion I2P Pass \x1b[0m', file=sys.stderr)
216+
print('\x1b[7m IPv4 IPv6 Onion I2P CJDNS Pass \x1b[0m', file=sys.stderr)
213217
print(f'{ip_stats(ips):s} Initial', file=sys.stderr)
214218
# Skip entries with invalid address.
215219
ips = [ip for ip in ips if ip is not None]
@@ -229,6 +233,7 @@ def main():
229233
'ipv6': 50,
230234
'onion': 10,
231235
'i2p' : 10,
236+
'cjdns': 10,
232237
}
233238
ips = [ip for ip in ips if ip['uptime'] > req_uptime[ip['net']]]
234239
print(f'{ip_stats(ips):s} Require minimum uptime', file=sys.stderr)
@@ -246,7 +251,7 @@ def main():
246251
# Sort the results by IP address (for deterministic output).
247252
ips.sort(key=lambda x: (x['net'], x['sortkey']))
248253
for ip in ips:
249-
if ip['net'] == 'ipv6':
254+
if ip['net'] == 'ipv6' or ip["net"] == "cjdns":
250255
print(f"[{ip['ip']}]:{ip['port']}", end="")
251256
else:
252257
print(f"{ip['ip']}:{ip['port']}", end="")

0 commit comments

Comments
 (0)