def worker_multiplexer(queue_multiplexer, queue_notifier): global shutdown def debug(*args, **kwargs): print(args, kwargs) multiplexer = Multiplexer(queue_notifier) while not shutdown: pycmd = queue_multiplexer.get() getattr(multiplexer, pycmd["command"], debug)(*pycmd["args"]) if pycmd['command'] == 'buried_all': break multiplexer.stop()
class DhcpNameserver: def __init__(self): self.dns = dnssrv.Handler() self.dhcp = dhcpsrv.Handler() self.mul = Multiplexer( DnsUdpServer(("", int(getenv("DNSPORT", 5353))), self.dns), DhcpUdpServer(("", int(getenv("DHCPPORT", 6767))), self.dhcp), ) self.dns.add_middleware(GoogleDnsHandler(), dnssrv.PRIO_LOWEST) def start(self): self.mul.start() def stop(self): self.mul.stop() def push(self, handler): if isinstance(handler, dnssrv.middlewares.Middleware): self.dns.add_middleware(handler) if isinstance(handler, dhcpsrv.middlewares.Middleware): self.dhcp.add_middleware(handler)