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)