Пример #1
0
class HostProcessServer(BaseProtocol):
    """Handles operations for the host-process data channel."""

    def __init__(self):
        self.__buffer = ReadBuffer()

    def dataReceived(self, data):
        cls = self.__class__

        try:
            client = _assignments.get_client_for_hp(self.session_id)
            if client is not None:
                client.transport.write(data)
                return
        
            self.__buffer.push(data)
    
            message_raw = self.__buffer.read_message()
            if message_raw is None:
                return
    
            hello = self.parse_or_raise(message_raw, Hello)
            self.__handle_hostprocess_hello()
        except:
            log.err()

    def connectionMade(self):
        log.msg("A data connection has been established with connection "
                "having session-ID (%d), but it will need to say hello." % 
                (self.session_id))

    def connectionLost(self, reason):
        try:
            _assignments.connection_lost_from_hp(self.session_id)
        except:
            log.err()
        
    def __handle_hostprocess_hello(self):
        """Handle a host-process hello."""

        cls = self.__class__

        try:
            log.msg("Host-process with session-ID (%d) has said hello." % 
                    (self.session_id))
    
            _assignments.queue_new_hp(self)
    
            host_info = self.transport.getHost()
            response = build_msg_data_hphelloresponse(self.session_id, 
                                                      host_info.host, 
                                                      ports[2])
    
            self.write_message(response)
        except:
            log.err()

    @property
    def session_id(self):
        return self.transport.sessionno
Пример #2
0
class HostProcessServer(BaseProtocol):
    """Handles operations for the host-process data channel."""
    def __init__(self):
        self.__buffer = ReadBuffer()

    def dataReceived(self, data):
        cls = self.__class__

        try:
            client = _assignments.get_client_for_hp(self.session_id)
            if client is not None:
                client.transport.write(data)
                return

            self.__buffer.push(data)

            message_raw = self.__buffer.read_message()
            if message_raw is None:
                return

            hello = self.parse_or_raise(message_raw, Hello)
            self.__handle_hostprocess_hello()
        except:
            log.err()

    def connectionMade(self):
        log.msg("A data connection has been established with connection "
                "having session-ID (%d), but it will need to say hello." %
                (self.session_id))

    def connectionLost(self, reason):
        try:
            _assignments.connection_lost_from_hp(self.session_id)
        except:
            log.err()

    def __handle_hostprocess_hello(self):
        """Handle a host-process hello."""

        cls = self.__class__

        try:
            log.msg("Host-process with session-ID (%d) has said hello." %
                    (self.session_id))

            _assignments.queue_new_hp(self)

            host_info = self.transport.getHost()
            response = build_msg_data_hphelloresponse(self.session_id,
                                                      host_info.host, ports[2])

            self.write_message(response)
        except:
            log.err()

    @property
    def session_id(self):
        return self.transport.sessionno
Пример #3
0
class CommandListener(BaseProtocol):
    """The relay server will emit messages to us over a separate command 
    channel. The messages are referred to as commands, but are also referred-to 
    as "announcements".
    """    
    
    def __init__(self):
        self.__buffer = ReadBuffer()
    
    def connectionMade(self):
        pass

    def __handle_new_connection(self, properties):
        """We're about to receive data from a new client."""
        
        assigned_session_id = properties.assigned_to_session 
        
        log.msg("Received announcement of assignment to session-no "
                      "(%d)." % (assigned_session_id))
        
    def __handle_dropped_connection(self, properties):
        """The client assigned to us has dropped their connection. Ours will be
        dropped imminently."""
        
        session_id = properties.session_id

        log.msg("Received announcement of a connection drop for client "
                      "with session-no (%d)." % (session_id))

    def __handle_announcement(self, announcement):
        log.msg("Receiving an announcement with message-type of (%d)." % 
                      (announcement.message_type))
        
        if announcement.message_type == Command.CONNECTION_OPEN:
            self.__handle_new_connection(announcement.open_properties)
        elif announcement.message_type == Command.CONNECTION_DROP:
            self.__handle_dropped_connection(announcement.drop_properties)

    def dataReceived(self, data):
        log.msg("(%d) bytes of data received on command-channel." % (len(data)))
        
        try:
            self.__buffer.push(data)

            message_raw = self.__buffer.read_message()
            if message_raw is None:
                return

            log.msg("Message extracted from command-channel.")

            announcement = self.parse_or_raise(message_raw, Command)
            self.__handle_announcement(announcement)            
        except:
            log.err()
Пример #4
0
class CommandListener(BaseProtocol):
    """The relay server will emit messages to us over a separate command 
    channel. The messages are referred to as commands, but are also referred-to 
    as "announcements".
    """
    def __init__(self):
        self.__buffer = ReadBuffer()

    def connectionMade(self):
        pass

    def __handle_new_connection(self, properties):
        """We're about to receive data from a new client."""

        assigned_session_id = properties.assigned_to_session

        log.msg("Received announcement of assignment to session-no "
                "(%d)." % (assigned_session_id))

    def __handle_dropped_connection(self, properties):
        """The client assigned to us has dropped their connection. Ours will be
        dropped imminently."""

        session_id = properties.session_id

        log.msg("Received announcement of a connection drop for client "
                "with session-no (%d)." % (session_id))

    def __handle_announcement(self, announcement):
        log.msg("Receiving an announcement with message-type of (%d)." %
                (announcement.message_type))

        if announcement.message_type == Command.CONNECTION_OPEN:
            self.__handle_new_connection(announcement.open_properties)
        elif announcement.message_type == Command.CONNECTION_DROP:
            self.__handle_dropped_connection(announcement.drop_properties)

    def dataReceived(self, data):
        log.msg("(%d) bytes of data received on command-channel." %
                (len(data)))

        try:
            self.__buffer.push(data)

            message_raw = self.__buffer.read_message()
            if message_raw is None:
                return

            log.msg("Message extracted from command-channel.")

            announcement = self.parse_or_raise(message_raw, Command)
            self.__handle_announcement(announcement)
        except:
            log.err()
Пример #5
0
class CommandServer(BaseProtocol):
    """Handles operations for host-process command-channel."""

    __command_channel = None

    def __init__(self):
        self.__buffer = ReadBuffer()

    def dataReceived(self, data):
        self.__buffer.push(data)

        message_raw = self.__buffer.read_message()
        if message_raw is None:
            return

        # We don't actually expect any data to be sent to us. Do not take any
        # further action, here.

    def connectionLost(self, reason):
        log.msg("Command channel dropped.")
        self.__class__.__command_channel = None

    def connectionMade(self):
        log.msg("Command channel connected.")
        self.__class__.__command_channel = self

    @classmethod
    def get_command_channel(cls):
        return cls.__command_channel

    def announce_assignment(self, hp_connection):
        log.msg("Announcing assignment of new client to HP session "
                "(%d)." % (hp_connection.session_id))

        command = build_msg_cmd_connopen(hp_connection.session_id)
        self.write_message(command)

    def announce_drop(self, hp_connection):
        log.msg("Announcing drop of client assigned to HP session "
                "(%d)." % (hp_connection.session_id))

        command = build_msg_cmd_conndrop(hp_connection.session_id)
        self.write_message(command)
Пример #6
0
class CommandServer(BaseProtocol):
    """Handles operations for host-process command-channel."""

    __command_channel = None

    def __init__(self):
        self.__buffer = ReadBuffer()

    def dataReceived(self, data):
        self.__buffer.push(data)

        message_raw = self.__buffer.read_message()
        if message_raw is None:
            return

        # We don't actually expect any data to be sent to us. Do not take any 
        # further action, here.

    def connectionLost(self, reason):
        log.msg("Command channel dropped.")
        self.__class__.__command_channel = None
        
    def connectionMade(self):
        log.msg("Command channel connected.")
        self.__class__.__command_channel = self
        
    @classmethod
    def get_command_channel(cls):
        return cls.__command_channel

    def announce_assignment(self, hp_connection):
        log.msg("Announcing assignment of new client to HP session "
                      "(%d)." % (hp_connection.session_id))
        
        command = build_msg_cmd_connopen(hp_connection.session_id)
        self.write_message(command)
                
    def announce_drop(self, hp_connection):
        log.msg("Announcing drop of client assigned to HP session "
                      "(%d)." % (hp_connection.session_id))

        command = build_msg_cmd_conndrop(hp_connection.session_id)
        self.write_message(command)
Пример #7
0
 def __init__(self):
     self.__buffer = ReadBuffer()
Пример #8
0
 def __init__(self):
     self.__buffer = ReadBuffer()