fix(android): 网关探测过滤 0.0.0.0 等无效地址

实测诊断截图里出现了 http://0.0.0.0:39393 这个候选。它来自默认路由的
空网关(直连链路无下一跳),永远不可能连上,白白占用探测预算并把真正
的候选挤到后面。回环与组播地址同理,一并过滤。
This commit is contained in:
zhy200308
2026-08-11 21:26:06 +08:00
parent 0281382c39
commit b5d124abe5
@@ -339,6 +339,10 @@ class WifiConnector(context: Context) {
return props.routes return props.routes
.asSequence() .asSequence()
.mapNotNull { it.gateway as? Inet4Address } .mapNotNull { it.gateway as? Inet4Address }
// 默认路由的网关可能是 0.0.0.0(直连链路,无下一跳),
// 回环和组播地址也不可能是对端。全都探测一遍纯属浪费时间,
// 而且会把真正的候选挤到后面。
.filterNot { it.isAnyLocalAddress || it.isLoopbackAddress || it.isMulticastAddress }
.map { "http://${it.hostAddress}:$port" } .map { "http://${it.hostAddress}:$port" }
.distinct() .distinct()
.toList() .toList()