def testStackUdp(): ''' initially master on port 7530 with eid of 1 minion on port 7531 with eid of 0 eventually master eid of 1 minion eid of 2 ''' console.reinit(verbosity=console.Wordage.concise) signer = nacling.Signer() masterSignKeyHex = signer.keyhex privateer = nacling.Privateer() masterPriKeyHex = privateer.keyhex signer = nacling.Signer() minionSignKeyHex = signer.keyhex privateer = nacling.Privateer() minionPriKeyHex = privateer.keyhex #master stack estate = estating.LocalEstate( eid=1, name='master', sigkey=masterSignKeyHex, prikey=masterPriKeyHex, ) stack0 = stacking.StackUdp(estate=estate) #minion stack estate = estating.LocalEstate( eid=0, name='minion1', ha=("", raeting.RAET_TEST_PORT), sigkey=minionSignKeyHex, prikey=minionPriKeyHex, ) stack1 = stacking.StackUdp(estate=estate) print "\n********* Join Transaction **********" stack1.join() timer = Timer(duration=0.5) while not timer.expired: stack1.serviceUdp() stack0.serviceUdp() stack0.serviceUdpRx() stack0.process() timer.restart() while not timer.expired: stack0.serviceUdp() stack1.serviceUdp() stack1.serviceUdpRx() print "{0} eid={1}".format(stack0.name, stack0.estate.eid) print "{0} estates=\n{1}".format(stack0.name, stack0.estates) print "{0} dids=\n{1}".format(stack0.name, stack0.eids) print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions) for estate in stack0.estates.values(): print "Remote Estate {0} joined= {1}".format(estate.eid, estate.joined) print "{0} eid={1}".format(stack1.name, stack1.estate.eid) print "{0} estates=\n{1}".format(stack1.name, stack1.estates) print "{0} dids=\n{1}".format(stack1.name, stack1.eids) print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions) for estate in stack1.estates.values(): print "Remote Estate {0} joined= {1}".format(estate.eid, estate.joined) print "\n********* Allow Transaction **********" stack1.allow() timer.restart() while not timer.expired: stack1.serviceUdp() stack0.serviceUdp() stack0.serviceUdpRx() timer.restart() while not timer.expired: stack0.serviceUdp() stack1.serviceUdp() stack1.serviceUdpRx() timer.restart() while not timer.expired: stack0.serviceUdp() stack1.serviceUdp() stack0.serviceUdpRx() timer.restart() while not timer.expired: stack0.serviceUdp() stack1.serviceUdp() stack1.serviceUdpRx() print "{0} eid={1}".format(stack0.name, stack0.estate.eid) print "{0} estates=\n{1}".format(stack0.name, stack0.estates) print "{0} dids=\n{1}".format(stack0.name, stack0.eids) print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions) for estate in stack0.estates.values(): print "Remote Estate {0} allowed= {1}".format(estate.eid, estate.allowed) print "{0} eid={1}".format(stack1.name, stack1.estate.eid) print "{0} estates=\n{1}".format(stack1.name, stack1.estates) print "{0} dids=\n{1}".format(stack1.name, stack1.eids) print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions) for estate in stack1.estates.values(): print "Remote Estate {0} allowed= {1}".format(estate.eid, estate.allowed) print "\n********* Message Transaction Minion to Master **********" body = odict(what="This is a message to the master. How are you", extra="And some more.") stack1.message(body=body, deid=1) timer.restart() while not timer.expired: stack1.serviceUdp() stack0.serviceUdp() stack0.serviceUdpRx() timer.restart() while not timer.expired: stack0.serviceUdp() stack1.serviceUdp() stack1.serviceUdpRx() print "{0} eid={1}".format(stack0.name, stack0.estate.eid) print "{0} estates=\n{1}".format(stack0.name, stack0.estates) print "{0} dids=\n{1}".format(stack0.name, stack0.eids) print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions) print "{0} Received Messages =\n{1}".format(stack0.name, stack0.rxMsgs) print "{0} eid={1}".format(stack1.name, stack1.estate.eid) print "{0} estates=\n{1}".format(stack1.name, stack1.estates) print "{0} dids=\n{1}".format(stack1.name, stack1.eids) print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions) print "{0} Received Messages =\n{1}".format(stack1.name, stack1.rxMsgs) print "\n********* Message Transaction Master to Minion **********" body = odict(what="This is a message to the minion. Get to Work", extra="Fix the fence.") stack0.message(body=body, deid=2) timer.restart() while not timer.expired: stack0.serviceUdp() stack1.serviceUdp() stack1.serviceUdpRx() timer.restart() while not timer.expired: stack1.serviceUdp() stack0.serviceUdp() stack0.serviceUdpRx() print "{0} eid={1}".format(stack0.name, stack0.estate.eid) print "{0} estates=\n{1}".format(stack0.name, stack0.estates) print "{0} dids=\n{1}".format(stack0.name, stack0.eids) print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions) print "{0} Received Messages =\n{1}".format(stack0.name, stack0.rxMsgs) print "{0} eid={1}".format(stack1.name, stack1.estate.eid) print "{0} estates=\n{1}".format(stack1.name, stack1.estates) print "{0} dids=\n{1}".format(stack1.name, stack1.eids) print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions) print "{0} Received Messages =\n{1}".format(stack1.name, stack1.rxMsgs) print "\n********* Message Transactions Both Ways **********" stack1.txMsgs.append((odict(house="Mama mia1", queue="fix me"), None)) stack1.txMsgs.append((odict(house="Mama mia2", queue="help me"), None)) stack1.txMsgs.append((odict(house="Mama mia3", queue="stop me"), None)) stack1.txMsgs.append((odict(house="Mama mia4", queue="run me"), None)) stack0.txMsgs.append((odict(house="Papa pia1", queue="fix me"), None)) stack0.txMsgs.append((odict(house="Papa pia2", queue="help me"), None)) stack0.txMsgs.append((odict(house="Papa pia3", queue="stop me"), None)) stack0.txMsgs.append((odict(house="Papa pia4", queue="run me"), None)) #segmented packets stuff = [] for i in range(300): stuff.append(str(i).rjust(4, " ")) stuff = "".join(stuff) stack1.txMsgs.append((odict(house="Mama mia1", queue="big stuff", stuff=stuff), None)) stack0.txMsgs.append((odict(house="Papa pia4", queue="gig stuff", stuff=stuff), None)) stack1.serviceTxMsg() stack0.serviceTxMsg() timer.restart() while not timer.expired: stack1.serviceUdp() stack0.serviceUdp() stack0.serviceUdpRx() stack1.serviceUdpRx() timer.restart() while not timer.expired: stack0.serviceUdp() stack1.serviceUdp() stack1.serviceUdpRx() stack0.serviceUdpRx() print "{0} eid={1}".format(stack0.name, stack0.estate.eid) print "{0} estates=\n{1}".format(stack0.name, stack0.estates) print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions) print "{0} Received Messages".format(stack0.name) for msg in stack0.rxMsgs: print msg print print "{0} eid={1}".format(stack1.name, stack1.estate.eid) print "{0} estates=\n{1}".format(stack1.name, stack1.estates) print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions) print "{0} Received Messages".format(stack1.name) for msg in stack1.rxMsgs: print msg print "\n********* Message Transactions Both Ways Again **********" stack1.txMsg(odict(house="Oh Boy1", queue="Nice")) stack1.txMsg(odict(house="Oh Boy2", queue="Mean")) stack1.txMsg(odict(house="Oh Boy3", queue="Ugly")) stack1.txMsg(odict(house="Oh Boy4", queue="Pretty")) stack0.txMsg(odict(house="Yeah Baby1", queue="Good")) stack0.txMsg(odict(house="Yeah Baby2", queue="Bad")) stack0.txMsg(odict(house="Yeah Baby3", queue="Fast")) stack0.txMsg(odict(house="Yeah Baby4", queue="Slow")) #segmented packets stuff = [] for i in range(300): stuff.append(str(i).rjust(4, " ")) stuff = "".join(stuff) stack1.txMsg(odict(house="Snake eyes", queue="near stuff", stuff=stuff)) stack0.txMsg(odict(house="Craps", queue="far stuff", stuff=stuff)) timer.restart(duration=2) while not timer.expired: stack1.serviceAll() stack0.serviceAll() print "{0} eid={1}".format(stack0.name, stack0.estate.eid) print "{0} estates=\n{1}".format(stack0.name, stack0.estates) print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions) print "{0} Received Messages".format(stack0.name) for msg in stack0.rxMsgs: print msg print print "{0} eid={1}".format(stack1.name, stack1.estate.eid) print "{0} estates=\n{1}".format(stack1.name, stack1.estates) print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions) print "{0} Received Messages".format(stack1.name) for msg in stack1.rxMsgs: print msg
def test(): ''' Test packeting. ''' data = odict(hk=1, bk=raeting.bodyKinds.json) body = odict(msg='Hello Raet World', extra='what is this') packet0 = packeting.TxPacket( embody=body, data=data, ) print packet0.body.data packet0.pack() print packet0.packed stuff = [] for i in range(300): stuff.append(str(i).rjust(4, " ")) stuff = "".join(stuff) data.update(bk=raeting.bodyKinds.raw) packet0 = packeting.TxPacket( embody=stuff, data=data, ) packet0.pack() print packet0.packed rejoin = [] if packet0.segmented: for index, segment in packet0.segments.items(): print index, segment.packed rejoin.append(segment.body.packed) rejoin = "".join(rejoin) print stuff == rejoin signer = nacling.Signer() masterSignKeyHex = signer.keyhex masterVerKeyHex = signer.verhex privateer = nacling.Privateer() masterPriKeyHex = privateer.keyhex masterPubKeyHex = privateer.pubhex signer = nacling.Signer() minionSignKeyHex = signer.keyhex minionVerKeyHex = signer.verhex privateer = nacling.Privateer() minionPriKeyHex = privateer.keyhex minionPubKeyHex = privateer.pubhex #master stack device = devicing.LocalDevice(did=1, signkey=masterSignKeyHex, prikey=masterPriKeyHex) stack0 = stacking.StackUdp(device=device) remote1 = devicing.RemoteDevice( did=2, verkey=minionVerKeyHex, pubkey=minionPubKeyHex, ) stack0.addRemoteDevice(remote1) #minion stack device = devicing.LocalDevice( did=2, ha=("", raeting.RAET_TEST_PORT), signkey=minionSignKeyHex, prikey=minionPriKeyHex, ) stack1 = stacking.StackUdp(device=device) remote0 = devicing.RemoteDevice( did=1, ha=('127.0.0.1', raeting.RAET_PORT), verkey=masterVerKeyHex, pubkey=masterPubKeyHex, ) stack1.addRemoteDevice(remote0) remote0.publee = nacling.Publican(key=remote1.privee.pubhex) remote1.publee = nacling.Publican(key=remote0.privee.pubhex) data.update(sd=1, dd=2, bk=raeting.bodyKinds.raw, fk=raeting.footKinds.nacl) packet0 = packeting.TxPacket( stack=stack0, embody=stuff, data=data, ) packet0.pack() print packet0.packed rejoin = [] if packet0.segmented: for index, segment in packet0.segments.items(): print index, segment.packed rejoin.append(segment.coat.packed) rejoin = "".join(rejoin) print stuff == rejoin segmentage = None if packet0.segmented: for segment in packet0.segments.values(): packet = packeting.RxPacket(stack=stack1, packed=segment.packed) packet.parseOuter() if packet.segmentive: if not segmentage: segmentage = packeting.RxPacket(stack=packet.stack, data=packet.data) segmentage.parseSegment(packet) if segmentage.desegmentable(): segmentage.desegmentize() break if segmentage: if not stack1.parseInner(segmentage): print "*******BAD SEGMENTAGE********" return print segmentage.body.packed print segmentage.body.data print segmentage.body.packed == packet0.body.packed body = odict(stuff=stuff) print body data.update(sd=1, dd=2, bk=raeting.bodyKinds.json, fk=raeting.footKinds.nacl) packet0 = packeting.TxPacket( stack=stack0, embody=body, data=data, ) packet0.pack() print packet0.packed segmentage = None if packet0.segmented: for segment in packet0.segments.values(): packet = packeting.RxPacket(stack=stack1, packed=segment.packed) packet.parseOuter() if packet.segmentive: if not segmentage: segmentage = packeting.RxPacket(stack=packet.stack, data=packet.data) segmentage.parseSegment(packet) if segmentage.desegmentable(): segmentage.desegmentize() break if segmentage: if not stack1.parseInner(segmentage): print "*******BAD SEGMENTAGE********" return print segmentage.body.packed print segmentage.body.data print segmentage.body.packed == packet0.body.packed body = odict(stuff=stuff) print body data.update(sd=1, dd=2, bk=raeting.bodyKinds.json, ck=raeting.coatKinds.nacl, fk=raeting.footKinds.nacl) packet0 = packeting.TxPacket( stack=stack0, embody=body, data=data, ) packet0.pack() print "Body" print packet0.body.size, packet0.body.packed print "Coat" print packet0.coat.size, packet0.coat.packed print "Head" print packet0.head.size, packet0.head.packed print "Foot" print packet0.foot.size, packet0.foot.packed print "Packet" print packet0.size, packet0.packed segmentage = None if packet0.segmented: for segment in packet0.segments.values(): packet = packeting.RxPacket(stack=stack1, packed=segment.packed) packet.parseOuter() if packet.segmentive: if not segmentage: segmentage = packeting.RxPacket(stack=packet.stack, data=packet.data) segmentage.parseSegment(packet) if segmentage.desegmentable(): segmentage.desegmentize() break if segmentage: if not stack1.parseInner(segmentage): print "*******BAD SEGMENTAGE********" print segmentage.body.packed print segmentage.body.data print segmentage.body.packed == packet0.body.packed
def test(): ''' initially master on port 7530 with did of 1 minion on port 7531 with did of 0 eventually master did of 1 minion did of 2 ''' signer = nacling.Signer() masterSignKeyHex = signer.keyhex privateer = nacling.Privateer() masterPriKeyHex = privateer.keyhex signer = nacling.Signer() minionSignKeyHex = signer.keyhex privateer = nacling.Privateer() minionPriKeyHex = privateer.keyhex #master stack device = devicing.LocalDevice( did=1, name='master', signkey=masterSignKeyHex, prikey=masterPriKeyHex,) stack0 = stacking.StackUdp(device=device) #minion stack device = devicing.LocalDevice( did=0, name='minion1', ha=("", raeting.RAET_TEST_PORT), signkey=minionSignKeyHex, prikey=minionPriKeyHex,) stack1 = stacking.StackUdp(device=device) print "\n********* Join Transaction **********" stack1.join() timer = Timer(duration=0.5) while not timer.expired: stack1.serviceUdp() stack0.serviceUdp() while stack0.udpRxes: stack0.processUdpRx() timer.restart() while not timer.expired: stack0.serviceUdp() stack1.serviceUdp() while stack1.udpRxes: stack1.processUdpRx() print "{0} did={1}".format(stack0.name, stack0.device.did) print "{0} devices=\n{1}".format(stack0.name, stack0.devices) print "{0} dids=\n{1}".format(stack0.name, stack0.dids) print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions) for device in stack0.devices.values(): print "Remote Device {0} joined= {1}".format(device.did, device.joined) print "{0} did={1}".format(stack1.name, stack1.device.did) print "{0} devices=\n{1}".format(stack1.name, stack1.devices) print "{0} dids=\n{1}".format(stack1.name, stack1.dids) print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions) for device in stack1.devices.values(): print "Remote Device {0} joined= {1}".format(device.did, device.joined) print "\n********* Allow Transaction **********" stack1.allow() timer.restart() while not timer.expired: stack1.serviceUdp() stack0.serviceUdp() while stack0.udpRxes: stack0.processUdpRx() timer.restart() while not timer.expired: stack0.serviceUdp() stack1.serviceUdp() while stack1.udpRxes: stack1.processUdpRx() timer.restart() while not timer.expired: stack0.serviceUdp() stack1.serviceUdp() while stack0.udpRxes: stack0.processUdpRx() timer.restart() while not timer.expired: stack0.serviceUdp() stack1.serviceUdp() while stack1.udpRxes: stack1.processUdpRx() print "{0} did={1}".format(stack0.name, stack0.device.did) print "{0} devices=\n{1}".format(stack0.name, stack0.devices) print "{0} dids=\n{1}".format(stack0.name, stack0.dids) print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions) for device in stack0.devices.values(): print "Remote Device {0} allowed= {1}".format(device.did, device.allowed) print "{0} did={1}".format(stack1.name, stack1.device.did) print "{0} devices=\n{1}".format(stack1.name, stack1.devices) print "{0} dids=\n{1}".format(stack1.name, stack1.dids) print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions) for device in stack1.devices.values(): print "Remote Device {0} allowed= {1}".format(device.did, device.allowed) print "\n********* Message Transaction Minion to Master **********" body = odict(what="This is a message to the master. How are you", extra="And some more.") stack1.message(body=body, ddid=1) timer.restart() while not timer.expired: stack1.serviceUdp() stack0.serviceUdp() while stack0.udpRxes: stack0.processUdpRx() timer.restart() while not timer.expired: stack0.serviceUdp() stack1.serviceUdp() while stack1.udpRxes: stack1.processUdpRx() print "{0} did={1}".format(stack0.name, stack0.device.did) print "{0} devices=\n{1}".format(stack0.name, stack0.devices) print "{0} dids=\n{1}".format(stack0.name, stack0.dids) print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions) print "{0} Received Messages =\n{1}".format(stack0.name, stack0.rxMsgs) print "{0} did={1}".format(stack1.name, stack1.device.did) print "{0} devices=\n{1}".format(stack1.name, stack1.devices) print "{0} dids=\n{1}".format(stack1.name, stack1.dids) print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions) print "{0} Received Messages =\n{1}".format(stack1.name, stack1.rxMsgs) print "\n********* Message Transaction Master to Minion **********" body = odict(what="This is a message to the minion. Get to Work", extra="Fix the fence.") stack0.message(body=body, ddid=2) timer.restart() while not timer.expired: stack0.serviceUdp() stack1.serviceUdp() while stack1.udpRxes: stack1.processUdpRx() timer.restart() while not timer.expired: stack1.serviceUdp() stack0.serviceUdp() while stack0.udpRxes: stack0.processUdpRx() print "{0} did={1}".format(stack0.name, stack0.device.did) print "{0} devices=\n{1}".format(stack0.name, stack0.devices) print "{0} dids=\n{1}".format(stack0.name, stack0.dids) print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions) print "{0} Received Messages =\n{1}".format(stack0.name, stack0.rxMsgs) print "{0} did={1}".format(stack1.name, stack1.device.did) print "{0} devices=\n{1}".format(stack1.name, stack1.devices) print "{0} dids=\n{1}".format(stack1.name, stack1.dids) print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions) print "{0} Received Messages =\n{1}".format(stack1.name, stack1.rxMsgs) print "\n********* Message Transactions Both Ways **********" stack1.txMsgs.append((odict(house="Mama mia1", queue="fix me"), None)) stack1.txMsgs.append((odict(house="Mama mia2", queue="help me"), None)) stack1.txMsgs.append((odict(house="Mama mia3", queue="stop me"), None)) stack1.txMsgs.append((odict(house="Mama mia4", queue="run me"), None)) stack0.txMsgs.append((odict(house="Papa pia1", queue="fix me"), None)) stack0.txMsgs.append((odict(house="Papa pia2", queue="help me"), None)) stack0.txMsgs.append((odict(house="Papa pia3", queue="stop me"), None)) stack0.txMsgs.append((odict(house="Papa pia4", queue="run me"), None)) #segmented packets stuff = [] for i in range(300): stuff.append(str(i).rjust(4, " ")) stuff = "".join(stuff) stack1.txMsgs.append((odict(house="Mama mia1", queue="big stuff", stuff=stuff), None)) stack0.txMsgs.append((odict(house="Papa pia4", queue="gig stuff", stuff=stuff), None)) stack1.serviceUdpTxMsg() stack0.serviceUdpTxMsg() timer.restart() while not timer.expired: stack1.serviceUdp() stack0.serviceUdp() while stack0.udpRxes: stack0.processUdpRx() while stack1.udpRxes: stack1.processUdpRx() timer.restart() while not timer.expired: stack0.serviceUdp() stack1.serviceUdp() while stack1.udpRxes: stack1.processUdpRx() while stack0.udpRxes: stack0.processUdpRx() print "{0} did={1}".format(stack0.name, stack0.device.did) print "{0} devices=\n{1}".format(stack0.name, stack0.devices) print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions) print "{0} Received Messages".format(stack0.name) for msg in stack0.rxMsgs: print msg print print "{0} did={1}".format(stack1.name, stack1.device.did) print "{0} devices=\n{1}".format(stack1.name, stack1.devices) print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions) print "{0} Received Messages".format(stack1.name) for msg in stack1.rxMsgs: print msg
def test(): ''' Test keeping. ''' masterDirpath = os.path.join(os.getcwd(), 'keep', 'master') signer = nacling.Signer() masterSignKeyHex = signer.keyhex masterVerKeyHex = signer.verhex privateer = nacling.Privateer() masterPriKeyHex = privateer.keyhex masterPubKeyHex = privateer.pubhex m1Dirpath = os.path.join(os.getcwd(), 'keep', 'minion1') signer = nacling.Signer() m1SignKeyHex = signer.keyhex m1VerKeyHex = signer.verhex privateer = nacling.Privateer() m1PriKeyHex = privateer.keyhex m1PubKeyHex = privateer.pubhex signer = nacling.Signer() m2SignKeyHex = signer.keyhex m2VerKeyHex = signer.verhex privateer = nacling.Privateer() m2PriKeyHex = privateer.keyhex m2PubKeyHex = privateer.pubhex signer = nacling.Signer() m3SignKeyHex = signer.keyhex m3VerKeyHex = signer.verhex privateer = nacling.Privateer() m3PriKeyHex = privateer.keyhex m3PubKeyHex = privateer.pubhex keeping.clearAllRoadSafe(masterDirpath) keeping.clearAllRoadSafe(m1Dirpath) #master stack dirpath = os.path.join(os.getcwd(), 'keep', 'master') estate = estating.LocalEstate( eid=1, name='master', sigkey=masterSignKeyHex, prikey=masterPriKeyHex,) stack0 = stacking.StackUdp(estate=estate, dirpath=masterDirpath) stack0.addRemoteEstate(estating.RemoteEstate(eid=2, ha=('127.0.0.1', 7532), verkey=m1VerKeyHex, pubkey=m1PubKeyHex,)) stack0.addRemoteEstate(estating.RemoteEstate(eid=3, ha=('127.0.0.1', 7533), verkey=m2VerKeyHex, pubkey=m2PubKeyHex,)) #minion stack dirpath = os.path.join(os.getcwd(), 'keep', 'minion1') estate = estating.LocalEstate( eid=2, name='minion1', ha=("", raeting.RAET_TEST_PORT), sigkey=m1SignKeyHex, prikey=m1PriKeyHex,) stack1 = stacking.StackUdp(estate=estate, dirpath=m1Dirpath) stack1.addRemoteEstate(estating.RemoteEstate(eid=1, ha=('127.0.0.1', 7532), verkey=masterVerKeyHex, pubkey=masterPubKeyHex,)) stack1.addRemoteEstate(estating.RemoteEstate(eid=4, ha=('127.0.0.1', 7534), verkey=m3VerKeyHex, pubkey=m3PubKeyHex,)) stack0.clearLocal() stack0.clearAllRemote() stack1.clearLocal() stack1.clearAllRemote() stack0.dumpLocal() stack0.dumpAllRemote() stack1.dumpLocal() stack1.dumpAllRemote() print "Road {0}".format(stack0.name) print stack0.road.loadLocalData() print stack0.road.loadAllRemoteData() print "Safe {0}".format(stack0.name) print stack0.safe.loadLocalData() print stack0.safe.loadAllRemoteData() print print "Road {0}".format(stack1.name) print stack1.road.loadLocalData() print stack1.road.loadAllRemoteData() print "Safe {0}".format(stack1.name) print stack1.safe.loadLocalData() print stack1.safe.loadAllRemoteData() stack0.serverUdp.close() stack1.serverUdp.close() #master stack dirpath = os.path.join(os.getcwd(), 'keep', 'master') estate = estating.LocalEstate( eid=1, name='master', sigkey=masterSignKeyHex, prikey=masterPriKeyHex,) stack0 = stacking.StackUdp(estate=estate, dirpath=masterDirpath) #minion stack dirpath = os.path.join(os.getcwd(), 'keep', 'minion1') estate = estating.LocalEstate( eid=2, name='minion1', ha=("", raeting.RAET_TEST_PORT), sigkey=m1SignKeyHex, prikey=m1PriKeyHex,) stack1 = stacking.StackUdp(estate=estate, dirpath=m1Dirpath) estate0 = stack0.loadLocal() print estate0.name, estate0.eid, estate0.sid, estate0.ha, estate0.signer, estate0.priver estate1 = stack1.loadLocal() print estate1.name, estate1.eid, estate1.sid, estate1.ha, estate1.signer, estate1.priver stack0.clearLocal() stack0.clearAllRemote() stack1.clearLocal() stack1.clearAllRemote()
def test(): ''' initially master on port 7530 with eid of 1 minion on port 7531 with eid of 0 eventually master eid of 1 minion eid of 2 ''' console.reinit(verbosity=console.Wordage.concise) store = storing.Store(stamp=0.0) #master stack masterName = "master" signer = nacling.Signer() masterSignKeyHex = signer.keyhex privateer = nacling.Privateer() masterPriKeyHex = privateer.keyhex dirpathMaster = os.path.join(os.getcwd(), 'keep', masterName) #minion0 stack minionName0 = "minion0" signer = nacling.Signer() minionSignKeyHex = signer.keyhex privateer = nacling.Privateer() minionPriKeyHex = privateer.keyhex dirpathMinion0 = os.path.join(os.getcwd(), 'keep', minionName0) keeping.clearAllRoadSafe(dirpathMaster) keeping.clearAllRoadSafe(dirpathMinion0) estate = estating.LocalEstate( eid=1, name=masterName, sigkey=masterSignKeyHex, prikey=masterPriKeyHex,) stack0 = stacking.StackUdp(estate=estate, store=store, auto=True, main=True, dirpath=dirpathMaster) estate = estating.LocalEstate( eid=0, name=minionName0, ha=("", raeting.RAET_TEST_PORT), sigkey=minionSignKeyHex, prikey=minionPriKeyHex,) stack1 = stacking.StackUdp(estate=estate, store=store, dirpath=dirpathMinion0) print "\n********* Join Transaction **********" stack1.join() timer = Timer(duration=2) timer.restart(duration=2) while not timer.expired: stack1.serviceAll() stack0.serviceAll() for estate in stack0.estates.values(): print "Remote Estate {0} joined= {1}".format(estate.eid, estate.joined) for estate in stack1.estates.values(): print "Remote Estate {0} joined= {1}".format(estate.eid, estate.joined) print "\n********* Allow Transaction **********" stack1.allow() timer.restart(duration=2) while not timer.expired: stack1.serviceAll() stack0.serviceAll() store.advanceStamp(0.1) for estate in stack0.estates.values(): print "Remote Estate {0} allowed= {1}".format(estate.eid, estate.allowed) for estate in stack1.estates.values(): print "Remote Estate {0} allowed= {1}".format(estate.eid, estate.allowed) print "\n********* Message Transactions Both Ways **********" stack1.transmit(odict(house="Oh Boy1", queue="Nice")) stack0.transmit(odict(house="Yeah Baby1", queue="Good")) #segmented packets stuff = [] for i in range(300): stuff.append(str(i).rjust(4, " ")) stuff = "".join(stuff) stack1.transmit(odict(house="Snake eyes", queue="near stuff", stuff=stuff)) stack0.transmit(odict(house="Craps", queue="far stuff", stuff=stuff)) timer.restart(duration=2) while not timer.expired: stack1.serviceAll() stack0.serviceAll() print "{0} Received Messages".format(stack0.name) for msg in stack0.rxMsgs: print msg print print "{0} Received Messages".format(stack1.name) for msg in stack1.rxMsgs: print msg print print "{0} eid={1}".format(stack0.name, stack0.estate.eid) print "{0} estates=\n{1}".format(stack0.name, stack0.estates) print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions) print "{0} eid={1}".format(stack1.name, stack1.estate.eid) print "{0} estates=\n{1}".format(stack1.name, stack1.estates) print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions) print "Road {0}".format(stack0.name) print stack0.road.loadLocalData() print stack0.road.loadAllRemoteData() print "Safe {0}".format(stack0.name) print stack0.safe.loadLocalData() print stack0.safe.loadAllRemoteData() print print "Road {0}".format(stack1.name) print stack1.road.loadLocalData() print stack1.road.loadAllRemoteData() print "Safe {0}".format(stack1.name) print stack1.safe.loadLocalData() print stack1.safe.loadAllRemoteData() print stack0.serverUdp.close() stack1.serverUdp.close()
def test(): ''' initially master on port 7530 with eid of 1 minion on port 7531 with eid of 0 eventually master eid of 1 minion eid of 2 ''' console.reinit(verbosity=console.Wordage.concise) #master stack masterName = "master" signer = nacling.Signer() masterSignKeyHex = signer.keyhex privateer = nacling.Privateer() masterPriKeyHex = privateer.keyhex dirpathMaster = os.path.join(os.getcwd(), 'keep', masterName) #minion0 stack minionName0 = "minion0" signer = nacling.Signer() minionSignKeyHex = signer.keyhex privateer = nacling.Privateer() minionPriKeyHex = privateer.keyhex dirpathMinion0 = os.path.join(os.getcwd(), 'keep', minionName0) #minion1 stack minionName1 = "minion1" signer = nacling.Signer() minionSignKeyHex = signer.keyhex privateer = nacling.Privateer() minionPriKeyHex = privateer.keyhex dirpathMinion1 = os.path.join(os.getcwd(), 'keep', minionName1) keeping.clearAllRoadSafe(dirpathMaster) keeping.clearAllRoadSafe(dirpathMinion0) keeping.clearAllRoadSafe(dirpathMinion1) estate = estating.LocalEstate( eid=1, name=masterName, sigkey=masterSignKeyHex, prikey=masterPriKeyHex,) stack0 = stacking.StackUdp(estate=estate, auto=True, main=True, dirpath=dirpathMaster) estate = estating.LocalEstate( eid=0, name=minionName0, ha=("", raeting.RAET_TEST_PORT), sigkey=minionSignKeyHex, prikey=minionPriKeyHex,) stack1 = stacking.StackUdp(estate=estate, dirpath=dirpathMinion0) estate = estating.LocalEstate( eid=0, name=minionName1, ha=("", 7532), sigkey=minionSignKeyHex, prikey=minionPriKeyHex,) stack2 = stacking.StackUdp(estate=estate, dirpath=dirpathMinion1) print "\n********* Join Transaction **********" stack1.join() timer = Timer(duration=2) timer.restart(duration=3) while not timer.expired: stack1.serviceAll() stack0.serviceAll() for estate in stack0.estates.values(): print "Remote Estate {0} joined= {1}".format(estate.eid, estate.joined) for estate in stack1.estates.values(): print "Remote Estate {0} joined= {1}".format(estate.eid, estate.joined) print "\n********* Allow Transaction **********" stack1.allow() timer.restart(duration=2) while not timer.expired: stack1.serviceAll() stack0.serviceAll() for estate in stack0.estates.values(): print "Remote Estate {0} allowed= {1}".format(estate.eid, estate.allowed) for estate in stack1.estates.values(): print "Remote Estate {0} allowed= {1}".format(estate.eid, estate.allowed) print "\n********* Message Transactions Both Ways **********" stack1.transmit(odict(house="Oh Boy1", queue="Nice")) stack1.transmit(odict(house="Oh Boy2", queue="Mean")) stack1.transmit(odict(house="Oh Boy3", queue="Ugly")) stack1.transmit(odict(house="Oh Boy4", queue="Pretty")) stack0.transmit(odict(house="Yeah Baby1", queue="Good")) stack0.transmit(odict(house="Yeah Baby2", queue="Bad")) stack0.transmit(odict(house="Yeah Baby3", queue="Fast")) stack0.transmit(odict(house="Yeah Baby4", queue="Slow")) #segmented packets stuff = [] for i in range(300): stuff.append(str(i).rjust(4, " ")) stuff = "".join(stuff) stack1.transmit(odict(house="Snake eyes", queue="near stuff", stuff=stuff)) stack0.transmit(odict(house="Craps", queue="far stuff", stuff=stuff)) timer.restart(duration=2) while not timer.expired: stack1.serviceAll() stack0.serviceAll() print "{0} Received Messages".format(stack0.name) for msg in stack0.rxMsgs: print msg print print "{0} Received Messages".format(stack1.name) for msg in stack1.rxMsgs: print msg print print "{0} eid={1}".format(stack0.name, stack0.estate.eid) print "{0} estates=\n{1}".format(stack0.name, stack0.estates) print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions) print "{0} eid={1}".format(stack1.name, stack1.estate.eid) print "{0} estates=\n{1}".format(stack1.name, stack1.estates) print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions) print "Road {0}".format(stack0.name) print stack0.road.loadLocalData() print stack0.road.loadAllRemoteData() print "Safe {0}".format(stack0.name) print stack0.safe.loadLocalData() print stack0.safe.loadAllRemoteData() print print "Road {0}".format(stack1.name) print stack1.road.loadLocalData() print stack1.road.loadAllRemoteData() print "Safe {0}".format(stack1.name) print stack1.safe.loadLocalData() print stack1.safe.loadAllRemoteData() print stack0.serverUdp.close() stack1.serverUdp.close() stack2.serverUdp.close() #estate0 = stack0.loadLocal() #print estate0.name, estate0.eid, estate0.sid, estate0.ha, estate0.signer, estate0.priver #estate1 = stack1.loadLocal() #print estate1.name, estate1.eid, estate1.sid, estate1.ha, estate1.signer, estate1.priver #master stack stack0 = stacking.StackUdp(dirpath=dirpathMaster, auto=True, main=True) #minion0 stack stack1 = stacking.StackUdp(dirpath=dirpathMinion0) #minion1 stack stack2 = stacking.StackUdp(dirpath=dirpathMinion1) print "\n********* Join Transaction **********" stack1.join() stack2.join() timer = Timer(duration=2) timer.restart(duration=2) while not timer.expired: stack1.serviceAll() stack2.serviceAll() stack0.serviceAll() for estate in stack0.estates.values(): print "{0} Remote Estate {1} joined= {2}".format( stack0.name, estate.eid, estate.joined) for estate in stack1.estates.values(): print "{0} Remote Estate {1} joined= {2}".format( stack1.name, estate.eid, estate.joined) for estate in stack2.estates.values(): print "{0} Remote Estate {1} joined= {2}".format( stack2.name, estate.eid, estate.joined) print "\n********* Allow Transaction **********" stack1.allow() stack2.allow() timer.restart(duration=2) while not timer.expired: stack1.serviceAll() stack2.serviceAll() stack0.serviceAll() for estate in stack0.estates.values(): print "{0} Remote Estate {1} allowed= {2}".format( stack1.name, estate.eid, estate.allowed) for estate in stack1.estates.values(): print "{0} Remote Estate {1} allowed= {2}".format( stack1.name, estate.eid, estate.allowed) for estate in stack2.estates.values(): print "{0} Remote Estate {1} allowed= {2}".format( stack2.name, estate.eid, estate.allowed) print "\n********* Message Transactions Both Ways **********" #console.reinit(verbosity=console.Wordage.verbose) stack1.transmit(odict(house="Oh Boy1", queue="Nice")) stack1.transmit(odict(house="Oh Boy2", queue="Mean")) stack1.transmit(odict(house="Oh Boy3", queue="Ugly")) stack1.transmit(odict(house="Oh Boy4", queue="Pretty")) stack2.transmit(odict(house="Really 1", queue="blue")) stack2.transmit(odict(house="Really 2", queue="green")) stack2.transmit(odict(house="Really 3", queue="red")) stack2.transmit(odict(house="Really 4", queue="yello")) stack0.transmit(odict(house="Yeah Baby1", queue="Good")) stack0.transmit(odict(house="Yeah Baby2", queue="Bad")) stack0.transmit(odict(house="Yeah Baby3", queue="Fast")) stack0.transmit(odict(house="Yeah Baby4", queue="Slow")) stack0.transmit(odict(house="Yeah Momma 1", queue="host"), stack2.estate.eid) stack0.transmit(odict(house="Yeah Momma 1", queue="cold"), stack2.estate.eid) stack0.transmit(odict(house="Yeah Momma 1", queue="boiling"), stack2.estate.eid) stack0.transmit(odict(house="Yeah Momma 1", queue="tepid"), stack2.estate.eid) # segmented packets stuff = [] for i in range(300): stuff.append(str(i).rjust(4, " ")) stuff = "".join(stuff) stack1.transmit(odict(house="Snake eyes", queue="near stuff", stuff=stuff)) stack0.transmit(odict(house="Craps", queue="far stuff", stuff=stuff)) stack2.transmit(odict(house="Lucky duck", queue="medium stuff", stuff=stuff)) stack0.transmit(odict(house="Boogle", queue="hight stuff", stuff=stuff), stack2.estate.eid) timer.restart(duration=4) while not timer.expired: stack1.serviceAll() stack2.serviceAll() stack0.serviceAll() print "{0} Received Messages".format(stack0.name) for msg in stack0.rxMsgs: print msg print print "{0} Received Messages".format(stack1.name) for msg in stack1.rxMsgs: print msg print print "{0} Received Messages".format(stack2.name) for msg in stack2.rxMsgs: print msg print print "{0} eid={1}".format(stack0.name, stack0.estate.eid) print "{0} estates=\n{1}".format(stack0.name, stack0.estates) print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions) print "{0} eid={1}".format(stack1.name, stack1.estate.eid) print "{0} estates=\n{1}".format(stack1.name, stack1.estates) print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions) print "{0} eid={1}".format(stack2.name, stack2.estate.eid) print "{0} estates=\n{1}".format(stack2.name, stack2.estates) print "{0} transactions=\n{1}".format(stack2.name, stack2.transactions) stack0.serverUdp.close() stack1.serverUdp.close() stack2.serverUdp.close() stack0.clearLocal() stack0.clearAllRemote() stack1.clearLocal() stack1.clearAllRemote() stack2.clearLocal() stack2.clearAllRemote()
def test(bk=raeting.bodyKinds.json): ''' Test packeting. ''' data = odict(hk=1, bk=bk) body = odict(msg='Hello Raet World', extra='what is this') packet0 = packeting.TxPacket( embody=body, data=data, ) print packet0.body.data packet0.pack() print packet0.packed packet1 = packeting.RxPacket(packed=packet0.packed) packet1.parse() print packet1.data print packet1.body.data stuff = [] for i in range(300): stuff.append(str(i).rjust(4, " ")) stuff = "".join(stuff) data.update(bk=raeting.bodyKinds.raw) packet0 = packeting.TxPacket( embody=stuff, data=data, ) packet0.pack() print packet0.packed packet1 = packeting.RxPacket(packed=packet0.packed) packet1.parse() print packet1.data print packet1.body.data rejoin = [] if packet0.segmented: for index, segment in packet0.segments.items(): print index, segment.packed rejoin.append(segment.body.packed) rejoin = "".join(rejoin) print stuff == rejoin #master stack masterName = "master" signer = nacling.Signer() masterSignKeyHex = signer.keyhex masterVerKeyHex = signer.verhex privateer = nacling.Privateer() masterPriKeyHex = privateer.keyhex masterPubKeyHex = privateer.pubhex dirpathMaster = os.path.join(os.getcwd(), 'keep', masterName) #minion stack minionName = "minion" signer = nacling.Signer() minionSignKeyHex = signer.keyhex minionVerKeyHex = signer.verhex privateer = nacling.Privateer() minionPriKeyHex = privateer.keyhex minionPubKeyHex = privateer.pubhex dirpathMinion = os.path.join(os.getcwd(), 'keep', minionName) keeping.clearAllRoadSafe(dirpathMaster) keeping.clearAllRoadSafe(dirpathMinion) estate = estating.LocalEstate(eid=1, name=masterName, sigkey=masterSignKeyHex, prikey=masterPriKeyHex) stack0 = stacking.StackUdp(estate=estate, main=True, dirpath=dirpathMaster) remote1 = estating.RemoteEstate( eid=2, name=minionName, ha=("127.0.0.1", raeting.RAET_TEST_PORT), verkey=minionVerKeyHex, pubkey=minionPubKeyHex, ) stack0.addRemoteEstate(remote1) estate = estating.LocalEstate( eid=2, name=minionName, ha=("", raeting.RAET_TEST_PORT), sigkey=minionSignKeyHex, prikey=minionPriKeyHex, ) stack1 = stacking.StackUdp(estate=estate) remote0 = estating.RemoteEstate( eid=1, name=masterName, ha=('127.0.0.1', raeting.RAET_PORT), verkey=masterVerKeyHex, pubkey=masterPubKeyHex, ) stack1.addRemoteEstate(remote0) remote0.publee = nacling.Publican(key=remote1.privee.pubhex) remote1.publee = nacling.Publican(key=remote0.privee.pubhex) print "\n___________Raw Body Test" data.update(se=1, de=2, bk=raeting.bodyKinds.raw, fk=raeting.footKinds.nacl) packet0 = packeting.TxPacket( stack=stack0, embody=stuff, data=data, ) packet0.pack() print packet0.packed #not signed if segmented each segment is signed rejoin = [] if packet0.segmented: for index, segment in packet0.segments.items(): print index, segment.packed rejoin.append(segment.coat.packed) rejoin = "".join(rejoin) print stuff == rejoin segmentage = None if packet0.segmented: for segment in packet0.segments.values(): packet = packeting.RxPacket(stack=stack1, packed=segment.packed) packet.parseOuter() if packet.segmentive: if not segmentage: segmentage = packeting.RxPacket(stack=packet.stack, data=packet.data) segmentage.parseSegment(packet) if segmentage.desegmentable(): segmentage.desegmentize() break if segmentage: if not stack1.parseInner(segmentage): print "*******BAD SEGMENTAGE********" return print segmentage.body.packed print segmentage.body.data print segmentage.body.packed == packet0.body.packed body = odict(stuff=stuff) print body print "\n_____________ Packed Body Test" data.update(se=1, de=2, bk=bk, fk=raeting.footKinds.nacl) packet0 = packeting.TxPacket( stack=stack0, embody=body, data=data, ) packet0.pack() print packet0.packed segmentage = None if packet0.segmented: for segment in packet0.segments.values(): packet = packeting.RxPacket(stack=stack1, packed=segment.packed) packet.parseOuter() if packet.segmentive: if not segmentage: segmentage = packeting.RxPacket(stack=packet.stack, data=packet.data) segmentage.parseSegment(packet) if segmentage.desegmentable(): segmentage.desegmentize() break if segmentage: if not stack1.parseInner(segmentage): print "*******BAD SEGMENTAGE********" return print segmentage.body.packed print segmentage.body.data print segmentage.body.packed == packet0.body.packed body = odict(stuff=stuff) print body print "\n___________ Encrypted Coat Test " data.update(se=1, de=2, bk=raeting.bodyKinds.json, ck=raeting.coatKinds.nacl, fk=raeting.footKinds.nacl) packet0 = packeting.TxPacket( stack=stack0, embody=body, data=data, ) packet0.pack() print "Body" print packet0.body.size, packet0.body.packed print "Coat" print packet0.coat.size, packet0.coat.packed print "Head" print packet0.head.size, packet0.head.packed print "Foot" print packet0.foot.size, packet0.foot.packed print "Packet" print packet0.size, packet0.packed segmentage = None if packet0.segmented: for segment in packet0.segments.values(): packet = packeting.RxPacket(stack=stack1, packed=segment.packed) packet.parseOuter() if packet.segmentive: if not segmentage: segmentage = packeting.RxPacket(stack=packet.stack, data=packet.data) segmentage.parseSegment(packet) if segmentage.desegmentable(): segmentage.desegmentize() break if segmentage: if not stack1.parseInner(segmentage): print "*******BAD SEGMENTAGE********" print segmentage.body.packed print segmentage.body.data print segmentage.body.packed == packet0.body.packed
def test(preClearMaster=False, preClearMinion=False, postClearMaster=False, postClearMinion=False): ''' initially master on port 7530 with eid of 1 minion on port 7531 with eid of 0 eventually master eid of 1 minion eid of 2 ''' console.reinit(verbosity=console.Wordage.concise) store = storing.Store(stamp=0.0) #master stack masterName = "master" signer = nacling.Signer() masterSignKeyHex = signer.keyhex privateer = nacling.Privateer() masterPriKeyHex = privateer.keyhex masterDirpath = os.path.join(os.getcwd(), 'keep', masterName) #minion0 stack minionName0 = "minion0" signer = nacling.Signer() minionSignKeyHex = signer.keyhex privateer = nacling.Privateer() minionPriKeyHex = privateer.keyhex m0Dirpath = os.path.join(os.getcwd(), 'keep', minionName0) if preClearMaster: keeping.clearAllRoadSafe(masterDirpath) if preClearMinion: keeping.clearAllRoadSafe(m0Dirpath) estate = estating.LocalEstate( eid=1, name=masterName, sigkey=masterSignKeyHex, prikey=masterPriKeyHex, ) stack0 = stacking.StackUdp(name=masterName, estate=estate, store=store, main=True, dirpath=masterDirpath) estate = estating.LocalEstate( eid=0, name=minionName0, ha=("", raeting.RAET_TEST_PORT), sigkey=minionSignKeyHex, prikey=minionPriKeyHex, ) stack1 = stacking.StackUdp(name=minionName0, estate=estate, store=store, dirpath=m0Dirpath) print "\n********* Join Transaction **********" stack1.join() #timer = StoreTimer(store=store, duration=3.0) while stack1.transactions or stack0.transactions: stack1.serviceAll() stack0.serviceAll() if store.stamp >= 0.5: for estate in stack0.estates.values(): if estate.acceptance == raeting.acceptances.pending: stack0.safe.acceptRemoteEstate(estate) store.advanceStamp(0.1) for estate in stack0.estates.values(): print "Remote Estate {0} joined= {1}".format(estate.eid, estate.joined) for estate in stack1.estates.values(): print "Remote Estate {0} joined= {1}".format(estate.eid, estate.joined) print "{0} eid={1}".format(stack0.name, stack0.estate.eid) print "{0} estates=\n{1}".format(stack0.name, stack0.estates) print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions) print "{0} eid={1}".format(stack1.name, stack1.estate.eid) print "{0} estates=\n{1}".format(stack1.name, stack1.estates) print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions) print "Road {0}".format(stack0.name) print stack0.road.loadLocalData() print stack0.road.loadAllRemoteData() print "Safe {0}".format(stack0.name) print stack0.safe.loadLocalData() print stack0.safe.loadAllRemoteData() print print "Road {0}".format(stack1.name) print stack1.road.loadLocalData() print stack1.road.loadAllRemoteData() print "Safe {0}".format(stack1.name) print stack1.safe.loadLocalData() print stack1.safe.loadAllRemoteData() print stack0.serverUdp.close() stack1.serverUdp.close() if postClearMaster: keeping.clearAllRoadSafe(masterDirpath) if postClearMinion: keeping.clearAllRoadSafe(m0Dirpath)