


























@@ -12,6 +12,7 @@ import java.io.IOException
1212import java.net.InetSocketAddress
1313import java.nio.ByteBuffer
1414import java.nio.charset.CodingErrorAction
15+import java.time.Duration
1516import java.util.concurrent.ConcurrentHashMap
1617import java.util.concurrent.Executor
1718import java.util.concurrent.Executors
@@ -132,38 +133,38 @@ class GatewayDiscovery(
132133object : NsdManager.ResolveListener {
133134override fun onResolveFailed(serviceInfo: NsdServiceInfo, errorCode: Int) {}
134135135-override fun onServiceResolved(resolved: NsdServiceInfo) {
136-val host = resolved.host?.hostAddress ?: return
137-val port = resolved.port
138-if (port <= 0) return
139-140-val rawServiceName = resolved.serviceName
141-val serviceName = BonjourEscapes.decode(rawServiceName)
142-val displayName = BonjourEscapes.decode(txt(resolved, "displayName") ?: serviceName)
143-val lanHost = txt(resolved, "lanHost")
144-val tailnetDns = txt(resolved, "tailnetDns")
145-val gatewayPort = txtInt(resolved, "gatewayPort")
146-val canvasPort = txtInt(resolved, "canvasPort")
147-val tlsEnabled = txtBool(resolved, "gatewayTls")
148-val tlsFingerprint = txt(resolved, "gatewayTlsSha256")
149-val id = stableId(serviceName, "local.")
150- localById[id] =
151-GatewayEndpoint(
152- stableId = id,
153- name = displayName,
154- host = host,
155- port = port,
156- lanHost = lanHost,
157- tailnetDns = tailnetDns,
158- gatewayPort = gatewayPort,
159- canvasPort = canvasPort,
160- tlsEnabled = tlsEnabled,
161- tlsFingerprintSha256 = tlsFingerprint,
162- )
163- publish()
164- }
165- },
166- )
136+ override fun onServiceResolved(resolved: NsdServiceInfo) {
137+ val host = resolved.host?.hostAddress ?: return
138+ val port = resolved.port
139+ if (port <= 0) return
140+141+ val rawServiceName = resolved.serviceName
142+ val serviceName = BonjourEscapes.decode(rawServiceName)
143+ val displayName = BonjourEscapes.decode(txt(resolved, "displayName") ?: serviceName)
144+ val lanHost = txt(resolved, "lanHost")
145+ val tailnetDns = txt(resolved, "tailnetDns")
146+ val gatewayPort = txtInt(resolved, "gatewayPort")
147+ val canvasPort = txtInt(resolved, "canvasPort")
148+ val tlsEnabled = txtBool(resolved, "gatewayTls")
149+ val tlsFingerprint = txt(resolved, "gatewayTlsSha256")
150+ val id = stableId(serviceName, "local.")
151+ localById[id] =
152+ GatewayEndpoint(
153+ stableId = id,
154+ name = displayName,
155+ host = host,
156+ port = port,
157+ lanHost = lanHost,
158+ tailnetDns = tailnetDns,
159+ gatewayPort = gatewayPort,
160+ canvasPort = canvasPort,
161+ tlsEnabled = tlsEnabled,
162+ tlsFingerprintSha256 = tlsFingerprint,
163+ )
164+ publish()
165+ }
166+ },
167+ )
167168 }
168169169170private fun publish() {
@@ -350,7 +351,7 @@ class GatewayDiscovery(
350351 }
351352352353private fun records(msg: Message?, section: Int): List<Record> {
353-return msg?.getSectionArray(section)?.toList() ?: emptyList()
354+return msg?.getSection(section).orEmpty()
354355 }
355356356357private fun keyName(raw: String): String {
@@ -426,14 +427,14 @@ class GatewayDiscovery(
426427try {
427428SimpleResolver().apply {
428429 setAddress(InetSocketAddress(addr, 53))
429- setTimeout(3)
430+ setTimeout(Duration.ofSeconds(3))
430431 }
431432 } catch (_: Throwable) {
432433null
433434 }
434435 }
435436if (resolvers.isEmpty()) return null
436-ExtendedResolver(resolvers.toTypedArray()).apply { setTimeout(3) }
437+ExtendedResolver(resolvers.toTypedArray()).apply { setTimeout(Duration.ofSeconds(3)) }
437438 } catch (_: Throwable) {
438439null
439440 }
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。