コード例 #1
0
ファイル: callback.py プロジェクト: LCROBOT/rce
 def sendRoutingInfo(self, dest, info):
     """ Internally used method to send routing info "info" to "dest".
     """
     if not info:
         # Only send a message if there is information to send
         return
     
     msg = Message()
     msg.msgType = msgTypes.ROUTE_INFO
     msg.dest = dest
     msg.content = info
     self._commManager.sendMessage(msg)
コード例 #2
0
ファイル: machine.py プロジェクト: LCROBOT/rce
 def registerMachine(self, machine):
     """ Register a new machine in which containers can be started.
         
         @param machine:     Machine which should be registered.
         @type  machine:     core.balancer.Machine
     """
     if machine in self._machines:
         raise InternalError('Tried to register the same machine twice.')
     
     # Inform container manager about the CommID of the relay manager.
     msg = Message()
     msg.msgType = msgTypes.COMM_INFO
     msg.dest = machine.containerID
     msg.content = machine.relayID
     self._commManager.sendMessage(msg)
     
     # Order the new machine to connect to all the other existing machines.
     order = [(m.relayID, m.ip) for m in self._machines]
     
     if order:
         msg = Message()
         msg.msgType = msgTypes.CONNECT
         msg.dest = machine.relayID
         msg.content = order
         self._commManager.sendMessage(msg)
     
     self._machines.add(machine)
コード例 #3
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()
コード例 #4
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:])
コード例 #5
0
ファイル: handler.py プロジェクト: LCROBOT/rce
 def unregisterProducer(self):
     """ Method which is used by the producer to signal that he has finished
         sending data.
     """
     super(_EndReceiver, self).unregisterProducer()
     
     try:
         self._handler.processMessage(
             Message.deserialize(self._buf, self._manager))
     except SerializationError as e:
         log.msg('Could not deserialize message: {0}'.format(e))
コード例 #6
0
ファイル: message.py プロジェクト: LCROBOT/rce
 def send(self, userID, tag, commID, senderTag, rosMsg, msgID):
     """ Send a message which was received from an endpoint to another
         interface.
         
         @param userID:      User ID of the interface owner.
         @type  userID:      str
         
         @param tag:         Tag of the interface at the destination.
         @type  tag:         str
         
         @param commID:      Communication ID of the destination.
         @type  commID:      str
         
         @param senderTag:   Tag of the interface who is sending the
                             message.
         @type  senderTag:   str
         
         @param rosMsg:      ROS message in serialized form which should be
                             sent.
         @type  rosMsg:      str
         
         @param msgID:       Identifier which is used to match a request to
                             a response.
         @type  msgID:       str
     """
     # First check if the message is for an interface in this endpoint
     if commID == self._commID:
         self._manager.received(userID, tag, commID, senderTag, rosMsg,
                                msgID)
         return
     
     msg = Message()
     msg.msgType = msgTypes.ROS_MSG
     msg.dest = commID
     msg.content = { 'msg'     : rosMsg,
                     'destTag' : tag,
                     'srcTag'  : senderTag,
                     'msgID'   : msgID,
                     'user'    : userID }
     self._commManager.sendMessage(msg)
コード例 #7
0
ファイル: manager.py プロジェクト: LCROBOT/rce
 def _publishEndpointChange(self, info):
     """ Send a routing info/update to the registered relays and the master
         manager.
         
         @param info:    Information which should be distributed. Tuple
                         consisting commID of endpoint which changed and
                         a bool indicated whether the endpoint is added
                         (True) or removed (False).
         @type  info:    ( str, bool )
     """
     msg = Message()
     msg.msgType = msgTypes.ROUTE_INFO
     msg.dest = self._MASTER_ID
     msg.content = [info]
     self._commManager.sendMessage(msg)
     
     for relayID in self._relays:
         msg = Message()
         msg.msgType = msgTypes.ROUTE_INFO
         msg.dest = relayID
         msg.content = [info]
         self._commManager.sendMessage(msg)