From 31077eb346e0e12abe9e4cfc7b276f311c1d085f Mon Sep 17 00:00:00 2001 From: shortcutme Date: Sun, 2 Oct 2016 14:22:01 +0200 Subject: [PATCH] Move uPnP port remove to fileserver --- src/Connection/ConnectionServer.py | 8 -------- src/File/FileServer.py | 15 ++++++++++++--- src/util/UpnpPunch.py | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Connection/ConnectionServer.py b/src/Connection/ConnectionServer.py index 2954c1e6..91d3e4e1 100644 --- a/src/Connection/ConnectionServer.py +++ b/src/Connection/ConnectionServer.py @@ -13,7 +13,6 @@ from Config import config from Crypt import CryptConnection from Crypt import CryptHash from Tor import TorManager -from util import UpnpPunch class ConnectionServer: @@ -74,13 +73,6 @@ class ConnectionServer: self.log.info("StreamServer bind error, must be running already: %s" % err) def stop(self): - self.log.debug('Closing port %d' % self.port) - if self.running: - try: - UpnpPunch.ask_to_close_port(self.port) - self.log.info('Closed port via upnp.') - except (UpnpPunch.UpnpError, UpnpPunch.IGDError), err: - self.log.info("Failed at attempt to use upnp to close port: %s" %err) self.running = False self.stream_server.stop() diff --git a/src/File/FileServer.py b/src/File/FileServer.py index 91dfe104..910b5c14 100644 --- a/src/File/FileServer.py +++ b/src/File/FileServer.py @@ -245,7 +245,8 @@ class FileServer(ConnectionServer): last_time = time.time() while 1: time.sleep(30) - if time.time() - max(self.last_request, last_time) > 60 * 3: # If taken more than 3 minute then the computer was in sleep mode + if time.time() - max(self.last_request, last_time) > 60 * 3: + # If taken more than 3 minute then the computer was in sleep mode self.log.info( "Wakeup detected: time warp from %s to %s (%s sleep seconds), acting like startup..." % (last_time, time.time(), time.time() - last_time) @@ -271,6 +272,14 @@ class FileServer(ConnectionServer): ConnectionServer.start(self) - # thread_wakeup_watcher.kill(exception=Debug.Notify("Stopping FileServer")) - # thread_announce_sites.kill(exception=Debug.Notify("Stopping FileServer")) self.log.debug("Stopped.") + + def stop(self): + if self.running and self.port_opened: + self.log.debug('Closing port %d' % self.port) + try: + UpnpPunch.ask_to_close_port(self.port) + self.log.info('Closed port via upnp.') + except (UpnpPunch.UpnpError, UpnpPunch.IGDError), err: + self.log.info("Failed at attempt to use upnp to close port: %s" % err) + ConnectionServer.stop(self) diff --git a/src/util/UpnpPunch.py b/src/util/UpnpPunch.py index b595e7bb..914816ca 100644 --- a/src/util/UpnpPunch.py +++ b/src/util/UpnpPunch.py @@ -272,7 +272,7 @@ def _orchestrate_soap_request(ip, port, msg_fn, desc=None): soap_messages = [ msg_fn(ip, port, desc, proto, idg_data['upnp_schema']) - for proto in ['TCP', 'UDP'] + for proto in ['TCP'] ] _send_requests(soap_messages, **idg_data)