Commit 0e1e8f06 authored by minus's avatar minus
Browse files

added hostname support to Address

parent 9bf07c18
......@@ -15,7 +15,7 @@ L = logging.getLogger(__name__)
def get_address(host, port=8303, family=0):
info = socket.getaddrinfo(host, port, family, socket.SOCK_DGRAM)
return Address(info[0][4][0], info[0][4][1], family)
return Address(info[0][4][0], info[0][4][1], family, hostname=host)
except socket.gaierror as e:
L.warning('getaddrinfo failed: ' + str(e))
return None
......@@ -54,10 +54,13 @@ def listdata2addresslist(listdata):
class Address(object):
def __init__(self, host=None, port=None, family=None):
def __init__(self, host=None, port=None, family=None, hostname=None): = host
self.port = port = family
self.hostname = hostname
if not hostname:
self.hostname = host
def address_tuple(self):
return (, self.port)
......@@ -25,16 +25,21 @@ L = logging.getLogger(__name__)
from .base import get_address
from .master import MasterServer
def create_masters(eventsocket, hostnames=["master{}".format(i+1) for i in range(4)], master_factory=MasterServer):
def get_master_addresses(hostnames=["master{}".format(i+1) for i in range(4)]):
masterlist = []
for mastername in hostnames:
# resolves host and picks the first address
master_addr = get_address(mastername, port=8300)
if master_addr:
L.debug("requesting {} ({})".format(mastername, master_addr))
master = master_factory(eventsocket, master_addr, mastername.partition(".")[0])
masterlist.append(get_address(mastername, port=8300))
return masterlist
def create_masters(eventsocket, addresses=get_master_addresses(), master_factory=MasterServer):
masterlist = []
for master_addr in addresses:
L.debug("requesting {} ({})".format(master_addr.hostname, master_addr))
master = master_factory(eventsocket, master_addr, master_addr.hostname)
return masterlist
def query_masters_serverlist(masterlist):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment