Пример #1
0
    def __init__(self):
        self.logger = logger
        config_path = os.path.join(module_data_path, "heroku_front.json")
        self.config = Config(config_path)

        ca_certs = os.path.join(current_path, "cacert.pem")
        self.host_manager = host_manager.HostManager(self.logger,
                                                     self.config.appids)

        openssl_context = SSLContext(logger, ca_certs=ca_certs)
        self.connect_creator = ConnectCreator(logger, self.config,
                                              openssl_context,
                                              self.host_manager)
        self.check_ip = CheckIp(xlog.null, self.config, self.connect_creator)

        ip_source = None
        default_ip_list_fn = os.path.join(current_path, "good_ip.txt")
        ip_list_fn = os.path.join(module_data_path, "heroku_ip_list.txt")
        self.ip_manager = IpManager(logger,
                                    self.config,
                                    ip_source,
                                    check_local_network,
                                    self.check_ip.check_ip,
                                    default_ip_list_fn,
                                    ip_list_fn,
                                    scan_ip_log=None)

        self.connect_manager = ConnectManager(logger, self.config,
                                              self.connect_creator,
                                              self.ip_manager,
                                              check_local_network)
        self.http_dispatcher = HttpsDispatcher(logger, self.config,
                                               self.ip_manager,
                                               self.connect_manager)
Пример #2
0
    def __init__(self):
        self.success_num = 0
        self.fail_num = 0
        self.continue_fail_num = 0
        self.last_fail_time = 0
        self.running = True

        self.logger = logger
        config_path = os.path.join(module_data_path, "tls_relay.json")
        self.config = Config(config_path)

        self.ca_cert_fn = os.path.join(module_data_path, "tls_relay_CA.crt")
        self.openssl_context = SSLContext(logger)
        if os.path.isfile(self.ca_cert_fn):
            self.openssl_context.set_ca(self.ca_cert_fn)

        host_fn = os.path.join(module_data_path, "tls_host.json")
        self.host_manager = host_manager.HostManager(host_fn)

        self.connect_creator = ConnectCreator(logger, self.config,
                                              self.openssl_context,
                                              self.host_manager)
        self.check_ip = CheckIp(xlog.null, self.config, self.connect_creator)

        ip_source = IpSimpleSource(self.config.ip_source_ips)

        default_ip_list_fn = ""
        ip_list_fn = os.path.join(module_data_path, "tls_relay_ip_list.txt")
        self.ip_manager = IpManager(logger,
                                    self.config,
                                    ip_source,
                                    check_local_network,
                                    self.check_ip.check_ip,
                                    default_ip_list_fn,
                                    ip_list_fn,
                                    scan_ip_log=None)
        for ip in self.config.ip_source_ips:
            self.ip_manager.add_ip(ip, 100)

        self.connect_manager = ConnectManager(logger, self.config,
                                              self.connect_creator,
                                              self.ip_manager,
                                              check_local_network)
        self.http_dispatcher = HttpsDispatcher(logger, self.config,
                                               self.ip_manager,
                                               self.connect_manager)

        self.rtts = collections.deque([(0, time.time())])
        self.rtts_lock = threading.Lock()
        self.traffics = collections.deque()
        self.traffics_lock = threading.Lock()
        self.recent_sent = 0
        self.recent_received = 0
        self.total_sent = 0
        self.total_received = 0

        self.account = ""
        self.password = ""

        threading.Thread(target=self.debug_data_clearup_thread).start()
Пример #3
0
    def get_dispatcher(self, host):
        if host not in self.dispatchs:
            http_dispatcher = HttpsDispatcher(logger, config, front.ip_manager,
                                              self.connect_manager)
            self.dispatchs[host] = http_dispatcher

        return self.dispatchs[host]
Пример #4
0
 def init_host_dispatcher(self, host):
     if host not in self.dispatchs:
         http_dispatcher = HttpsDispatcher(
             logger,
             self.config,
             self.ip_manager,
             self.connect_manager,
             http2worker=CloudflareHttp2Worker)
         self.dispatchs[host] = http_dispatcher
