mirror of https://github.com/huashengdun/webssh
Close websocket with no reason when invalid worker id provided or addr unmatched
parent
311fcfedc9
commit
9ba2512be4
21
main.py
21
main.py
|
@ -246,18 +246,15 @@ class WsockHandler(MixinHandler, tornado.websocket.WebSocketHandler):
|
||||||
def open(self):
|
def open(self):
|
||||||
self.src_addr = self.get_addr()
|
self.src_addr = self.get_addr()
|
||||||
logging.info('Connected from {}:{}'.format(*self.src_addr))
|
logging.info('Connected from {}:{}'.format(*self.src_addr))
|
||||||
worker = workers.pop(self.get_argument('id'), None)
|
worker = workers.get(self.get_argument('id'), None)
|
||||||
if not worker:
|
if worker and worker.src_addr[0] == self.src_addr[0]:
|
||||||
self.close(reason='Invalid worker id.')
|
workers.pop(worker.id)
|
||||||
return
|
self.set_nodelay(True)
|
||||||
if self.src_addr[0] != worker.src_addr[0]:
|
worker.set_handler(self)
|
||||||
self.close(reason='Invalid client addr.')
|
self.worker_ref = weakref.ref(worker)
|
||||||
return
|
self.loop.add_handler(worker.fd, worker, IOLoop.READ)
|
||||||
|
else:
|
||||||
self.set_nodelay(True)
|
self.close()
|
||||||
worker.set_handler(self)
|
|
||||||
self.worker_ref = weakref.ref(worker)
|
|
||||||
self.loop.add_handler(worker.fd, worker, IOLoop.READ)
|
|
||||||
|
|
||||||
def on_message(self, message):
|
def on_message(self, message):
|
||||||
logging.debug('"{}" from {}:{}'.format(message, *self.src_addr))
|
logging.debug('"{}" from {}:{}'.format(message, *self.src_addr))
|
||||||
|
|
Loading…
Reference in New Issue