Example #1
0
    def start(self):
        self.ack_pool.reset()
        self.download_order_queue.reset()

        self.roundtrip_thread = {}

        self.session_id = utils.generate_random_lowercase(8)
        self.last_conn_id = 0
        self.last_transfer_no = 0
        self.conn_list = {}
        self.transfer_list = {}
        self.last_roundtrip_time = 0
        self.on_road_num = 0
        self.last_download_data_time = 0
        self.traffic = 0

        if not self.login_session():
            xlog.warn("x-tunnel login_session fail, session not start")
            return False

        self.last_roundtrip_time = time.time()
        self.running = True
        self.upload_task_queue.start()

        server_port = g.server_port
        for i in range(0, g.config.concurent_thread_num):
            if g.config.port_range > 1:
                server_port += 1
                if server_port > g.server_port + g.config.port_range:
                    server_port = g.server_port
            server_address = (g.server_host, server_port)
            self.roundtrip_thread[i] = threading.Thread(target=self.normal_roundtrip_worker, args=(server_address,))
            self.roundtrip_thread[i].daemon = True
            self.roundtrip_thread[i].start()
        return True
Example #2
0
    def __init__(self):
        self.wait_queue = base_container.WaitQueue()
        self.send_buffer = base_container.SendBuffer(
            max_payload=g.config.max_payload)
        self.receive_process = base_container.BlockReceivePool(
            self.download_data_processor)
        self.lock = threading.Lock(
        )  # lock for conn_id, sn generation, on_road_num change,

        self.send_delay = g.config.send_delay / 1000.0
        self.ack_delay = g.config.ack_delay / 1000.0
        self.resend_timeout = g.config.resend_timeout / 1000.0

        self.running = False
        self.roundtrip_thread = {}
        self.session_id = utils.generate_random_lowercase(8)
        self.last_conn_id = 0
        self.last_transfer_no = 0
        self.conn_list = {}
        self.transfer_list = {}
        self.on_road_num = 0
        self.last_receive_time = 0
        self.last_send_time = 0
        self.traffic = 0
        self.server_send_buf_size = 0
Example #3
0
    def __init__(self):
        self.wait_queue = base_container.WaitQueue()
        self.send_buffer = base_container.SendBuffer(max_payload=g.config.max_payload)
        self.receive_process = base_container.BlockReceivePool(self.download_data_processor)
        self.lock = threading.Lock()  # lock for conn_id, sn generation, on_road_num change,

        self.send_delay = g.config.send_delay / 1000.0
        self.ack_delay = g.config.ack_delay / 1000.0
        self.resend_timeout = g.config.resend_timeout / 1000.0

        self.running = False
        self.round_trip_thread = {}
        self.session_id = utils.generate_random_lowercase(8)
        self.last_conn_id = 0
        self.last_transfer_no = 0
        self.conn_list = {}
        self.transfer_list = {}
        self.on_road_num = 0
        self.last_receive_time = 0
        self.last_send_time = 0
        self.traffic = 0
        self.server_send_buf_size = 0
        self.target_on_roads = 0

        # the receive time of the tail of the socket receive buffer
        # if now - oldest_received_time > delay, then send.
        # set only no data in receive buffer
        # if no data left, set to 0
        self.oldest_received_time = 0

        self.last_state = {
            "timeout": 0,
        }
        if g.config.enable_tls_relay:
            threading.Thread(target=self.reporter).start()
    def start(self):
        self.ack_pool.reset()
        self.download_order_queue.reset()

        self.roundtrip_thread = {}

        self.session_id = utils.generate_random_lowercase(8)
        self.last_conn_id = 0
        self.last_transfer_no = 0
        self.conn_list = {}
        self.transfer_list = {}
        self.last_roundtrip_time = 0
        self.on_road_num = 0
        self.last_download_data_time = 0
        self.traffic = 0

        if not self.login_session():
            xlog.warn("x-tunnel session not start")
            return False

        self.running = True
        self.upload_task_queue.start()

        server_port = g.server_port
        for i in range(0, g.config.concurent_thread_num):
            if g.config.port_range > 1:
                server_port += 1
                if server_port > g.server_port + g.config.port_range:
                    server_port = g.server_port
            server_address = (g.server_host, server_port)
            self.roundtrip_thread[i] = threading.Thread(target=self.normal_roundtrip_worker, args=(server_address,))
            self.roundtrip_thread[i].daemon = True
            self.roundtrip_thread[i].start()
Example #5
0
    def __init__(self):
        self.wait_queue = base_container.WaitQueue()
        self.send_buffer = base_container.SendBuffer(max_payload=g.config.max_payload)
        self.receive_process = base_container.BlockReceivePool(self.download_data_processor)
        self.lock = threading.Lock()  # lock for conn_id, sn generation, on_road_num change,

        self.send_delay = g.config.send_delay / 1000.0
        self.ack_delay = g.config.ack_delay / 1000.0
        self.resend_timeout = g.config.resend_timeout / 1000.0

        self.running = False
        self.roundtrip_thread = {}
        self.session_id = utils.generate_random_lowercase(8)
        self.last_conn_id = 0
        self.last_transfer_no = 0
        self.conn_list = {}
        self.transfer_list = {}
        self.on_road_num = 0
        self.last_receive_time = 0
        self.last_send_time = 0
        self.traffic = 0
        self.server_send_buf_size = 0

        self.last_state = {
            "timeout": 0,
        }
        if g.config.enable_tls_relay:
            threading.Thread(target=self.reporter).start()
