From 5af198db752ea6c05a649dfee0132f9364447e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Thu, 27 Oct 2016 08:25:30 +0200 Subject: [PATCH] More fixes (in fact, fixing fixes... :P) for actors --- actors/src/udsactor/httpserver.py | 17 ++++++++++++----- actors/src/udsactor/service.py | 7 +++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/actors/src/udsactor/httpserver.py b/actors/src/udsactor/httpserver.py index c4e3eacc..1c0faed7 100644 --- a/actors/src/udsactor/httpserver.py +++ b/actors/src/udsactor/httpserver.py @@ -198,11 +198,15 @@ class HTTPServerThread(threading.Thread): def initiateServer(self, address): - self.server = socketserver.TCPServer(address, HTTPServerHandler) + self.address = (address[0], address[1]) # Copy address & keep it for future reference... + + addr = ('0.0.0.0', address[1]) # Adapt to listen on 0.0.0.0 + + self.server = socketserver.TCPServer(addr, HTTPServerHandler) self.server.socket = ssl.wrap_socket(self.server.socket, certfile=self.certFile, server_side=True) def getServerUrl(self): - return 'https://{}:{}/{}'.format(self.server.server_address[0], self.server.server_address[1], HTTPServerHandler.uuid) + return 'https://{}:{}/{}'.format(self.address[0], self.address[1], HTTPServerHandler.uuid) def stop(self): logger.debug('Stopping REST Service') @@ -211,11 +215,14 @@ class HTTPServerThread(threading.Thread): def restart(self, address=None): if address is None: - address = self.server.server_address + # address = self.server.server_address + address = self.address - self.stop() + self.address = (address[0], address[1]) # Copy address & keep it for future reference - self.initiateServer(address) + # Listening on 0.0.0.0, does not need to restart listener.. + # self.stop() + # self.initiateServer(address) def run(self): self.server.serve_forever() diff --git a/actors/src/udsactor/service.py b/actors/src/udsactor/service.py index 5af864ea..282ffb07 100644 --- a/actors/src/udsactor/service.py +++ b/actors/src/udsactor/service.py @@ -210,9 +210,9 @@ class CommonService(object): self.knownIps = dict(((v.mac, v.ip) for v in netInfo)) # And notify new listening address to broker - # address = (self.knownIps[self.api.mac], random.randrange(43900, 44000)) + address = (self.knownIps[self.api.mac], random.randrange(43900, 44000)) # And new listening address - # self.httpServer.restart(address) + self.httpServer.restart(address) # sends notification self.api.notifyComm(self.httpServer.getServerUrl()) @@ -252,8 +252,7 @@ class CommonService(object): self.ipc.start() if self.api.mac in self.knownIps: - # address = (self.knownIps[self.api.mac], random.randrange(43900, 44000)) - address = ('0.0.0.0', random.randrange(43900, 44000)) + address = (self.knownIps[self.api.mac], random.randrange(43900, 44000)) logger.info('Starting REST listener at {}'.format(address)) self.httpServer = httpserver.HTTPServerThread(address, self) self.httpServer.start()