Skip to content

Commit 0a52a79

Browse files
authored
Support interval range (#5440)
1 parent 9dc1b1f commit 0a52a79

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

V2rayNG/app/src/main/java/com/v2ray/ang/fmt/Hysteria2Fmt.kt

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,36 @@ object Hysteria2Fmt : FmtBase() {
7272
dicQuery["mport"] = config.portHopping.orEmpty()
7373
}
7474
if (config.portHoppingInterval.isNotNullEmpty()) {
75-
var portHoppingInterval = config.portHoppingInterval.orEmpty()
76-
if (portHoppingInterval.contains('-')) {
77-
// interval range
78-
portHoppingInterval = portHoppingInterval.substringBefore('-')
75+
val rawInterval = config.portHoppingInterval?.trim().nullIfBlank()
76+
val interval = if (rawInterval == null) {
77+
null
78+
} else {
79+
val singleValue = rawInterval.toIntOrNull()
80+
if (singleValue != null) {
81+
if (singleValue < 5) {
82+
null
83+
} else {
84+
rawInterval
85+
}
86+
} else {
87+
val parts = rawInterval.split('-')
88+
if (parts.size == 2) {
89+
val start = parts[0].trim().toIntOrNull()
90+
val end = parts[1].trim().toIntOrNull()
91+
if (start != null && end != null) {
92+
val minStart = maxOf(5, start)
93+
val minEnd = maxOf(minStart, end)
94+
(minStart + minEnd) / 2
95+
} else {
96+
null
97+
}
98+
} else {
99+
null
100+
}
101+
}
79102
}
80-
val trimmedPortHoppingInterval = portHoppingInterval.trim()
81-
if (trimmedPortHoppingInterval.isNotEmpty()) {
82-
dicQuery["mportHopInt"] = trimmedPortHoppingInterval
103+
if (interval != null) {
104+
dicQuery["mportHopInt"] = interval.toString()
83105
}
84106
}
85107
if (config.pinnedCA256.isNotNullEmpty()) {

V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ class ServerActivity : BaseActivity() {
543543
} else if (config.configType == EConfigType.HYSTERIA2) {
544544
config.obfsPassword = et_obfs_password?.text?.toString()
545545
config.portHopping = et_port_hop?.text?.toString()
546-
config.portHoppingInterval = et_port_hop_interval?.text?.toString()
546+
config.portHoppingInterval = et_port_hop_interval?.text?.toString()?.trim()
547547
config.bandwidthDown = et_bandwidth_down?.text?.toString()
548548
config.bandwidthUp = et_bandwidth_up?.text?.toString()
549549
}

V2rayNG/app/src/main/res/layout/activity_server_hysteria2.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@
8585
<EditText
8686
android:id="@+id/et_port_hop_interval"
8787
android:layout_width="match_parent"
88-
android:layout_height="wrap_content"
89-
android:inputType="number" />
88+
android:layout_height="wrap_content" />
9089

9190
</LinearLayout>
9291

0 commit comments

Comments
 (0)