Пример #5
0
    def __init__(self):
        self.running = True

        self.logger = logger
        self.config = config

        self.host_manager = host_manager.HostManager(self.config, logger)

        ca_certs = os.path.join(current_path, "cacert.pem")
        self.openssl_context = SSLContext(
            logger,
            ca_certs=ca_certs,
            support_http2=config.support_http2,
            cipher_suites=[
                'ALL', "!RC4-SHA", "!ECDHE-RSA-RC4-SHA",
                "!ECDHE-RSA-AES128-GCM-SHA256", "!AES128-GCM-SHA256",
                "!ECDHE-RSA-AES128-SHA", "!AES128-SHA"
            ])
        self.connect_creator = ConnectCreator(logger, self.config,
                                              self.openssl_context,
                                              self.host_manager)

        self.appid_manager = AppidManager(self.config, logger)

        self.host_manager.appid_manager = self.appid_manager

        self.check_ip = CheckIp(xlog.null, self.config, self.connect_creator)

        self.ipv4_source = Ipv4RangeSource(
            logger, self.config, os.path.join(current_path, "ip_range.txt"),
            os.path.join(module_data_path, "ip_range.txt"))
        self.ipv6_source = Ipv6PoolSource(
            logger, self.config, os.path.join(current_path, "ipv6_list.txt"))
        self.ip_source = IpCombineSource(logger, self.config, self.ipv4_source,
                                         self.ipv6_source)
        self.ip_manager = IpManager(logger,
                                    self.config,
                                    self.ip_source,
                                    check_local_network,
                                    self.check_ip.check_ip,
                                    None,
                                    os.path.join(module_data_path,
                                                 "good_ip.txt"),
                                    scan_ip_log=None)

        self.appid_manager.check_api = self.check_ip.check_ip
        self.appid_manager.ip_manager = self.ip_manager

        self.connect_manager = ConnectManager(logger, self.config,
                                              self.connect_creator,
                                              self.ip_manager,
                                              check_local_network)

        self.http_dispatcher = HttpsDispatcher(logger, self.config,
                                               self.ip_manager,
                                               self.connect_manager)
Пример #6
0
    def get_dispatcher(self, host=None):
        if host is None:
            host = self.last_host
        else:
            self.last_host = host

        if host not in self.dispatchs:
            http_dispatcher = HttpsDispatcher(
                logger, self.config, self.ip_manager, self.connect_manager
            )
            self.dispatchs[host] = http_dispatcher

        dispatcher = self.dispatchs[host]
        return dispatcher
Пример #7
0
    def __init__(self):
        self.running = True

        self.logger = logger
        config_path = os.path.join(module_data_path, "tls_relay.json")
        self.config = Config(config_path)

        self.ca_cert_fn = os.path.join(module_data_path, "tls_relay_CA.crt")
        self.openssl_context = SSLContext(logger)
        if os.path.isfile(self.ca_cert_fn):
            self.openssl_context.set_ca(self.ca_cert_fn)

        if not os.path.isdir(module_data_path):
            os.mkdir(module_data_path)

        if not os.path.isdir(tls_certs_path):
            os.mkdir(tls_certs_path)

        host_fn = os.path.join(module_data_path, "tls_host.json")
        self.host_manager = host_manager.HostManager(host_fn)

        self.connect_creator = connect_creator.ConnectCreator(
            logger, self.config, self.openssl_context, self.host_manager)
        self.check_ip = CheckIp(xlog.null, self.config, self.connect_creator)

        ip_source = IpSimpleSource(self.config.ip_source_ips)

        default_ip_list_fn = ""
        ip_list_fn = os.path.join(module_data_path, "tls_relay_ip_list.txt")
        self.ip_manager = IpManager(logger,
                                    self.config,
                                    ip_source,
                                    check_local_network,
                                    self.check_ip.check_ip,
                                    default_ip_list_fn,
                                    ip_list_fn,
                                    scan_ip_log=None)
        for ip in self.config.ip_source_ips:
            self.ip_manager.add_ip(ip, 100)

        self.connect_manager = ConnectManager(logger, self.config,
                                              self.connect_creator,
                                              self.ip_manager,
                                              check_local_network)
        self.http_dispatcher = HttpsDispatcher(logger, self.config,
                                               self.ip_manager,
                                               self.connect_manager)

        self.account = ""
        self.password = ""
Пример #8
0
    def __init__(self):
        self.logger = logger
        config_path = os.path.join(module_data_path, "heroku_front.json")
        self.config = Config(config_path)

        ca_certs = os.path.join(current_path, "cacert.pem")
        self.host_manager = host_manager.HostManager(self.config.appids)

        openssl_context = SSLContext(logger, ca_certs=ca_certs)
        self.connect_creator = ConnectCreator(logger, self.config,
                                              openssl_context,
                                              self.host_manager)
        self.check_ip = CheckIp(xlog.null, self.config, self.connect_creator)

        ip_source = None
        default_ip_list_fn = os.path.join(current_path, "good_ip.txt")
        ip_list_fn = os.path.join(module_data_path, "heroku_ip_list.txt")
        self.ip_manager = IpManager(logger,
                                    self.config,
                                    ip_source,
                                    check_local_network,
                                    self.check_ip.check_ip,
                                    default_ip_list_fn,
                                    ip_list_fn,
                                    scan_ip_log=None)

        self.connect_manager = ConnectManager(logger, self.config,
                                              self.connect_creator,
                                              self.ip_manager,
                                              check_local_network)
        self.http_dispatcher = HttpsDispatcher(logger, self.config,
                                               self.ip_manager,
                                               self.connect_manager)

        self.success_num = 0
        self.fail_num = 0
        self.continue_fail_num = 0
        self.last_fail_time = 0
        self.running = True

        self.rtts = collections.deque([(0, time.time())])
        self.rtts_lock = threading.Lock()
        self.traffics = collections.deque()
        self.traffics_lock = threading.Lock()
        self.recent_sent = 0
        self.recent_received = 0
        self.total_sent = 0
        self.total_received = 0

        threading.Thread(target=self.debug_data_clearup_thread).start()
