Commit 1041dc37 authored by Mygod's avatar Mygod

Move non-options to command line options

parent d734e9fd
...@@ -42,6 +42,8 @@ import okhttp3.{Dns, FormBody, OkHttpClient, Request} ...@@ -42,6 +42,8 @@ import okhttp3.{Dns, FormBody, OkHttpClient, Request}
import org.json.JSONObject import org.json.JSONObject
import scala.collection.mutable import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.collection.JavaConversions._
import scala.util.Random import scala.util.Random
trait BaseService extends Service { trait BaseService extends Service {
...@@ -49,7 +51,7 @@ trait BaseService extends Service { ...@@ -49,7 +51,7 @@ trait BaseService extends Service {
@volatile private var state = State.STOPPED @volatile private var state = State.STOPPED
@volatile protected var profile: Profile = _ @volatile protected var profile: Profile = _
@volatile private var plugin: PluginOptions = _ @volatile private var plugin: PluginOptions = _
@volatile private var pluginPath: String = _ @volatile protected var pluginPath: String = _
case class NameNotResolvedException() extends IOException case class NameNotResolvedException() extends IOException
case class NullConnectionException() extends NullPointerException case class NullConnectionException() extends NullPointerException
...@@ -313,24 +315,22 @@ trait BaseService extends Service { ...@@ -313,24 +315,22 @@ trait BaseService extends Service {
} }
} }
protected def buildShadowsocksConfig(file: String, localPortOffset: Int = 0, vpn: Boolean = false): String = { protected def buildPluginCommandLine(): ArrayBuffer[String] = {
val result = ArrayBuffer(pluginPath)
if (TcpFastOpen.sendEnabled) result += "--fast-open"
result
}
protected def buildShadowsocksConfig(file: String, localPortOffset: Int = 0): String = {
val config = new JSONObject() val config = new JSONObject()
config.put("server", profile.host) .put("server", profile.host)
config.put("server_port", profile.remotePort) .put("server_port", profile.remotePort)
config.put("local_port", profile.localPort + localPortOffset) .put("local_port", profile.localPort + localPortOffset)
config.put("password", profile.password) .put("password", profile.password)
config.put("method", profile.method) .put("method", profile.method)
if (profile.auth) config.put("auth", true) if (profile.auth) config.put("auth", true)
if (pluginPath != null) { if (pluginPath != null) config
config.put("plugin", pluginPath) .put("plugin", Commandline.toString(buildPluginCommandLine()))
val plugin_opts = if (vpn) { .put("plugin_opts", plugin.toString)
"V;P=" + getApplicationInfo.dataDir + ";" + plugin.toString
} else {
plugin.toString
}
Log.d("shadowsocks", plugin_opts)
config.put("plugin_opts", plugin_opts)
}
IOUtils.writeString(file, config.toString) IOUtils.writeString(file, config.toString)
file file
} }
......
...@@ -162,12 +162,15 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -162,12 +162,15 @@ class ShadowsocksVpnService extends VpnService with BaseService {
} }
} }
override protected def buildPluginCommandLine(): ArrayBuffer[String] =
super.buildPluginCommandLine() ++= Seq("-V", "-P", getApplicationInfo.dataDir)
def startShadowsocksDaemon() { def startShadowsocksDaemon() {
val cmd = ArrayBuffer[String](getApplicationInfo.nativeLibraryDir + "/libss-local.so", "-V" val cmd = ArrayBuffer[String](getApplicationInfo.nativeLibraryDir + "/libss-local.so", "-V"
, "-b", "127.0.0.1" , "-b", "127.0.0.1"
, "-t", "600" , "-t", "600"
, "-P", getApplicationInfo.dataDir , "-P", getApplicationInfo.dataDir
, "-c", buildShadowsocksConfig(getApplicationInfo.dataDir + "/ss-local-vpn.conf", 0, true)) , "-c", buildShadowsocksConfig(getApplicationInfo.dataDir + "/ss-local-vpn.conf", 0))
if (profile.udpdns) cmd += "-u" if (profile.udpdns) cmd += "-u"
...@@ -190,7 +193,7 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -190,7 +193,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
, "-b", "127.0.0.1" , "-b", "127.0.0.1"
, "-L" , if (profile.remoteDns == null) "8.8.8.8:53" else profile.remoteDns + ":53" , "-L" , if (profile.remoteDns == null) "8.8.8.8:53" else profile.remoteDns + ":53"
, "-P", getApplicationInfo.dataDir , "-P", getApplicationInfo.dataDir
, "-c", buildShadowsocksConfig(getApplicationInfo.dataDir + "/ss-tunnel-vpn.conf", 53, true)) , "-c", buildShadowsocksConfig(getApplicationInfo.dataDir + "/ss-tunnel-vpn.conf", 53))
if (BuildConfig.DEBUG) Log.d(TAG, Commandline.toString(cmd)) if (BuildConfig.DEBUG) Log.d(TAG, Commandline.toString(cmd))
sstunnelProcess = new GuardedProcess(cmd).start() sstunnelProcess = new GuardedProcess(cmd).start()
} }
......
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