Skip to content
Snippets Groups Projects
epidemic.py 427 B
Newer Older
  • Learn to ignore specific revisions
  • Jarrod Pas's avatar
    Jarrod Pas committed
    from collections import defaultdict
    
    def epidemic(self, packet, state):
        '''
        Routes a packet if it hasn't sent the packet on a link yet.
        Always returns False.
        '''
        if 'sent' not in state:
            state['sent'] = defaultdict(dict)
        sent = state['sent']
    
        for met in self.links:
            if packet not in sent[met]:
                sent[met][packet] = True
                self.send(met, packet)
        return False