Пример #9
0
    def start(self):
        self.running = True

        ca_certs = os.path.join(current_path, "cacert.pem")
        self.openssl_context = SSLContext(
            logger,
            ca_certs=ca_certs,
            support_http2=config.support_http2,
            cipher_suites=[
                'ALL', "!RC4-SHA", "!ECDHE-RSA-RC4-SHA",
                "!ECDHE-RSA-AES128-GCM-SHA256", "!AES128-GCM-SHA256",
                "!ECDHE-RSA-AES128-SHA", "!AES128-SHA"
            ])

        self.appid_manager = AppidManager(self.config, logger)

        self.host_manager = host_manager.HostManager(self.config, logger)
        self.host_manager.appid_manager = self.appid_manager

        self.connect_creator = ConnectCreator(logger, self.config,
                                              self.openssl_context,
                                              self.host_manager)

        #self.ip_checker = CheckIp(logger, self.config, self.connect_creator)

        self.ipv6_source = Ipv6PoolSource(logger, self.config, "ipv6_list.txt")
        self.ip_source = self.ipv6_source
        self.ip_manager = IpManager(logger,
                                    self.config,
                                    self.ip_source,
                                    check_local_network,
                                    None,
                                    os.path.join(data_path, "good_ip.txt"),
                                    scan_ip_log=None)

        #self.appid_manager.check_api = self.ip_checker.check_ip
        self.appid_manager.ip_manager = self.ip_manager

        self.connect_manager = ConnectManager(logger, self.config,
                                              self.connect_creator,
                                              self.ip_manager,
                                              check_local_network)

        self.http_dispatcher = HttpsDispatcher(logger, self.config,
                                               self.ip_manager,
                                               self.connect_manager)
Пример #10
0
    def start(self):
        self.running = True

        ca_certs = 'cacert.pem'
        self.openssl_context = SSLContext(
            logger,
            ca_certs=ca_certs,
            support_http2=config.support_http2,
            protocol="TLSv1_2"
            #cipher_suites=[b'ALL', b"!RC4-SHA", b"!ECDHE-RSA-RC4-SHA", b"!ECDHE-RSA-AES128-GCM-SHA256",
            #               b"!AES128-GCM-SHA256", b"!ECDHE-RSA-AES128-SHA", b"!AES128-SHA"]
        )

        self.appid_manager = AppidManager(self.config, logger)

        self.host_manager = host_manager.HostManager(self.config, logger)
        self.host_manager.appid_manager = self.appid_manager

        self.connect_creator = ConnectCreator(logger, self.config,
                                              self.openssl_context,
                                              self.host_manager)

        # self.ip_checker = CheckIp(xlog.null, self.config, self.connect_creator)

        self.ip_manager = IpManager(logger,
                                    self.config,
                                    check_local_network,
                                    None,
                                    'good_ip.txt',
                                    scan_ip_log=None)

        # self.appid_manager.check_api = self.ip_checker.check_ip
        self.appid_manager.ip_manager = self.ip_manager

        self.connect_manager = ConnectManager(logger, self.config,
                                              self.connect_creator,
                                              self.ip_manager,
                                              check_local_network)

        self.http_dispatcher = HttpsDispatcher(logger, self.config,
                                               self.ip_manager,
                                               self.connect_manager)
Пример #11
0
    def get_dispatcher(self, host=None):
        if not host:
            host = self.last_host
        else:
            self.last_host = host

        if host not in self.dispatchs:
            if host in ["center.xx-net.org", "dns.xx-net.org"]:
                config = self.light_config
            else:
                config = self.config

            http_dispatcher = HttpsDispatcher(
                logger,
                config,
                self.ip_manager,
                self.connect_manager,
                http2worker=CloudflareHttp2Worker)
            self.dispatchs[host] = http_dispatcher

        dispatcher = self.dispatchs[host]
        return dispatcher