()
| 42 | |
| 43 | |
| 44 | def dns(): |
| 45 | # DNS bootstrap. This could be programmed to use the SOCKS proxy to do the |
| 46 | # DNS lookup some day but for now we will just rely on the entries in |
| 47 | # defaultKnownNodes.py. Hopefully either they are up to date or the user |
| 48 | # has run Bitmessage recently without SOCKS turned on and received good |
| 49 | # bootstrap nodes using that method. |
| 50 | def try_add_known_node(stream, addr, port, method=''): |
| 51 | try: |
| 52 | socket.inet_aton(addr) |
| 53 | except (TypeError, socket.error): |
| 54 | return |
| 55 | logger.info( |
| 56 | 'Adding %s to knownNodes based on %s DNS bootstrap method', |
| 57 | addr, method) |
| 58 | addKnownNode(stream, state.Peer(addr, port)) |
| 59 | |
| 60 | proxy_type = BMConfigParser().get('bitmessagesettings', 'socksproxytype') |
| 61 | |
| 62 | if proxy_type == 'none': |
| 63 | for port in [8080, 8444]: |
| 64 | try: |
| 65 | for item in socket.getaddrinfo( |
| 66 | 'bootstrap%s.bitmessage.org' % port, 80): |
| 67 | try_add_known_node(1, item[4][0], port) |
| 68 | except: |
| 69 | logger.error( |
| 70 | 'bootstrap%s.bitmessage.org DNS bootstrapping failed.', |
| 71 | port, exc_info=True |
| 72 | ) |
| 73 | elif proxy_type == 'SOCKS5': |
| 74 | addKnownNode(1, state.Peer('quzwelsuziwqgpt2.onion', 8444)) |
| 75 | logger.debug("Adding quzwelsuziwqgpt2.onion:8444 to knownNodes.") |
| 76 | for port in [8080, 8444]: |
| 77 | logger.debug("Resolving %i through SOCKS...", port) |
| 78 | address_family = socket.AF_INET |
| 79 | sock = socks.socksocket(address_family, socket.SOCK_STREAM) |
| 80 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
| 81 | sock.settimeout(20) |
| 82 | proxytype = socks.PROXY_TYPE_SOCKS5 |
| 83 | sockshostname = BMConfigParser().get( |
| 84 | 'bitmessagesettings', 'sockshostname') |
| 85 | socksport = BMConfigParser().getint( |
| 86 | 'bitmessagesettings', 'socksport') |
| 87 | rdns = True # Do domain name lookups through the proxy; though this setting doesn't really matter since we won't be doing any domain name lookups anyway. |
| 88 | if BMConfigParser().getboolean('bitmessagesettings', 'socksauthentication'): |
| 89 | socksusername = BMConfigParser().get( |
| 90 | 'bitmessagesettings', 'socksusername') |
| 91 | sockspassword = BMConfigParser().get( |
| 92 | 'bitmessagesettings', 'sockspassword') |
| 93 | sock.setproxy( |
| 94 | proxytype, sockshostname, socksport, rdns, socksusername, sockspassword) |
| 95 | else: |
| 96 | sock.setproxy( |
| 97 | proxytype, sockshostname, socksport, rdns) |
| 98 | try: |
| 99 | ip = sock.resolve("bootstrap" + str(port) + ".bitmessage.org") |
| 100 | sock.shutdown(socket.SHUT_RDWR) |
| 101 | sock.close() |
nothing calls this directly
no test coverage detected