Skip to content
Snippets Groups Projects
bubble.py 1.18 KiB
Newer Older
  • Learn to ignore specific revisions
  • Jarrod Pas's avatar
    Jarrod Pas committed
    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