don't try to resolve a service more than once
This commit is contained in:
parent
b315480c5a
commit
d60a85e83a
@ -113,6 +113,7 @@ class PresenceService(gobject.GObject):
|
|||||||
# Keep track of stuff we're already browsing with ZC
|
# Keep track of stuff we're already browsing with ZC
|
||||||
self._service_type_browsers = {}
|
self._service_type_browsers = {}
|
||||||
self._service_browsers = {}
|
self._service_browsers = {}
|
||||||
|
self._resolve_queue = [] # Track resolve requests
|
||||||
|
|
||||||
# Resolved service list
|
# Resolved service list
|
||||||
self._service_advs = []
|
self._service_advs = []
|
||||||
@ -250,6 +251,8 @@ class PresenceService(gobject.GObject):
|
|||||||
return False
|
return False
|
||||||
adv = adv_list[0]
|
adv = adv_list[0]
|
||||||
adv.set_resolved(True)
|
adv.set_resolved(True)
|
||||||
|
if adv in self._resolve_queue:
|
||||||
|
self._resolve_queue.remove(adv)
|
||||||
|
|
||||||
# Update the service now that it's been resolved
|
# Update the service now that it's been resolved
|
||||||
service = Service.Service(name=name, stype=full_stype, domain=domain,
|
service = Service.Service(name=name, stype=full_stype, domain=domain,
|
||||||
@ -268,12 +271,12 @@ class PresenceService(gobject.GObject):
|
|||||||
gobject.idle_add(self._resolve_service_reply_cb, interface, protocol,
|
gobject.idle_add(self._resolve_service_reply_cb, interface, protocol,
|
||||||
name, stype, domain, host, aprotocol, address, port, txt, flags)
|
name, stype, domain, host, aprotocol, address, port, txt, flags)
|
||||||
|
|
||||||
def _resolve_service(self, interface, protocol, name, stype, domain, flags):
|
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."""
|
||||||
# Ask avahi to resolve this particular service
|
# Ask avahi to resolve this particular service
|
||||||
print 'Resolving service ' + name + ' ' + stype
|
self._log('resolving service %s %s' % (adv.name(), adv.stype()))
|
||||||
self._server.ResolveService(int(interface), int(protocol), name,
|
self._server.ResolveService(int(adv.interface()), int(adv.protocol()), adv.name(),
|
||||||
stype, domain, avahi.PROTO_UNSPEC, dbus.UInt32(0), # use flags here maybe?
|
adv.stype(), adv.domain(), avahi.PROTO_UNSPEC, dbus.UInt32(0),
|
||||||
reply_handler=self._resolve_service_reply_cb_glue,
|
reply_handler=self._resolve_service_reply_cb_glue,
|
||||||
error_handler=self._resolve_service_error_handler)
|
error_handler=self._resolve_service_error_handler)
|
||||||
return False
|
return False
|
||||||
@ -284,10 +287,13 @@ class PresenceService(gobject.GObject):
|
|||||||
# Add the service to our unresolved services list
|
# Add the service to our unresolved services list
|
||||||
adv_list = self._find_service_adv(interface=interface, protocol=protocol,
|
adv_list = self._find_service_adv(interface=interface, protocol=protocol,
|
||||||
name=name.encode(), stype=full_stype.encode(), domain=domain.encode())
|
name=name.encode(), stype=full_stype.encode(), domain=domain.encode())
|
||||||
|
adv = None
|
||||||
if not adv_list:
|
if not adv_list:
|
||||||
adv = ServiceAdv(interface=interface, protocol=protocol, name=name.encode(),
|
adv = ServiceAdv(interface=interface, protocol=protocol, name=name.encode(),
|
||||||
stype=full_stype.encode(), domain=domain.encode())
|
stype=full_stype.encode(), domain=domain.encode())
|
||||||
self._service_advs.append(adv)
|
self._service_advs.append(adv)
|
||||||
|
else:
|
||||||
|
adv = adv_list[0]
|
||||||
|
|
||||||
# Find out the IP address of this interface, if we haven't already
|
# Find out the IP address of this interface, if we haven't already
|
||||||
if interface not in self._local_addrs.keys():
|
if interface not in self._local_addrs.keys():
|
||||||
@ -310,8 +316,9 @@ class PresenceService(gobject.GObject):
|
|||||||
resolve = True
|
resolve = True
|
||||||
if self._is_special_service_type(short_stype):
|
if self._is_special_service_type(short_stype):
|
||||||
resolve = True
|
resolve = True
|
||||||
if resolve:
|
if resolve and not adv in self._resolve_queue:
|
||||||
gobject.idle_add(self._resolve_service, interface, protocol, name, full_stype, domain, flags)
|
self._resolve_queue.append(adv)
|
||||||
|
gobject.idle_add(self._resolve_service, adv)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _service_appeared_cb_glue(self, interface, protocol, name, stype, domain, flags):
|
def _service_appeared_cb_glue(self, interface, protocol, name, stype, domain, flags):
|
||||||
@ -331,6 +338,8 @@ class PresenceService(gobject.GObject):
|
|||||||
|
|
||||||
# Get the service object; if none, we have nothing left to do
|
# Get the service object; if none, we have nothing left to do
|
||||||
adv = adv_list[0]
|
adv = adv_list[0]
|
||||||
|
if adv in self._resolve_queue:
|
||||||
|
self._resolve_queue.remove(adv)
|
||||||
service = adv.service()
|
service = adv.service()
|
||||||
if not service:
|
if not service:
|
||||||
return False
|
return False
|
||||||
@ -457,10 +466,11 @@ class PresenceService(gobject.GObject):
|
|||||||
if specific_stype is not None:
|
if specific_stype is not None:
|
||||||
resolv_list = resolv_list + self._find_service_adv(stype=specific_stype)
|
resolv_list = resolv_list + self._find_service_adv(stype=specific_stype)
|
||||||
|
|
||||||
# Request resolution for them
|
# Request resolution for them if they aren't in-process already
|
||||||
for adv in resolv_list:
|
for adv in resolv_list:
|
||||||
gobject.idle_add(self._resolve_service, adv.interface(),
|
if adv not in self._resolve_queue:
|
||||||
adv.protocol(), adv.name(), adv.stype(), adv.domain(), 0)
|
self._resolve_queue.append(adv)
|
||||||
|
gobject.idle_add(self._resolve_service, adv)
|
||||||
|
|
||||||
def untrack_service_type(self, short_stype):
|
def untrack_service_type(self, short_stype):
|
||||||
"""Stop tracking a certain mDNS service."""
|
"""Stop tracking a certain mDNS service."""
|
||||||
|
Loading…
Reference in New Issue
Block a user