def __init__(s):
        s.debug = False
        s.errordebug = False
        s.statusdebug = False

        s.addr = "new"
        s.messages = MessageStorage()

        s.connected = False
Ejemplo n.º 2
0
 def __init__(self, accountName):
     
     # The ServerProtocol state machine can work in a connection oriented
     # or connectionless fashion. The restore signals return it to the 
     # saved state
     
     self.__fsm = StateMachine()
     
     self.__fsm.addState(self.STATE_UNINIT,
                         (SessionRunMobileCode, self.STATE_RESTORE_STATE),
                         (CheckMobileCodeResult, self.STATE_RESTORE_STATE),
                         (PurchaseDecryptionKey, self.STATE_RESTORE_STATE),
                         (RerequestDecryptionKey, self.STATE_RESTORE_STATE),
                         
                         (OpenSession, self.STATE_OPEN))
     
     self.__fsm.addState(self.STATE_RESTORE_STATE,
                         (self.SIGNAL_RESTORE_OPEN, self.STATE_OPEN),
                         (self.SIGNAL_RESTORE_RUNNING, self.STATE_RUNNING),
                         (self.SIGNAL_RESTORE_PURCHASE, self.STATE_PURCHASE),
                         (self.SIGNAL_RESTORE_FINISHED, self.STATE_FINISHED),
                         onEnter=self.__handleRestoreState)
     
     self.__fsm.addState(self.STATE_OPEN, 
                         (SessionRunMobileCode, self.STATE_RUNNING),
                         onEnter=self.__handleOpenSession)
     
     self.__fsm_addState(self.STATE_RUNNING, 
                         # TRANSITIONS
                         (self.SIGNAL_CODE_EXECUTION_COMPLETE, self.STATE_PURCHASE),
                         (CheckMobileCodeResult, self.STATE_RUNNING),
                         # Callback
                         onEnter=self.__handleRunMobileCode)
     
     self.__fsm.addState(self.STATE_PURCHASE,
                         (self.SIGNAL_NO_CHARGE, self.STATE_FINISHED), 
                         (PurchaseDecryptionKey, self.STATE_FINISHED),
                         (CheckMobileCodeResult, self.STATE_PURCHASE),
                         onEnter=self.__mobileCodeComplete)
     
     self.__fsm.addState(self.STATE_FINISHED, 
                         (CheckMobileCodeResult, self.STATE_FINISHED),
                         (RerequestDecryptionKey, self.STATE_FINISHED),
                         onEnter=self.__handleFinished)
     self.__fsm.addState(self.STATE_ERROR, onEnter=self.__handleError)
     self.__fsm.start(self.STATE_UNINIT, self.STATE_ERROR)
 
     self.__stateContext = None
     self.__accountName = accountName
     self.__codeString = None
     self.__curState = None
     self.__storage = MessageStorage()
Ejemplo n.º 3
0
    def gameloop(self, ctx):
        logger = logging.getLogger(__name__ + ".RemoteWorkerBrain")
        logger.info("Starting Game Loop")

        self.__running = True
        cAndC = ctx.socket()
        logger.info("Connect to %s:10001" % (ctx.socket.ORIGIN))
        cAndC.connect("ORIGIN_SERVER", 10001)
        tickCount = 0
        connected = False
        messageBuffer = MessageStorage(CommandAndControlRequest)
        while self.__running:
            tickCount += 1
            if cAndC.connected():
                if not connected:
                    connected = True
                    tickCount = 0
                if tickCount % 60 == 0:
                    logger.info("Sending heartbeat at tickcount %d" %
                                tickCount)
                    response = CommandAndControlResponse(
                        reqID=0,
                        success=True,
                        message="Heartbeat %d" % tickCount)
                    cAndC.send(response.__serialize__())

                data = cAndC.recv(timeout=1)
                if not data:
                    continue

                messageBuffer.update(data)
                for msg in messageBuffer.iterateMessages():
                    try:
                        for result, resultMessage in self.processRequest(
                                ctx, msg):
                            response = CommandAndControlResponse(
                                reqID=msg.ID,
                                success=result,
                                message=resultMessage)
                            cAndC.send(response.__serialize__())
                    except Exception, e:
                        response = CommandAndControlResponse(
                            reqID=msg.ID,
                            success=False,
                            message="Error: %s" % e)
                        cAndC.send(response.__serialize__())
            elif tickCount % 10 == 9:
                logger.info("Could not connect to C&C within %d ticks" %
                            (tickCount + 1))
Ejemplo n.º 4
0
    def __init__(s):
        s.debug = False
        s.errordebug = False
        s.statusdebug = False

        s.messages = MessageStorage()
        s.OBBuffer = ""  # outbound buffer, should prbly be a list
        s.fsm = s.RIP_FSM()
        s.connected = False
        s.sendClose = False  # flag to indicate sending loop should send a close
        s.waiting = False
        s.finishing = False
        s.closeRcvd = False
        s.finalExpSeq = None
        s.closeSent = False
        s.shuttingDown = False

        s.seqnum = 0  # gets set later but this should be the sequence of the next new packet
        s.lastAckRcvd = None  # this is the sequence number the other party expects

        s.AckQ = list()
        s.transmitQ = list()
        s.retransmitQ = list()

        s.expectedSeq = None  # this is the sequence number of the next expected packet
        s.lastAckSent = None  # this is what we told the other party we're expecting
        s.rcvdMsgs = dict()  # unprocessed rcvdMsgs
        s.deferreds = list()  # so we can disable them when shutting down

        s.MSS = 4096  # fixed
        s.maxUnAcked = 256
        s.transmitDelay = 0.005
        s.retransmit_delay = 3
        s.maxAttempts = 256
        s.sessionID = ""  # gets set after nonces are exchanged
        s.myNonce = urandom(8).encode('hex')  # random hex nonce

        s.addr = "new"

        s.otherCerts = None  # store the other certs here

        s.ripPrint("RIPProtocol Initialized")

        if s.statusdebug:
            s.printStatus()
Ejemplo n.º 5
0
    def __init__(self):

        self.buffer = ""
        self.storage = MessageStorage()
        self.TCB = TransmissionControlBlock()
        self.higherTransport = RipTransport(self.transport, self, self.TCB)
        self.fsm = FSM("RipStateMachine")
        self.fsm.addState("Closed", ("Send_SNN", "SNN-SENT"))
        self.fsm.addState("Listening", ("SNN_Received", "ACK-Sent"))
        self.fsm.addState("SNN-SENT", ("SNN_ACK_Received", "Established"),
                          onEnter=self.sendSyn)
        self.fsm.addState("ACK-Sent", ("ACK_Received", "Established"),
                          onEnter=self.sendSynAck)
        self.fsm.addState("Established", ("CLOSE_Requested", "CLOSE-REQ"),
                          ("CLOSE_Received", "CLOSE-RECV"),
                          onEnter=self.sendAck)
        self.fsm.addState("CLOSE-REQ", ("CLOSE_ACK_Received", "Closed"))
        self.fsm.addState("CLOSE-RECV", ("CLOSE_ACK_Sent", "Listening"),
                          onEnter=self.sendFinAck)
Ejemplo n.º 6
0
 def __init__(self):
     #The nonce sent by the RIP
     self.lastNonce = None
     #Storage for received messages
     self.storage = MessageStorage()
     #The higher transport layer
     self.higherTransport = None
     #The peer RIP's public key
     self.peerPublicKey = None
     #The current host, set upon connection made
     self.host = ""
     #Messages received whose preceeding messages have not be received
     self.outOfOrderMessages = []
     #The session ID of the peer RIP, check to prevent replay
     self.expectedSessionId = ""
     #The next sequence number you expect to reveive from the peer RIP
     self.expectPeerSeqNum = ""
     #The maximum number of messages received without an ack
     self.maxRecv = 256
Ejemplo n.º 7
0
 def __init__(self):
     self.__storage = MessageStorage(ReprogrammingResponse)
     self.__requests = {}
     self.__reqId = 0
Ejemplo n.º 8
0
 def __init__(self):
     self.messageStorage = MessageStorage()
Ejemplo n.º 9
0
 def __init__(self):
     self.storage = MessageStorage(CommandAndControlResponse)
Ejemplo n.º 10
0
 def __init__(self):
     self.__buffer = MessageStorage()
     self.__listenLookup = {}
     self.__connLookup = {}
Ejemplo n.º 11
0
 def __init__(self):
     print "@RIP_Server.__init__()"
     self.nonce = os.urandom(8).encode('hex')
     self.storage = MessageStorage()
     self.STATES = [LISTEN(self.nonce), SYN_RECV(), ESTAB()]
Ejemplo n.º 12
0
 def __init__(self):
     print "@RIP_Client.__init__()"
     self.nonce = os.urandom(8).encode('hex')
     #self.nonce = randint(1000, 9999)
     self.storage = MessageStorage()
     self.STATES = [CLOSED(), SYN_SENT(), ESTAB()]
Ejemplo n.º 13
0
 def __init__(self):
     self.__storage = MessageStorage(ReprogrammingRequest)
 def __init__(self):
     self.msgs = MessageStorage()
Ejemplo n.º 15
0
 def __init__(self, factory, testControl):
     self.factory = factory
     self.control = testControl
     self.sendDone = False
     self.recvDone = False
     self.messageStorage = MessageStorage()