Implement a ZMQ prefix-match countermeasure in EHBase

This commit is contained in:
Kristóf Tóth 2018-07-12 15:17:39 +02:00
parent 558e660268
commit 17b24377dd

View File

@ -31,10 +31,25 @@ class EventHandlerBase(ABC):
a response back in case the handler returned something.
This is subscribed in __init__().
"""
if not self.check_key(message):
return
response = self.dispatch_handling(message)
if response:
self.server_connector.send(response)
def check_key(self, message):
"""
Checks whether the message is intended for this
EventHandler.
This is necessary because ZMQ handles PUB - SUB
connetions with pattern matching (e.g. someone
subscribed to 'fsm' will receive 'fsm_update'
messages as well.
"""
return self.key == message['key']
def dispatch_handling(self, message):
"""
Used to dispatch messages to their specific handlers.