From ca09e868f16eb48d4070a283cb4cbcd515e3dc5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 25 Jul 2018 15:45:54 +0200 Subject: [PATCH] Fix ZMQWSProxy not executing filters/callbacks on nested messages --- .../networking/server/zmq_websocket_proxy.py | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/tfw/networking/server/zmq_websocket_proxy.py b/lib/tfw/networking/server/zmq_websocket_proxy.py index f456d94..cb43a30 100644 --- a/lib/tfw/networking/server/zmq_websocket_proxy.py +++ b/lib/tfw/networking/server/zmq_websocket_proxy.py @@ -105,14 +105,9 @@ class TFWProxy: raise ValueError('Invalid TFW message format!') def __call__(self, message): - try: - self.proxy_filters._execute_callbacks(message) - except ValueError: - LOG.exception('Invalid TFW message received!') + if not self.filter_and_execute_callbacks(message): return - self.proxy_callbacks._execute_callbacks(message) - if message['key'] not in self.keyhandlers: self.to_destination(message) else: @@ -122,13 +117,26 @@ class TFWProxy: except KeyError: LOG.error('Invalid "%s" message format! Ignoring.', handler.__name__) + def filter_and_execute_callbacks(self, message): + try: + self.proxy_filters._execute_callbacks(message) + self.proxy_callbacks._execute_callbacks(message) + return True + except ValueError: + LOG.exception('Invalid TFW message received!') + return False + def mirror(self, message): message = message['data'] + if not self.filter_and_execute_callbacks(message): + return LOG.debug('Mirroring message: %s', message) self.to_source(message) def broadcast(self, message): message = message['data'] + if not self.filter_and_execute_callbacks(message): + return LOG.debug('Broadcasting message: %s', message) self.to_source(message) self.to_destination(message)