resolve chinese domain names directly

This commit is contained in:
Max Lv
2014-04-06 10:56:46 +08:00
parent 1b2247a86e
commit 0fa4d150bf
5 changed files with 78 additions and 14 deletions
+2 -2
View File
@@ -5,8 +5,8 @@ import sbtandroid._
import sbtandroid.AndroidPlugin._
object App {
val version = "2.1.3"
val versionCode = 64
val version = "2.1.4"
val versionCode = 65
}
object General {
File diff suppressed because one or more lines are too long
@@ -118,7 +118,12 @@ class ShadowsocksNatService extends Service with BaseService {
Path.BASE + "ss-local.pid")
.format(config.proxy, config.remotePort, 8153, config.sitekey, config.encMethod)
} else {
val conf = ConfigUtils.PDNSD.format("127.0.0.1")
val conf = {
if (config.isGFWList)
ConfigUtils.PDNSD_BYPASS.format("127.0.0.1", getString(R.string.exclude))
else
ConfigUtils.PDNSD.format("127.0.0.1")
}
ConfigUtils.printToFile(new File(Path.BASE + "pdnsd.conf"))(p => {
p.println(conf)
})
@@ -306,6 +311,11 @@ class ShadowsocksNatService extends Service with BaseService {
init_sb.append(cmd_bypass.replace("-d 0.0.0.0", "-d " + config.proxy))
}
init_sb.append(cmd_bypass.replace("0.0.0.0", "127.0.0.1"))
if (config.isGFWList) {
// Bypass DNS in China
init_sb.append(cmd_bypass.replace("-p tcp -d 0.0.0.0", "-d 114.114.114.114"))
init_sb.append(cmd_bypass.replace("-p tcp -d 0.0.0.0", "-d 114.114.115.115"))
}
if (hasRedirectSupport) {
init_sb
.append(Utils.getIptables + " -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to "
@@ -75,6 +75,11 @@ class ShadowsocksVpnService extends VpnService with BaseService {
val handler: Handler = new Handler()
def isByass(net: SubnetUtils): Boolean = {
val info = net.getInfo
info.isInRange(config.proxy) || info.isInRange("114.114.114.114") || info.isInRange("114.114.115.115")
}
def startShadowsocksDaemon() {
val cmd: String = (Path.BASE +
"ss-local -b 127.0.0.1 -s \"%s\" -p \"%d\" -l \"%d\" -k \"%s\" -m \"%s\" -u -f " +
@@ -85,7 +90,12 @@ class ShadowsocksVpnService extends VpnService with BaseService {
}
def startDnsDaemon() {
val conf = ConfigUtils.PDNSD.format("0.0.0.0")
val conf = {
if (config.isGFWList)
ConfigUtils.PDNSD_BYPASS.format("0.0.0.0", getString(R.string.exclude))
else
ConfigUtils.PDNSD.format("0.0.0.0")
}
ConfigUtils.printToFile(new File(Path.BASE + "pdnsd.conf"))(p => {
p.println(conf)
})
@@ -108,8 +118,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
def startVpn() {
val proxy_address = config.proxy
val builder = new Builder()
builder
.setSession(config.profileName)
@@ -128,8 +136,8 @@ class ShadowsocksVpnService extends VpnService with BaseService {
}
}
gfwList.foreach(cidr => {
val net = new SubnetUtils(cidr).getInfo
if (!net.isInRange(proxy_address)) {
val net = new SubnetUtils(cidr)
if (!isByass(net)) {
val addr = cidr.split('/')
builder.addRoute(addr(0), addr(1).toInt)
}
@@ -139,9 +147,9 @@ class ShadowsocksVpnService extends VpnService with BaseService {
if (i != 26 && i != 127) {
val addr = i.toString + ".0.0.0"
val cidr = addr + "/8"
val net = new SubnetUtils(cidr).getInfo
val net = new SubnetUtils(cidr)
if (!net.isInRange(proxy_address)) {
if (!isByass(net)) {
if (!InetAddress.getByName(addr).isSiteLocalAddress) {
builder.addRoute(addr, 8)
}
@@ -149,8 +157,8 @@ class ShadowsocksVpnService extends VpnService with BaseService {
for (j <- 0 to 255) {
val subAddr = i.toString + "." + j.toString + ".0.0"
val subCidr = subAddr + "/16"
val subNet = new SubnetUtils(subCidr).getInfo
if (!subNet.isInRange(proxy_address)) {
val subNet = new SubnetUtils(subCidr)
if (!isByass(subNet)) {
if (!InetAddress.getByName(subAddr).isSiteLocalAddress) {
builder.addRoute(subAddr, 16)
}
@@ -78,8 +78,49 @@ object ConfigUtils {
|}
|
|server {
| label = "root-servers";
| ip = 8.8.8.8, 8.8.4.4, 208.67.222.222, 208.67.220.220;
| label = "google-servers";
| ip = 8.8.8.8, 8.8.4.4;
| timeout = 5;
|}
|
|rr {
| name=localhost;
| reverse=on;
| a=127.0.0.1;
| owner=localhost;
| soa=localhost,root.localhost,42,86400,900,86400,86400;
|}
""".stripMargin
val PDNSD_BYPASS =
"""
|global {
| perm_cache = 2048;
| cache_dir = "/data/data/com.github.shadowsocks";
| server_ip = %s;
| server_port = 8153;
| query_method = tcp_only;
| run_ipv4 = on;
| min_ttl = 15m;
| max_ttl = 1w;
| timeout = 10;
| daemon = on;
| pid_file = "/data/data/com.github.shadowsocks/pdnsd.pid";
|}
|
|server {
| label = "china-servers";
| ip = 114.114.114.114, 114.114.115.115;
| uptest = none;
| preset = on;
| include = %s;
| policy = excluded;
| timeout = 3;
|}
|
|server {
| label = "google-servers";
| ip = 8.8.8.8, 8.8.4.4;
| timeout = 5;
|}
|