Example #1
0
        else:
            logging.debug("!backend: no request message, closing")
    except AssertionError:
        logging.debug("!backend: invalid protocol, closing")

@metrics.time_calls(name='control_conn')
def handle_control_request(socket, request):
    try:
        tunnel = Tunnel.get_by_control_request(request)
    except RuntimeError, e:
        protocol.send_message(socket, error_reply('notavailable'))
        socket.close()
        return
    protocol.send_message(socket, protocol.control_reply(
        host=HOST_TEMPLATE.format(tunnel.name),
        banner=BANNER,
        concurrency=Tunnel.max_pool_size,
    ))
    logging.info("created tunnel:\"{0}\" by client:\"{1}\"".format(
            tunnel.name, tunnel.client))

    try:
        while True:
            eventlet.sleep(HEARTBEAT_INTERVAL)
            protocol.send_message(socket, protocol.control_ping())
            with Timeout(HEARTBEAT_INTERVAL):
                message = protocol.recv_message(socket)
                assert message == protocol.control_pong()
    except (IOError, AssertionError, Timeout):
        logging.debug("expiring tunnel:\"{0}\"".format(tunnel.name))
        tunnel.destroy()
Example #2
0
        logging.debug("!backend: invalid protocol, closing")


@metrics.time_calls(name="control_conn")
def handle_control_request(socket, request):
    try:
        tunnel = Tunnel.get_by_control_request(request)
    except RuntimeError, e:
        protocol.send_message(socket, protocol.error_reply("notavailable"))
        socket.close()
        return
    protocol.send_message(
        socket,
        protocol.control_reply(
            host=HOST_TEMPLATE.format(tunnel.name, Tunnel.domain_suffix),
            banner=BANNER,
            concurrency=Tunnel.max_pool_size,
        ),
    )
    logging.info('created tunnel:"{0}" by client:"{1}"'.format(tunnel.name, tunnel.client))

    try:
        while True:
            eventlet.sleep(HEARTBEAT_INTERVAL)
            protocol.send_message(socket, protocol.control_ping())
            with Timeout(HEARTBEAT_INTERVAL):
                message = protocol.recv_message(socket)
                assert message == protocol.control_pong()
    except (IOError, AssertionError, Timeout):
        logging.debug('expiring tunnel:"{0}"'.format(tunnel.name))
        tunnel.destroy()
Example #3
0
    except AssertionError:
        logging.debug("!backend: invalid protocol, closing")


def handle_control(socket, request):
    try:
        tunnel = Tunnel.get_by_control_request(request)
    except RuntimeError, e:
        protocol.send_message(socket, error_reply('notavailable'))
        socket.close()
        return
    protocol.send_message(
        socket,
        protocol.control_reply(
            host=HOST_TEMPLATE.format(tunnel.name),
            banner=BANNER,
            concurrency=Tunnel.max_pool_size,
        ))
    logging.info("created tunnel:\"{0}\" by client:\"{1}\"".format(
        tunnel.name, tunnel.client))

    try:
        while True:
            eventlet.sleep(HEARTBEAT_INTERVAL)
            protocol.send_message(socket, protocol.control_ping())
            with Timeout(HEARTBEAT_INTERVAL):
                message = protocol.recv_message(socket)
                assert message == protocol.control_pong()
    except (IOError, AssertionError, Timeout):
        logging.debug("expiring tunnel:\"{0}\"".format(tunnel.name))
        tunnel.destroy()
Example #4
0
        else:
            logging.debug("!backend: no request message, closing")
    except AssertionError:
        logging.debug("!backend: invalid protocol, closing")

@metrics.time_calls(name='control_conn')
def handle_control_request(socket, request):
    try:
        tunnel = Tunnel.get_by_control_request(request)
    except RuntimeError, e:
        protocol.send_message(socket, protocol.error_reply('notavailable'))
        socket.close()
        return
    protocol.send_message(socket, protocol.control_reply(
        host=HOST_TEMPLATE.format(tunnel.name, Tunnel.domain_suffix),
        banner=BANNER,
        concurrency=Tunnel.max_pool_size,
    ))
    logging.info("created tunnel:\"{0}\" by client:\"{1}\"".format(
            tunnel.name, tunnel.client))

    try:
        while True:
            eventlet.sleep(HEARTBEAT_INTERVAL)
            protocol.send_message(socket, protocol.control_ping())
            with Timeout(HEARTBEAT_INTERVAL):
                message = protocol.recv_message(socket)
                assert message == protocol.control_pong()
    except (IOError, AssertionError, Timeout):
        logging.debug("expiring tunnel:\"{0}\"".format(tunnel.name))
        tunnel.destroy()