Check IP before adding to knownnodes in helper_bootstrap

This commit is contained in:
Dmitri Bogomolov 2017-10-07 17:28:32 +03:00
parent 4c9006a632
commit 8e76169388
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13

View File

@ -9,6 +9,7 @@ import knownnodes
import socks import socks
import state import state
def addKnownNode(stream, peer, lastseen=None, self=False): def addKnownNode(stream, peer, lastseen=None, self=False):
if lastseen is None: if lastseen is None:
lastseen = time.time() lastseen = time.time()
@ -18,6 +19,7 @@ def addKnownNode(stream, peer, lastseen=None, self=False):
"self": self, "self": self,
} }
def knownNodes(): def knownNodes():
try: try:
with open(state.appdata + 'knownnodes.dat', 'rb') as pickleFile: 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.') logger.error('Bitmessage cannot read future versions of the keys file (keys.dat). Run the newer version of Bitmessage.')
raise SystemExit raise SystemExit
def dns(): def dns():
# DNS bootstrap. This could be programmed to use the SOCKS proxy to do the # 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 # 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 # defaultKnownNodes.py. Hopefully either they are up to date or the user
# has run Bitmessage recently without SOCKS turned on and received good # has run Bitmessage recently without SOCKS turned on and received good
# bootstrap nodes using that method. # bootstrap nodes using that method.
if BMConfigParser().get('bitmessagesettings', 'socksproxytype') == 'none': def try_add_known_node(stream, addr, port, method=''):
try: try:
for item in socket.getaddrinfo('bootstrap8080.bitmessage.org', 80): socket.inet_aton(addr)
logger.info('Adding ' + item[4][0] + ' to knownNodes based on DNS bootstrap method') except (TypeError, socket.error):
addKnownNode(1, state.Peer(item[4][0], 8080)) return
except: logger.info(
logger.error('bootstrap8080.bitmessage.org DNS bootstrapping failed.') '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: try:
for item in socket.getaddrinfo('bootstrap8444.bitmessage.org', 80): for item in socket.getaddrinfo(
logger.info ('Adding ' + item[4][0] + ' to knownNodes based on DNS bootstrap method') 'bootstrap%s.bitmessage.org' % port, 80):
addKnownNode(1, state.Peer(item[4][0], 8444)) try_add_known_node(1, item[4][0], port)
except: except:
logger.error('bootstrap8444.bitmessage.org DNS bootstrapping failed.') logger.error(
elif BMConfigParser().get('bitmessagesettings', 'socksproxytype') == 'SOCKS5': 'bootstrap%s.bitmessage.org DNS bootstrapping failed.',
port, exc_info=True
)
elif proxy_type == 'SOCKS5':
addKnownNode(1, state.Peer('quzwelsuziwqgpt2.onion', 8444)) addKnownNode(1, state.Peer('quzwelsuziwqgpt2.onion', 8444))
logger.debug("Adding quzwelsuziwqgpt2.onion:8444 to knownNodes.") logger.debug("Adding quzwelsuziwqgpt2.onion:8444 to knownNodes.")
for port in [8080, 8444]: for port in [8080, 8444]:
@ -89,8 +102,9 @@ def dns():
except: except:
logger.error("SOCKS DNS resolving failed", exc_info=True) logger.error("SOCKS DNS resolving failed", exc_info=True)
else: else:
if ip is not None: try_add_known_node(1, ip, port, 'SOCKS')
logger.info ('Adding ' + ip + ' to knownNodes based on SOCKS DNS bootstrap method')
addKnownNode(1, state.Peer(ip, port))
else: 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.'
)