From dbafe746625af9736e5b4482b27f6d4b579d749f Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Tue, 15 Sep 2015 11:22:55 +0200 Subject: [PATCH] zeroconf: Use Avahi's host management by default Fixes #1283 --- mopidy/zeroconf.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/mopidy/zeroconf.py b/mopidy/zeroconf.py index 57d3f62d..64a9b111 100644 --- a/mopidy/zeroconf.py +++ b/mopidy/zeroconf.py @@ -40,18 +40,17 @@ class Zeroconf(object): :param str stype: service type, e.g. '_mpd._tcp' :param int port: TCP port of the service, e.g. 6600 :param str domain: local network domain name, defaults to '' - :param str host: interface to advertise the service on, defaults to all - interfaces + :param str host: interface to advertise the service on, defaults to '' :param text: extra information depending on ``stype``, defaults to empty list :type text: list of str """ - def __init__(self, name, stype, port, domain=None, text=None): - self.group = None + def __init__(self, name, stype, port, domain='', host='', text=None): self.stype = stype - self.domain = domain or '' self.port = port + self.domain = domain + self.host = host self.text = text or [] self.bus = None @@ -65,10 +64,9 @@ class Zeroconf(object): except dbus.exceptions.DBusException as e: logger.debug('%s: Server failed: %s', self, e) - template = string.Template(name) - self.name = template.safe_substitute( - hostname=socket.getfqdn(), port=self.port) - self.host = '%s.local' % socket.getfqdn() + self.display_hostname = '%s.local' % socket.getfqdn() + self.name = string.Template(name).safe_substitute( + hostname=self.display_hostname, port=port) def __str__(self): return 'Zeroconf service %s at [%s]:%d' % ( @@ -110,7 +108,8 @@ class Zeroconf(object): self.group.AddService( _AVAHI_IF_UNSPEC, _AVAHI_PROTO_UNSPEC, - dbus.UInt32(_AVAHI_PUBLISHFLAGS_NONE), self.name, self.stype, + dbus.UInt32(_AVAHI_PUBLISHFLAGS_NONE), + self.name, self.stype, self.domain, self.host, dbus.UInt16(self.port), _convert_text_list_to_dbus_format(self.text))