diff --git a/src/helper_startup.py b/src/helper_startup.py index ab59cf81..23aea35c 100644 --- a/src/helper_startup.py +++ b/src/helper_startup.py @@ -390,3 +390,18 @@ def start_proxyconfig(): logger.info( 'Started proxy config plugin %s in %s sec', proxy_type, time.time() - proxyconfig_start) + + +def enumerate_bootstrap_servers(): + """Generator of (IP, port) pairs resolved from dns seeds""" + for port in [8080, 8444]: + for item in socket.getaddrinfo( + 'bootstrap%s.bitmessage.org' % port, port, type=socket.SOCK_STREAM + ): + try: + peer = item[4] + socket.inet_aton(peer[0]) + except (TypeError, socket.error): + continue + else: + yield peer[:2] diff --git a/src/tests/core.py b/src/tests/core.py index 4857951a..2971f2f7 100644 --- a/src/tests/core.py +++ b/src/tests/core.py @@ -25,6 +25,7 @@ import helper_addressbook from bmconfigparser import BMConfigParser from helper_msgcoding import MsgEncode, MsgDecode from helper_sql import sqlQuery +from helper_startup import enumerate_bootstrap_servers from network import asyncore_pollchoose as asyncore, knownnodes from network.bmproto import BMProto from network.connectionpool import BMConnectionPool @@ -237,16 +238,8 @@ class TestCore(unittest.TestCase): def test_connection(self): """test connection to bootstrap servers""" self._initiate_bootstrap() - for port in [8080, 8444]: - for item in socket.getaddrinfo( - 'bootstrap%s.bitmessage.org' % port, 80): - try: - addr = item[4][0] - socket.inet_aton(item[4][0]) - except (TypeError, socket.error): - continue - else: - knownnodes.addKnownNode(1, Peer(addr, port)) + for peer in enumerate_bootstrap_servers(): + knownnodes.addKnownNode(1, Peer(*peer)) self._check_connection(True) def test_bootstrap(self):