-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_filters.py
executable file
·87 lines (72 loc) · 3.58 KB
/
example_filters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# *** these filters do NOT see ping messages, nor do routers see them ***
# *** global imports are NOT accessible, do imports in __init__ and bind them to an attribute ***
class Filters(Base):
def __init__(self, logger):
# init parent class
super().__init__(logger)
# nice_colors:
self.colors = {
"red": (255,0,0),
"green": (0,255,0),
"blue": (0,0,255),
"white": (255,255,255)
}
# some imports needed later
self.random = __import__("random")
def gui_command_incoming(self, command):
if command["_command"] == "start":
pass #self.logger.info("*********** STARTING")
def gui_command_completed(self, command, error):
if command["_command"] == "start":
if not error:
pass #self.logger.info("*********** STARTED")
else:
pass #self.logger.info("*********** ERROR STARTING ROUTER: %s" % str(error))
def gui_event_outgoing(self, event):
pass
def router_command_incoming(self, command, router):
pass
def subscribed_datamsg_incoming(self, msg, router):
pass
def covert_msg_incoming(self, msg, con):
#self.logger.info("*********** COVERT INCOMING(%s) connection %s ***********" % (msg.get_type(), con))
# example to indicate incoming ant
if msg.get_type() == "ACO_ant":
# do something meaningful here
pass #logger.error("received ant %s" % msg["id"])
# example to indicate incoming returning ant
if msg.get_type() == "ACO_ant" and msg["returning"]:
# do something meaningful here
pass #logger.error("returning ant coming from peer %s" % con.get_peer_id())
def covert_msg_outgoing(self, msg, con):
#self.logger.info("*********** COVERT OUTGOING(%s) connection %s ***********" % (msg.get_type(), con))
# example to indicate outgoing ant
if msg.get_type() == "ACO_ant":
# do something meaningful here
pass #logger.error("sending out ant %s" % msg["id"])
# example to indicate outgoing returning activating ant
if msg.get_type() == "ACO_ant" and msg["returning"] and msg["activating"]:
# do something meaningful here
pass #logger.error("sending returning and activating ant to peer %s" % con.get_peer_id())
def msg_incoming(self, msg, con):
#self.logger.info("*********** INCOMING(%s) connection %s ***********" % (msg.get_type(), con))
if msg.get_type() == "GroupRouter_data":
self.leds[8].on(self.colors["green"], 0.25)
elif msg.get_type() == "Flooding_publish":
self.leds[0].on(self.colors["red"], 0.5)
else:
self.leds[4].on(self.colors["red"], 0.5)
def msg_outgoing(self, msg, con):
#self.logger.info("*********** OUTGOING(%s) connection %s ***********" % (msg.get_type(), con))
if msg.get_type() == "GroupRouter_data":
self.leds[9].on(self.colors["white"], 0.25)
elif msg.get_type() == "Flooding_publish":
self.leds[1].on(self.colors["blue"], 0.5)
else:
self.leds[5].on(self.colors["blue"], 0.5)
#if self.router.__class__.__name__ == "Flooding" and self.router.master[msg["channel"]]:
#return False
#drop = self.random.choice([True, False])
#if drop:
#self.leds[1].on(self.colors["white"], 0.5)
#return drop # this will drop the message in 50% of the cases