Esempio n. 1
0
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
Esempio n. 2
0
def testStackUxd(kind=raeting.packKinds.json):
    '''
    initially


    '''
    console.reinit(verbosity=console.Wordage.concise)

    stacking.LaneStack.Pk = kind

    #lord stack
    #yard0 = yarding.Yard(name='lord')
    stack0 = stacking.LaneStack(dirpath='/tmp/raet/test_stacking',
                                sockdirpath='/tmp/raet/test_stacking')

    #serf stack
    #yard1 = yarding.Yard(name='serf', yid=1)
    stack1 = stacking.LaneStack(dirpath='/tmp/raet/test_stacking',
                                sockdirpath='/tmp/raet/test_stacking')

    stack0.addRemote(yarding.RemoteYard(ha=stack1.local.ha))
    stack1.addRemote(yarding.RemoteYard(ha=stack0.local.ha))
    #stack0.addRemoteYard(stack1.local)
    #stack1.addRemoteYard(stack0.local)

    print "{0} yard name={1} ha={2}".format(stack0.name, stack0.local.name,
                                            stack0.local.ha)
    print "{0} yards=\n{1}".format(stack0.name, stack0.remotes)
    print "{0} names=\n{1}".format(stack0.name, stack0.uids)

    print "{0} yard name={1} ha={2}".format(stack1.name, stack1.local.name,
                                            stack1.local.ha)
    print "{0} yards=\n{1}".format(stack1.name, stack1.remotes)
    print "{0} names=\n{1}".format(stack1.name, stack1.uids)

    print "\n********* UXD Message lord to serf serf to lord **********"
    msg = odict(what="This is a message to the serf. Get to Work",
                extra="Fix the fence.")
    stack0.transmit(msg=msg)

    msg = odict(what="This is a message to the lord. Let me be",
                extra="Go away.")
    stack1.transmit(msg=msg)

    timer = Timer(duration=0.5)
    timer.restart()
    while not timer.expired:
        stack0.serviceAll()
        stack1.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 "\n********* Multiple Messages Both Ways **********"

    stack1.transmit(odict(house="Mama mia1", queue="fix me"), None)
    stack1.transmit(odict(house="Mama mia2", queue="help me"), None)
    stack1.transmit(odict(house="Mama mia3", queue="stop me"), None)
    stack1.transmit(odict(house="Mama mia4", queue="run me"), None)

    stack0.transmit(odict(house="Papa pia1", queue="fix me"), None)
    stack0.transmit(odict(house="Papa pia2", queue="help me"), None)
    stack0.transmit(odict(house="Papa pia3", queue="stop me"), None)
    stack0.transmit(odict(house="Papa pia4", queue="run me"), None)

    #big packets
    stuff = []
    for i in range(10000):
        stuff.append(str(i).rjust(10, " "))
    stuff = "".join(stuff)

    stack1.transmit(odict(house="Mama mia1", queue="big stuff", stuff=stuff),
                    None)
    stack0.transmit(odict(house="Papa pia4", queue="gig stuff", stuff=stuff),
                    None)

    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

    src = ('minion', 'serf', None)
    dst = ('master', None, None)
    route = odict(src=src, dst=dst)
    msg = odict(route=route, stuff="Hey buddy what is up?")
    stack0.transmit(msg)

    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

    estate = 'minion1'
    #lord stack yard0
    stack0 = stacking.LaneStack(name='lord',
                                lanename='cherry',
                                dirpath='/tmp/raet/test_stacking',
                                sockdirpath='/tmp/raet/test_stacking')

    #serf stack yard1
    stack1 = stacking.LaneStack(name='serf',
                                lanename='cherry',
                                dirpath='/tmp/raet/test_stacking',
                                sockdirpath='/tmp/raet/test_stacking')

    print "Yid", yarding.Yard.Yid

    print "\n********* Attempt Auto Accept ************"
    #stack0.addRemoteYard(stack1.local)
    yard = yarding.RemoteYard(name=stack0.local.name,
                              lanename='cherry',
                              dirpath='/tmp/raet/test_stacking')
    stack1.addRemote(yard)

    print "{0} yard name={1} ha={2}".format(stack0.name, stack0.local.name,
                                            stack0.local.ha)
    print "{0} yards=\n{1}".format(stack0.name, stack0.remotes)
    print "{0} names=\n{1}".format(stack0.name, stack0.uids)

    print "{0} yard name={1} ha={2}".format(stack1.name, stack1.local.name,
                                            stack1.local.ha)
    print "{0} yards=\n{1}".format(stack1.name, stack1.remotes)
    print "{0} names=\n{1}".format(stack1.name, stack1.uids)

    print "\n********* UXD Message serf to lord **********"
    src = (estate, stack1.local.name, None)
    dst = (estate, stack0.local.name, None)
    route = odict(src=src, dst=dst)
    msg = odict(route=route, stuff="Serf to my lord. Feed me!")
    stack1.transmit(msg=msg)

    timer = Timer(duration=0.5)
    timer.restart()
    while not timer.expired:
        stack0.serviceAll()
        stack1.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 "\n********* UXD Message lord to serf **********"
    src = (estate, stack0.local.name, None)
    dst = (estate, stack1.local.name, None)
    route = odict(src=src, dst=dst)
    msg = odict(route=route, stuff="Lord to serf. Feed yourself!")
    stack0.transmit(msg=msg)

    timer = Timer(duration=0.5)
    timer.restart()
    while not timer.expired:
        stack0.serviceAll()
        stack1.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} yard name={1} ha={2}".format(stack0.name, stack0.local.name,
                                            stack0.local.ha)
    print "{0} yards=\n{1}".format(stack0.name, stack0.remotes)
    print "{0} names=\n{1}".format(stack0.name, stack0.uids)

    print "{0} yard name={1} ha={2}".format(stack1.name, stack1.local.name,
                                            stack1.local.ha)
    print "{0} yards=\n{1}".format(stack1.name, stack1.remotes)
    print "{0} names=\n{1}".format(stack1.name, stack1.uids)

    stack0.server.close()
    stack1.server.close()
Esempio n. 3
0
def test():
    '''
    initially
    master on port 7530 with did of 1
    minion on port 7531 with did of 0
    eventually
    master did of 1
    minion did of 2
    '''

    signer = nacling.Signer()
    masterSignKeyHex = signer.keyhex
    privateer = nacling.Privateer()
    masterPriKeyHex = privateer.keyhex

    signer = nacling.Signer()
    minionSignKeyHex = signer.keyhex
    privateer = nacling.Privateer()
    minionPriKeyHex = privateer.keyhex

    #master stack
    device = devicing.LocalDevice(   did=1,
                                     name='master',
                                     signkey=masterSignKeyHex,
                                     prikey=masterPriKeyHex,)
    stack0 = stacking.StackUdp(device=device)

    #minion stack
    device = devicing.LocalDevice(   did=0,
                                     name='minion1',
                                     ha=("", raeting.RAET_TEST_PORT),
                                     signkey=minionSignKeyHex,
                                     prikey=minionPriKeyHex,)
    stack1 = stacking.StackUdp(device=device)


    print "\n********* Join Transaction **********"
    stack1.join()

    timer = Timer(duration=0.5)
    while not timer.expired:
        stack1.serviceUdp()
        stack0.serviceUdp()

    while stack0.udpRxes:
        stack0.processUdpRx()

    timer.restart()
    while not timer.expired:
        stack0.serviceUdp()
        stack1.serviceUdp()

    while stack1.udpRxes:
        stack1.processUdpRx()


    print "{0} did={1}".format(stack0.name, stack0.device.did)
    print "{0} devices=\n{1}".format(stack0.name, stack0.devices)
    print "{0} dids=\n{1}".format(stack0.name, stack0.dids)
    print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions)
    for device in stack0.devices.values():
        print "Remote Device {0} joined= {1}".format(device.did, device.joined)

    print "{0} did={1}".format(stack1.name, stack1.device.did)
    print "{0} devices=\n{1}".format(stack1.name, stack1.devices)
    print "{0} dids=\n{1}".format(stack1.name, stack1.dids)
    print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions)
    for device in stack1.devices.values():
            print "Remote Device {0} joined= {1}".format(device.did, device.joined)


    print "\n********* Allow Transaction **********"

    stack1.allow()
    timer.restart()
    while not timer.expired:
        stack1.serviceUdp()
        stack0.serviceUdp()

    while stack0.udpRxes:
        stack0.processUdpRx()

    timer.restart()
    while not timer.expired:
        stack0.serviceUdp()
        stack1.serviceUdp()

    while stack1.udpRxes:
        stack1.processUdpRx()

    timer.restart()
    while not timer.expired:
        stack0.serviceUdp()
        stack1.serviceUdp()

    while stack0.udpRxes:
        stack0.processUdpRx()

    timer.restart()
    while not timer.expired:
        stack0.serviceUdp()
        stack1.serviceUdp()

    while stack1.udpRxes:
        stack1.processUdpRx()

    print "{0} did={1}".format(stack0.name, stack0.device.did)
    print "{0} devices=\n{1}".format(stack0.name, stack0.devices)
    print "{0} dids=\n{1}".format(stack0.name, stack0.dids)
    print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions)
    for device in stack0.devices.values():
        print "Remote Device {0} allowed= {1}".format(device.did, device.allowed)

    print "{0} did={1}".format(stack1.name, stack1.device.did)
    print "{0} devices=\n{1}".format(stack1.name, stack1.devices)
    print "{0} dids=\n{1}".format(stack1.name, stack1.dids)
    print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions)
    for device in stack1.devices.values():
            print "Remote Device {0} allowed= {1}".format(device.did, device.allowed)


    print "\n********* Message Transaction Minion to Master **********"
    body = odict(what="This is a message to the master. How are you", extra="And some more.")
    stack1.message(body=body, ddid=1)

    timer.restart()
    while not timer.expired:
        stack1.serviceUdp()
        stack0.serviceUdp()

    while stack0.udpRxes:
        stack0.processUdpRx()

    timer.restart()
    while not timer.expired:
        stack0.serviceUdp()
        stack1.serviceUdp()

    while stack1.udpRxes:
        stack1.processUdpRx()

    print "{0} did={1}".format(stack0.name, stack0.device.did)
    print "{0} devices=\n{1}".format(stack0.name, stack0.devices)
    print "{0} dids=\n{1}".format(stack0.name, stack0.dids)
    print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions)
    print "{0} Received Messages =\n{1}".format(stack0.name, stack0.rxMsgs)

    print "{0} did={1}".format(stack1.name, stack1.device.did)
    print "{0} devices=\n{1}".format(stack1.name, stack1.devices)
    print "{0} dids=\n{1}".format(stack1.name, stack1.dids)
    print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions)
    print "{0} Received Messages =\n{1}".format(stack1.name, stack1.rxMsgs)

    print "\n********* Message Transaction Master to Minion **********"
    body = odict(what="This is a message to the minion. Get to Work", extra="Fix the fence.")
    stack0.message(body=body, ddid=2)

    timer.restart()
    while not timer.expired:
        stack0.serviceUdp()
        stack1.serviceUdp()

    while stack1.udpRxes:
        stack1.processUdpRx()

    timer.restart()
    while not timer.expired:
        stack1.serviceUdp()
        stack0.serviceUdp()

    while stack0.udpRxes:
        stack0.processUdpRx()

    print "{0} did={1}".format(stack0.name, stack0.device.did)
    print "{0} devices=\n{1}".format(stack0.name, stack0.devices)
    print "{0} dids=\n{1}".format(stack0.name, stack0.dids)
    print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions)
    print "{0} Received Messages =\n{1}".format(stack0.name, stack0.rxMsgs)

    print "{0} did={1}".format(stack1.name, stack1.device.did)
    print "{0} devices=\n{1}".format(stack1.name, stack1.devices)
    print "{0} dids=\n{1}".format(stack1.name, stack1.dids)
    print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions)
    print "{0} Received Messages =\n{1}".format(stack1.name, stack1.rxMsgs)

    print "\n********* Message Transactions Both Ways **********"

    stack1.txMsgs.append((odict(house="Mama mia1", queue="fix me"), None))
    stack1.txMsgs.append((odict(house="Mama mia2", queue="help me"), None))
    stack1.txMsgs.append((odict(house="Mama mia3", queue="stop me"), None))
    stack1.txMsgs.append((odict(house="Mama mia4", queue="run me"), None))

    stack0.txMsgs.append((odict(house="Papa pia1", queue="fix me"), None))
    stack0.txMsgs.append((odict(house="Papa pia2", queue="help me"), None))
    stack0.txMsgs.append((odict(house="Papa pia3", queue="stop me"), None))
    stack0.txMsgs.append((odict(house="Papa pia4", queue="run me"), None))

    #segmented packets
    stuff = []
    for i in range(300):
        stuff.append(str(i).rjust(4, " "))
    stuff = "".join(stuff)

    stack1.txMsgs.append((odict(house="Mama mia1", queue="big stuff", stuff=stuff), None))
    stack0.txMsgs.append((odict(house="Papa pia4", queue="gig stuff", stuff=stuff), None))

    stack1.serviceUdpTxMsg()
    stack0.serviceUdpTxMsg()

    timer.restart()
    while not timer.expired:
        stack1.serviceUdp()
        stack0.serviceUdp()

    while stack0.udpRxes:
        stack0.processUdpRx()
    while stack1.udpRxes:
        stack1.processUdpRx()

    timer.restart()
    while not timer.expired:
        stack0.serviceUdp()
        stack1.serviceUdp()

    while stack1.udpRxes:
        stack1.processUdpRx()
    while stack0.udpRxes:
        stack0.processUdpRx()

    print "{0} did={1}".format(stack0.name, stack0.device.did)
    print "{0} devices=\n{1}".format(stack0.name, stack0.devices)
    print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions)
    print "{0} Received Messages".format(stack0.name)
    for msg in stack0.rxMsgs:
        print msg
    print
    print "{0} did={1}".format(stack1.name, stack1.device.did)
    print "{0} devices=\n{1}".format(stack1.name, stack1.devices)
    print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions)
    print "{0} Received Messages".format(stack1.name)
    for msg in stack1.rxMsgs:
            print msg
Esempio n. 4
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()
Esempio n. 5
0
def test( pk=raeting.packKinds.json):
    '''
    Test paging.
    '''
    console.reinit(verbosity=console.Wordage.concise)

    #data = odict(hk=hk, bk=bk)
    body = odict(raeting.PAGE_DEFAULTS)
    page0 = paging.TxPage(kind=pk, data=body)
    print page0.data
    page0.pack()
    print len(page0.packed)
    print page0.packed
    page1 = paging.RxPage(packed=page0.packed)
    page1.parse()
    print page1.data

    stuff = []
    for i in range(10000):
        stuff.append(str(i).rjust(10, " "))
    stuff = "".join(stuff)
    body = odict(msg=stuff)
    page0 = paging.TxPage(kind=pk, data=body)
    try:
        page0.pack()
    except raeting.PageError as ex:
        print ex
        print "Need to use book"

    data = odict(syn="boy", dyn='girl', mid=1)
    book0 = paging.TxBook(data=data, body=body, kind=pk)
    book0.pack()
    print book0.packed
    print book0.pages

    book1 = paging.RxBook()
    for page in book0.pages:
        page = paging.RxPage(packed=page.packed)
        page.parse()
        book1.parse(page)

    print book1.data
    print book1.body

    print body == book1.body

    stacking.StackUxd.Pk = pk
    store = storing.Store(stamp=0.0)

    #lord stack
    stack0 = stacking.StackUxd(store=store)

    #serf stack
    stack1 = stacking.StackUxd(store=store)

    stack0.addRemoteYard(yarding.RemoteYard(ha=stack1.yard.ha))
    stack1.addRemoteYard(yarding.RemoteYard(ha=stack0.yard.ha))

    print "{0} yard name={1} ha={2}".format(stack0.name, stack0.yard.name, stack0.yard.ha)
    print "{0} yards=\n{1}".format(stack0.name, stack0.yards)
    print "{0} names=\n{1}".format(stack0.name, stack0.names)

    print "{0} yard name={1} ha={2}".format(stack1.name, stack1.yard.name, stack1.yard.ha)
    print "{0} yards=\n{1}".format(stack1.name, stack1.yards)
    print "{0} names=\n{1}".format(stack1.name, stack1.names)

    print "\n____________ Messaging through stack tests "

    msg = odict(stuff=stuff)
    stack0.transmit(msg=body)

    msg = odict(what="This is a message to the serf. Get to Work", extra="Fix the fence.")
    stack0.transmit(msg=msg)

    msg = odict(what="This is a message to the lord. Let me be", extra="Go away.")
    stack1.transmit(msg=msg)



    timer = Timer(duration=0.5)
    timer.restart()
    while not timer.expired or store.stamp < 1.0:
        stack0.serviceAll()
        stack1.serviceAll()
        store.advanceStamp(0.1)

    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


    stack0.server.close()
    stack1.server.close()
Esempio n. 6
0
def testStackUxd(kind=raeting.packKinds.json):
    '''
    initially


    '''
    console.reinit(verbosity=console.Wordage.concise)

    stacking.LaneStack.Pk = kind

    #lord stack
    #yard0 = yarding.Yard(name='lord')
    stack0 = stacking.LaneStack(dirpath='/tmp/raet/test_stacking',
                                sockdirpath='/tmp/raet/test_stacking')

    #serf stack
    #yard1 = yarding.Yard(name='serf', yid=1)
    stack1 = stacking.LaneStack(dirpath='/tmp/raet/test_stacking',
                                sockdirpath='/tmp/raet/test_stacking')

    stack0.addRemote(yarding.RemoteYard(ha=stack1.local.ha))
    stack1.addRemote(yarding.RemoteYard(ha=stack0.local.ha))
    #stack0.addRemoteYard(stack1.local)
    #stack1.addRemoteYard(stack0.local)

    print "{0} yard name={1} ha={2}".format(stack0.name, stack0.local.name, stack0.local.ha)
    print "{0} yards=\n{1}".format(stack0.name, stack0.remotes)
    print "{0} names=\n{1}".format(stack0.name, stack0.uids)

    print "{0} yard name={1} ha={2}".format(stack1.name, stack1.local.name, stack1.local.ha)
    print "{0} yards=\n{1}".format(stack1.name, stack1.remotes)
    print "{0} names=\n{1}".format(stack1.name, stack1.uids)

    print "\n********* UXD Message lord to serf serf to lord **********"
    msg = odict(what="This is a message to the serf. Get to Work", extra="Fix the fence.")
    stack0.transmit(msg=msg)

    msg = odict(what="This is a message to the lord. Let me be", extra="Go away.")
    stack1.transmit(msg=msg)

    timer = Timer(duration=0.5)
    timer.restart()
    while not timer.expired:
        stack0.serviceAll()
        stack1.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 "\n********* Multiple Messages Both Ways **********"

    stack1.transmit(odict(house="Mama mia1", queue="fix me"), None)
    stack1.transmit(odict(house="Mama mia2", queue="help me"), None)
    stack1.transmit(odict(house="Mama mia3", queue="stop me"), None)
    stack1.transmit(odict(house="Mama mia4", queue="run me"), None)

    stack0.transmit(odict(house="Papa pia1", queue="fix me"), None)
    stack0.transmit(odict(house="Papa pia2", queue="help me"), None)
    stack0.transmit(odict(house="Papa pia3", queue="stop me"), None)
    stack0.transmit(odict(house="Papa pia4", queue="run me"), None)

    #big packets
    stuff = []
    for i in range(10000):
        stuff.append(str(i).rjust(10, " "))
    stuff = "".join(stuff)

    stack1.transmit(odict(house="Mama mia1", queue="big stuff", stuff=stuff), None)
    stack0.transmit(odict(house="Papa pia4", queue="gig stuff", stuff=stuff), None)

    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

    src = ('minion', 'serf', None)
    dst = ('master', None, None)
    route = odict(src=src, dst=dst)
    msg = odict(route=route, stuff="Hey buddy what is up?")
    stack0.transmit(msg)

    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

    estate = 'minion1'
    #lord stack yard0
    stack0 = stacking.LaneStack(name='lord',
                                lanename='cherry',
                                dirpath='/tmp/raet/test_stacking',
                                sockdirpath='/tmp/raet/test_stacking')

    #serf stack yard1
    stack1 = stacking.LaneStack(name='serf',
                                lanename='cherry',
                                dirpath='/tmp/raet/test_stacking',
                                sockdirpath='/tmp/raet/test_stacking')

    print "Yid", yarding.Yard.Yid

    print "\n********* Attempt Auto Accept ************"
    #stack0.addRemoteYard(stack1.local)
    yard = yarding.RemoteYard(name=stack0.local.name,
                            lanename='cherry',
                            dirpath='/tmp/raet/test_stacking')
    stack1.addRemote(yard)

    print "{0} yard name={1} ha={2}".format(stack0.name, stack0.local.name, stack0.local.ha)
    print "{0} yards=\n{1}".format(stack0.name, stack0.remotes)
    print "{0} names=\n{1}".format(stack0.name, stack0.uids)

    print "{0} yard name={1} ha={2}".format(stack1.name, stack1.local.name, stack1.local.ha)
    print "{0} yards=\n{1}".format(stack1.name, stack1.remotes)
    print "{0} names=\n{1}".format(stack1.name, stack1.uids)

    print "\n********* UXD Message serf to lord **********"
    src = (estate, stack1.local.name, None)
    dst = (estate, stack0.local.name, None)
    route = odict(src=src, dst=dst)
    msg = odict(route=route, stuff="Serf to my lord. Feed me!")
    stack1.transmit(msg=msg)

    timer = Timer(duration=0.5)
    timer.restart()
    while not timer.expired:
        stack0.serviceAll()
        stack1.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 "\n********* UXD Message lord to serf **********"
    src = (estate, stack0.local.name, None)
    dst = (estate, stack1.local.name, None)
    route = odict(src=src, dst=dst)
    msg = odict(route=route, stuff="Lord to serf. Feed yourself!")
    stack0.transmit(msg=msg)


    timer = Timer(duration=0.5)
    timer.restart()
    while not timer.expired:
        stack0.serviceAll()
        stack1.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} yard name={1} ha={2}".format(stack0.name, stack0.local.name, stack0.local.ha)
    print "{0} yards=\n{1}".format(stack0.name, stack0.remotes)
    print "{0} names=\n{1}".format(stack0.name, stack0.uids)

    print "{0} yard name={1} ha={2}".format(stack1.name, stack1.local.name, stack1.local.ha)
    print "{0} yards=\n{1}".format(stack1.name, stack1.remotes)
    print "{0} names=\n{1}".format(stack1.name, stack1.uids)

    stack0.server.close()
    stack1.server.close()
