From ba87ce9496e107d2c372daaa66da046f340496f9 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Wed, 8 Aug 2018 13:48:24 -0400 Subject: [PATCH] check for commands being found, try to fallback to miniupnpc if they arent --- txupnp/__init__.py | 2 +- txupnp/upnp.py | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/txupnp/__init__.py b/txupnp/__init__.py index 7585237..67686da 100644 --- a/txupnp/__init__.py +++ b/txupnp/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.0.1a9" +__version__ = "0.0.1a10" __name__ = "txupnp" __author__ = "Jack Robison" __maintainer__ = "Jack Robison" diff --git a/txupnp/upnp.py b/txupnp/upnp.py index 0b4e1b5..371d1d2 100644 --- a/txupnp/upnp.py +++ b/txupnp/upnp.py @@ -4,7 +4,6 @@ from twisted.internet import defer from txupnp.fault import UPnPError from txupnp.soap import SOAPServiceManager from txupnp.scpd import UPnPFallback -from txupnp.util import DeferredDict log = logging.getLogger(__name__) @@ -24,7 +23,17 @@ class UPnP(object): @property def commands(self): try: - return self.soap_manager.get_runner() + runner = self.soap_manager.get_runner() + required_commands = [ + "GetExternalIPAddress", + "AddPortMapping", + "GetSpecificPortMappingEntry", + "GetGenericPortMappingEntry", + "DeletePortMapping" + ] + if all((command in runner._registered_commands for command in required_commands)): + return runner + raise UPnPError("required commands not found") except UPnPError as err: if self.try_miniupnpc_fallback and self.miniupnpc_runner: return self.miniupnpc_runner @@ -57,6 +66,19 @@ class UPnP(object): finally: if not keep_listening: self.soap_manager.sspd_factory.disconnect() + if found: + try: + runner = self.soap_manager.get_runner() + required_commands = [ + "GetExternalIPAddress", + "AddPortMapping", + "GetSpecificPortMappingEntry", + "GetGenericPortMappingEntry", + "DeletePortMapping" + ] + found = all((command in runner._registered_commands for command in required_commands)) + except UPnPError: + found = False if not found and self.try_miniupnpc_fallback: found = yield self.start_miniupnpc_fallback() defer.returnValue(found)