diff --git a/.arclint b/.arclint --- a/.arclint +++ b/.arclint @@ -3,7 +3,10 @@ "clang-format": { "type": "clang-format", "include": "(^src/.*\\.(h|c|cpp)$)", - "exclude": "(^src/(secp256k1|leveldb)/)" + "exclude": [ + "(^src/(secp256k1|leveldb)/)", + "(^src/chainparamsseeds\\.h$)" + ] }, "autopep8": { "type": "autopep8", diff --git a/contrib/seeds/makeseeds.py b/contrib/seeds/makeseeds.py --- a/contrib/seeds/makeseeds.py +++ b/contrib/seeds/makeseeds.py @@ -6,9 +6,9 @@ # Generate seeds.txt from Pieter's DNS seeder # -NSEEDS=512 +NSEEDS = 512 -MAX_SEEDS_PER_ASN=2 +MAX_SEEDS_PER_ASN = 2 MIN_BLOCKS = 337600 @@ -27,15 +27,19 @@ import dns.resolver import collections -PATTERN_IPV4 = re.compile(r"^((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})):(\d+)$") +PATTERN_IPV4 = re.compile( + r"^((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})):(\d+)$") PATTERN_IPV6 = re.compile(r"^\[([0-9a-z:]+)\]:(\d+)$") -PATTERN_ONION = re.compile(r"^([abcdefghijklmnopqrstuvwxyz234567]{16}\.onion):(\d+)$") -PATTERN_AGENT = re.compile(r"^(/Satoshi:0.12.(0|1|99)/|/Satoshi:0.13.(0|1|2|99)/)$") +PATTERN_ONION = re.compile( + r"^([abcdefghijklmnopqrstuvwxyz234567]{16}\.onion):(\d+)$") +PATTERN_AGENT = re.compile( + r"^(/Satoshi:0.12.(0|1|99)/|/Satoshi:0.13.(0|1|2|99)/)$") + def parseline(line): sline = line.split() if len(sline) < 11: - return None + return None m = PATTERN_IPV4.match(sline[0]) sortkey = None ip = None @@ -51,18 +55,18 @@ port = int(m.group(2)) else: net = 'ipv6' - if m.group(1) in ['::']: # Not interested in localhost + if m.group(1) in ['::']: # Not interested in localhost return None ipstr = m.group(1) - sortkey = ipstr # XXX parse IPv6 into number, could use name_to_ipv6 from generate-seeds + sortkey = ipstr # XXX parse IPv6 into number, could use name_to_ipv6 from generate-seeds port = int(m.group(2)) else: # Do IPv4 sanity check ip = 0 - for i in range(0,4): - if int(m.group(i+2)) < 0 or int(m.group(i+2)) > 255: + for i in range(0, 4): + if int(m.group(i + 2)) < 0 or int(m.group(i + 2)) > 255: return None - ip = ip + (int(m.group(i+2)) << (8*(3-i))) + ip = ip + (int(m.group(i + 2)) << (8 * (3 - i))) if ip == 0: return None net = 'ipv4' @@ -99,14 +103,17 @@ 'sortkey': sortkey, } + def filtermultiport(ips): '''Filter out hosts with more nodes per IP''' hist = collections.defaultdict(list) for ip in ips: hist[ip['sortkey']].append(ip) - return [value[0] for (key,value) in list(hist.items()) if len(value)==1] + return [value[0] for (key, value) in list(hist.items()) if len(value) == 1] # Based on Greg Maxwell's seed_filter.py + + def filterbyasn(ips, max_per_asn, max_total): # Sift out ips by type ips_ipv4 = [ip for ip in ips if ip['net'] == 'ipv4'] @@ -120,7 +127,8 @@ if len(result) == max_total: break try: - asn = int([x.to_text() for x in dns.resolver.query('.'.join(reversed(ip['ip'].split('.'))) + '.origin.asn.cymru.com', 'TXT').response.answer][0].split('\"')[1].split(' ')[0]) + asn = int([x.to_text() + for x in dns.resolver.query('.'.join(reversed(ip['ip'].split('.'))) + '.origin.asn.cymru.com', 'TXT').response.answer][0].split('\"')[1].split(' ')[0]) if asn not in asn_count: asn_count[asn] = 0 if asn_count[asn] == max_per_asn: @@ -128,7 +136,8 @@ asn_count[asn] += 1 result.append(ip) except: - sys.stderr.write('ERR: Could not resolve ASN for "' + ip['ip'] + '"\n') + sys.stderr.write( + 'ERR: Could not resolve ASN for "' + ip['ip'] + '"\n') # TODO: filter IPv6 by ASN @@ -137,6 +146,7 @@ result.extend(ips_onion) return result + def main(): lines = sys.stdin.readlines() ips = [parseline(line) for line in lines] @@ -154,7 +164,8 @@ # Require a known and recent user agent. ips = [ip for ip in ips if PATTERN_AGENT.match(ip['agent'])] # Sort by availability (and use last success as tie breaker) - ips.sort(key=lambda x: (x['uptime'], x['lastsuccess'], x['ip']), reverse=True) + ips.sort(key=lambda x: + (x['uptime'], x['lastsuccess'], x['ip']), reverse=True) # Filter out hosts with multiple bitcoin ports, these are likely abusive ips = filtermultiport(ips) # Look up ASNs and limit results, both per ASN and globally. @@ -168,5 +179,6 @@ else: print('%s:%i' % (ip['ip'], ip['port'])) + if __name__ == '__main__': main()