Newer
Older
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
def bubble(self, packet, state):
''''''
if len(self.community) == 0:
return False
dest = packet.destination
community_of = lambda n: self.network.community[n]
same_community = lambda a, b: community_of(a) == community_of(b)
gp_of = lambda n: self.network.community.get_gp(n)
lp_of = lambda n: self.network.community.get_lp(n)
max = lambda a, b: a if a[0] >= b[0] else b
max_gp = (-1, None)
if same_community(self, dest):
max_lp = (lp_of(self), self)
for met in self.links:
if same_community(met, dest):
max_lp = max((lp_of(met), met), max_lp)
if max_lp[1] is not self:
self.send(max_lp[1], packet)
return True
else:
max_gp = (-1, None)
max_lp = (-1, None)
for met in self.links:
if same_community(met, dest):
max_lp = max((lp_of(met), met), max_lp)
max_gp = max((gp_of(met), met), max_gp)
if max_lp[1] is not None:
self.send(max_lp[1], packet)
return True
if max_gp[1] is not None:
self.send(max_gp[1], packet)
return True
return False