XEP-0030: Don’t call the timeout_callback on each domain which doesn’t reply to disco#info.

This commit is contained in:
Emmanuel Gil Peyrot 2018-10-27 23:21:27 +02:00
parent bd22a41a78
commit e241d4e3c7
2 changed files with 10 additions and 11 deletions

View File

@ -299,18 +299,18 @@ class XEP_0030(BasePlugin):
return self.api['has_identity'](jid, node, ifrom, data) return self.api['has_identity'](jid, node, ifrom, data)
async def get_info_from_domain(self, domain=None, timeout=None, async def get_info_from_domain(self, domain=None, timeout=None,
cached=True, callback=None, **kwargs): cached=True, callback=None):
if domain is None: if domain is None:
domain = self.xmpp.boundjid.domain domain = self.xmpp.boundjid.domain
if not cached or domain not in self.domain_infos: if not cached or domain not in self.domain_infos:
infos = [self.get_info( infos = [self.get_info(
domain, timeout=timeout, **kwargs)] domain, timeout=timeout)]
iq_items = await self.get_items( iq_items = await self.get_items(
domain, timeout=timeout, **kwargs) domain, timeout=timeout)
items = iq_items['disco_items']['items'] items = iq_items['disco_items']['items']
infos += [ infos += [
self.get_info(item[0], timeout=timeout, **kwargs) self.get_info(item[0], timeout=timeout)
for item in items] for item in items]
info_futures, _ = await asyncio.wait( info_futures, _ = await asyncio.wait(
infos, infos,
@ -319,7 +319,7 @@ class XEP_0030(BasePlugin):
) )
self.domain_infos[domain] = [ self.domain_infos[domain] = [
future.result() for future in info_futures] future.result() for future in info_futures if not future.exception()]
results = self.domain_infos[domain] results = self.domain_infos[domain]

View File

@ -67,10 +67,9 @@ class XEP_0363(BasePlugin):
def _handle_request(self, iq): def _handle_request(self, iq):
self.xmpp.event('http_upload_request', iq) self.xmpp.event('http_upload_request', iq)
async def find_upload_service(self, domain=None, timeout=None, timeout_callback=None): async def find_upload_service(self, domain=None, timeout=None):
results = await self.xmpp['xep_0030'].get_info_from_domain( results = await self.xmpp['xep_0030'].get_info_from_domain(
domain=domain, domain=domain, timeout=timeout)
timeout=timeout, timeout_callback=timeout_callback)
candidates = [] candidates = []
for info in results: for info in results:
@ -101,8 +100,7 @@ class XEP_0363(BasePlugin):
''' Helper function which does all of the uploading process. ''' ''' Helper function which does all of the uploading process. '''
if self.upload_service is None: if self.upload_service is None:
info_iq = await self.find_upload_service( info_iq = await self.find_upload_service(
domain=domain, domain=domain, timeout=timeout)
timeout=timeout, timeout_callback=timeout_callback)
if info_iq is None: if info_iq is None:
raise UploadServiceNotFound() raise UploadServiceNotFound()
self.upload_service = info_iq['from'] self.upload_service = info_iq['from']
@ -133,7 +131,8 @@ class XEP_0363(BasePlugin):
basename = os.path.basename(filename) basename = os.path.basename(filename)
slot_iq = await self.request_slot(self.upload_service, basename, size, slot_iq = await self.request_slot(self.upload_service, basename, size,
content_type, ifrom, timeout) content_type, ifrom, timeout,
timeout_callback=timeout_callback)
slot = slot_iq['http_upload_slot'] slot = slot_iq['http_upload_slot']
headers = { headers = {