Beispiel #1
0
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 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)
Beispiel #3
0
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(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)
Beispiel #5
0
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()
Beispiel #6
0
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()
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.clearAllKeepSafe(dirpathMaster)
    keeping.clearAllKeepSafe(dirpathMinion0)
    keeping.clearAllKeepSafe(dirpathMinion1)

    estate = estating.LocalEstate(
        eid=1,
        name=masterName,
        sigkey=masterSignKeyHex,
        prikey=masterPriKeyHex,
    )
    stack0 = stacking.RoadStack(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.RoadStack(estate=estate, dirpath=dirpathMinion0)

    estate = estating.LocalEstate(
        eid=0,
        name=minionName1,
        ha=("", 7532),
        sigkey=minionSignKeyHex,
        prikey=minionPriKeyHex,
    )
    stack2 = stacking.RoadStack(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.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()
    stack2.server.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.RoadStack(dirpath=dirpathMaster, auto=True, main=True)

    #minion0 stack
    stack1 = stacking.RoadStack(dirpath=dirpathMinion0)

    #minion1 stack
    stack2 = stacking.RoadStack(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.uid)
    stack0.transmit(odict(house="Yeah Momma 1", queue="cold"),
                    stack2.estate.uid)
    stack0.transmit(odict(house="Yeah Momma 1", queue="boiling"),
                    stack2.estate.uid)
    stack0.transmit(odict(house="Yeah Momma 1", queue="tepid"),
                    stack2.estate.uid)

    # segmented packets
    stuff = []
    for i in range(600):
        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.uid)

    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} 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 "{0} Stats".format(stack2.name)
    for key, val in stack2.stats.items():
        print "   {0}={1}".format(key, val)
    print

    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 "{0} eid={1}".format(stack2.name, stack2.estate.uid)
    print "{0} estates=\n{1}".format(stack2.name, stack2.estates)
    print "{0} transactions=\n{1}".format(stack2.name, stack2.transactions)

    stack0.server.close()
    stack1.server.close()
    stack2.server.close()

    stack0.clearLocal()
    stack0.clearRemoteKeeps()
    stack1.clearLocal()
    stack1.clearRemoteKeeps()
    stack2.clearLocal()
    stack2.clearRemoteKeeps()