Exemple #1
0
    def __init__(self, stack=None, kind=None, timeout=None, start=None,
                 rdid=None, rmt=False, bcst=False, sid=None, tid=None,
                 txData=None, txPacket=None, rxPacket=None):
        '''
        Setup Transaction instance
        timeout of 0.0 means no timeout go forever
        '''
        self.stack = stack
        self.kind = kind or raeting.PACKET_DEFAULTS['tk']

        if timeout is None:
            timeout = self.Timeout
        self.timeout = timeout
        self.timer = aiding.StoreTimer(self.stack.store, duration=self.timeout)
        if start: #enables synchronized starts not just current time
            self.timer.restart(start=start)

        # local device is the .stack.device
        self.rdid = rdid  # remote device did

        self.rmt = rmt
        self.bcst = bcst

        self.sid = sid
        self.tid = tid

        self.txData = txData or odict() # data used to prepare last txPacket
        self.txPacket = txPacket  # last tx packet needed for retries
        self.rxPacket = rxPacket  # last rx packet
Exemple #2
0
    def __init__(
        self,
        name='',
        version=raeting.VERSION,
        store=None,
        keep=None,
        dirpath='',
        local=None,
        server=None,
        rxMsgs=None,
        txMsgs=None,
        rxes=None,
        txes=None,
        stats=None,
    ):
        '''
        Setup StackUdp instance
        '''
        if not name:
            name = "stack{0}".format(Stack.Count)
            Stack.Count += 1
        self.name = name
        self.version = version
        self.store = store or storing.Store(stamp=0.0)

        self.keep = keep or keeping.LotKeep(dirpath=dirpath,
                                            stackname=self.name)
        self.loadLocal(
            local)  # load local data from saved data else passed in local
        self.remotes = odict()  # remotes indexed by uid
        self.uids = odict()  # remote uids indexed by name
        self.loadRemotes()  # load remotes from saved data
        self.server = server
        if self.server:
            if not self.server.reopen():  # open socket
                raise raeting.StackError("Stack {0}: Can't open server at"
                                         " {1}\n".format(
                                             self.name, self.server.ha))
            if self.local:
                self.local.ha = self.server.ha  # update local host address after open

        self.rxMsgs = rxMsgs if rxMsgs is not None else deque(
        )  # messages received
        self.txMsgs = txMsgs if txMsgs is not None else deque(
        )  # messages to transmit
        self.rxes = rxes if rxes is not None else deque(
        )  # udp packets received
        self.txes = txes if txes is not None else deque(
        )  # udp packet to transmit
        self.stats = stats if stats is not None else odict()  # udp statistics
        self.statTimer = aiding.StoreTimer(self.store)

        self.dumpLocal()  # save local data
        self.dumpRemotes()  # save remote data
Exemple #3
0
    def __init__(self, redoTimeout=None, **kwa):
        '''
        Setup Transaction instance
        '''
        kwa['kind'] = raeting.trnsKinds.join
        super(Joinent, self).__init__(**kwa)
        if redoTimeout is None:
            redoTimeout = self.RedoTimeout
        self.redoTimeout = redoTimeout
        self.redoTimer = aiding.StoreTimer(self.stack.store, duration=0.0)

        self.prep()
        # Since corresponding bootstrap transaction use packet.index not self.index
        self.add(self.rxPacket.index)
Exemple #4
0
    def __init__(self,
                 stack,
                 verkey=None,
                 pubkey=None,
                 acceptance=None,
                 rsid=0,
                 period=None,
                 offset=None,
                 **kwa):
        '''
        Setup Estate instance

        stack is required parameter for RemoteEstate unlike its superclass

        verkey is either nacl VerifyKey or raw or hex encoded key
        pubkey is either nacl PublicKey or raw or hex encoded key
        '''
        if 'host' not in kwa and 'ha' not in kwa:
            kwa['ha'] = ('127.0.0.1', raeting.RAET_TEST_PORT)
        super(RemoteEstate, self).__init__(stack, **kwa)
        self.joined = None
        self.allowed = None
        self.alived = None
        self.acceptance = acceptance
        self.privee = nacling.Privateer()  # short term key manager
        self.publee = nacling.Publican(
        )  # correspondent short term key  manager
        self.verfer = nacling.Verifier(
            verkey)  # correspondent verify key manager
        self.pubber = nacling.Publican(
            pubkey)  # correspondent long term key manager

        self.rsid = rsid  # last sid received from remote when RmtFlag is True
        #self.rtid = rtid # last tid received from remote when RmtFlag is True
        self.indexes = set(
        )  # indexes to outstanding transactions for this remote

        # persistence keep alive heatbeat timer. Initial duration has offset so
        # not synced with other side persistence heatbeet
        self.period = period if period is not None else self.Period
        self.offset = offset if offset is not None else self.Offset
        # by default do not use offset on main unless it is explicity provided
        if self.stack.local.main and offset is None:
            duration = self.period
        else:
            duration = self.period + self.offset
        self.timer = aiding.StoreTimer(store=self.stack.store,
                                       duration=duration)
Exemple #5
0
    def __init__(
        self,
        store=None,
        version=raeting.VERSION,
        main=None,
        puid=None,
        local=None,  #passed up from subclass
        name='',
        uid=None,
        server=None,
        ha=None,
        bufcnt=2,
        rxMsgs=None,
        txMsgs=None,
        rxes=None,
        txes=None,
        stats=None,
    ):
        '''
        Setup Stack instance
        '''
        self.store = store or storing.Store(stamp=0.0)

        self.version = version
        self.main = main

        if getattr(self, 'puid', None) is None:
            self.puid = puid if puid is not None else self.Uid

        self.local = local or lotting.Lot(
            stack=self,
            name=name,
            uid=uid,
            ha=ha,
        )
        self.local.stack = self

        self.remotes = self.uidRemotes = odict()  # remotes indexed by uid
        self.nameRemotes = odict()  # remotes indexed by name

        self.bufcnt = bufcnt
        if not server:
            server = self.serverFromLocal()

        self.server = server
        if self.server:
            if not self.server.reopen():  # open socket
                raise raeting.StackError(
                    "Stack '{0}': Failed opening server at"
                    " '{1}'\n".format(self.name, self.server.ha))

            self.ha = self.server.ha  # update local host address after open

            console.verbose("Stack '{0}': Opened server at '{1}'\n".format(
                self.name, self.ha))

        self.rxMsgs = rxMsgs if rxMsgs is not None else deque(
        )  # messages received
        self.txMsgs = txMsgs if txMsgs is not None else deque(
        )  # messages to transmit
        self.rxes = rxes if rxes is not None else deque(
        )  # udp packets received
        self.txes = txes if txes is not None else deque(
        )  # udp packet to transmit
        self.stats = stats if stats is not None else odict()  # udp statistics
        self.statTimer = aiding.StoreTimer(self.store)
Exemple #6
0
    def __init__(self,
                 stack,
                 uid=None,
                 fuid=0,
                 main=False,
                 kind=0,
                 verkey=None,
                 pubkey=None,
                 acceptance=None,
                 joined=None,
                 rsid=0,
                 **kwa):
        '''
        Setup instance

        stack is required parameter

        verkey is either nacl VerifyKey or raw or hex encoded key
        pubkey is either nacl PublicKey or raw or hex encoded key

        acceptance is accepted state of remote on Road

        rsid is last received session id used by remotely initiated transaction


        '''
        if uid is None:
            uid = stack.nextUid()
            while uid in stack.remotes or uid == stack.local.uid:
                uid = stack.nextUid()

        if 'ha' not in kwa:
            kwa['ha'] = ('127.0.0.1', raeting.RAET_TEST_PORT)
        super(RemoteEstate, self).__init__(stack, uid=uid, **kwa)
        self.fuid = fuid
        self.main = main
        self.kind = kind
        self.joined = joined
        self.allowed = None
        self.alived = None
        self.reaped = None
        self.acceptance = acceptance
        self.privee = nacling.Privateer()  # short term key manager
        self.publee = nacling.Publican(
        )  # correspondent short term key  manager
        self.verfer = nacling.Verifier(
            verkey)  # correspondent verify key manager
        self.pubber = nacling.Publican(
            pubkey)  # correspondent long term key manager

        self.rsid = rsid  # last sid received from remote when RmtFlag is True

        # persistence keep alive heartbeat timer. Initial duration has offset so
        # not synced with other side persistence heatbeet
        # by default do not use offset on main
        if self.stack.main:
            duration = self.stack.period
        else:
            duration = self.stack.period + self.stack.offset
        self.timer = aiding.StoreTimer(store=self.stack.store,
                                       duration=duration)

        self.reapTimer = aiding.StoreTimer(self.stack.store,
                                           duration=self.stack.interim)
        self.messages = deque(
        )  # deque of saved stale message body data to remote.uid
Exemple #7
0
    def __init__(self,
                 name='',
                 version=raeting.VERSION,
                 store=None,
                 keep=None,
                 dirpath='',
                 basedirpath='',
                 local=None,
                 localname='',
                 bufcnt=2,
                 server=None,
                 rxMsgs=None,
                 txMsgs=None,
                 rxes=None,
                 txes=None,
                 stats=None,
                 clean=False,
                 ):
        '''
        Setup Stack instance
        '''
        if not name:
            name = "stack{0}".format(Stack.Count)
            Stack.Count += 1

        self.name = name
        self.version = version
        self.store = store or storing.Store(stamp=0.0)

        self.keep = keep or keeping.LotKeep(dirpath=dirpath,
                                            basedirpath=basedirpath,
                                            stackname=self.name)

        if clean: # clear persisted data so uses provided or default data
            self.clearLocal()
            self.clearRemoteKeeps()

        self.loadLocal(local=local, name=localname) # load local data from saved data else passed in local
        self.remotes = odict() # remotes indexed by uid
        self.uids = odict() # remote uids indexed by name
        self.loadRemotes() # load remotes from saved data

        for remote in self.remotes.values():
            remote.nextSid()

        self.bufcnt = bufcnt
        if not server:
            server = self.serverFromLocal()

        self.server = server
        if self.server:
            if not self.server.reopen():  # open socket
                raise raeting.StackError("Stack '{0}': Failed opening server at"
                            " '{1}'\n".format(self.name, self.server.ha))
            if self.local:
                self.local.ha = self.server.ha  # update local host address after open

            console.verbose("Stack '{0}': Opened server at '{1}'\n".format(self.name, self.local.ha))

        self.rxMsgs = rxMsgs if rxMsgs is not None else deque() # messages received
        self.txMsgs = txMsgs if txMsgs is not None else deque() # messages to transmit
        self.rxes = rxes if rxes is not None else deque() # udp packets received
        self.txes = txes if txes is not None else deque() # udp packet to transmit
        self.stats = stats if stats is not None else odict() # udp statistics
        self.statTimer = aiding.StoreTimer(self.store)

        self.dumpLocal() # save local data
        self.dumpRemotes() # save remote data