Empty addresses are valid, meaning the buddy own address.
For group (multicast) services publisher_address != service_address, introduce the distinction in the API and in the avahi announcement.
This commit is contained in:
parent
53f00b05b1
commit
6d7940949a
@ -1,4 +1,5 @@
|
||||
import base64
|
||||
import logging
|
||||
|
||||
import pygtk
|
||||
pygtk.require('2.0')
|
||||
@ -65,7 +66,8 @@ class Buddy(gobject.GObject):
|
||||
True if the service was successfully added, and False if it was not."""
|
||||
if service.get_name() != self._nick_name:
|
||||
return False
|
||||
if service.get_address() != self._address:
|
||||
if service.get_publisher_address() != self._address:
|
||||
logging.error('Service publisher and buddy address doesnt match: %s %s' % (service.get_publisher_address(), self._address))
|
||||
return False
|
||||
if service.get_type() in self._services.keys():
|
||||
return False
|
||||
|
@ -322,6 +322,9 @@ class PresenceService(gobject.GObject):
|
||||
if resolve and not adv in self._resolve_queue:
|
||||
self._resolve_queue.append(adv)
|
||||
gobject.idle_add(self._resolve_service, adv)
|
||||
else:
|
||||
logging.debug("Do not resolve service '%s' of type '%s', we don't care about it." % (name, full_stype))
|
||||
|
||||
return False
|
||||
|
||||
def _service_appeared_cb_glue(self, interface, protocol, name, stype, domain, flags):
|
||||
@ -507,17 +510,17 @@ class PresenceService(gobject.GObject):
|
||||
real_stype = Service.compose_service_type(stype, uid)
|
||||
if address and type(address) != type(""):
|
||||
raise ValueError("address must be a valid string.")
|
||||
if not address:
|
||||
if address == None:
|
||||
# Use random currently unassigned multicast address
|
||||
address = "232.%d.%d.%d" % (random.randint(0, 254), random.randint(1, 254),
|
||||
random.randint(1, 254))
|
||||
|
||||
if port and (type(port) != type(1) or port <= 1024 or port >= 65535):
|
||||
raise ValueError("port must be a number between 1024 and 65535")
|
||||
if not port:
|
||||
# random port #
|
||||
port = random.randint(5000, 65535)
|
||||
|
||||
logging.debug('Share activity %s, address %s, port %d' % (stype, address, port))
|
||||
service = Service.Service(name=owner_nick, stype=real_stype, domain="local",
|
||||
address=address, port=port, properties=properties)
|
||||
# Publish it to the world
|
||||
@ -536,6 +539,7 @@ class PresenceService(gobject.GObject):
|
||||
raise ValueError("invalid service port.")
|
||||
rs_props = service.get_properties()
|
||||
rs_domain = service.get_domain()
|
||||
rs_address = service.get_address()
|
||||
if not rs_domain or not len(rs_domain):
|
||||
rs_domain = ""
|
||||
logging.debug("registered service name '%s' type '%s' on port %d with args %s" % (rs_name, rs_stype, rs_port, rs_props))
|
||||
@ -543,6 +547,8 @@ class PresenceService(gobject.GObject):
|
||||
try:
|
||||
group = dbus.Interface(self._bus.get_object(avahi.DBUS_NAME, self._server.EntryGroupNew()), avahi.DBUS_INTERFACE_ENTRY_GROUP)
|
||||
info = ["%s=%s" % (k, v) for k, v in rs_props.items()]
|
||||
if rs_address and len(rs_address):
|
||||
info.append("address=%s" % (rs_address))
|
||||
group.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, 0, rs_name, rs_stype,
|
||||
rs_domain, "", # let Avahi figure the 'host' out
|
||||
dbus.UInt16(rs_port), info,)
|
||||
|
@ -92,12 +92,16 @@ class Service(object):
|
||||
self._full_stype = full_stype
|
||||
self._activity_stype = short_stype
|
||||
self._domain = domain
|
||||
self._address = None
|
||||
self.set_address(address)
|
||||
self._port = -1
|
||||
self.set_port(port)
|
||||
self._properties = {}
|
||||
self.set_properties(properties)
|
||||
self._publisher_address = address
|
||||
self._address = None
|
||||
if self._properties.has_key('address'):
|
||||
self.set_address(self._properties['address'])
|
||||
else:
|
||||
self.set_address(address)
|
||||
|
||||
# Ensure that an ActivityUID tag, if given, matches
|
||||
# what we expect from the service type
|
||||
@ -166,6 +170,9 @@ class Service(object):
|
||||
raise ValueError("must specify a valid port number.")
|
||||
self._port = port
|
||||
|
||||
def get_publisher_address(self):
|
||||
return self._publisher_address
|
||||
|
||||
def get_address(self):
|
||||
return self._address
|
||||
|
||||
@ -173,8 +180,6 @@ class Service(object):
|
||||
if address is not None:
|
||||
if type(address) != type("") and type(address) != type(u""):
|
||||
raise ValueError("must specify a valid address.")
|
||||
if not len(address):
|
||||
raise ValueError("must specify a valid address.")
|
||||
if address and type(address) == type(u""):
|
||||
address = address.encode()
|
||||
self._address = address
|
||||
|
Loading…
Reference in New Issue
Block a user