Skip to content

Commit 9463f86

Browse files
committed
fix: clamp gecko packet sizes; clarify obfs password visibility
- buildHysteria2SidecarConfig: clamp gecko min/max to hysteria's accepted bounds (1 <= min <= max <= 2048) to avoid emitting an invalid config. - Document why the obfs password field is shown for both Salamander and Gecko (Gecko requires a password too).
1 parent 4b985ad commit 9463f86

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

app/src/main/java/io/nekohasekai/sagernet/fmt/hysteria/HysteriaFmt.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,12 +430,15 @@ fun HysteriaBean.buildHysteria2SidecarConfig(
430430
if (caText.isNotBlank()) put("ca", caText)
431431
})
432432
if (hysteria2ObfsType == HysteriaBean.OBFS_GECKO && obfuscation.isNotBlank()) {
433+
// Clamp to hysteria's accepted bounds: 1 <= min <= max <= 2048.
434+
val min = geckoMinPacketSize.coerceIn(1, 2048)
435+
val max = geckoMaxPacketSize.coerceIn(min, 2048)
433436
put("obfs", JSONObject().apply {
434437
put("type", "gecko")
435438
put("gecko", JSONObject().apply {
436439
put("password", obfuscation)
437-
put("minPacketSize", geckoMinPacketSize)
438-
put("maxPacketSize", geckoMaxPacketSize)
440+
put("minPacketSize", min)
441+
put("maxPacketSize", max)
439442
})
440443
})
441444
} else if (hysteria2ObfsType == HysteriaBean.OBFS_SALAMANDER && obfuscation.isNotBlank()) {

app/src/main/java/io/nekohasekai/sagernet/ui/profile/HysteriaSettingsActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class HysteriaSettingsActivity : ProfileSettingsActivity<HysteriaBean>() {
9696
val isHy2 = version == 2
9797
obfsType.isVisible = isHy2
9898
if (isHy2) {
99+
// Both Salamander and Gecko require an obfs password (apernet/hysteria
100+
// clientConfigObfsGecko.Password is mandatory), so show it for either.
99101
obfsPassword.isVisible = type != HysteriaBean.OBFS_NONE
100102
val isGecko = type == HysteriaBean.OBFS_GECKO
101103
geckoMin.isVisible = isGecko

0 commit comments

Comments
 (0)