Example #1
0
def run():
    global proc_handler, ready, dns_srv, g, redirect_srv

    if not proc_handler:
        return False

    load_config()

    if "gae_proxy" in proc_handler:
        g.gae_proxy = proc_handler["gae_proxy"]["imp"].local
    else:
        xlog.debug("gae_proxy not running")

    if "x_tunnel" in proc_handler:
        g.x_tunnel = proc_handler["x_tunnel"]["imp"].local
    else:
        xlog.debug("x_tunnel not running")

    redirect_srv = redirect_server.RedirectHandler(bind_ip=g.config.bind_ip,
                                                   port=g.config.redirect_port,
                                                   handler=redirect_handler)
    redirect_srv.start()

    dns_srv = dns_server.DnsServer(bind_ip=g.config.bind_ip,
                                   port=g.config.dns_port,
                                   query_cb=remote_query_dns,
                                   cache_size=g.config.cache_size,
                                   ttl=g.config.ttl)
    ready = True
    dns_srv.server_forever()
Example #2
0
def run(args):
    global proc_handler, ready, g

    if not proc_handler:
        return False

    if "gae_proxy" in proc_handler:
        g.gae_proxy = proc_handler["gae_proxy"]["imp"].local
    else:
        xlog.debug("gae_proxy not running")

    if "x_tunnel" in proc_handler:
        g.x_tunnel = proc_handler["x_tunnel"]["imp"].local
    else:
        xlog.debug("x_tunnel not running")

    load_config()
    g.gfwlist = gfwlist.GfwList()
    g.ip_region = ip_region.IpRegion()

    g.domain_cache = host_records.DomainRecords(
        os.path.join(data_path, "domain_records.txt"),
        capacity=g.config.dns_cache_size,
        ttl=g.config.dns_ttl)
    g.ip_cache = host_records.IpRecord(os.path.join(data_path,
                                                    "ip_records.txt"),
                                       capacity=g.config.ip_cache_size)

    g.user_rules = user_rules.Config()

    connect_manager.load_proxy_config()
    g.connect_manager = connect_manager.ConnectManager()
    g.pipe_socks = pipe_socks.PipeSocks(g.config.pip_cache_size)
    g.pipe_socks.run()
    g.dns_client = dns_server.DnsClient()

    allow_remote = args.get("allow_remote", 0)
    if allow_remote:
        listen_ip = "0.0.0.0"
    else:
        listen_ip = g.config.proxy_bind_ip
    g.proxy_server = simple_http_server.HTTPServer(
        (listen_ip, g.config.proxy_port),
        proxy_handler.ProxyServer,
        logger=xlog)
    g.proxy_server.start()
    xlog.info("Proxy server listen:%s:%d.", listen_ip, g.config.proxy_port)

    allow_remote = args.get("allow_remote", 0)
    if allow_remote:
        listen_ip = "0.0.0.0"
    else:
        listen_ip = g.config.dns_bind_ip
    g.dns_srv = dns_server.DnsServer(bind_ip=listen_ip,
                                     port=g.config.dns_port,
                                     backup_port=g.config.dns_backup_port,
                                     ttl=g.config.dns_ttl)
    ready = True
    g.dns_srv.server_forever()