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 estate = estating.LocalEstate(eid=1, sigkey=masterSignKeyHex, prikey=masterPriKeyHex) remote0 = estating.RemoteEstate( eid=2, ha=('127.0.0.1', 7532), verkey=minionVerKeyHex, pubkey=minionPubKeyHex, ) remote1 = estating.RemoteEstate( eid=3, ha=('127.0.0.1', 7533), verkey=minionVerKeyHex, pubkey=minionPubKeyHex, ) pond = keeping.RoadKeep(dirpath=os.getcwd()) safe = keeping.SafeKeep(dirpath=os.getcwd()) pond.dumpLocalEstate(estate) pond.dumpRemoteEstate(remote0) pond.dumpRemoteEstate(remote1) safe.dumpLocalEstate(estate) safe.dumpRemoteEstate(remote0) safe.dumpRemoteEstate(remote1) data = pond.loadLocalData() print data data = pond.loadAllRemoteData() print data data = safe.loadLocalData() print data data = safe.loadAllRemoteData() print data
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.clearAllKeepSafe(masterDirpath) if preClearMinion: keeping.clearAllKeepSafe(m0Dirpath) estate = estating.LocalEstate( eid=1, name=masterName, sigkey=masterSignKeyHex, prikey=masterPriKeyHex, ) stack0 = stacking.RoadStack(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.RoadStack(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.3: for estate in stack0.estates.values(): if estate.acceptance == raeting.acceptances.pending: stack0.safe.acceptRemote(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.uid) 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.uid) 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 print "\n********* Allow Transaction **********" if not stack1.estates.values()[0].joined: return stack1.allow() #timer = StoreTimer(store=store, duration=3.0) while stack1.transactions or stack0.transactions: 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 "{0} eid={1}".format(stack0.name, stack0.estate.uid) 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.uid) print "{0} estates=\n{1}".format(stack1.name, stack1.estates) print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions) while stack1.transactions or stack0.transactions: stack1.serviceAll() stack0.serviceAll() store.advanceStamp(0.1) print "{0} Stats".format(stack0.name) for key, val in stack0.stats.items(): print " {0}={1}".format(key, val) print print "{0} Stats".format(stack1.name) for key, val in stack1.stats.items(): print " {0}={1}".format(key, val) print stack0.server.close() stack1.server.close() if postClearMaster: keeping.clearAllKeepSafe(masterDirpath) if postClearMinion: keeping.clearAllKeepSafe(m0Dirpath)
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 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) keeping.clearAllKeepSafe(masterDirpath) keeping.clearAllKeepSafe(m0Dirpath) estate = estating.LocalEstate( eid=1, name=masterName, sigkey=masterSignKeyHex, prikey=masterPriKeyHex, ) stack0 = stacking.RoadStack(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.RoadStack(name=minionName0, estate=estate, store=store, dirpath=m0Dirpath) print "\n********* Join Transaction **********" stack1.join() #timer = StoreTimer(store=store, duration=3.0) while store.stamp < 2.0: stack1.serviceAll() stack0.serviceAll() if store.stamp >= 0.3: for estate in stack0.estates.values(): if estate.acceptance == raeting.acceptances.pending: stack0.safe.acceptRemote(estate) store.advanceStamp(0.1) time.sleep(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.uid) 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.uid) 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 print "\n********* Allow Transaction **********" if not stack1.estates.values()[0].joined: return stack1.allow() #timer = StoreTimer(store=store, duration=3.0) while store.stamp < 4.0: stack1.serviceAll() stack0.serviceAll() store.advanceStamp(0.1) time.sleep(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 "{0} eid={1}".format(stack0.name, stack0.estate.uid) 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.uid) print "{0} estates=\n{1}".format(stack1.name, stack1.estates) print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions) #while stack1.transactions or stack0.transactions: #stack1.serviceAll() #stack0.serviceAll() #store.advanceStamp(0.1) print "{0} Stats".format(stack0.name) for key, val in stack0.stats.items(): print " {0}={1}".format(key, val) print print "{0} Stats".format(stack1.name) for key, val in stack1.stats.items(): print " {0}={1}".format(key, val) print print "\n********* Message Transactions Both Ways Again **********" #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(10, " ")) 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=3) while store.stamp < 8.0: #not timer.expired stack1.serviceAll() stack0.serviceAll() store.advanceStamp(0.1) time.sleep(0.1) print "{0} eid={1}".format(stack0.name, stack0.estate.uid) 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 "{0} Stats".format(stack0.name) for key, val in stack0.stats.items(): print " {0}={1}".format(key, val) print print "{0} eid={1}".format(stack1.name, stack1.estate.uid) 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 "{0} Stats".format(stack1.name) for key, val in stack1.stats.items(): print " {0}={1}".format(key, val) print stack0.server.close() stack1.server.close() stack0.clearLocal() stack0.clearRemoteKeeps() stack1.clearLocal() stack1.clearRemoteKeeps()
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(): ''' 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.clearAllKeepSafe(dirpathMaster) keeping.clearAllKeepSafe(dirpathMinion0) estate = estating.LocalEstate( eid=1, name=masterName, sigkey=masterSignKeyHex, prikey=masterPriKeyHex, ) stack0 = stacking.RoadStack(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.RoadStack(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")) timer.restart(duration=1) while not timer.expired: stack0.serviceAllTx() timer.restart(duration=1) while not timer.expired: stack1.serviceRx() print "{0} Received Messages".format(stack1.name) for msg in stack1.rxMsgs: print msg print stack0.transactions = odict() #clear transactions timer.restart(duration=2) while not timer.expired: stack1.serviceAllTx() stack0.serviceRx() print "{0} Received Messages".format(stack0.name) for msg in stack0.rxMsgs: print msg print print "{0} Stats".format(stack0.name) for key, val in stack0.stats.items(): print " {0}={1}".format(key, val) print print "{0} Stats".format(stack1.name) for key, val in stack1.stats.items(): print " {0}={1}".format(key, val) print stack0.server.close() stack1.server.close() stack0.clearLocal() stack0.clearRemoteKeeps() stack1.clearLocal() stack1.clearRemoteKeeps()
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(): ''' 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 estate = estating.LocalEstate(eid=1, sigkey=masterSignKeyHex, prikey=masterPriKeyHex) stack0 = stacking.StackUdp(estate=estate) remote1 = estating.RemoteEstate( eid=2, verkey=minionVerKeyHex, pubkey=minionPubKeyHex, ) stack0.addRemoteEstate(remote1) #minion stack estate = estating.LocalEstate( eid=2, ha=("", raeting.RAET_TEST_PORT), sigkey=minionSignKeyHex, prikey=minionPriKeyHex, ) stack1 = stacking.StackUdp(estate=estate) remote0 = estating.RemoteEstate( eid=1, 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) 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 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(se=1, de=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(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(): ''' 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(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) pkiDirpath = os.path.join(os.getcwd(), 'keyo', 'master', 'pki') if not os.path.exists(pkiDirpath): os.makedirs(pkiDirpath) acceptedDirpath = os.path.join(pkiDirpath, 'accepted') if not os.path.exists(acceptedDirpath): os.makedirs(acceptedDirpath) pendingDirpath = os.path.join(pkiDirpath, 'pending') if not os.path.exists(pendingDirpath): os.makedirs(pendingDirpath) rejectedDirpath = os.path.join(pkiDirpath, 'rejected') if not os.path.exists(rejectedDirpath): os.makedirs(rejectedDirpath) localFilepath = os.path.join(pkiDirpath, 'local.key') if os.path.exists(localFilepath): mode = os.stat(localFilepath).st_mode print mode os.chmod(localFilepath, mode | stat.S_IWUSR | stat.S_IWUSR) cacheDirpath = os.path.join(os.getcwd(), 'cache', 'master') sockDirpath = os.path.join('/tmp/raet', 'sock', 'master') masterOpts = dict( pki_dir=pkiDirpath, sock_dir=sockDirpath, cachedir=cacheDirpath, open_mode=False, auto_accept=False, transport='raet', ) masterSafe = salting.SaltSafe(opts=masterOpts) print masterSafe.loadLocalData() print masterSafe.loadAllRemoteData() pkiDirpath = os.path.join(os.getcwd(), 'keyo', 'minion', 'pki') if not os.path.exists(pkiDirpath): os.makedirs(pkiDirpath) acceptedDirpath = os.path.join(pkiDirpath, 'accepted') if not os.path.exists(acceptedDirpath): os.makedirs(acceptedDirpath) pendingDirpath = os.path.join(pkiDirpath, 'pending') if not os.path.exists(pendingDirpath): os.makedirs(pendingDirpath) rejectedDirpath = os.path.join(pkiDirpath, 'rejected') if not os.path.exists(rejectedDirpath): os.makedirs(rejectedDirpath) localFilepath = os.path.join(pkiDirpath, 'local.key') if os.path.exists(localFilepath): mode = os.stat(localFilepath).st_mode print mode os.chmod(localFilepath, mode | stat.S_IWUSR | stat.S_IWUSR) cacheDirpath = os.path.join(os.getcwd(), 'cache', 'minion') sockDirpath = os.path.join('/tmp/raet', 'sock', 'minion') minionOpts = dict(pki_dir=pkiDirpath, sock_dir=sockDirpath, cachedir=cacheDirpath, open_mode=False, auto_accept=True, transport='raet') minionSafe = salting.SaltSafe(opts=minionOpts) print minionSafe.loadLocalData() print minionSafe.loadAllRemoteData() 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: salting.clearAllKeepSafe(masterDirpath, masterOpts) if preClearMinion: salting.clearAllKeepSafe(m0Dirpath, minionOpts) estate = estating.LocalEstate( eid=1, name=masterName, sigkey=masterSignKeyHex, prikey=masterPriKeyHex, ) stack0 = stacking.RoadStack( name=masterName, estate=estate, store=store, main=True, dirpath=masterDirpath, safe=masterSafe, ) estate = estating.LocalEstate( eid=0, name=minionName0, ha=("", raeting.RAET_TEST_PORT), sigkey=minionSignKeyHex, prikey=minionPriKeyHex, ) stack1 = stacking.RoadStack( name=minionName0, estate=estate, store=store, dirpath=m0Dirpath, safe=minionSafe, ) print stack0.safe.loadLocalData() print stack1.safe.loadLocalData() 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.3: for estate in stack0.estates.values(): if estate.acceptance == raeting.acceptances.pending: stack0.safe.acceptRemote(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.uid) 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.uid) 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.server.close() stack1.server.close() if postClearMaster: salting.clearAllKeepSafe(masterDirpath, masterOpts) if postClearMinion: salting.clearAllKeepSafe(m0Dirpath, minionOpts)
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(hk=raeting.headKinds.json, bk=raeting.bodyKinds.json): ''' Test packeting. ''' data = odict(hk=hk, 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, ) try: packet0.pack() except raeting.PacketError as ex: print ex print "Need to use tray" tray0 = packeting.TxTray(data=data, body=stuff) tray0.pack() print tray0.packed print tray0.packets tray1 = packeting.RxTray() for packet in tray0.packets: tray1.parse(packet) print tray1.data print tray1.body print stuff == tray1.body #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.clearAllKeepSafe(dirpathMaster) keeping.clearAllKeepSafe(dirpathMinion) estate = estating.LocalEstate(eid=1, name=masterName, sigkey=masterSignKeyHex, prikey=masterPriKeyHex) stack0 = stacking.RoadStack(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.addRemote(remote1) estate = estating.LocalEstate( eid=2, name=minionName, ha=("", raeting.RAET_TEST_PORT), sigkey=minionSignKeyHex, prikey=minionPriKeyHex, ) stack1 = stacking.RoadStack(estate=estate) remote0 = estating.RemoteEstate( eid=1, name=masterName, ha=('127.0.0.1', raeting.RAET_PORT), verkey=masterVerKeyHex, pubkey=masterPubKeyHex, ) stack1.addRemote(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) tray0 = packeting.TxTray(stack=stack0, data=data, body=stuff) tray0.pack() print tray0.packed print tray0.packets tray1 = packeting.RxTray(stack=stack1) for packet in tray0.packets: tray1.parse(packet) print tray1.data print tray1.body print stuff == tray1.body print "\n_____________ Packed Body Test" body = odict(stuff=stuff) print body data.update(se=1, de=2, bk=bk, fk=raeting.footKinds.nacl) tray0 = packeting.TxTray(stack=stack0, data=data, body=body) tray0.pack() print tray0.packed print tray0.packets tray1 = packeting.RxTray(stack=stack1) for packet in tray0.packets: tray1.parse(packet) print tray1.data print tray1.body print body == tray1.body print "\n___________ Encrypted Coat Test " body = odict(stuff=stuff) print body data.update(se=1, de=2, bk=raeting.bodyKinds.json, ck=raeting.coatKinds.nacl, fk=raeting.footKinds.nacl) tray0 = packeting.TxTray(stack=stack0, data=data, body=body) tray0.pack() print tray0.packed print tray0.packets tray1 = packeting.RxTray(stack=stack1) for packet in tray0.packets: tray1.parse(packet) print tray1.data print tray1.body print body == tray1.body stack0.server.close() stack1.server.close()
def test(): ''' Test keeping. ''' pkiDirpath = os.path.join(os.getcwd(), 'keyo', 'pki') if not os.path.exists(pkiDirpath): os.makedirs(pkiDirpath) acceptedDirpath = os.path.join(pkiDirpath, 'accepted') if not os.path.exists(acceptedDirpath): os.makedirs(acceptedDirpath) pendingDirpath = os.path.join(pkiDirpath, 'pending') if not os.path.exists(pendingDirpath): os.makedirs(pendingDirpath) rejectedDirpath = os.path.join(pkiDirpath, 'rejected') if not os.path.exists(rejectedDirpath): os.makedirs(rejectedDirpath) localFilepath = os.path.join(pkiDirpath, 'local.key') if os.path.exists(localFilepath): mode = os.stat(localFilepath).st_mode print mode os.chmod(localFilepath, mode | stat.S_IWUSR | stat.S_IWUSR) cacheDirpath = os.path.join(os.getcwd(), 'salt', 'cache') sockDirpath = os.path.join('/tmp/raet', 'salt', 'sock') opts = dict( pki_dir=pkiDirpath, sock_dir=sockDirpath, cachedir=cacheDirpath, open_mode=True, auto_accept=True, ) masterKeeper = RaetKey(opts=opts) print masterKeeper.all_keys() masterName = 'master' masterDirpath = os.path.join(os.getcwd(), 'keep', masterName) signer = nacling.Signer() masterSignKeyHex = signer.keyhex masterVerKeyHex = signer.verhex privateer = nacling.Privateer() masterPriKeyHex = privateer.keyhex masterPubKeyHex = privateer.pubhex m1Name = 'minion1' m1Dirpath = os.path.join(os.getcwd(), 'keep', m1Name) signer = nacling.Signer() m1SignKeyHex = signer.keyhex m1VerKeyHex = signer.verhex privateer = nacling.Privateer() m1PriKeyHex = privateer.keyhex m1PubKeyHex = privateer.pubhex m2Name = 'minion2' signer = nacling.Signer() m2SignKeyHex = signer.keyhex m2VerKeyHex = signer.verhex privateer = nacling.Privateer() m2PriKeyHex = privateer.keyhex m2PubKeyHex = privateer.pubhex m3Name = 'minion3' signer = nacling.Signer() m3SignKeyHex = signer.keyhex m3VerKeyHex = signer.verhex privateer = nacling.Privateer() m3PriKeyHex = privateer.keyhex m3PubKeyHex = privateer.pubhex keeping.clearAllKeepSafe(masterDirpath) keeping.clearAllKeepSafe(m1Dirpath) local = masterKeeper.read_local() print local if not local: masterKeeper.write_local(masterPriKeyHex, masterSignKeyHex) print masterKeeper.read_local() print masterKeeper.all_keys() print masterKeeper.status(m1Name, 2, m1PubKeyHex, m1VerKeyHex) print masterKeeper.status(m2Name, 3, m2PubKeyHex, m2VerKeyHex) print masterKeeper.all_keys() print masterKeeper.read_remote(m1Name) print masterKeeper.read_remote(m2Name) print masterKeeper.list_keys() print masterKeeper.read_all_remote() #master stack estate = estating.LocalEstate( eid=1, name=masterName, sigkey=masterSignKeyHex, prikey=masterPriKeyHex, ) stack0 = stacking.RoadStack(estate=estate, dirpath=masterDirpath) stack0.addRemote( estating.RemoteEstate( eid=2, name=m1Name, ha=('127.0.0.1', 7532), verkey=m1VerKeyHex, pubkey=m1PubKeyHex, )) stack0.addRemote( estating.RemoteEstate( eid=3, name=m2Name, ha=('127.0.0.1', 7533), verkey=m2VerKeyHex, pubkey=m2PubKeyHex, )) #minion stack estate = estating.LocalEstate( eid=2, name=m1Name, ha=("", raeting.RAET_TEST_PORT), sigkey=m1SignKeyHex, prikey=m1PriKeyHex, ) stack1 = stacking.RoadStack(estate=estate, dirpath=m1Dirpath) stack1.addRemote( estating.RemoteEstate( eid=1, name=masterName, ha=('127.0.0.1', 7532), verkey=masterVerKeyHex, pubkey=masterPubKeyHex, )) stack1.addRemote( estating.RemoteEstate( eid=4, name=m3Name, ha=('127.0.0.1', 7534), verkey=m3VerKeyHex, pubkey=m3PubKeyHex, )) stack0.clearLocal() stack0.clearRemoteKeeps() stack1.clearLocal() stack1.clearRemoteKeeps() stack0.dumpLocal() stack0.dumpRemotes() stack1.dumpLocal() stack1.dumpRemotes() 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.server.close() stack1.server.close() #master stack dirpath = os.path.join(os.getcwd(), 'keep', 'master') estate = estating.LocalEstate( eid=1, name='master', sigkey=masterSignKeyHex, prikey=masterPriKeyHex, ) stack0 = stacking.RoadStack(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.RoadStack(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.clearRemoteKeeps() stack1.clearLocal() stack1.clearRemoteKeeps()