Skip to content

Commit

Permalink
Refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
Ertan Onur authored and Ertan Onur committed Apr 29, 2022
1 parent fe3e1e8 commit bb29e5a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,11 @@ def senddownbroadcast(self, eventobj: Event, whosends, sequencenumber):
self.send_down(Event(self, EventTypes.MFRT, broadcastmessage))
self.broadcastdb.append(broadcastmessage.uniqueid)

def update_topology(self):
Topology().nodecolors[self.componentinstancenumber] = 'r'
Topology().plot()

def on_broadcast(self, eventobj: Event):
self.update_topology()
self.uniquebroadcastidentifier = self.uniquebroadcastidentifier + 1
self.senddownbroadcast(eventobj, self.componentinstancenumber, self.uniquebroadcastidentifier)

def on_message_from_top(self, eventobj: Event):
self.update_topology()
evt = Event(self, BroadcastingEventTypes.BROADCAST, eventobj.eventcontent)
self.send_self(evt)

Expand All @@ -63,14 +57,13 @@ def on_message_from_bottom(self, eventobj: Event):
pass # we have already handled this flooded message
else:
# Send to higher layers
self.update_topology()
self.send_up(Event(self, EventTypes.MFRB, payload))
# Also continue flooding once
time.sleep(random.randint(1, 3))
self.senddownbroadcast(eventobj, eventobj.eventcontent.header.messagefrom,
eventobj.eventcontent.header.sequencenumber)

def __init__(self, componentname, componentinstancenumber):
super().__init__(componentname, componentinstancenumber)
def __init__(self, componentname, componentinstancenumber, context=None, configurationparameters=None, num_worker_threads=1, topology=None):
super().__init__(componentname, componentinstancenumber, context, configurationparameters, num_worker_threads, topology)
self.eventhandlers[BroadcastingEventTypes.BROADCAST] = self.on_broadcast
# add events here
9 changes: 6 additions & 3 deletions adhoccomputing/GenericModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def send_down(self, event: Event):
p.trigger_event(event)
#self.connectors[ConnectorTypes.DOWN].on_message_from_top(event)
except Exception as e:
raise(f"Cannot send message to Down Connector {self.componentname } -- {self.componentinstancenumber}")
#raise(f"Cannot send message to Down Connector {self.componentname } -- {self.componentinstancenumber}")
pass


def send_up(self, event: Event):
Expand All @@ -67,14 +68,16 @@ def send_up(self, event: Event):
for p in self.connectors[ConnectorTypes.UP]:
p.trigger_event(event)
except Exception as e:
raise(f"Cannot send message to UP Connector {self.componentname } -- {self.componentinstancenumber}")
pass
#raise(f"Cannot send message to UP Connector {self.componentname } -- {self.componentinstancenumber}")

def send_peer(self, event: Event):
try:
for p in self.connectors[ConnectorTypes.PEER]:
p.trigger_event(event)
except Exception as e:
raise(f"Cannot send message to UP Connector {self.componentname } -- {self.componentinstancenumber}")
pass
#raise(f"Cannot send message to UP Connector {self.componentname } -- {self.componentinstancenumber}")

def connect_me_to_component(self, name, component):
#self.connectors[name] = component
Expand Down

0 comments on commit bb29e5a

Please sign in to comment.