Skip to content
Snippets Groups Projects
hcbf.py 1.18 KiB
Newer Older
from .community import CommunityRouter

class HCBFRouter(CommunityRouter):
    def __call__(self, packet):
        me = self.node
        dest = packet.destination

Jarrod Pas's avatar
Jarrod Pas committed
        if dest in me.neighbours:
            return dest, 'direct', True

        if me.community is not dest.community and self.not_local_community:
            best, cbc = self.best_cbc(dest.community)
            if cbc > self.cbc(dest.community):
                return best, 'cbc', True

        if self.local_community:
            if me.community is not dest.community:
                best, ncf = self.best_ncf(dest.community)
                if ncf > self.ncf(dest.community):
                    return best, 'ncf', True
                elif ncf < self.ncf(dest.community):
                    return None, None, False

            best, ui = self.best_ui()
            if ui > self.ui():
                return best, 'ui', True
            elif ui < self.ui():
                return None, None, False

            best, lp = self.best_lp()
            if lp > self.lp():
                return best, 'lp', True

        return None, None, False
Jarrod Pas's avatar
Jarrod Pas committed

    def on_send_failure(self, target, packet):
        self.node.buffer.add(packet)