Commit 655ef1ee authored by Mygod's avatar Mygod

Refine TFO

parent 04be6057
......@@ -112,12 +112,7 @@ class ShadowsocksApplication extends Application {
}
pending.setResultCallback(callback, 2, TimeUnit.SECONDS)
// TFO
val tfo = settings.getBoolean(Key.tfo, false)
if (tfo && !TcpFastOpen.isEnabled)
{
TcpFastOpen.enabled(true)
}
TcpFastOpen.enabled(settings.getBoolean(Key.tfo, false))
}
def refreshContainerHolder {
......
......@@ -105,7 +105,7 @@ class ShadowsocksNatService extends BaseService {
if (profile.auth) cmd += "-A"
if (TcpFastOpen.isEnabled) cmd += "--fast-open"
if (TcpFastOpen.sendEnabled) cmd += "--fast-open"
if (profile.route != Route.ALL) {
cmd += "--acl"
......
......@@ -155,17 +155,14 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
}
switch.setChecked(BootReceiver.getEnabled(activity))
if (getPreferenceManager.getSharedPreferences.getBoolean(Key.tfo, false) && !TcpFastOpen.isEnabled) {
TcpFastOpen.enabled(true)
}
val tfo = findPreference(Key.tfo).asInstanceOf[SwitchPreference]
tfo.setChecked(TcpFastOpen.isEnabled)
tfo.setChecked(TcpFastOpen.sendEnabled)
tfo.setOnPreferenceChangeListener((_, v) => {
val value = v.asInstanceOf[Boolean]
val result = TcpFastOpen.enabled(value)
if (result != null && result != "Success.")
Snackbar.make(activity.findViewById(android.R.id.content), result, Snackbar.LENGTH_LONG).show()
value == TcpFastOpen.isEnabled
value == TcpFastOpen.sendEnabled
})
if (!TcpFastOpen.supported) {
tfo.setEnabled(false)
......
......@@ -266,7 +266,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
cmd += (getApplicationInfo.dataDir + "/acl.list")
}
if (TcpFastOpen.isEnabled) cmd += "--fast-open"
if (TcpFastOpen.sendEnabled) cmd += "--fast-open"
if (BuildConfig.DEBUG) Log.d(TAG, cmd.mkString(" "))
......
......@@ -23,12 +23,12 @@ object TcpFastOpen {
case _ => false
}
def isEnabled = {
def sendEnabled = {
val file = new File("/proc/sys/net/ipv4/tcp_fastopen")
file.canRead && (Utils.readAllLines(file).toInt & 1) > 0
}
def enabled(value: Boolean): String = {
def enabled(value: Boolean): String = if (sendEnabled != value) {
val res = Shell.run("su", Array(
"if echo " + (if (value) 3 else 0) + " > /proc/sys/net/ipv4/tcp_fastopen; then",
" echo Success.",
......@@ -36,5 +36,5 @@ object TcpFastOpen {
" echo Failed.",
"fi"), null, true)
if (res != null) res.asScala.mkString("\n") else null
}
} else null
}
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