Skip to content

Commit 87458e3

Browse files
committed
Add support for "optimize tcp buffers" option per profile.
- It tunes down the local sslocal listener socket buffers which is the right thing to do in 99.999% of cases of mobile app. - It additionally also tunes down the remote socket buffers of sslocal when a plugin is used. This is needed to ensure there's no bufferbloat between sslocal and the plugin itself. - Ideally the plugin on its side should also choke its local listening socket buffers and leave only its remote side socket buffers unrestricted.
1 parent 5a10078 commit 87458e3

File tree

20 files changed

+69
-11
lines changed

20 files changed

+69
-11
lines changed

core/schemas/com.github.shadowsocks.database.PrivateDatabase/29.json

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"formatVersion": 1,
33
"database": {
44
"version": 29,
5-
"identityHash": "5b5c55a1277c63e14416316f9198ed43",
5+
"identityHash": "edf35c5851b4cb55bb5dbbf278199450",
66
"entities": [
77
{
88
"tableName": "Profile",
9-
"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)",
9+
"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)",
1010
"fields": [
1111
{
1212
"fieldPath": "id",
@@ -104,6 +104,12 @@
104104
"affinity": "INTEGER",
105105
"notNull": false
106106
},
107+
{
108+
"fieldPath": "optimizeBuffers",
109+
"columnName": "optimizeBuffers",
110+
"affinity": "INTEGER",
111+
"notNull": true
112+
},
107113
{
108114
"fieldPath": "subscription",
109115
"columnName": "subscription",
@@ -130,10 +136,10 @@
130136
}
131137
],
132138
"primaryKey": {
139+
"autoGenerate": true,
133140
"columnNames": [
134141
"id"
135-
],
136-
"autoGenerate": true
142+
]
137143
},
138144
"indices": [],
139145
"foreignKeys": []
@@ -162,10 +168,10 @@
162168
}
163169
],
164170
"primaryKey": {
171+
"autoGenerate": false,
165172
"columnNames": [
166173
"key"
167-
],
168-
"autoGenerate": false
174+
]
169175
},
170176
"indices": [],
171177
"foreignKeys": []
@@ -174,7 +180,7 @@
174180
"views": [],
175181
"setupQueries": [
176182
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
177-
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '5b5c55a1277c63e14416316f9198ed43')"
183+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'edf35c5851b4cb55bb5dbbf278199450')"
178184
]
179185
}
180186
}

core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,22 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
117117
val cmd = arrayListOf(
118118
File((service as Context).applicationInfo.nativeLibraryDir, Executable.SS_LOCAL).absolutePath,
119119
"--stat-path", stat.absolutePath,
120-
"-c", configFile.absolutePath,
120+
"-c", configFile.absolutePath
121121
)
122122

123-
if (service.isVpnService) cmd += "--vpn"
123+
if (profile.optimizeBuffers) {
124+
cmd += "--inbound-send-buffer-size 16384"
125+
cmd += "--inbound-recv-buffer-size 16384"
126+
127+
if (profile.plugin?.isNotBlank() == true) {
128+
cmd += "--outbound-send-buffer-size 16384"
129+
cmd += "--outbound-recv-buffer-size 16384"
130+
}
131+
}
132+
133+
if (service.isVpnService) {
134+
cmd += "--vpn"
135+
}
124136

