Commit 34c09abb authored by chenhuaqing's avatar chenhuaqing Committed by hanakeichen

update dns server

parent 73965ce2
......@@ -17,8 +17,8 @@ object AccVpn {
val configContent = """
[General]
loglevel = trace
dns-server = 223.5.5.5
tun-fd = ${tunFd}
dns-server = 8.8.8.8
tun-fd = $tunFd
[Proxy]
Direct = direct
SS = ss, ${profile.host}, ${profile.remotePort}, encrypt-method=chacha20-ietf-poly1305, password=123456, auth_timeout=${profile.authTimeout}, beats_interval=${profile.beatsInterval}, retry_limit=${profile.retryLimit}, token=${profile.token}
......
/*******************************************************************************
* *
* Copyright (C) 2017 by Max Lv <max.c.lv@gmail.com> *
* Copyright (C) 2017 by Mygod Studio <contact-shadowsocks-android@mygod.be> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
package com.github.shadowsocks.bg
import android.system.ErrnoException
import android.system.Os
import android.system.OsConstants
import android.text.TextUtils
import timber.log.Timber
import java.io.File
import java.io.IOException
object Executable {
// const val REDSOCKS = "libredsocks.so"
const val SS_LOCAL = "libsslocal.so"
const val TUN2SOCKS = "libtun2socks.so"
private val EXECUTABLES = setOf(SS_LOCAL, TUN2SOCKS)
fun killAll() {
for (process in File("/proc").listFiles { _, name -> TextUtils.isDigitsOnly(name) } ?: return) {
val exe = File(try {
File(process, "cmdline").inputStream().bufferedReader().readText()
} catch (_: IOException) {
continue
}.split(Character.MIN_VALUE, limit = 2).first())
if (EXECUTABLES.contains(exe.name)) try {
Os.kill(process.name.toInt(), OsConstants.SIGKILL)
} catch (e: ErrnoException) {
if (e.errno != OsConstants.ESRCH) {
Timber.w("SIGKILL ${exe.absolutePath} (${process.name}) failed")
Timber.w(e)
}
}
}
}
}
......@@ -20,23 +20,15 @@
package com.github.shadowsocks.bg
import android.content.Context
import com.github.shadowsocks.Core.app
import com.github.shadowsocks.acl.Acl
import com.github.shadowsocks.acl.AclSyncer
import com.github.shadowsocks.core.BuildConfig
import com.github.shadowsocks.core.R
import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.plugin.PluginConfiguration
import com.github.shadowsocks.plugin.PluginManager
import com.github.shadowsocks.preference.DataStore
import kotlinx.coroutines.CoroutineScope
import org.json.JSONArray
import org.json.JSONObject
import timber.log.Timber
import java.io.File
import java.net.URI
import java.net.URISyntaxException
/**
* This class sets up environment for ss-local.
......@@ -62,81 +54,81 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
suspend fun start(service: BaseService.Interface, stat: File, configFile: File, mode: String, dnsRelay: Boolean = true) {
// setup traffic monitor path
trafficMonitor = TrafficMonitor(stat)
val cmdSupplier: suspend () -> List<String> = {
AuthManager.initAuthProfile(profile)
// init JSON config
this.configFile = configFile
val config = profile.toJson()
plugin?.let { (path, opts, isV2) ->
if (service.isVpnService) {
if (isV2) opts["__android_vpn"] = "" else config.put("plugin_args", JSONArray(arrayOf("-V")))
}
config.put("plugin", path).put("plugin_opts", opts.toString())
}
config.put("dns", "unix://local_dns_path")
config.put("locals", JSONArray().apply {
// local SOCKS5 proxy
put(JSONObject().apply {
put("local_address", DataStore.listenAddress)
put("local_port", DataStore.portProxy)
put("local_udp_address", DataStore.listenAddress)
put("local_udp_port", DataStore.portProxy)
put("mode", mode)
})
// local DNS proxy
if (dnsRelay) try {
URI("dns://${profile.remoteDns}")
} catch (e: URISyntaxException) {
throw BaseService.ExpectedExceptionWrapper(e)
}.let { dns ->
put(JSONObject().apply {
put("local_address", DataStore.listenAddress)
put("local_port", DataStore.portLocalDns)
put("local_dns_address", "local_dns_path")
put("remote_dns_address", dns.host ?: "0.0.0.0")
put("remote_dns_port", if (dns.port < 0) 53 else dns.port)
put("protocol", "dns")
put("mode", "udp_only")
})
}
})
configFile.writeText(config.toString())
Timber.d("prepare start service with config: $config")
// build the command line
val cmd = arrayListOf(
File((service as Context).applicationInfo.nativeLibraryDir, Executable.SS_LOCAL).absolutePath,
"--stat-path", stat.absolutePath,
"-c", configFile.absolutePath,
)
if (service.isVpnService) cmd += "--vpn"
if (route != Acl.ALL) {
cmd += "--acl"
cmd += Acl.getFile(route).absolutePath
Timber.d("start vpn service with acl ${Acl.getFile(route).readText()}")
}
// DataStore.outboundBindInterface = "rmnet_data1"
if (DataStore.outboundBindInterface.isNotBlank()) {
cmd += "--outbound-bind-interface"
cmd += DataStore.outboundBindInterface
}
if (BuildConfig.DEBUG) {
cmd += "-v"
cmd += "-v"
cmd += "-v"
cmd += "-v"
}
cmd
}
service.data.processes!!.start(cmdSupplier)
// val cmdSupplier: suspend () -> List<String> = {
// AuthManager.initAuthProfile(profile)
// // init JSON config
// this.configFile = configFile
// val config = profile.toJson()
// plugin?.let { (path, opts, isV2) ->
// if (service.isVpnService) {
// if (isV2) opts["__android_vpn"] = "" else config.put("plugin_args", JSONArray(arrayOf("-V")))
// }
// config.put("plugin", path).put("plugin_opts", opts.toString())
// }
// config.put("dns", "unix://local_dns_path")
// config.put("locals", JSONArray().apply {
// // local SOCKS5 proxy
// put(JSONObject().apply {
// put("local_address", DataStore.listenAddress)
// put("local_port", DataStore.portProxy)
// put("local_udp_address", DataStore.listenAddress)
// put("local_udp_port", DataStore.portProxy)
// put("mode", mode)
// })
//
// // local DNS proxy
// if (dnsRelay) try {
// URI("dns://${profile.remoteDns}")
// } catch (e: URISyntaxException) {
// throw BaseService.ExpectedExceptionWrapper(e)
// }.let { dns ->
// put(JSONObject().apply {
// put("local_address", DataStore.listenAddress)
// put("local_port", DataStore.portLocalDns)
// put("local_dns_address", "local_dns_path")
// put("remote_dns_address", dns.host ?: "0.0.0.0")
// put("remote_dns_port", if (dns.port < 0) 53 else dns.port)
// put("protocol", "dns")
// put("mode", "udp_only")
// })
// }
// })
// configFile.writeText(config.toString())
//
// Timber.d("prepare start service with config: $config")
//
// // build the command line
// val cmd = arrayListOf(
// File((service as Context).applicationInfo.nativeLibraryDir, Executable.SS_LOCAL).absolutePath,
// "--stat-path", stat.absolutePath,
// "-c", configFile.absolutePath,
// )
//
// if (service.isVpnService) cmd += "--vpn"
//
// if (route != Acl.ALL) {
// cmd += "--acl"
// cmd += Acl.getFile(route).absolutePath
// Timber.d("start vpn service with acl ${Acl.getFile(route).readText()}")
// }
//
//// DataStore.outboundBindInterface = "rmnet_data1"
//
// if (DataStore.outboundBindInterface.isNotBlank()) {
// cmd += "--outbound-bind-interface"
// cmd += DataStore.outboundBindInterface
// }
//
// if (BuildConfig.DEBUG) {
// cmd += "-v"
// cmd += "-v"
// cmd += "-v"
// cmd += "-v"
// }
// cmd
// }
//
// service.data.processes!!.start(cmdSupplier)
}
fun scheduleUpdate() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment