Example #1
0
    def _send_ping(self):
        self.logger.debug("sending PING RTS PDU to client")
        packet = RPCRTSOutPacket(self.logger)
        packet.flags = RTS_FLAG_PING
        self.bytes_written = self.bytes_written + packet.size

        return packet.make()
Example #2
0
    def _send_ping(self):
        self.logger.debug("sending PING RTS PDU to client")
        packet = RPCRTSOutPacket(self.logger)
        packet.flags = RTS_FLAG_PING
        self.bytes_written = self.bytes_written + packet.size

        return packet.make()
Example #3
0
    def _send_conn_a3(self):
        self.logger.debug("sending CONN/A3 to client")
            # send the A3 response to the client
        packet = RPCRTSOutPacket(self.logger)
        # we set the min timeout value allowed, as we would actually need
        # either configuration values from Apache or from some config file
        packet.add_command(RTS_CMD_CONNECTION_TIMEOUT, OUTBOUND_PROXY_CONN_TIMEOUT)
        self.bytes_written = self.bytes_written + packet.size

        return packet.make()
Example #4
0
    def _send_conn_a3(self):
        self.logger.debug("sending CONN/A3 to client")
        # send the A3 response to the client
        packet = RPCRTSOutPacket(self.logger)
        # we set the min timeout value allowed, as we would actually need
        # either configuration values from Apache or from some config file
        packet.add_command(RTS_CMD_CONNECTION_TIMEOUT, 120000)
        self.bytes_written = self.bytes_written + packet.size

        return packet.make()
Example #5
0
    def handle_echo_request(self, environ, start_response):
        self.logger.debug("handling echo request")

        packet = RPCRTSOutPacket()
        packet.flags = RTS_FLAG_ECHO
        data = packet.make()
        self.bytes_written = self.bytes_written + packet.size

        start_response("200 Success", [("Content-length", "%d" % packet.size), ("Content-Type", "application/rpc")])

        return [data]
Example #6
0
    def handle_echo_request(self, environ, start_response):
        self.logger.debug("handling echo request")

        packet = RPCRTSOutPacket()
        packet.flags = RTS_FLAG_ECHO
        data = packet.make()
        self.bytes_written = self.bytes_written + packet.size

        start_response("200 Success", [("Content-length", "%d" % packet.size),
                                       ("Content-Type", "application/rpc")])

        return [data]
Example #7
0
    def sequence(self, environ, start_response):
        self.logger.debug("processing request")
        if "REMOTE_PORT" in environ:
            self.logger.debug("remote port = %s" % environ["REMOTE_PORT"])
        # self.logger.debug("path: ' + self.path)

        content_length = int(environ["CONTENT_LENGTH"])
        self.logger.debug("request size is %d" % content_length)

        # echo request
        if content_length <= 0x10:
            for data in self.handle_echo_request(environ, start_response):
                yield data
            self.logger.debug("exiting from echo request")
        elif content_length >= 128:
            self.logger.debug("processing IN channel request")

            self.client_socket = environ["wsgi.input"]
            self._receive_conn_b1()
            connected = self._connect_to_OUT_channel()

            if connected:
                start_response("200 Success",
                               [("Content-Type", "application/rpc"),
                                ("Content-length", "0")])
                self._runloop()

                # shutting down sockets
                self.logger.debug("notifying OUT channel of shutdown")
                try:
                    packet = RPCRTSOutPacket(self.logger)
                    packet.add_command(RTS_CMD_CUSTOM_OUT)
                    self.unix_socket.sendall(packet.make())
                    _safe_close(self.unix_socket)
                    self.logger.debug("OUT channel successfully notified")
                except socket_error:
                    self.logger.debug("(OUT channel already shutdown the unix socket)")
                    # OUT channel already closed the connection
                    pass

                _safe_close(self.oc_conn)

            self.log_connection_stats()
            self.logger.debug("exiting from main sequence")

            # TODO: error handling
            start_response("200 Success",
                           [("Content-length", "0"),
                            ("Content-Type", "application/rpc")])
            yield ""
        else:
            raise Exception("This content-length is not handled")
Example #8
0
    def _send_conn_c2(self):
        self.logger.debug("sending CONN/C2 to client")
        # send the C2 response to the client
        packet = RPCRTSOutPacket(self.logger)
        # we set the min timeout value allowed, as we would actually need
        # either configuration values from Apache or from some config file
        packet.add_command(RTS_CMD_VERSION, 1)
        packet.add_command(RTS_CMD_RECEIVE_WINDOW_SIZE, self.in_window_size)
        packet.add_command(RTS_CMD_CONNECTION_TIMEOUT, self.in_conn_timeout)
        self.bytes_written = self.bytes_written + packet.size

        return packet.make()
Example #9
0
    def _send_conn_c2(self):
        self.logger.debug("sending CONN/C2 to client")
            # send the C2 response to the client
        packet = RPCRTSOutPacket(self.logger)
        # we set the min timeout value allowed, as we would actually need
        # either configuration values from Apache or from some config file
        packet.add_command(RTS_CMD_VERSION, 1)
        packet.add_command(RTS_CMD_RECEIVE_WINDOW_SIZE, self.in_window_size)
        packet.add_command(RTS_CMD_CONNECTION_TIMEOUT, self.in_conn_timeout)
        self.bytes_written = self.bytes_written + packet.size

        return packet.make()
Example #10
0
    def _send_flow_control_ack(self):
        """Send FlowControlAckWithDestination RTS command to say the client there
        is room for sending more information"""
        self.logger.debug('Send to client the FlowControlAckWithDestination RTS command '
                          'after %d of avalaible window size' % self.local_available_window)
        rts_packet = RPCRTSOutPacket(self.logger)
        # We always returns back the same available maximum received size
        rts_packet.add_command(RTS_CMD_DESTINATION, 0)  # Forward this to client
        rts_packet.add_command(RTS_CMD_FLOW_CONTROL_ACK,
                               {'bytes_received': self.rpc_pdu_bytes_received,  # Only RPC PDUs are subject to flow control
                                'available_window': self.window_size,
                                'channel_cookie': self.channel_cookie})

        # Send the message to the OUT channel
        self.unix_socket.sendall(rts_packet.make())
Example #11
0
    def _send_flow_control_ack(self):
        """Send FlowControlAckWithDestination RTS command to say the client there
        is room for sending more information"""
        self.logger.debug(
            'Send to client the FlowControlAckWithDestination RTS command '
            'after %d of avalaible window size' % self.local_available_window)
        rts_packet = RPCRTSOutPacket(self.logger)
        # We always returns back the same available maximum received size
        rts_packet.add_command(RTS_CMD_DESTINATION,
                               0)  # Forward this to client
        rts_packet.add_command(
            RTS_CMD_FLOW_CONTROL_ACK,
            {
                'bytes_received': self.
                rpc_pdu_bytes_received,  # Only RPC PDUs are subject to flow control
                'available_window': self.window_size,
                'channel_cookie': self.channel_cookie
            })

        # Send the message to the OUT channel
        self.unix_socket.sendall(rts_packet.make())
Example #12
0
    def sequence(self, environ, start_response):
        self.logger.debug("processing request")
        if "REMOTE_PORT" in environ:
            self.logger.debug("remote port = %s" % environ["REMOTE_PORT"])
        # self.logger.debug("path: ' + self.path)

        content_length = int(environ["CONTENT_LENGTH"])
        self.logger.debug("request size is %d" % content_length)

        # echo request
        if content_length <= 0x10:
            for data in self.handle_echo_request(environ, start_response):
                yield data
            self.logger.debug("exiting from echo request")
        elif content_length >= 128:
            self.logger.debug("processing IN channel request")

            self.client_socket = environ["wsgi.input"]

            try:
                self._receive_conn_b1()
                connected = True
            except IOError as e:
                self.logger.debug("handling socker.error")
                self.logger.exception(e)
                self.logger.error("client connection closed")
                connected = False

            if connected:
                connected = self._connect_to_OUT_channel()

            if connected:
                start_response("200 Success",
                               [("Content-Type", "application/rpc"),
                                ("Content-length", "0")])
                self._runloop()

                # shutting down sockets
                self.logger.debug("notifying OUT channel of shutdown")
                try:
                    packet = RPCRTSOutPacket(self.logger)
                    packet.add_command(RTS_CMD_CUSTOM_OUT)
                    self.unix_socket.sendall(packet.make())
                    _safe_close(self.unix_socket)
                    self.logger.debug("OUT channel successfully notified")
                except socket_error:
                    self.logger.debug(
                        "(OUT channel already shutdown the unix socket)")
                    # OUT channel already closed the connection
                    pass

                _safe_close(self.oc_conn)

            self.log_connection_stats()
            self.logger.debug("exiting from main sequence")

            # TODO: error handling
            start_response("200 Success",
                           [("Content-length", "0"),
                            ("Content-Type", "application/rpc")])
            yield ""
        else:
            raise Exception("This content-length is not handled")