MixNode.py 638 B

1234567891011121314151617181920212223242526
  1. import numpy
  2. import simpy
  3. import random
  4. from classes.Utilities import random_string, StructuredMessage
  5. from classes.Node import Node
  6. import math
  7. class MixNode(Node):
  8. def __init__(self, env, conf, net=None, logger=None, corrupt=False, id=None):
  9. super().__init__(env=env, net=net, loggers=logger, conf=conf, id=id)
  10. def drop_random(self):
  11. '''Drops a packet from the pool at random, and returns it.'''
  12. pkt_id = random.choice(list(self.pool.keys()))
  13. self.pool[pkt_id].dropped = True
  14. pkt=self.pool.pop(pkt_id)
  15. return pkt
  16. def __hash__(self):
  17. return self.id.__hash__()