Move uPnP port remove to fileserver

This commit is contained in:
shortcutme 2016-10-02 14:22:01 +02:00
parent 2ab04deded
commit 31077eb346
3 changed files with 13 additions and 12 deletions

View File

@ -13,7 +13,6 @@ from Config import config
from Crypt import CryptConnection from Crypt import CryptConnection
from Crypt import CryptHash from Crypt import CryptHash
from Tor import TorManager from Tor import TorManager
from util import UpnpPunch
class ConnectionServer: class ConnectionServer:
@ -74,13 +73,6 @@ class ConnectionServer:
self.log.info("StreamServer bind error, must be running already: %s" % err) self.log.info("StreamServer bind error, must be running already: %s" % err)
def stop(self): 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.running = False
self.stream_server.stop() self.stream_server.stop()

View File

@ -245,7 +245,8 @@ class FileServer(ConnectionServer):
last_time = time.time() last_time = time.time()
while 1: while 1:
time.sleep(30) 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( self.log.info(
"Wakeup detected: time warp from %s to %s (%s sleep seconds), acting like startup..." % "Wakeup detected: time warp from %s to %s (%s sleep seconds), acting like startup..." %
(last_time, time.time(), time.time() - last_time) (last_time, time.time(), time.time() - last_time)
@ -271,6 +272,14 @@ class FileServer(ConnectionServer):
ConnectionServer.start(self) 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.") 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)

View File

@ -272,7 +272,7 @@ def _orchestrate_soap_request(ip, port, msg_fn, desc=None):
soap_messages = [ soap_messages = [
msg_fn(ip, port, desc, proto, idg_data['upnp_schema']) 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) _send_requests(soap_messages, **idg_data)