def __init__(self, port: int, msgHandler: Callable, name: str = None, basedirpath: str = None, seed=None, onlyListener=False, msgRejectHandler=None): stackParams = { "name": name or randomString(8), "ha": HA("0.0.0.0", port), "auth_mode": AuthMode.ALLOW_ANY.value } if basedirpath: stackParams["basedirpath"] = os.path.join(basedirpath, "keys") seed = seed or randomSeed() SimpleZStack.__init__(self, stackParams, self.tracedMsgHandler, seed=seed, onlyListener=onlyListener, msgRejectHandler=msgRejectHandler) self.msgHandler = msgHandler
def __init__(self, stackParams: dict, msgHandler: Callable, seed=None, config=None): config = config or getConfig() SimpleZStack.__init__(self, stackParams, msgHandler, seed=seed, onlyListener=True, config=config) MessageProcessor.__init__(self, allowDictOnly=False) self.connectedClients = set()
def testSimpleZStacksMsgs(tdir, looper): names = ['Alpha', 'Beta'] genKeys(tdir, names) names = ['Alpha', 'Beta'] aseed = randomSeed() bseed = randomSeed() size = 100000 msg = json.dumps({'random': randomSeed(size).decode()}).encode() def aHandler(m): str_m = "{}".format(m) print('{} printing... {}'.format(names[0], str_m[:100])) d, _ = m print('Message size is {}'.format(len(d['random']))) assert len(d['random']) == size def bHandler(m): print(beta.msgHandler) a = m[1] try: beta.listener.send_multipart([a, msg], flags=zmq.NOBLOCK) except zmq.Again: return False str_m = "{}".format(m) print('{} printing... {}'.format(names[1], str_m[:100])) stackParams = { "name": names[0], "ha": genHa(), "auto": 2, "basedirpath": tdir } alpha = SimpleZStack(stackParams, aHandler, aseed, False) stackParams = { "name": names[1], "ha": genHa(), "auto": 2, "basedirpath": tdir } beta = SimpleZStack(stackParams, bHandler, bseed, True) amotor = SMotor(alpha) looper.add(amotor) bmotor = SMotor(beta) looper.add(bmotor) alpha.connect(name=beta.name, ha=beta.ha, verKeyRaw=beta.verKeyRaw, publicKeyRaw=beta.publicKeyRaw) looper.runFor(0.25) alpha.send({'greetings': 'hi'}, beta.name) looper.runFor(1)
def clientstack(tdir, looper, alpha_handler): names = ['ClientA', 'Alpha'] genKeys(tdir, names) aseed = randomSeed() cseed = randomSeed() stackParams = { "name": names[0], "ha": genHa(), "auto": 2, "basedirpath": tdir } timer = MockTimer(0) client = ClientZStack(stackParams, alpha_handler.handle, cseed, False, timer=timer) stackParams = { "name": names[1], "ha": genHa(), "auto": 2, "basedirpath": tdir } timer = MockTimer(0) alpha = SimpleZStack(stackParams, alpha_handler, aseed, True, timer=timer) amotor = SMotor(alpha) looper.add(amotor) cmotor = SMotor(client) looper.add(cmotor) return alpha, client
def __init__(self, stackParams: dict, msgHandler: Callable, registry: Dict[str, HA], seed=None, sighex: str = None, config=None): SimpleZStack.__init__(self, stackParams, msgHandler, seed=seed, sighex=sighex, config=config) KITNetworkInterface.__init__(self, registry=registry) self._retry_connect = {}
def testSimpleZStacksMsgs(tdir, looper): names = ['Alpha', 'Beta'] genKeys(tdir, names) names = ['Alpha', 'Beta'] aseed = randomSeed() bseed = randomSeed() size = 100000 msg = json.dumps({'random': randomSeed(size).decode()}).encode() def aHandler(m): str_m = "{}".format(m) print('{} printing... {}'.format(names[0], str_m[:100])) d, _ = m print('Message size is {}'.format(len(d['random']))) assert len(d['random']) == size def bHandler(m): print(beta.msgHandler) a = m[1] try: beta.listener.send_multipart([a, msg], flags=zmq.NOBLOCK) except zmq.Again: return False str_m = "{}".format(m) print('{} printing... {}'.format(names[1], str_m[:100])) stackParams = { "name": names[0], "ha": genHa(), "auto": 2, "basedirpath": tdir } alpha = SimpleZStack(stackParams, aHandler, aseed, False) stackParams = { "name": names[1], "ha": genHa(), "auto": 2, "basedirpath": tdir } beta = SimpleZStack(stackParams, bHandler, bseed, True) amotor = SMotor(alpha) looper.add(amotor) bmotor = SMotor(beta) looper.add(bmotor) alpha.connect(name=beta.name, ha=beta.ha, verKeyRaw=beta.verKeyRaw, publicKeyRaw=beta.publicKeyRaw) looper.runFor(0.25) alpha.send({'greetings': 'hi'}, beta.name) looper.runFor(1)
def stacks(tdir, looper, alpha_handler): names = ['Alpha', 'Beta'] genKeys(tdir, names) aseed = randomSeed() bseed = randomSeed() def bHandler(m): msg, a = m beta.send(msg, a) stackParams = { "name": names[0], "ha": genHa(), "auto": 2, "basedirpath": tdir } timer = MockTimer(0) alpha = SimpleZStack(stackParams, alpha_handler.handle, aseed, False, timer=timer) stackParams = { "name": names[1], "ha": genHa(), "auto": 2, "basedirpath": tdir } timer = MockTimer(0) beta = SimpleZStack(stackParams, bHandler, bseed, True, timer=timer) amotor = SMotor(alpha) looper.add(amotor) bmotor = SMotor(beta) looper.add(bmotor) return alpha, beta
def __init__(self, *args, **kwargs): self.silencer = Silencer() self._RemoteClass = Remote_ SimpleZStack.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): self.silencer = Silencer() self._RemoteClass = Remote_ SimpleZStack.__init__(self, *args, **kwargs)