Example #1
0
def pick_proxy_and_forward(client):
    global dns_polluted_at
    if lan_ip.is_lan_ip(client.dst_ip):
        try:
            DIRECT_PROXY.forward(client)
        except ProxyFallBack:
            pass
        return
    if client.dst_ip in fqdns.WRONG_ANSWERS:
        LOGGER.error('[%s] destination is GFW wrong answer' % repr(client))
        dns_polluted_at = time.time()
        NONE_PROXY.forward(client)
        return
    data_peeked = False
    if china_shortcut_enabled:
        china_dst = False
        if china_ip.is_china_ip(client.dst_ip):
            china_dst = True
        else:
            peek_data(client)
            data_peeked = True
            if client.host:
                china_dst = fqdns.is_china_domain(client.host)
        if china_dst:
            try:
                DIRECT_PROXY.forward(client)
            except ProxyFallBack:
                pass
            return
    if not data_peeked:
        peek_data(client)
    for i in range(3):
        try:
            proxy = pick_proxy(client)
        except NotHttp:
            return  # give up
        if not proxy:
            raise NoMoreProxy()
        if 'DIRECT' in proxy.flags:
            LOGGER.debug('[%s] picked proxy: %s' % (repr(client), repr(proxy)))
        else:
            LOGGER.info('[%s] picked proxy: %s' % (repr(client), repr(proxy)))
        try:
            proxy.forward(client)
            return
        except ProxyFallBack as e:
            if not e.silently:
                LOGGER.error('[%s] fall back to other proxy due to %s: %s' %
                             (repr(client), e.reason, repr(proxy)))
            client.tried_proxies[proxy] = e.reason
        except NotHttp:
            return  # give up
    raise NoMoreProxy()
Example #2
0
def pick_proxy_and_forward(client):
    global dns_polluted_at
    if lan_ip.is_lan_traffic(client.src_ip, client.dst_ip):
        try:
            DIRECT_PROXY.forward(client)
        except ProxyFallBack:
            pass
        return
    if client.dst_ip in fqdns.WRONG_ANSWERS:
        LOGGER.error('[%s] destination is GFW wrong answer' % repr(client))
        dns_polluted_at = time.time()
        NONE_PROXY.forward(client)
        return
    if china_shortcut_enabled and china_ip.is_china_ip(client.dst_ip):
        try:
            DIRECT_PROXY.forward(client)
        except ProxyFallBack:
            pass
        return
    if should_fix():
        gevent.spawn(fix_by_refreshing_proxies)
    peek_data(client)
    if china_shortcut_enabled and client.host and fqdns.is_china_domain(client.host):
        try:
            DIRECT_PROXY.forward(client)
        except ProxyFallBack:
            pass
        return
    for i in range(3):
        proxy = pick_proxy(client)
        if not proxy:
            raise NoMoreProxy()
        if 'DIRECT' in proxy.flags:
            LOGGER.debug('[%s] picked proxy: %s' % (repr(client), repr(proxy)))
        else:
            LOGGER.info('[%s] picked proxy: %s' % (repr(client), repr(proxy)))
        try:
            proxy.forward(client)
            return
        except ProxyFallBack as e:
            if not e.silently:
                LOGGER.error('[%s] fall back to other proxy due to %s: %s' % (repr(client), e.reason, repr(proxy)))
            client.tried_proxies[proxy] = e.reason
        except NotHttp:
            try:
                return DIRECT_PROXY.forward(client)
            except client.ProxyFallBack:
                return # give up
    raise NoMoreProxy()
Example #3
0
def is_china_dst(client):
    if china_ip.is_china_ip(client.dst_ip):
        return True
    if client.host and fqdns.is_china_domain(client.host):
        return True
    return False
Example #4
0
def is_china_dst(client):
    if china_ip.is_china_ip(client.dst_ip):
        return True
    if client.host and fqdns.is_china_domain(client.host):
        return True
    return False