Commit a9e8116a authored by Mygod's avatar Mygod

Make code style more Kotlin

parent 288f1a99
...@@ -81,37 +81,32 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro ...@@ -81,37 +81,32 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
config.put("plugin", path).put("plugin_opts", opts.toString()) config.put("plugin", path).put("plugin_opts", opts.toString())
} }
config.put("dns", "unix://local_dns_path") config.put("dns", "unix://local_dns_path")
config.put("locals", JSONArray().apply {
// init local config array // local SOCKS5 proxy
val localConfigs = JSONArray() put(JSONObject().apply {
put("local_address", DataStore.listenAddress)
// local SOCKS5 proxy put("local_port", DataStore.portProxy)
val proxyConfig = JSONObject() put("local_udp_address", DataStore.listenAddress)
proxyConfig.put("local_address", DataStore.listenAddress) put("local_udp_port", DataStore.portProxy)
proxyConfig.put("local_port", DataStore.portProxy) put("mode", mode)
proxyConfig.put("local_udp_address", DataStore.listenAddress) })
proxyConfig.put("local_udp_port", DataStore.portProxy)
proxyConfig.put("mode", mode) // local DNS proxy
localConfigs.put(proxyConfig) if (dnsRelay) try {
URI("dns://${profile.remoteDns}")
// local DNS proxy } catch (e: URISyntaxException) {
if (dnsRelay) try { throw BaseService.ExpectedExceptionWrapper(e)
URI("dns://${profile.remoteDns}") }.let { dns ->
} catch (e: URISyntaxException) { put(JSONObject().apply {
throw BaseService.ExpectedExceptionWrapper(e) put("local_address", DataStore.listenAddress)
}.let { dns -> put("local_port", DataStore.portLocalDns)
val dnsConfig = JSONObject() put("local_dns_address", "local_dns_path")
dnsConfig.put("local_address", DataStore.listenAddress) put("remote_dns_address", dns.host ?: "0.0.0.0")
dnsConfig.put("local_port", DataStore.portLocalDns) put("remote_dns_port", if (dns.port < 0) 53 else dns.port)
dnsConfig.put("local_dns_address", "local_dns_path") put("protocol", "dns")
dnsConfig.put("remote_dns_address", dns.host ?: "0.0.0.0") })
dnsConfig.put("remote_dns_port", if (dns.port < 0) 53 else dns.port) }
dnsConfig.put("protocol", "dns") })
localConfigs.put(dnsConfig)
}
// add all the locals
config.put("locals", localConfigs)
configFile.writeText(config.toString()) configFile.writeText(config.toString())
// build the command line // build the command line
...@@ -121,7 +116,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro ...@@ -121,7 +116,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
"-c", configFile.absolutePath, "-c", configFile.absolutePath,
) )
if (service.isVpnService) cmd += arrayListOf("--vpn") if (service.isVpnService) cmd += "--vpn"
if (route != Acl.ALL) { if (route != Acl.ALL) {
cmd += "--acl" cmd += "--acl"
......
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