shadowsocks-android
ea738d17d717
Refine #1217
Mygod
4 days ago

313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 313 314 315 316 317 318 319 320 321 322
.put("plugin_opts", plugin.toString) IOUtils.writeString(new File(getFilesDir, file), config.toString) file }
private final def buildRemoteDns(remoteDns: String): String = { val addr = InetAddress.getByName(remoteDns) if (addr.isInstanceOf[Inet6Address]) return "[" + remoteDns + "]" remoteDns }
protected final def buildOvertureConfig(file: String): String = { val config = new JSONObject() .put("BindAddress", ":" + (profile.localPort + 53)) .put("RedirectIPv6Record", true) .put("DomainBase64Decode", true)
...
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
.put("MinimumTTL", 3600) .put("CacheSize", 4096) def makeDns(name: String, address: String, edns: Boolean = true) = { val dns = new JSONObject() .put("Name", name)
.put("Address", address + ":53")
.put("Address", (Utils.parseNumericAddress(address) match { case _: Inet6Address => '[' + address + ']' case _ => address }) + ":53")
.put("Timeout", 6) .put("EDNSClientSubnet", new JSONObject().put("Policy", "disable")) if (edns) dns .put("Protocol", "tcp") .put("Socks5Address", "127.0.0.1:" + profile.localPort) else dns.put("Protocol", "udp") dns }
val remoteDns = new JSONArray(profile.remoteDns.split(",").zipWithIndex.map { case (dns, i) => makeDns("UserDef-" + i, dns.trim) })
profile.route match { case Acl.BYPASS_CHN | Acl.BYPASS_LAN_CHN | Acl.GFWLIST | Acl.CUSTOM_RULES => config .put("PrimaryDNS", new JSONArray(Array( makeDns("Primary-1", "119.29.29.29", edns = false), makeDns("Primary-2", "114.114.114.114", edns = false) )))
.put("AlternativeDNS", new JSONArray( for (remoteDns <- profile.remoteDns.split(",")) yield makeDns(remoteDns.trim, buildRemoteDns(remoteDns.trim) )))
.put("AlternativeDNS", remoteDns)
.put("IPNetworkFile", "china_ip_list.txt") .put("DomainFile", "gfwlist.txt") case Acl.CHINALIST => config .put("PrimaryDNS", new JSONArray().put(makeDns("Primary", "119.29.29.29")))
.put("AlternativeDNS", new JSONArray( for (remoteDns <- profile.remoteDns.split(",")) yield makeDns(remoteDns.trim, buildRemoteDns(remoteDns.trim) )))
.put("AlternativeDNS", remoteDns)
case _ => config
.put("PrimaryDNS", new JSONArray( for (remoteDns <- profile.remoteDns.split(",")) yield makeDns(remoteDns.trim, buildRemoteDns(remoteDns.trim) )))
.put("PrimaryDNS", new JSONArray(remoteDns))
// no need to setup AlternativeDNS in Acl.ALL/BYPASS_LAN mode .put("OnlyPrimaryDNS", true) } IOUtils.writeString(new File(getFilesDir, file), config.toString) file

72 73 74 75 76 77 78 79 80 81 82 72 73 74 75 76 77 78 79 80 81 82
def startDNSTunnel() { val cmd = ArrayBuffer[String](getApplicationInfo.nativeLibraryDir + "/libss-tunnel.so", "-t", "10", "-b", "127.0.0.1", "-l", (profile.localPort + 63).toString,
"-L", profile.remoteDns.split(",")(0).trim + ":53",
"-L", profile.remoteDns.split(",").head.trim + ":53",
"-c", buildShadowsocksConfig("ss-tunnel-nat.conf")) if (profile.udpdns) cmd.append("-u") sstunnelProcess = new GuardedProcess(cmd: _*).start()

20 21 22 23 24 25 26 27 28 29 30 31 20 21 22 23 24 25 26 27 28 29
package com.github.shadowsocks import java.io.File import java.util.Locale
import java.net.InetAddress import java.net.Inet6Address
import android.content._ import android.content.pm.PackageManager.NameNotFoundException import android.net.VpnService import android.os._
...
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 219 220 221 222 223 224 225 226 227 228 229 230
} else { getResources.getStringArray(R.array.bypass_private_route).foreach(cidr => { val subnet = Subnet.fromString(cidr) builder.addRoute(subnet.address.getHostAddress, subnet.prefixSize) })
profile.remoteDns.split(",").foreach(remoteDns => { val addr = InetAddress.getByName(remoteDns.trim) if (addr.isInstanceOf[Inet6Address]) builder.addRoute(addr, 128) else if (addr.isInstanceOf[InetAddress]) builder.addRoute(addr, 32) })
profile.remoteDns.split(",").map(dns => Utils.parseNumericAddress(dns.trim)).foreach(dns => builder.addRoute(dns, dns.getAddress.length << 3))
} conn = builder.establish() if (conn == null) throw new NullConnectionException
About FluentSend Feedback