125137
if (route != Acl.ALL) {
126138
cmd += "--acl"

core/src/main/java/com/github/shadowsocks/database/Profile.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ data class Profile(
7070
var individual: String = "",
7171
var plugin: String? = null,
7272
var udpFallback: Long? = null,
73+
var optimizeBuffers: Boolean = true,
7374

7475
// managed fields
7576
var subscription: SubscriptionStatus = SubscriptionStatus.UserConfigured,
@@ -355,6 +356,7 @@ data class Profile(
355356
DataStore.individual = individual
356357
DataStore.plugin = plugin ?: ""
357358
DataStore.udpFallback = udpFallback
359+
DataStore.optimizeBuffers = optimizeBuffers
358360
DataStore.privateStore.remove(Key.dirty)
359361
}
360362

@@ -378,5 +380,6 @@ data class Profile(
378380
individual = DataStore.individual
379381
plugin = DataStore.plugin
380382
udpFallback = DataStore.udpFallback
383+
optimizeBuffers = DataStore.optimizeBuffers
381384
}
382385
}

core/src/main/java/com/github/shadowsocks/preference/DataStore.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ object DataStore : OnPreferenceDataStoreChangeListener {
104104
var udpFallback: Long?
105105
get() = privateStore.getLong(Key.udpFallback)
106106
set(value) = privateStore.putLong(Key.udpFallback, value)
107+
var optimizeBuffers: Boolean
108+
get() = privateStore.getBoolean(Key.optimizeBuffers) ?: true
109+
set(value) = privateStore.putBoolean(Key.optimizeBuffers, value)
107110
var dirty: Boolean
108111
get() = privateStore.getBoolean(Key.dirty) ?: false
109112
set(value) = privateStore.putBoolean(Key.dirty, value)

core/src/main/java/com/github/shadowsocks/utils/Constants.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ object Key {
6161
const val plugin = "plugin"
6262
const val pluginConfigure = "plugin.configure"
6363
const val udpFallback = "udpFallback"
64+
const val optimizeBuffers = "optimizeBuffers";
6465

6566
const val dirty = "profileDirty"
6667

core/src/main/res/values-ar/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@
3434
<string name="remote_port">"المنفذ"</string>
3535
<string name="sitekey">"كلمة المرور"</string>
3636
<string name="enc_method">"طريقة التشفير"</string>
37+
<string name="optimize_buffers">حسِن مخازن الذاكرة ل TCP</string>
38+
<string name="optimize_buffers_summary">يعالج مشكلة نفاذ الوقت اثناء الرفع نتيجة تضخم مخازن الذاكرة</string>
3739
</resources>

core/src/main/res/values-de/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Empfangen: \t%4$s\t↓\t%2$s"</string>
3939
<string name="enc_method">"Verschlüsselungsmethode"</string>
4040

4141
<!-- feature category -->
42+
<string name="optimize_buffers">TCP-Puffer optimieren</string>
4243
<string name="ipv6">"IPv6-Route"</string>
4344
<string name="ipv6_summary">"Leite IPv6-Traffic zu Remote um"</string>
4445
<string name="route_entry_gfwlist">"GFW-Liste"</string>
@@ -49,6 +50,7 @@ Empfangen: \t%4$s\t↓\t%2$s"</string>
4950
<string name="bypass_apps_summary">"Aktiviere um ausgewählte Apps zu umgehen"</string>
5051
<string name="auto_connect">"Automatisch verbinden"</string>
5152
<string name="auto_connect_summary">"Starte Shadowsocks bei Systemstart/nach App-Update automatisch, falls es zuvor aktiv war"</string>
53+
<string name="optimize_buffers_summary">Upload-Zeitüberschreitung (Bufferbloat) beheben</string>
5254
<string name="tcp_fastopen_summary">"Umschalten benötigt eventuell ROOT-Zugriff"</string>
5355
<string name="tcp_fastopen_summary_unsupported">"Nicht unterstützte Kernel-Version: %s &lt; 3.7.1"</string>
5456
<string name="udp_dns">"Sende DNS über UDP"</string>

core/src/main/res/values-es/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Recibido: \t%4$s\t↓\t%2$s"</string>
4040
<string name="enc_method">"Método de Cifrado"</string>
4141

4242
<!-- feature category -->
43+
<string name="optimize_buffers">Optimizar buffers TCP</string>
4344
<string name="ipv6">"Ruta IPv6"</string>
4445
<string name="ipv6_summary">"Redireccionar tráfico IPv6 a ruta"</string>
4546
<string name="route_list">"Ruta"</string>
@@ -54,6 +55,7 @@ Recibido: \t%4$s\t↓\t%2$s"</string>
5455

5556
<!-- Fuzzy -->
5657
<string name="auto_connect_summary">"Activar Shadowsocks al iniciar"</string>
58+
<string name="optimize_buffers_summary">Corregir el error de tiempo de espera de carga debido a bufferbloat</string>
5759
<string name="tcp_fastopen_summary_unsupported">"Versión del Núcleo sin soporte: %s &lt; 3.7.1"</string>
5860
<string name="udp_dns">"Enviar DNS sobre UDP"</string>
5961

core/src/main/res/values-fa/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<string name="enc_method">"روش رمزگذاری"</string>
4242

4343
<!-- feature category -->
44+
<string name="optimize_buffers">بهینه‌سازی بافرهای TCP</string>
4445
<string name="ipv6">"مسیر IPv6"</string>
4546
<string name="ipv6_summary">"ترافیک IPv6 را به سرور هدایت کن"</string>
4647
<string name="route_list">"مسیر"</string>
@@ -52,6 +53,7 @@
5253
<string name="bypass_apps_summary">"این گزینه را فعال کنید تا اپلیکیشن‌های انتخاب شده از VPN استفاده نکنند"</string>
5354
<string name="auto_connect">"وصل‌شدن اتوماتیک"</string>
5455
<string name="auto_connect_summary">"فعال‌شدن شدوساکس لحظه روشن‌شدن گوشی بروزرسانی شود اگر از قبل درحال اجرا بوده است"</string>
56+
<string name="optimize_buffers_summary">رفع مشکل تایم اوت آپلود به دلیل بافرهای بزرگ</string>
5557
<string name="tcp_fastopen_summary">"تغییر وضعیت ممکن است به مجوز ROOT نیاز داشته باشد"</string>
5658
<string name="tcp_fastopen_summary_unsupported">"نسخه هسته پشتیبانی نشده: %s &lt;3.7.1"</string>
5759
<string name="udp_dns">"ارسال DNS از طریق UDP"</string>

core/src/main/res/values-fr/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Reçu : \t\t\t%4$s\t↓\t%2$s"</string>
4040
<string name="enc_method">"Méthode d'Encryption"</string>
4141

4242
<!-- feature category -->
43+
<string name="optimize_buffers">Optimiser les tampons TCP</string>
4344
<string name="ipv6">"Route IPv6"</string>
4445
<string name="ipv6_summary">"Rediriger le trafic IPv6 vers le serveur distant"</string>
4546
<string name="route_list">"Route"</string>
@@ -57,6 +58,7 @@ Reçu : \t\t\t%4$s\t↓\t%2$s"</string>
5758
<string name="auto_connect_summary">"Activer Shadowsocks au démarrage"</string>
5859

5960
<!-- Fuzzy -->
61+
<string name="optimize_buffers_summary">Résoudre le problème de délai d\'envoi lié au bufferbloat</string>
6062
<string name="tcp_fastopen_summary">"Activer nécessite la permission ROOT"</string>
6163
<string name="tcp_fastopen_summary_unsupported">"Version du noyau non supportée : %s &lt;3.7.1"</string>
6264

0 commit comments

Comments
 (0)