Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for "optimize tcp buffers" option per profile. #3137

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"formatVersion": 1,
"database": {
"version": 29,
"identityHash": "5b5c55a1277c63e14416316f9198ed43",
"identityHash": "edf35c5851b4cb55bb5dbbf278199450",
"entities": [
{
"tableName": "Profile",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT, `host` TEXT NOT NULL, `remotePort` INTEGER NOT NULL, `password` TEXT NOT NULL, `method` TEXT NOT NULL, `route` TEXT NOT NULL, `remoteDns` TEXT NOT NULL, `proxyApps` INTEGER NOT NULL, `bypass` INTEGER NOT NULL, `udpdns` INTEGER NOT NULL, `ipv6` INTEGER NOT NULL, `metered` INTEGER NOT NULL, `individual` TEXT NOT NULL, `plugin` TEXT, `udpFallback` INTEGER, `subscription` INTEGER NOT NULL, `tx` INTEGER NOT NULL, `rx` INTEGER NOT NULL, `userOrder` INTEGER NOT NULL)",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT, `host` TEXT NOT NULL, `remotePort` INTEGER NOT NULL, `password` TEXT NOT NULL, `method` TEXT NOT NULL, `route` TEXT NOT NULL, `remoteDns` TEXT NOT NULL, `proxyApps` INTEGER NOT NULL, `bypass` INTEGER NOT NULL, `udpdns` INTEGER NOT NULL, `ipv6` INTEGER NOT NULL, `metered` INTEGER NOT NULL, `individual` TEXT NOT NULL, `plugin` TEXT, `udpFallback` INTEGER, `optimizeBuffers` INTEGER NOT NULL, `subscription` INTEGER NOT NULL, `tx` INTEGER NOT NULL, `rx` INTEGER NOT NULL, `userOrder` INTEGER NOT NULL)",
"fields": [
{
"fieldPath": "id",
Expand Down Expand Up @@ -104,6 +104,12 @@
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "optimizeBuffers",
"columnName": "optimizeBuffers",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "subscription",
"columnName": "subscription",
Expand All @@ -130,10 +136,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
],
"autoGenerate": true
]
},
"indices": [],
"foreignKeys": []
Expand Down Expand Up @@ -162,10 +168,10 @@
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"key"
],
"autoGenerate": false
]
},
"indices": [],
"foreignKeys": []
Expand All @@ -174,7 +180,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '5b5c55a1277c63e14416316f9198ed43')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'edf35c5851b4cb55bb5dbbf278199450')"
]
}
}
16 changes: 14 additions & 2 deletions core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,22 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
val cmd = arrayListOf(
File((service as Context).applicationInfo.nativeLibraryDir, Executable.SS_LOCAL).absolutePath,
"--stat-path", stat.absolutePath,
"-c", configFile.absolutePath,
"-c", configFile.absolutePath
)

if (service.isVpnService) cmd += "--vpn"
if (profile.optimizeBuffers) {
cmd += "--inbound-send-buffer-size=16384"
cmd += "--inbound-recv-buffer-size=16384"

if (profile.plugin?.isNotBlank() == true) {
cmd += "--outbound-send-buffer-size=16384"
cmd += "--outbound-recv-buffer-size=16384"
}
}

if (service.isVpnService) {
cmd += "--vpn"
}

if (route != Acl.ALL) {
cmd += "--acl"
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/com/github/shadowsocks/database/Profile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ data class Profile(
var individual: String = "",
var plugin: String? = null,
var udpFallback: Long? = null,
var optimizeBuffers: Boolean = true,

// managed fields
var subscription: SubscriptionStatus = SubscriptionStatus.UserConfigured,
Expand Down Expand Up @@ -355,6 +356,7 @@ data class Profile(
DataStore.individual = individual
DataStore.plugin = plugin ?: ""
DataStore.udpFallback = udpFallback
DataStore.optimizeBuffers = optimizeBuffers
DataStore.privateStore.remove(Key.dirty)
}

Expand All @@ -378,5 +380,6 @@ data class Profile(
individual = DataStore.individual
plugin = DataStore.plugin
udpFallback = DataStore.udpFallback
optimizeBuffers = DataStore.optimizeBuffers
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ object DataStore : OnPreferenceDataStoreChangeListener {
var udpFallback: Long?
get() = privateStore.getLong(Key.udpFallback)
set(value) = privateStore.putLong(Key.udpFallback, value)
var optimizeBuffers: Boolean
get() = privateStore.getBoolean(Key.optimizeBuffers) ?: true
set(value) = privateStore.putBoolean(Key.optimizeBuffers, value)
var dirty: Boolean
get() = privateStore.getBoolean(Key.dirty) ?: false
set(value) = privateStore.putBoolean(Key.dirty, value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ object Key {
const val plugin = "plugin"
const val pluginConfigure = "plugin.configure"
const val udpFallback = "udpFallback"
const val optimizeBuffers = "optimizeBuffers";

const val dirty = "profileDirty"

Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<string name="remote_port">Remote Port</string>
<string name="sitekey">Password</string>
<string name="enc_method">Encrypt Method</string>
<string name="optimize_buffers">Optimize TCP Buffers</string>
<string name="optimize_buffers_summary">Fix upload timeout (bufferbloat)</string>

<!-- feature category -->
<string name="ipv6">IPv6 Route</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class ProfileConfigFragment : PreferenceFragmentCompat(),
private lateinit var pluginConfiguration: PluginConfiguration
private lateinit var receiver: BroadcastReceiver
private lateinit var udpFallback: Preference
private lateinit var optimizeBuffers: SwitchPreference

private fun makeDirt() {
DataStore.dirty = true
Expand Down Expand Up @@ -115,6 +116,8 @@ class ProfileConfigFragment : PreferenceFragmentCompat(),
pluginConfiguration = PluginConfiguration(DataStore.plugin)
initPlugins()
udpFallback = findPreference(Key.udpFallback)!!
optimizeBuffers = findPreference(Key.optimizeBuffers)!!
optimizeBuffers.isChecked = DataStore.optimizeBuffers
DataStore.privateStore.registerChangeListener(this)

val profile = ProfileManager.getProfile(profileId) ?: Profile()
Expand Down
7 changes: 5 additions & 2 deletions mobile/src/main/res/xml/pref_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@
app:key="remoteDns"
app:icon="@drawable/ic_action_dns"
app:title="@string/remote_dns"
app:useSimpleSummaryProvider="true"/>

app:useSimpleSummaryProvider="true" />
<SwitchPreference
app:key="optimizeBuffers"
app:title="@string/optimize_buffers"
app:summary="@string/optimize_buffers_summary" />
</PreferenceCategory>

<PreferenceCategory
Expand Down