Esempio n. 7
0
def test( pk=raeting.packKinds.json):
    '''
    Test paging.
    '''
    console.reinit(verbosity=console.Wordage.concise)

    #data = odict(hk=hk, bk=bk)
    body = odict(raeting.PAGE_DEFAULTS)
    page0 = paging.TxPage(kind=pk, data=body)
    print page0.data
    page0.pack()
    print len(page0.packed)
    print page0.packed
    page1 = paging.RxPage(packed=page0.packed)
    page1.parse()
    print page1.data

    stuff = []
    for i in range(10000):
        stuff.append(str(i).rjust(10, " "))
    stuff = "".join(stuff)
    body = odict(msg=stuff)
    page0 = paging.TxPage(kind=pk, data=body)
    try:
        page0.pack()
    except raeting.PageError as ex:
        print ex
        print "Need to use book"

    data = odict(syn="boy", dyn='girl', mid=1)
    book0 = paging.TxBook(data=data, body=body, kind=pk)
    book0.pack()
    print book0.packed
    print book0.pages

    book1 = paging.RxBook()
    for page in book0.pages:
        page = paging.RxPage(packed=page.packed)
        page.parse()
        book1.parse(page)

    print book1.data
    print book1.body

    print body == book1.body

    stacking.LaneStack.Pk = pk
    store = storing.Store(stamp=0.0)

    #lord stack
    stack0 = stacking.LaneStack(store=store)

    #serf stack
    stack1 = stacking.LaneStack(store=store)

    stack0.addRemote(yarding.RemoteYard(ha=stack1.yard.ha))
    stack1.addRemote(yarding.RemoteYard(ha=stack0.yard.ha))

    print "{0} yard name={1} ha={2}".format(stack0.name, stack0.yard.name, stack0.yard.ha)
    print "{0} yards=\n{1}".format(stack0.name, stack0.yards)
    print "{0} names=\n{1}".format(stack0.name, stack0.names)

    print "{0} yard name={1} ha={2}".format(stack1.name, stack1.yard.name, stack1.yard.ha)
    print "{0} yards=\n{1}".format(stack1.name, stack1.yards)
    print "{0} names=\n{1}".format(stack1.name, stack1.names)

    print "\n____________ Messaging through stack tests "

    msg = odict(stuff=stuff)
    stack0.transmit(msg=body)

    msg = odict(what="This is a message to the serf. Get to Work", extra="Fix the fence.")
    stack0.transmit(msg=msg)

    msg = odict(what="This is a message to the lord. Let me be", extra="Go away.")
    stack1.transmit(msg=msg)



    timer = Timer(duration=0.5)
    timer.restart()
    while not timer.expired or store.stamp < 1.0:
        stack0.serviceAll()
        stack1.serviceAll()
        store.advanceStamp(0.1)

    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


    stack0.server.close()
    stack1.server.close()
Esempio n. 8
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()
Esempio n. 9
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.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()
Esempio n. 10
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)

    #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.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.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(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.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} 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.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.server.close()
    stack1.server.close()
    stack2.server.close()

    stack0.clearLocal()
    stack0.clearAllRemote()
    stack1.clearLocal()
    stack1.clearAllRemote()
    stack2.clearLocal()
    stack2.clearAllRemote()
Esempio n. 11
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)

    #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()
Esempio n. 12
0
def testStackUdp(bk=raeting.bodyKinds.json):
    '''
    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)

    stacking.StackUdp.Bk = bk  #set class body kind for serialization

    #master stack
    masterName = "master"
    signer = nacling.Signer()
    masterSignKeyHex = signer.keyhex
    privateer = nacling.Privateer()
    masterPriKeyHex = privateer.keyhex
    dirpathMaster = os.path.join(os.getcwd(), 'keep', masterName)

    #minion stack
    minionName = "minion1"
    signer = nacling.Signer()
    minionSignKeyHex = signer.keyhex
    privateer = nacling.Privateer()
    minionPriKeyHex = privateer.keyhex
    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,
                               auto=True,
                               main=True,
                               dirpath=dirpathMaster)

    estate = estating.LocalEstate(   eid=0,
                                     name=minionName,
                                     ha=("", raeting.RAET_TEST_PORT),
                                     sigkey=minionSignKeyHex,
                                     prikey=minionPriKeyHex,)
    stack1 = stacking.StackUdp(estate=estate,  dirpath=dirpathMinion)

    print "\n********* Join Transaction **********"
    stack1.join()

    timer = Timer(duration=0.5)
    while not timer.expired:
        stack1.serviceUdp()
        stack0.serviceUdp()

    stack0.serviceRxes()
    stack0.process()

    timer.restart()
    while not timer.expired:
        stack0.serviceUdp()
        stack1.serviceUdp()

    stack1.serviceRxes()


    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.serviceRxes()

    timer.restart()
    while not timer.expired:
        stack0.serviceUdp()
        stack1.serviceUdp()

    stack1.serviceRxes()

    timer.restart()
    while not timer.expired:
        stack0.serviceUdp()
        stack1.serviceUdp()

    stack0.serviceRxes()

    timer.restart()
    while not timer.expired:
        stack0.serviceUdp()
        stack1.serviceUdp()

    stack1.serviceRxes()

    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.serviceRxes()

    timer.restart()
    while not timer.expired:
        stack0.serviceUdp()
        stack1.serviceUdp()

    stack1.serviceRxes()

    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.serviceRxes()

    timer.restart()
    while not timer.expired:
        stack1.serviceUdp()
        stack0.serviceUdp()

    stack0.serviceRxes()

    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.serviceTxMsgs()
    stack0.serviceTxMsgs()

    timer.restart()
    while not timer.expired:
        stack1.serviceUdp()
        stack0.serviceUdp()

    stack0.serviceRxes()
    stack1.serviceRxes()

    timer.restart()
    while not timer.expired:
        stack0.serviceUdp()
        stack1.serviceUdp()

    stack1.serviceRxes()
    stack0.serviceRxes()


    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.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} 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 "{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.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 "{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.clearAllRemote()
    stack1.clearLocal()
    stack1.clearAllRemote()
Esempio n. 13
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.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} 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} 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.server.close()
    stack1.server.close()