Retry resolution of a buddy presence service up to 3 times
This commit is contained in:
parent
c15e05ed39
commit
6290a5fae9
@ -49,6 +49,7 @@ class ServiceAdv(object):
|
|||||||
self._local = local
|
self._local = local
|
||||||
self._state = _SA_UNRESOLVED
|
self._state = _SA_UNRESOLVED
|
||||||
self._resolver = None
|
self._resolver = None
|
||||||
|
self._resolv_tries = 0
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if self._resolver:
|
if self._resolver:
|
||||||
@ -66,6 +67,10 @@ class ServiceAdv(object):
|
|||||||
return self._domain
|
return self._domain
|
||||||
def is_local(self):
|
def is_local(self):
|
||||||
return self._local
|
return self._local
|
||||||
|
def resolv_tries(self):
|
||||||
|
return self._resolv_tries
|
||||||
|
def inc_resolv_tries(self):
|
||||||
|
self._resolv_tries += 1
|
||||||
def service(self):
|
def service(self):
|
||||||
return self._service
|
return self._service
|
||||||
def set_service(self, service):
|
def set_service(self, service):
|
||||||
@ -76,8 +81,10 @@ class ServiceAdv(object):
|
|||||||
def resolver(self):
|
def resolver(self):
|
||||||
return self._resolver
|
return self._resolver
|
||||||
def set_resolver(self, resolver):
|
def set_resolver(self, resolver):
|
||||||
if not isinstance(resolver, dbus.Interface):
|
if resolver and not isinstance(resolver, dbus.Interface):
|
||||||
raise ValueError("must be a valid dbus object")
|
raise ValueError("'resolver' must be a valid dbus object")
|
||||||
|
if not resolver and self._resolver:
|
||||||
|
del self._resolver
|
||||||
self._resolver = resolver
|
self._resolver = resolver
|
||||||
def state(self):
|
def state(self):
|
||||||
return self._state
|
return self._state
|
||||||
@ -85,6 +92,8 @@ class ServiceAdv(object):
|
|||||||
if state == _SA_RESOLVE_PENDING:
|
if state == _SA_RESOLVE_PENDING:
|
||||||
if self._state == _SA_RESOLVED:
|
if self._state == _SA_RESOLVED:
|
||||||
raise ValueError("Can't reset to resolve pending from resolved.")
|
raise ValueError("Can't reset to resolve pending from resolved.")
|
||||||
|
if state == _SA_UNRESOLVED:
|
||||||
|
self._resolv_tries = 0
|
||||||
self._state = state
|
self._state = state
|
||||||
|
|
||||||
class RegisteredServiceType(object):
|
class RegisteredServiceType(object):
|
||||||
@ -565,8 +574,21 @@ class PresenceService(object):
|
|||||||
port, txt, flags, updated)
|
port, txt, flags, updated)
|
||||||
|
|
||||||
def _service_resolved_failure_cb(self, adv, err):
|
def _service_resolved_failure_cb(self, adv, err):
|
||||||
|
retried = False
|
||||||
|
adv.set_resolver(None)
|
||||||
|
if adv.stype() == Buddy.PRESENCE_SERVICE_TYPE:
|
||||||
|
# Retry the presence service type a few times
|
||||||
|
if adv.resolv_tries() < 4:
|
||||||
|
adv.set_state(_SA_RESOLVE_PENDING)
|
||||||
|
gobject.timeout_add(250, self._resolve_service, adv)
|
||||||
|
retried = True
|
||||||
|
logging.error("Retrying resolution of service %s.%s: %s" % (adv.name(),
|
||||||
|
adv.stype(), err))
|
||||||
|
|
||||||
|
if not retried:
|
||||||
|
logging.error("Error resolving service %s.%s: %s" % (adv.name(),
|
||||||
|
adv.stype(), err))
|
||||||
adv.set_state(_SA_UNRESOLVED)
|
adv.set_state(_SA_UNRESOLVED)
|
||||||
logging.error("Error resolving service %s.%s: %s" % (adv.name(), adv.stype(), err))
|
|
||||||
|
|
||||||
def _resolve_service(self, adv):
|
def _resolve_service(self, adv):
|
||||||
"""Resolve and lookup a ZeroConf service to obtain its address and TXT records."""
|
"""Resolve and lookup a ZeroConf service to obtain its address and TXT records."""
|
||||||
@ -578,6 +600,7 @@ class PresenceService(object):
|
|||||||
avahi.DBUS_INTERFACE_SERVICE_RESOLVER)
|
avahi.DBUS_INTERFACE_SERVICE_RESOLVER)
|
||||||
resolver.connect_to_signal('Found', lambda *args: self._service_resolved_cb_glue(adv, *args))
|
resolver.connect_to_signal('Found', lambda *args: self._service_resolved_cb_glue(adv, *args))
|
||||||
resolver.connect_to_signal('Failure', lambda *args: self._service_resolved_failure_cb(adv, *args))
|
resolver.connect_to_signal('Failure', lambda *args: self._service_resolved_failure_cb(adv, *args))
|
||||||
|
adv.inc_resolv_tries()
|
||||||
adv.set_resolver(resolver)
|
adv.set_resolver(resolver)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user