def createStack(self, name, port): ''' Create a RoadStack object bound to the specified port on localhost. :param name: stack name :param port: port to bind to :return: the stack ''' dirpath = os.path.join(self.baseDirpath, 'road', 'keep', name) signer = nacling.Signer() mainSignKeyHex = signer.keyhex privateer = nacling.Privateer() mainPriKeyHex = privateer.keyhex keeping.clearAllKeep(dirpath) return stacking.RoadStack(store=self.store, name=name, main=True, auto=raeting.AutoMode.once.value, ha=("", port), sigkey=mainSignKeyHex, prikey=mainPriKeyHex, dirpath=dirpath, )
def bootstrapJoinedRemotes(self): alphaData = self.createRoadData(base=self.base, name='alpha', ha=("", raeting.RAET_PORT), main=True, auto=raeting.autoModes.once) keeping.clearAllKeep(alphaData['dirpath']) alpha = self.createRoadStack(data=alphaData) betaData = self.createRoadData(base=self.base, name='beta', ha=("", raeting.RAET_TEST_PORT), main=None, auto=raeting.autoModes.once) keeping.clearAllKeep(betaData['dirpath']) beta = self.createRoadStack(data=betaData) console.terse("\nJoin from Beta to Alpha *********\n") self.assertIs(alpha.main, True) self.assertIs(alpha.keep.auto, raeting.autoModes.once) self.assertEqual(len(alpha.remotes), 0) self.assertIs(beta.main, None) self.assertIs(beta.keep.auto, raeting.autoModes.once) self.assertEqual(len(beta.remotes), 0) self.assertIs(beta.mutable, None) self.assertIs(alpha.mutable, None) return alpha, beta
def testJoinBasic(self): ''' Test join ''' console.terse("{0}\n".format(self.testJoinBasic.__doc__)) alphaData = self.createRoadData(base=self.base, name='alpha', ha=("", raeting.RAET_PORT), main=True, auto=raeting.autoModes.once) keeping.clearAllKeep(alphaData['dirpath']) alpha = self.createRoadStack(data=alphaData) betaData = self.createRoadData(base=self.base, name='beta', ha=("", raeting.RAET_TEST_PORT), main=None, auto=raeting.autoModes.once) keeping.clearAllKeep(betaData['dirpath']) beta = self.createRoadStack(data=betaData) console.terse("\nJoin from Beta to Alpha *********\n") self.assertIs(alpha.main, True) self.assertIs(alpha.keep.auto, raeting.autoModes.once) self.assertEqual(len(alpha.remotes), 0) self.assertIs(beta.main, None) self.assertIs(beta.keep.auto, raeting.autoModes.once) self.assertEqual(len(beta.remotes), 0) self.join(beta, alpha) for stack in [alpha, beta]: self.assertEqual(len(stack.transactions), 0) self.assertEqual(len(stack.remotes), 1) self.assertEqual(len(stack.nameRemotes), 1) for remote in stack.remotes.values(): self.assertIs(remote.joined, True) self.assertIs(remote.allowed, None) self.assertIs(remote.alived, None) console.terse("\nAllow Beta to Alpha *********\n") self.allow(beta, alpha) for stack in [alpha, beta]: self.assertEqual(len(stack.transactions), 0) self.assertEqual(len(stack.remotes), 1) self.assertEqual(len(stack.nameRemotes), 1) for remote in stack.remotes.values(): self.assertIs(remote.joined, True) self.assertIs(remote.allowed, True) self.assertIs(remote.alived, None) for stack in [alpha, beta]: stack.server.close() stack.clearAllKeeps()
def setUp(self): self.store = storing.Store(stamp=0.0) self.timer = StoreTimer(store=self.store, duration=1.0) self.baseDirpath=tempfile.mkdtemp(prefix="raet", suffix="base", dir='/tmp') stacking.RoadStack.Bk = raeting.bodyKinds.json #main stack mainName = "main" mainDirpath = os.path.join(self.baseDirpath, 'road', 'keep', mainName) signer = nacling.Signer() mainSignKeyHex = signer.keyhex privateer = nacling.Privateer() mainPriKeyHex = privateer.keyhex #other stack otherName = "other" otherDirpath = os.path.join(self.baseDirpath, 'road', 'keep', otherName) signer = nacling.Signer() otherSignKeyHex = signer.keyhex privateer = nacling.Privateer() otherPriKeyHex = privateer.keyhex keeping.clearAllKeep(mainDirpath) keeping.clearAllKeep(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)
def setUp(self): self.store = storing.Store(stamp=0.0) self.timer = StoreTimer(store=self.store, duration=1.0) self.baseDirpath = tempfile.mkdtemp(prefix="raet", suffix="base", dir=TEMPDIR) stacking.RoadStack.Bk = raeting.bodyKinds.json #main stack mainName = "main" mainDirpath = os.path.join(self.baseDirpath, 'road', 'keep', mainName) signer = nacling.Signer() mainSignKeyHex = signer.keyhex privateer = nacling.Privateer() mainPriKeyHex = privateer.keyhex #other stack otherName = "other" otherDirpath = os.path.join(self.baseDirpath, 'road', 'keep', otherName) signer = nacling.Signer() otherSignKeyHex = signer.keyhex privateer = nacling.Privateer() otherPriKeyHex = privateer.keyhex keeping.clearAllKeep(mainDirpath) keeping.clearAllKeep(otherDirpath) self.main = stacking.RoadStack( store=self.store, name=mainName, main=True, auto=raeting.autoModes.once, sigkey=mainSignKeyHex, prikey=mainPriKeyHex, dirpath=mainDirpath, ) self.other = stacking.RoadStack( store=self.store, name=otherName, auto=raeting.autoModes.once, ha=("", raeting.RAET_TEST_PORT), sigkey=otherSignKeyHex, prikey=otherPriKeyHex, dirpath=otherDirpath, )
def setUp(self): self.store = storing.Store(stamp=0.0) self.timer = StoreTimer(store=self.store, duration=1.0) self.baseDirpath=tempfile.mkdtemp(prefix="raet", suffix="base", dir=TEMPDIR) stacking.RoadStack.Bk = raeting.BodyKind.json.value #main stack mainName = "main" mainDirpath = os.path.join(self.baseDirpath, 'road', 'keep', mainName) signer = nacling.Signer() mainSignKeyHex = signer.keyhex privateer = nacling.Privateer() mainPriKeyHex = privateer.keyhex #other stack otherName = "other" otherDirpath = os.path.join(self.baseDirpath, 'road', 'keep', otherName) signer = nacling.Signer() otherSignKeyHex = signer.keyhex privateer = nacling.Privateer() otherPriKeyHex = privateer.keyhex keeping.clearAllKeep(mainDirpath) keeping.clearAllKeep(otherDirpath) self.main = stacking.RoadStack(store=self.store, name=mainName, main=True, auto=raeting.AutoMode.once.value, sigkey=mainSignKeyHex, prikey=mainPriKeyHex, dirpath=mainDirpath, ) self.other = stacking.RoadStack(store=self.store, name=otherName, auto=raeting.AutoMode.once.value, ha=("", raeting.RAET_TEST_PORT), sigkey=otherSignKeyHex, prikey=otherPriKeyHex, dirpath=otherDirpath, )
def createStack(self, name, port): dirpath = os.path.join(self.baseDirpath, 'road', 'keep', name) signer = nacling.Signer() mainSignKeyHex = signer.keyhex privateer = nacling.Privateer() mainPriKeyHex = privateer.keyhex keeping.clearAllKeep(dirpath) return stacking.RoadStack(store=self.store, name=name, main=True, auto=raeting.AutoMode.once.value, ha=("", port), sigkey=mainSignKeyHex, prikey=mainPriKeyHex, dirpath=dirpath, )
def getAcceptedStacks(self): alphaData = self.createRoadData(base=self.base, name='alpha', ha=("", raeting.RAET_PORT), main=True, auto=raeting.autoModes.once) keeping.clearAllKeep(alphaData['dirpath']) alpha = self.createRoadStack(data=alphaData) betaData = self.createRoadData(base=self.base, name='beta', ha=("", raeting.RAET_TEST_PORT), main=None, auto=raeting.autoModes.once) keeping.clearAllKeep(betaData['dirpath']) beta = self.createRoadStack(data=betaData) console.terse("\nJoin from Beta to Alpha *********\n") self.assertIs(alpha.main, True) self.assertIs(alpha.keep.auto, raeting.autoModes.once) self.assertEqual(len(alpha.remotes), 0) self.assertIs(beta.main, None) self.assertIs(beta.keep.auto, raeting.autoModes.once) self.assertEqual(len(beta.remotes), 0) self.assertIs(beta.mutable, None) self.assertIs(alpha.mutable, None) self.join(beta, alpha) for stack in [alpha, beta]: self.assertEqual(len(stack.transactions), 0) self.assertEqual(len(stack.remotes), 1) self.assertEqual(len(stack.nameRemotes), 1) for remote in stack.remotes.values(): self.assertIs(remote.joined, True) self.assertIs(remote.allowed, None) self.assertIs(remote.alived, None) self.assertIs(beta.mutable, None) self.assertIs(alpha.mutable, None) return alpha, beta
def setUp(self): self.store = Store(stamp=0.0) self.timer = StoreTimer(store=self.store, duration=1.0) self.dirpathBase = tempfile.mkdtemp(prefix="raet", suffix="base", dir=TEMPDIR) stacking.RoadStack.Bk = raeting.BodyKind.json.value #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.clearAllKeep(mainDirpath) keeping.clearAllKeep(otherDirpath) self.main = stacking.RoadStack(name=mainName, uid=1, sigkey=mainSignKeyHex, prikey=mainPriKeyHex, auto=raeting.AutoMode.once.value, main=True, dirpath=mainDirpath, store=self.store) remote1 = estating.RemoteEstate( stack=self.main, uid=2, name=otherName, ha=("127.0.0.1", raeting.RAET_TEST_PORT), verkey=otherVerKeyHex, pubkey=otherPubKeyHex, ) self.main.addRemote(remote1) self.other = stacking.RoadStack(name=otherName, uid=2, auto=raeting.AutoMode.once.value, ha=("", raeting.RAET_TEST_PORT), sigkey=otherSignKeyHex, prikey=otherPriKeyHex, dirpath=otherDirpath, store=self.store) remote0 = estating.RemoteEstate( stack=self.other, uid=3, name=mainName, ha=('127.0.0.1', raeting.RAET_PORT), verkey=mainVerKeyHex, pubkey=mainPubKeyHex, ) 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 = ns2b("".join(stuff)) self.data = odict(hk=raeting.HeadKind.raet.value)
def setUp(self): self.store = Store(stamp=0.0) self.timer = StoreTimer(store=self.store, duration=1.0) self.dirpathBase=tempfile.mkdtemp(prefix="raet", suffix="base", dir=TEMPDIR) stacking.RoadStack.Bk = raeting.BodyKind.json.value #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.clearAllKeep(mainDirpath) keeping.clearAllKeep(otherDirpath) self.main = stacking.RoadStack(name=mainName, uid=1, sigkey=mainSignKeyHex, prikey=mainPriKeyHex, auto=raeting.AutoMode.once.value, main=True, dirpath=mainDirpath, store=self.store) remote1 = estating.RemoteEstate(stack=self.main, uid=2, name=otherName, ha=("127.0.0.1", raeting.RAET_TEST_PORT), verkey=otherVerKeyHex, pubkey=otherPubKeyHex,) self.main.addRemote(remote1) self.other = stacking.RoadStack(name=otherName, uid=2, auto=raeting.AutoMode.once.value, ha=("", raeting.RAET_TEST_PORT), sigkey=otherSignKeyHex, prikey=otherPriKeyHex, dirpath=otherDirpath, store=self.store) remote0 = estating.RemoteEstate(stack=self.other, uid=3, name=mainName, ha=('127.0.0.1', raeting.RAET_PORT), verkey=mainVerKeyHex, pubkey=mainPubKeyHex,) 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 = ns2b("".join(stuff)) self.data = odict(hk=raeting.HeadKind.raet.value)
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.clearAllKeep(mainDirpath) keeping.clearAllKeep(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)