fix: improve QR direct connection reliability and speed

This commit is contained in:
zhy200308
2026-08-12 11:14:34 +08:00
parent 9c16cc1690
commit f9e25819ee
8 changed files with 152 additions and 13 deletions
@@ -7,6 +7,38 @@ import java.nio.ByteOrder
import java.util.zip.CRC32
class ProtocolTest {
@Test
fun routeCandidatesOnlyKeepEndpointsOnTheActiveSubnet() {
val endpoints = listOf(
"http://192.168.137.1:39393",
"http://192.168.49.1:39393",
"http://192.168.1.20:39393",
"http://10.20.30.40:39393",
)
assertEquals(
listOf("http://192.168.1.20:39393"),
EndpointRouting.onAnySubnet(endpoints, 39393, listOf("192.168.1.88" to 24)),
)
assertEquals(
listOf("http://10.20.30.40:39393"),
EndpointRouting.onAnySubnet(endpoints, 39393, listOf("10.20.99.2" to 16)),
)
}
@Test
fun routeCandidatesRejectWrongPortsAndMalformedAddresses() {
val endpoints = listOf(
"http://192.168.1.20:39394",
"http://192.168.1.999:39393",
"http://192.168.1.30:39393",
)
assertEquals(
listOf("http://192.168.1.30:39393"),
EndpointRouting.onAnySubnet(endpoints, 39393, listOf("192.168.1.88" to 24)),
)
}
@Test
fun parsesPcToPhoneAutomaticDownloadPairing() {
val json = """{"v":2,"s":"abcdefghijklmnopqrstuvwxyz012345","n":"DESKTOP-QFT","p":39393,"e":["http://192.168.49.1:39393"],"d":"d","f":"sample.bin","z":42,"h":"${"00".repeat(32)}"}"""