Example #6
0
    def __init__(self):
        self.upload_task_queue = base_container.BlockSendPool(max_payload=g.config.block_max_size, send_delay=0)
        self.ack_pool = base_container.AckPool()
        self.mutex = threading.Lock()  # lock for conn_id, sn generation, on_road_num change,
        self.download_order_queue = base_container.BlockReceivePool(process_callback=self.download_data_processor)

        self.running = False
        self.roundtrip_thread = {}
        self.session_id = utils.generate_random_lowercase(8)
        self.last_conn_id = 0
        self.last_transfer_no = 0
        self.conn_list = {}
        self.transfer_list = {}
        self.last_roundtrip_time = 0
        self.on_road_num = 0
        self.last_download_data_time = 0
        self.traffic = 0
Example #7
0
    def start(self):
        try:
            self.lock.acquire()
            if self.running is True:
                return True

            self.roundtrip_thread = {}

            self.session_id = utils.generate_random_lowercase(8)
            self.last_conn_id = 0
            self.last_transfer_no = 0
            self.conn_list = {}
            self.transfer_list = {}
            self.last_send_time = time.time()
            self.on_road_num = 0
            self.last_receive_time = 0
            self.traffic = 0

            # sn => (payload, send_time)
            # sn => acked
            self.unacked_send_list = {}
            self.acked_send_continue_sn = 0

            self.received_sn = []
            self.receive_next_sn = 1

            if not self.login_session():
                xlog.warn("x-tunnel login_session fail, session not start")
                return False

            self.running = True

            for i in range(0, g.config.concurent_thread_num):
                self.roundtrip_thread[i] = threading.Thread(
                    target=self.normal_roundtrip_worker)
                self.roundtrip_thread[i].daemon = True
                self.roundtrip_thread[i].start()
                time.sleep(0.2)

            self.timer_th = threading.Thread(target=self.timer)
            self.timer_th.daemon = True
            self.timer_th.start()
            xlog.info("session started.")
            return True
        finally:
            self.lock.release()
Example #8
0
    def __init__(self):
        self.upload_task_queue = base_container.BlockSendPool(max_payload=g.config.block_max_size, send_delay=0)
        self.ack_pool = base_container.AckPool()
        self.mutex = threading.Lock()  # lock for conn_id, sn generation, on_road_num change,
        self.download_order_queue = base_container.BlockReceivePool(process_callback=self.download_data_processor)

        self.running = False
        self.roundtrip_thread = {}
        self.session_id = utils.generate_random_lowercase(8)
        self.last_conn_id = 0
        self.last_transfer_no = 0
        self.conn_list = {}
        self.transfer_list = {}
        self.last_roundtrip_time = 0
        self.on_road_num = 0
        self.last_download_data_time = 0
        self.traffic = 0
Example #9
0
    def start(self):
        try:
            self.lock.acquire()
            if self.running is True:
                return True

            self.roundtrip_thread = {}

            self.session_id = utils.generate_random_lowercase(8)
            self.last_conn_id = 0
            self.last_transfer_no = 0
            self.conn_list = {}
            self.transfer_list = {}
            self.last_send_time = time.time()
            self.on_road_num = 0
            self.last_receive_time = 0
            self.traffic = 0

            # sn => (payload, send_time)
            # sn => acked
            self.unacked_send_list = {}
            self.acked_send_continue_sn = 0

            self.received_sn = []
            self.receive_next_sn = 1

            if not self.login_session():
                xlog.warn("x-tunnel login_session fail, session not start")
                return False

            self.running = True

            for i in range(0, g.config.concurent_thread_num):
                self.roundtrip_thread[i] = threading.Thread(target=self.normal_roundtrip_worker)
                self.roundtrip_thread[i].daemon = True
                self.roundtrip_thread[i].start()
                time.sleep(0.2)

            self.timer_th = threading.Thread(target=self.timer)
            self.timer_th.daemon = True
            self.timer_th.start()
            xlog.info("session started.")
            return True
        finally:
            self.lock.release()
Example #10
0
    def start(self):
        with self.lock:
            if self.running is True:
                xlog.warn("session try to run but is running.")
                return True

            self.round_trip_thread = {}

            self.session_id = utils.generate_random_lowercase(8)
            self.last_conn_id = 0
            self.last_transfer_no = 0
            self.conn_list = {}
            self.transfer_list = {}
            self.last_send_time = time.time()
            self.on_road_num = 0
            self.last_receive_time = 0
            self.traffic = 0

            # sn => (payload, send_time)
            # sn => ack
            self.wait_ack_send_list = dict()
            self.ack_send_continue_sn = 0

            self.received_sn = []
            self.receive_next_sn = 1
            self.target_on_roads = 0

            if not self.login_session():
                xlog.warn("x-tunnel login_session fail, session not start")
                return False

            self.running = True

            for i in range(0, g.config.concurent_thread_num):
                self.round_trip_thread[i] = threading.Thread(
                    target=self.normal_round_trip_worker, args=(i, ))
                self.round_trip_thread[i].daemon = True
                self.round_trip_thread[i].start()

            threading.Thread(target=self.timer).start()
            xlog.info("session started.")
            return True