allow skipping straight to miniupnpc fallback

This commit is contained in:
Jack Robison 2018-08-07 18:39:16 -04:00
parent 626ebd9b27
commit cab039a9db
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -45,15 +45,19 @@ class UPnP(object):
return self.soap_manager.sspd_factory.m_search(address, timeout=timeout, max_devices=max_devices) return self.soap_manager.sspd_factory.m_search(address, timeout=timeout, max_devices=max_devices)
@defer.inlineCallbacks @defer.inlineCallbacks
def discover(self, timeout=1, max_devices=1, keep_listening=False): def discover(self, timeout=1, max_devices=1, keep_listening=False, try_txupnp=True):
try: found = False
yield self.soap_manager.discover_services(timeout=timeout, max_devices=max_devices) if not try_txupnp and not self.try_miniupnpc_fallback:
found = True log.warning("nothing left to try")
except defer.TimeoutError: if try_txupnp:
found = False try:
finally: yield self.soap_manager.discover_services(timeout=timeout, max_devices=max_devices)
if not keep_listening: found = True
self.soap_manager.sspd_factory.disconnect() except defer.TimeoutError:
found = False
finally:
if not keep_listening:
self.soap_manager.sspd_factory.disconnect()
if not found and self.try_miniupnpc_fallback: if not found and self.try_miniupnpc_fallback:
found = yield self.start_miniupnpc_fallback() found = yield self.start_miniupnpc_fallback()
defer.returnValue(found) defer.returnValue(found)