예제 #1
0
파일: protocol.py 프로젝트: LCROBOT/rce
 def startInit(self, conn):
     msg = Message()
     msg.msgType = types.INIT_REQUEST
     msg.dest = definition.NEIGHBOR_ADDR
     
     msg.content = { 'data' : [self._serverID] + self.getInitData() }
     
     try:
         buf = msg.serialize(self._commManager)
         _Sender(len(buf),
                 self._commManager.commID,
                 msg.dest,
                 buf).send(conn)
     except SerializationError as e:
         log.msg('Could not serialize message: {0}'.format(e))
         conn.transport.loseConnection()
예제 #2
0
파일: protocol.py 프로젝트: LCROBOT/rce
 def processInitMessage(self, msg, conn):
     # First some base checks of message header
     if msg.msgType != types.INIT_REQUEST:
         log.msg('Received message type different from INIT_REQUEST '
                 'before initialization of protocol instance has been '
                 'completed.')
         conn.transport.loseConnection()
         return
     
     data = msg.content['data']
     
     if data[0] != self._commManager.commID:
         log.msg("Received target ID does not match this node's for "
                 'initialization of protocol instance.')
         conn.transport.loseConnection()
         return
     
     origin = msg.origin
     
     if not self.authOrigin(origin):
         log.msg('Origin could not be authenticated.')
         conn.transport.loseConnection()
         return
     
     msg = Message()
     msg.msgType = types.INIT_REQUEST
     msg.dest = origin
     msg.content = { 'data' : self.getInitData() }
     
     try:
         buf = msg.serialize(self._commManager)
         _Sender(len(buf), self._commManager.commID, msg.dest, buf).send(
             conn)
     except SerializationError as e:
         log.msg('Could not serialize message: {0}'.format(e))
         conn.transport.loseConnection()
         return
     
     # Set protocol to initialized and register connection in manager
     conn.dest = origin
     conn.initialized = True
     self._commManager.router.registerConnection(conn)
     log.msg('Connection established to "{0}".'.format(origin))
     
     # Trigger the post init method
     for cb in self._postInit:
         cb.postInit(origin, conn.ip, data[1:])