Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix(ios): keep a computer's best 16 addresses, once each, like Android

leepokai4ca0ea9656b0
diff --git a/apps/ios/Kit/Sources/CodyncKit/Client/ChannelTransport+Incoming.swift b/apps/ios/Kit/Sources/CodyncKit/Client/ChannelTransport+Incoming.swift
index 261d0dd1..6618c8be 100644
--- a/apps/ios/Kit/Sources/CodyncKit/Client/ChannelTransport+Incoming.swift
+++ b/apps/ios/Kit/Sources/CodyncKit/Client/ChannelTransport+Incoming.swift
@@ -215,7 +215,7 @@ extension ChannelTransport {
var c = computer
if !hello.name.isEmpty { c.name = hello.name }
if let bk = hello.boxKey, Data(base64URL: bk)?.count == 32 { c.boxKey = bk }
- if let urls = hello.urls { c.urls = urls.filter(Pairing.isDirectURL) }
+ if let urls = hello.urls { c.urls = Pairing.directURLs(urls) }
c.cloud = hello.cloud.flatMap(URL.init(string:)).flatMap { Pairing.isCloudURL($0) ? $0 : nil }
if let device = hello.device { c.device = device }
guard c != computer else { return }
diff --git a/apps/ios/Kit/Sources/CodyncKit/Client/Pairing.swift b/apps/ios/Kit/Sources/CodyncKit/Client/Pairing.swift
index 12eded2a..f27337b9 100644
--- a/apps/ios/Kit/Sources/CodyncKit/Client/Pairing.swift
+++ b/apps/ios/Kit/Sources/CodyncKit/Client/Pairing.swift
@@ -46,7 +46,7 @@ public struct Pairing: Hashable, Sendable {
Data(base64URL: bk)?.count == 32,
Data(base64URL: code)?.count == 16,
RelayCrypto.computerId(signKey: skRaw) == id else { throw .invalid }
- let urls = (q["urls"] ?? "").split(separator: ",").map(String.init).filter(Self.isDirectURL)
+ let urls = directURLs((q["urls"] ?? "").split(separator: ",").map(String.init))
var cloud: URL?
if let raw = q["cloud"], !raw.isEmpty {
guard let u = URL(string: raw), Self.isCloudURL(u) else { throw .invalid }
@@ -65,6 +65,15 @@ public struct Pairing: Hashable, Sendable {
/// The relay's pairing socket parameter.
var offerId: String? { Data(base64URL: code).map(RelayCrypto.offerId(code:)) }
+ /// Phones keep at most this many direct addresses; a computer with many networks sends more, best first.
+ static let maxURLs = 16
+
+ /// The direct addresses kept from a computer's list (pairing link or `hello`): valid ones, once each, the best `maxURLs`.
+ static func directURLs(_ urls: [String]) -> [String] {
+ var seen = Set<String>()
+ return Array(urls.filter { isDirectURL($0) && seen.insert($0).inserted }.prefix(maxURLs))
+ }
+
static func isDirectURL(_ s: String) -> Bool {
guard let u = URL(string: s), u.scheme == "http" || u.scheme == "https", u.host() != nil else { return false }
return true
diff --git a/apps/ios/Kit/Tests/CodyncKitTests/PairingStorageTests.swift b/apps/ios/Kit/Tests/CodyncKitTests/PairingStorageTests.swift
index c76d5561..85cd8ae8 100644
--- a/apps/ios/Kit/Tests/CodyncKitTests/PairingStorageTests.swift
+++ b/apps/ios/Kit/Tests/CodyncKitTests/PairingStorageTests.swift
@@ -32,6 +32,14 @@ private func link(_ overrides: [String: String?] = [:]) -> String {
#expect(Pairing(string: link(["cloud": nil])) != nil)
}
+@Test func aComputerWithManyNetworksPairsWithItsBestSixteenAddresses() throws {
+ let urls = (1...30).map { "http://172.\($0 + 1).0.1:19222" }
+ let p = try Pairing.parse(link(["urls": (urls + [urls[0], "ftp://x"]).joined(separator: ",")]))
+ #expect(p.computer.urls == Array(urls.prefix(16)))
+ // A hello's list is kept the same way.
+ #expect(Pairing.directURLs(urls.reversed() + urls) == Array(urls.reversed().prefix(16)))
+}
+
@Test func rejectsBadPairingLinks() {
#expect(throws: Pairing.Problem.outdatedHost) { try Pairing.parse(link(["v": nil])) }
#expect(throws: Pairing.Problem.outdatedHost) { try Pairing.parse(link(["v": "2"])) }