def test(): ''' Test keeping. ''' 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, sigkey=masterSignKeyHex, prikey=masterPriKeyHex) remote0 = devicing.RemoteDevice(did=2, ha=('127.0.0.1', 7532), verkey=minionVerKeyHex, pubkey=minionPubKeyHex,) remote1 = devicing.RemoteDevice(did=3, ha=('127.0.0.1', 7533), verkey=minionVerKeyHex, pubkey=minionPubKeyHex,) pond = keeping.RoadKeep(dirpath=os.getcwd()) safe = keeping.SafeKeep(dirpath=os.getcwd()) pond.dumpLocalDevice(device) pond.dumpRemoteDevice(remote0) pond.dumpRemoteDevice(remote1) safe.dumpLocalDevice(device) safe.dumpRemoteDevice(remote0) safe.dumpRemoteDevice(remote1) data = pond.loadLocalData() print data data = pond.loadAllRemoteData() print data data = safe.loadLocalData() print data data = safe.loadAllRemoteData() print data
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 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