Changeset View
Changeset View
Standalone View
Standalone View
contrib/seeds/makeseeds.py
Show All 28 Lines | |||||
PATTERN_IPV4 = re.compile( | PATTERN_IPV4 = re.compile( | ||||
r"^((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})):(\d+)$") | r"^((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})):(\d+)$") | ||||
PATTERN_IPV6 = re.compile(r"^\[([0-9a-z:]+)\]:(\d+)$") | PATTERN_IPV6 = re.compile(r"^\[([0-9a-z:]+)\]:(\d+)$") | ||||
PATTERN_ONION = re.compile( | PATTERN_ONION = re.compile( | ||||
r"^([abcdefghijklmnopqrstuvwxyz234567]{16}\.onion):(\d+)$") | r"^([abcdefghijklmnopqrstuvwxyz234567]{16}\.onion):(\d+)$") | ||||
# Used to only select nodes with a user agent string compatible with the | # Used to only select nodes with a user agent string compatible with the | ||||
# BCC/UAHF specification. | # BCH/UAHF specification. | ||||
PATTERN_AGENT = re.compile( | PATTERN_AGENT = re.compile( | ||||
r"^(/BitcoinABC:0.16.(\d+)\(\S+\)/|/BitcoinXT:0.11.0G\(\S+\)/|/BUCash:1.1.(\d+)\(\S+\)/|/Classic:1.3.(\d+)\(\S+\)/)") | r"^(/BitcoinABC:0.16.(\d+)\(\S+\)/|/BitcoinXT:0.11.0G\(\S+\)/|/BUCash:1.1.(\d+)\(\S+\)/|/Classic:1.3.(\d+)\(\S+\)/)") | ||||
def parseline(line): | def parseline(line): | ||||
sline = line.split() | sline = line.split() | ||||
if len(sline) < 11: | if len(sline) < 11: | ||||
return None | return None | ||||
# All BCC clients apart BU and Classic has a space in the useragent string | # All BCH clients apart BU and Classic has a space in the useragent string | ||||
if len(sline) == 13: | if len(sline) == 13: | ||||
sline[11] = sline[11] + sline[12] | sline[11] = sline[11] + sline[12] | ||||
if len(sline) == 14: | if len(sline) == 14: | ||||
sline[11] = sline[11] + sline[12] + sline[13] | sline[11] = sline[11] + sline[12] + sline[13] | ||||
m = PATTERN_IPV4.match(sline[0]) | m = PATTERN_IPV4.match(sline[0]) | ||||
sortkey = None | sortkey = None | ||||
ip = None | ip = None | ||||
if m is None: | if m is None: | ||||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | def main(): | ||||
# Require a known and recent user agent. | # Require a known and recent user agent. | ||||
ips = [ip for ip in ips if PATTERN_AGENT.match(ip['agent'])] | ips = [ip for ip in ips if PATTERN_AGENT.match(ip['agent'])] | ||||
# Sort by availability (and use last success as tie breaker) | # Sort by availability (and use last success as tie breaker) | ||||
ips.sort(key=lambda x: | ips.sort(key=lambda x: | ||||
(x['uptime'], x['lastsuccess'], x['ip']), reverse=True) | (x['uptime'], x['lastsuccess'], x['ip']), reverse=True) | ||||
# Filter out hosts with multiple bitcoin ports, these are likely abusive | # Filter out hosts with multiple bitcoin ports, these are likely abusive | ||||
ips = filtermultiport(ips) | ips = filtermultiport(ips) | ||||
# Look up ASNs and limit results, both per ASN and globally. | # Look up ASNs and limit results, both per ASN and globally. | ||||
# TODO during this bootstrap phase we need any BCC full nodes | # TODO during this bootstrap phase we need any BCH full nodes | ||||
# active on the network, uncomment the following line once the | # active on the network, uncomment the following line once the | ||||
# BCC chain will be consolidated. | # BCH chain will be consolidated. | ||||
# ips = filterbyasn(ips, MAX_SEEDS_PER_ASN, NSEEDS) | # ips = filterbyasn(ips, MAX_SEEDS_PER_ASN, NSEEDS) | ||||
# Sort the results by IP address (for deterministic output). | # Sort the results by IP address (for deterministic output). | ||||
ips.sort(key=lambda x: (x['net'], x['sortkey'])) | ips.sort(key=lambda x: (x['net'], x['sortkey'])) | ||||
for ip in ips: | for ip in ips: | ||||
if ip['net'] == 'ipv6': | if ip['net'] == 'ipv6': | ||||
print('[%s]:%i' % (ip['ip'], ip['port'])) | print('[%s]:%i' % (ip['ip'], ip['port'])) | ||||
else: | else: | ||||
print('%s:%i' % (ip['ip'], ip['port'])) | print('%s:%i' % (ip['ip'], ip['port'])) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
main() | main() |