Commit a9e8116a authored by Mygod's avatar Mygod

Make code style more Kotlin

parent 288f1a99
...@@ -81,18 +81,15 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro ...@@ -81,18 +81,15 @@ 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
val localConfigs = JSONArray()
// local SOCKS5 proxy // local SOCKS5 proxy
val proxyConfig = JSONObject() put(JSONObject().apply {
proxyConfig.put("local_address", DataStore.listenAddress) put("local_address", DataStore.listenAddress)
proxyConfig.put("local_port", DataStore.portProxy) put("local_port", DataStore.portProxy)
proxyConfig.put("local_udp_address", DataStore.listenAddress) put("local_udp_address", DataStore.listenAddress)
proxyConfig.put("local_udp_port", DataStore.portProxy) put("local_udp_port", DataStore.portProxy)
proxyConfig.put("mode", mode) put("mode", mode)
localConfigs.put(proxyConfig) })
// local DNS proxy // local DNS proxy
if (dnsRelay) try { if (dnsRelay) try {
...@@ -100,18 +97,16 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro ...@@ -100,18 +97,16 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
} catch (e: URISyntaxException) { } catch (e: URISyntaxException) {
throw BaseService.ExpectedExceptionWrapper(e) throw BaseService.ExpectedExceptionWrapper(e)
}.let { dns -> }.let { dns ->
val dnsConfig = JSONObject() put(JSONObject().apply {
dnsConfig.put("local_address", DataStore.listenAddress) put("local_address", DataStore.listenAddress)
dnsConfig.put("local_port", DataStore.portLocalDns) put("local_port", DataStore.portLocalDns)
dnsConfig.put("local_dns_address", "local_dns_path") put("local_dns_address", "local_dns_path")
dnsConfig.put("remote_dns_address", dns.host ?: "0.0.0.0") put("remote_dns_address", dns.host ?: "0.0.0.0")
dnsConfig.put("remote_dns_port", if (dns.port < 0) 53 else dns.port) put("remote_dns_port", if (dns.port < 0) 53 else dns.port)
dnsConfig.put("protocol", "dns") 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