From 8e761693889b914ef52c4c27b3c57e28ff096c65 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Sat, 7 Oct 2017 17:28:32 +0300 Subject: [PATCH] Check IP before adding to knownnodes in helper_bootstrap --- src/helper_bootstrap.py | 48 ++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/src/helper_bootstrap.py b/src/helper_bootstrap.py index 7c7456e1..0ba86348 100644 --- a/src/helper_bootstrap.py +++ b/src/helper_bootstrap.py @@ -9,6 +9,7 @@ import knownnodes import socks import state + def addKnownNode(stream, peer, lastseen=None, self=False): if lastseen is None: lastseen = time.time() @@ -18,6 +19,7 @@ def addKnownNode(stream, peer, lastseen=None, self=False): "self": self, } + def knownNodes(): try: with open(state.appdata + 'knownnodes.dat', 'rb') as pickleFile: @@ -38,26 +40,37 @@ def knownNodes(): logger.error('Bitmessage cannot read future versions of the keys file (keys.dat). Run the newer version of Bitmessage.') raise SystemExit + def dns(): # DNS bootstrap. This could be programmed to use the SOCKS proxy to do the # DNS lookup some day but for now we will just rely on the entries in # defaultKnownNodes.py. Hopefully either they are up to date or the user # has run Bitmessage recently without SOCKS turned on and received good # bootstrap nodes using that method. - if BMConfigParser().get('bitmessagesettings', 'socksproxytype') == 'none': + def try_add_known_node(stream, addr, port, method=''): try: - for item in socket.getaddrinfo('bootstrap8080.bitmessage.org', 80): - logger.info('Adding ' + item[4][0] + ' to knownNodes based on DNS bootstrap method') - addKnownNode(1, state.Peer(item[4][0], 8080)) - except: - logger.error('bootstrap8080.bitmessage.org DNS bootstrapping failed.') - try: - for item in socket.getaddrinfo('bootstrap8444.bitmessage.org', 80): - logger.info ('Adding ' + item[4][0] + ' to knownNodes based on DNS bootstrap method') - addKnownNode(1, state.Peer(item[4][0], 8444)) - except: - logger.error('bootstrap8444.bitmessage.org DNS bootstrapping failed.') - elif BMConfigParser().get('bitmessagesettings', 'socksproxytype') == 'SOCKS5': + socket.inet_aton(addr) + except (TypeError, socket.error): + return + logger.info( + 'Adding %s to knownNodes based on %s DNS bootstrap method', + addr, method) + addKnownNode(stream, state.Peer(addr, port)) + + proxy_type = BMConfigParser().get('bitmessagesettings', 'socksproxytype') + + if proxy_type == 'none': + for port in [8080, 8444]: + try: + for item in socket.getaddrinfo( + 'bootstrap%s.bitmessage.org' % port, 80): + try_add_known_node(1, item[4][0], port) + except: + logger.error( + 'bootstrap%s.bitmessage.org DNS bootstrapping failed.', + port, exc_info=True + ) + elif proxy_type == 'SOCKS5': addKnownNode(1, state.Peer('quzwelsuziwqgpt2.onion', 8444)) logger.debug("Adding quzwelsuziwqgpt2.onion:8444 to knownNodes.") for port in [8080, 8444]: @@ -89,8 +102,9 @@ def dns(): except: logger.error("SOCKS DNS resolving failed", exc_info=True) else: - if ip is not None: - logger.info ('Adding ' + ip + ' to knownNodes based on SOCKS DNS bootstrap method') - addKnownNode(1, state.Peer(ip, port)) + try_add_known_node(1, ip, port, 'SOCKS') else: - logger.info('DNS bootstrap skipped because the proxy type does not support DNS resolution.') + logger.info( + 'DNS bootstrap skipped because the proxy type does not support' + ' DNS resolution.' + )