From 84c800b815c7700a6a92fe89d04dcf51a66fd9ed Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Mon, 8 Aug 2022 13:29:24 +0530 Subject: [PATCH] Common: Remove MRO logic from PypubsubEventQueue This isn't needed. The Agent's responsibility is to just declare what it did in the form of events. For example, although CredentialsStolenEvent is a type of SecurityEvent technically, the Agent doesn't care about this. The Island does, which is why this should be handled on the pub/sub implementation on the Island side. The Agent merely conveys the information that it stole credentials. Whatever is to be done or however that information is to be handled after that is the Island's responsibility. I don't see a use case in the Agent where a concrete event is derived from another concrete event. So, the MRO logic is removed in this commit. --- .../event_queue/pypubsub_event_queue.py | 23 ++++--------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/monkey/common/event_queue/pypubsub_event_queue.py b/monkey/common/event_queue/pypubsub_event_queue.py index 5336a1e14..7f53dfb15 100644 --- a/monkey/common/event_queue/pypubsub_event_queue.py +++ b/monkey/common/event_queue/pypubsub_event_queue.py @@ -26,25 +26,10 @@ class PypubsubEventQueue(IEventQueue): @staticmethod def publish(event: AbstractEvent, data: Any): - # someClass.mro() returns a list of types that someClass is derived from, - # in order of resolution - # we can be sure that for any valid event, the last three items in the list will be - # , , and - - # for some event, say, CredentialsStolenEvent which was derived from SecurityEvent, - # we want to publish the data to both events, so, we loop through the super - # classes of the CredentialsStolenEvent which was initially passed as an argument - # to the function, and publish to each class's type and tags (except the last 3 classes) - for event_type in event.mro()[:-3]: - PypubsubEventQueue._publish_to_type(event_type, data) - PypubsubEventQueue._publish_to_tags(event_type, data) - - @staticmethod - def _publish_to_type(event_type: AbstractEvent, data: Any): - event_type_name = event_type.__name__ + # publish to event type's topic + event_type_name = event.__name__ pub.sendMessage(event_type_name, data) - @staticmethod - def _publish_to_tags(event_type: AbstractEvent, data: Any): - for tag in event_type.tags: + # publish to tags' topics + for tag in event.tags: pub.sendMessage(tag, data)