def setUp(self): self.store = storing.Store(stamp=0.0) dirpathBase='/tmp/raet/' #main stack mainName = "main" mainDirpath = os.path.join(dirpathBase, 'road', 'keep', mainName) signer = nacling.Signer() mainSignKeyHex = signer.keyhex privateer = nacling.Privateer() mainPriKeyHex = privateer.keyhex #other stack otherName = "other" otherDirpath = os.path.join(dirpathBase, 'road', 'keep', otherName) signer = nacling.Signer() otherSignKeyHex = signer.keyhex privateer = nacling.Privateer() otherPriKeyHex = privateer.keyhex keeping.clearAllKeepSafe(mainDirpath) keeping.clearAllKeepSafe(otherDirpath) local = estating.LocalEstate(eid=1, name=mainName, sigkey=mainSignKeyHex, prikey=mainPriKeyHex,) self.main = stacking.RoadStack(name=mainName, local=local, auto=True, main=True, dirpath=mainDirpath, store=self.store) local = estating.LocalEstate(eid=0, name=otherName, ha=("", raeting.RAET_TEST_PORT), sigkey=otherSignKeyHex, prikey=otherPriKeyHex,) self.other = stacking.RoadStack(name=otherName, local=local, dirpath=otherDirpath, store=self.store) self.timer = StoreTimer(store=self.store, duration=1.0)
def createRoadStack(self, data, eid=0, main=False, auto=False, ha=None): ''' Clears any old keep data from data['dirpath'] Creates stack and local estate from data with local estate.eid = eid stack.main = main stack.auto = auto stack.name = data['name'] local estate.name = data['name'] local estate.ha = ha returns stack ''' keeping.clearAllKeepSafe(data['dirpath']) local = estating.LocalEstate( eid=eid, name=data['name'], ha=ha, sigkey=data['sighex'], prikey=data['prihex'], ) stack = stacking.RoadStack(name=data['name'], local=local, auto=auto, main=main, dirpath=data['dirpath'], store=self.store) return stack
def createRoadStack(self, data, eid=0, main=None, auto=None, ha=None): ''' Creates stack and local estate from data with local estate.eid = eid stack.main = main stack.auto = auto stack.name = data['name'] local estate.name = data['name'] local estate.ha = ha returns stack ''' local = estating.LocalEstate(eid=eid, name=data['name'], ha=ha, sigkey=data['sighex'], prikey=data['prihex'],) stack = stacking.RoadStack(name=data['name'], local=local, auto=auto if auto is not None else data['auto'], main=main, dirpath=data['dirpath'], store=self.store) return stack
def createRoadStack(self, data, keep, eid=0, main=None, ha=None): ''' Creates stack and local estate from data with local estate.eid = eid stack.main = main stack.auto = auto stack.name = data['name'] local estate.name = data['name'] local estate.ha = ha returns stack ''' local = estating.LocalEstate(eid=eid, name=data['name'], ha=ha, sigkey=data['sighex'], prikey=data['prihex'],) stack = stacking.RoadStack(name=data['name'], local=local, main=main, store=self.store, keep=keep) return stack
def test(): ''' Test keeping. ''' pkiDirpath = os.path.join('/tmp', 'raet', '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_IRUSR) mode = os.stat(localFilepath).st_mode print mode cacheDirpath = os.path.join('/tmp/raet', 'cache', 'master') if not os.path.exists(cacheDirpath): os.makedirs(cacheDirpath) sockDirpath = os.path.join('/tmp/raet', 'sock', 'master') if not os.path.exists(sockDirpath): os.makedirs(sockDirpath) opts = dict( pki_dir=pkiDirpath, sock_dir=sockDirpath, cachedir=cacheDirpath, open_mode=True, auto_accept=True, transport='raet', ) masterSafe = salting.SaltSafe(opts=opts) print("masterSafe local =\n{0}".format(masterSafe.loadLocalData())) print("masterSafe remote =\n{0}".format(masterSafe.loadAllRemoteData())) pkiDirpath = os.path.join('/tmp', 'raet', '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_IRUSR) mode = os.stat(localFilepath).st_mode print mode cacheDirpath = os.path.join('/tmp/raet', 'cache', 'minion') sockDirpath = os.path.join('/tmp/raet', 'sock', 'minion') opts = dict( pki_dir=pkiDirpath, sock_dir=sockDirpath, cachedir=cacheDirpath, open_mode=True, auto_accept=True, transport='raet', ) minionSafe = salting.SaltSafe(opts=opts) print("minionSafe local =\n{0}".format(minionSafe.loadLocalData())) print("minionSafe remote =\n{0}".format(minionSafe.loadAllRemoteData())) masterName = 'master' masterDirpath = os.path.join('/tmp', 'raet', '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('/tmp', 'raet', '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) #saltsafe = salting.SaltSafe(opts=opts) #print saltsafe.loadLocalData() #print saltsafe.loadAllRemoteData() #master stack local = estating.LocalEstate( eid=1, name=masterName, sigkey=masterSignKeyHex, prikey=masterPriKeyHex, ) stack0 = stacking.RoadStack(local=local, dirpath=masterDirpath, safe=masterSafe) 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 local = estating.LocalEstate( eid=2, name=m1Name, ha=("", raeting.RAET_TEST_PORT), sigkey=m1SignKeyHex, prikey=m1PriKeyHex, ) stack1 = stacking.RoadStack(local=local, dirpath=m1Dirpath, safe=minionSafe) 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.keep.loadLocalData() print stack0.keep.loadAllRemoteData() print "Safe {0}".format(stack0.name) print stack0.safe.loadLocalData() print stack0.safe.loadAllRemoteData() print print "Road {0}".format(stack1.name) print stack1.keep.loadLocalData() print stack1.keep.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('/tmp/raet', 'keep', 'master') local = estating.LocalEstate( eid=1, name='master', sigkey=masterSignKeyHex, prikey=masterPriKeyHex, ) stack0 = stacking.RoadStack(local=local, dirpath=masterDirpath, safe=masterSafe) #minion stack dirpath = os.path.join('/tmp/raet', 'keep', 'minion1') local = estating.LocalEstate( eid=2, name='minion1', ha=("", raeting.RAET_TEST_PORT), sigkey=m1SignKeyHex, prikey=m1PriKeyHex, ) stack1 = stacking.RoadStack(local=local, dirpath=m1Dirpath, safe=minionSafe) stack0.loadLocal() print stack0.local.name, stack0.local.eid, stack0.local.sid, stack0.local.ha, stack0.local.signer, stack0.local.priver stack1.loadLocal() print stack1.local.name, stack1.local.eid, stack1.local.sid, stack1.local.ha, stack1.local.signer, stack1.local.priver stack0.clearLocal() stack0.clearRemoteKeeps() stack1.clearLocal() stack1.clearRemoteKeeps()
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) #transacting.Joiner.Timeout = 0 # make join go on forever 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('/tmp/raet/road', 'keep', masterName) #minion0 stack minionName0 = "minion0" signer = nacling.Signer() minionSignKeyHex = signer.keyhex privateer = nacling.Privateer() minionPriKeyHex = privateer.keyhex m0Dirpath = os.path.join('/tmp/raet/road', 'keep', minionName0) if preClearMaster: keeping.clearAllKeepSafe(masterDirpath) if preClearMinion: keeping.clearAllKeepSafe(m0Dirpath) local = estating.LocalEstate( eid=1, name=masterName, sigkey=masterSignKeyHex, prikey=masterPriKeyHex, ) stack0 = stacking.RoadStack(name=masterName, local=local, store=store, main=True, dirpath=masterDirpath) local = estating.LocalEstate( eid=0, name=minionName0, ha=("", raeting.RAET_TEST_PORT), sigkey=minionSignKeyHex, prikey=minionPriKeyHex, ) stack1 = stacking.RoadStack(name=minionName0, local=local, 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 remote in stack0.remotes.values(): if remote.acceptance == raeting.acceptances.pending: stack0.safe.acceptRemote(remote) store.advanceStamp(0.1) for remote in stack0.remotes.values(): print "Remote Estate {0} joined= {1}".format(remote.eid, remote.joined) for remote in stack1.remotes.values(): print "Remote Estate {0} joined= {1}".format(remote.eid, remote.joined) print "{0} eid={1}".format(stack0.name, stack0.local.uid) print "{0} remotes=\n{1}".format(stack0.name, stack0.remotes) print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions) print "{0} eid={1}".format(stack1.name, stack1.local.uid) print "{0} remotes=\n{1}".format(stack1.name, stack1.remotes) print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions) print "Road {0}".format(stack0.name) print stack0.keep.loadLocalData() print stack0.keep.loadAllRemoteData() print "Safe {0}".format(stack0.name) print stack0.safe.loadLocalData() print stack0.safe.loadAllRemoteData() print print "Road {0}".format(stack1.name) print stack1.keep.loadLocalData() print stack1.keep.loadAllRemoteData() print "Safe {0}".format(stack1.name) print stack1.safe.loadLocalData() print stack1.safe.loadAllRemoteData() 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() if postClearMaster: keeping.clearAllKeepSafe(masterDirpath) if postClearMinion: keeping.clearAllKeepSafe(m0Dirpath)
def setUp(self): self.store = storing.Store(stamp=0.0) self.timer = StoreTimer(store=self.store, duration=1.0) self.dirpathBase = tempfile.mkdtemp(prefix="raet", suffix="base", dir='/tmp') stacking.RoadStack.Bk = raeting.bodyKinds.json #main stack mainName = "main" mainDirpath = os.path.join(self.dirpathBase, 'road', 'keep', mainName) signer = nacling.Signer() mainSignKeyHex = signer.keyhex mainVerKeyHex = signer.verhex privateer = nacling.Privateer() mainPriKeyHex = privateer.keyhex mainPubKeyHex = privateer.pubhex #other stack otherName = "other" otherDirpath = os.path.join(self.dirpathBase, 'road', 'keep', otherName) signer = nacling.Signer() otherSignKeyHex = signer.keyhex otherVerKeyHex = signer.verhex privateer = nacling.Privateer() otherPriKeyHex = privateer.keyhex otherPubKeyHex = privateer.pubhex keeping.clearAllKeepSafe(mainDirpath) keeping.clearAllKeepSafe(otherDirpath) local = estating.LocalEstate( eid=1, name=mainName, sigkey=mainSignKeyHex, prikey=mainPriKeyHex, ) self.main = stacking.RoadStack(name=mainName, local=local, auto=True, main=True, dirpath=mainDirpath, store=self.store) remote1 = estating.RemoteEstate( stack=self.main, eid=2, name=otherName, ha=("127.0.0.1", raeting.RAET_TEST_PORT), verkey=otherVerKeyHex, pubkey=otherPubKeyHex, period=self.main.period, offset=self.main.offset, ) self.main.addRemote(remote1) local = estating.LocalEstate( eid=2, name=otherName, ha=("", raeting.RAET_TEST_PORT), sigkey=otherSignKeyHex, prikey=otherPriKeyHex, ) self.other = stacking.RoadStack(name=otherName, local=local, dirpath=otherDirpath, store=self.store) remote0 = estating.RemoteEstate( stack=self.other, eid=1, name=mainName, ha=('127.0.0.1', raeting.RAET_PORT), verkey=mainVerKeyHex, pubkey=mainPubKeyHex, period=self.other.period, offset=self.other.offset, ) self.other.addRemote(remote0) remote0.publee = nacling.Publican(key=remote1.privee.pubhex) remote1.publee = nacling.Publican(key=remote0.privee.pubhex) stuff = [] for i in range(300): stuff.append(str(i).rjust(4, " ")) self.stuff = "".join(stuff) self.data = odict(hk=raeting.headKinds.raet)
def test(preClearMaster=True, preClearMinion=True, postClearMaster=True, postClearMinion=True): ''' 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('/tmp/raet/road', 'keep', masterName) #minion0 stack minionName0 = "minion0" signer = nacling.Signer() minionSignKeyHex = signer.keyhex privateer = nacling.Privateer() minionPriKeyHex = privateer.keyhex m0Dirpath = os.path.join('/tmp/raet/road', 'keep', minionName0) if preClearMaster: keeping.clearAllKeepSafe(masterDirpath) if preClearMinion: keeping.clearAllKeepSafe(m0Dirpath) local = estating.LocalEstate( eid=1, name=masterName, sigkey=masterSignKeyHex, prikey=masterPriKeyHex, ) stack0 = stacking.RoadStack(name=masterName, local=local, auto=True, store=store, main=True, dirpath=masterDirpath) local = estating.LocalEstate( eid=0, name=minionName0, ha=("", raeting.RAET_TEST_PORT), sigkey=minionSignKeyHex, prikey=minionPriKeyHex, ) stack1 = stacking.RoadStack(name=minionName0, local=local, store=store, dirpath=m0Dirpath) print "\n********* Join Forever Transaction **********" #transacting.Joiner.Timeout = 0 # make join go on forever stack1.join(timeout=0.0) # make join go on forever timer = StoreTimer(store=store, duration=30.0) while (stack1.transactions or stack0.transactions) and not timer.expired: stack1.serviceAll() if timer.elapsed > 20.0: stack0.serviceAll() store.advanceStamp(0.1) for remote in stack0.remotes.values(): print "{0} Remote Estate {1} joined= {2}".format( stack0.name, remote.eid, remote.joined) for remote in stack1.remotes.values(): print "{0} Remote Estate {1} joined= {2}".format( stack1.name, remote.eid, remote.joined) 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********* Join Default Timeout Transaction **********" stack1.join(timeout=None) timer.restart() while (stack1.transactions or stack0.transactions) and not timer.expired: stack1.serviceAll() if timer.elapsed > 20.0: stack0.serviceAll() store.advanceStamp(0.1) for remote in stack0.remotes.values(): print "{0} Remote Estate {1} joined= {2}".format( stack0.name, remote.eid, remote.joined) for remote in stack1.remotes.values(): print "{0} Remote Estate {1} joined= {2}".format( stack1.name, remote.eid, remote.joined) 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 for uid in stack0.remotes: stack0.removeRemote(uid) for uid in stack1.remotes: stack1.removeRemote(uid) if postClearMaster: keeping.clearAllKeepSafe(masterDirpath) if postClearMinion: keeping.clearAllKeepSafe(m0Dirpath) print "Road {0}".format(stack0.name) print stack0.keep.loadLocalData() print stack0.keep.loadAllRemoteData() print "Safe {0}".format(stack0.name) print stack0.safe.loadLocalData() print stack0.safe.loadAllRemoteData() print print "Road {0}".format(stack1.name) print stack1.keep.loadLocalData() print stack1.keep.loadAllRemoteData() print "Safe {0}".format(stack1.name) print stack1.safe.loadLocalData() print stack1.safe.loadAllRemoteData() print print "\n********* Join Default Timeout Transaction After Clear Keeps **********" stack1.join(timeout=None) timer.restart() while (stack1.transactions or stack0.transactions) and not timer.expired: stack1.serviceAll() if timer.elapsed > 20.0: stack0.serviceAll() store.advanceStamp(0.1) for remote in stack0.remotes.values(): print "{0} Remote Estate {1} joined= {2}".format( stack0.name, remote.eid, remote.joined) for remote in stack1.remotes.values(): print "{0} Remote Estate {1} joined= {2}".format( stack1.name, remote.eid, remote.joined) 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********* Join Forever Timeout Transaction After Clear Keeps**********" stack1.join(timeout=0.0) timer.restart() while (stack1.transactions or stack0.transactions) and not timer.expired: stack1.serviceAll() if timer.elapsed > 20.0: stack0.serviceAll() store.advanceStamp(0.1) for remote in stack0.remotes.values(): print "{0} Remote Estate {1} joined= {2}".format( stack0.name, remote.eid, remote.joined) for remote in stack1.remotes.values(): print "{0} Remote Estate {1} joined= {2}".format( stack1.name, remote.eid, remote.joined) 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)