More PS fixes
This commit is contained in:
parent
bca4e1ca9b
commit
1d0b4e12b8
@ -369,6 +369,11 @@ class PresenceService(object):
|
||||
self._services[key] = service
|
||||
else:
|
||||
service = self._services[key]
|
||||
if not service.get_address():
|
||||
set_addr = service.get_one_property('address')
|
||||
if not set_addr:
|
||||
set_addr = address
|
||||
service.set_address(set_addr)
|
||||
adv.set_service(service)
|
||||
|
||||
# Merge the service into our buddy and activity lists, if needed
|
||||
@ -382,6 +387,9 @@ class PresenceService(object):
|
||||
gobject.idle_add(self._resolve_service_reply_cb, interface, protocol,
|
||||
name, stype, domain, host, aprotocol, address, port, txt, flags)
|
||||
|
||||
def _resolve_service_error_handler(self, err):
|
||||
logging.error("error resolving service: %s" % err)
|
||||
|
||||
def _resolve_service(self, adv):
|
||||
"""Resolve and lookup a ZeroConf service to obtain its address and TXT records."""
|
||||
# Ask avahi to resolve this particular service
|
||||
@ -523,47 +531,35 @@ class PresenceService(object):
|
||||
|
||||
def register_service(self, name, stype, properties={}, address=None, port=None, domain=u"local"):
|
||||
"""Register a new service, advertising it to other Buddies on the network."""
|
||||
objid = self._get_next_object_id()
|
||||
service = Service.Service(self._bus_name, objid, name=name,
|
||||
stype=stype, domain=domain, address=address, port=port,
|
||||
properties=properties)
|
||||
key = (name, stype)
|
||||
self._services[key] = service
|
||||
|
||||
if self.get_owner() and name != self.get_owner().get_nick_name():
|
||||
raise RuntimeError("Tried to register a service that didn't have Owner nick as the service name!")
|
||||
actid = service.get_activity_id()
|
||||
rs_name = name
|
||||
if actid:
|
||||
rs_name = Service.compose_service_name(rs_name, actid)
|
||||
rs_stype = service.get_type()
|
||||
rs_port = service.get_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))
|
||||
if not domain or not len(domain):
|
||||
domain = u"local"
|
||||
|
||||
try:
|
||||
obj = self._session_bus.get_object(avahi.DBUS_NAME, self._mdns_service.EntryGroupNew())
|
||||
obj = self._system_bus.get_object(avahi.DBUS_NAME, self._mdns_service.EntryGroupNew())
|
||||
group = dbus.Interface(obj, avahi.DBUS_INTERFACE_ENTRY_GROUP)
|
||||
|
||||
# Add properties; ensure they are converted to ByteArray types
|
||||
# because python sometimes can't figure that out
|
||||
info = [""]
|
||||
for k, v in rs_props.items():
|
||||
tmp_item = "%s=%s" % (k, v)
|
||||
info.append(dbus.types.ByteArray(tmp_item))
|
||||
info = []
|
||||
for k, v in properties.items():
|
||||
info.append(dbus.types.ByteArray("%s=%s" % (k, v)))
|
||||
|
||||
if rs_address and len(rs_address):
|
||||
info.append("address=%s" % (rs_address))
|
||||
logging.debug("PS: about to call AddService for Avahi with rs_name='%s' (%s), rs_stype='%s' (%s)," \
|
||||
" rs_domain='%s' (%s), rs_port=%d (%s), info='%s' (%s)" % (rs_name, type(rs_name), rs_stype,
|
||||
type(rs_stype), rs_domain, type(rs_domain), rs_port, type(rs_port), info, type(info)))
|
||||
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,)
|
||||
objid = self._get_next_object_id()
|
||||
service = Service.Service(self._bus_name, objid, name=name,
|
||||
stype=stype, domain=domain, address=address, port=port,
|
||||
properties=properties)
|
||||
self._services[(name, stype)] = service
|
||||
port = service.get_port()
|
||||
|
||||
if address and len(address):
|
||||
info.append("address=%s" % (address))
|
||||
logging.debug("PS: Will register service with name='%s', stype='%s'," \
|
||||
" domain='%s', port=%d, info='%s'" % (name, stype, domain, port, info))
|
||||
group.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, 0, name, stype,
|
||||
domain, "", # let Avahi figure the 'host' out
|
||||
dbus.UInt16(port), info,)
|
||||
group.Commit()
|
||||
except dbus.dbus_bindings.DBusException, exc:
|
||||
# FIXME: ignore local name collisions, since that means
|
||||
@ -571,8 +567,7 @@ class PresenceService(object):
|
||||
# should un-register it an re-register with the correct info
|
||||
if str(exc) == "Local name collision":
|
||||
pass
|
||||
activity_stype = service.get_type()
|
||||
self.register_service_type(activity_stype)
|
||||
self.register_service_type(stype)
|
||||
return service
|
||||
|
||||
def register_service_type(self, stype):
|
||||
|
@ -247,6 +247,8 @@ class Service(object):
|
||||
if type(address) != type(u""):
|
||||
raise ValueError("address must be unicode")
|
||||
self._address = address
|
||||
if not self._publisher_address:
|
||||
self._publisher_address = address
|
||||
|
||||
def get_domain(self):
|
||||
"""Return the ZeroConf/mDNS domain the service was found in."""
|
||||
|
@ -53,7 +53,7 @@ class PresenceServiceProcess(Process):
|
||||
return "PresenceService"
|
||||
|
||||
def start(self):
|
||||
Process.start(self, True)
|
||||
Process.start(self)
|
||||
time.sleep(3)
|
||||
|
||||
class Session:
|
||||
|
Loading…
Reference in New Issue
Block a user