Skip to content

Linux + iPhone Continuity / iMessage / SMS

fix discovery

Zack Bartelc2bbb9266fb5
diff --git a/apple/Tether/Services/BonjourDiscovery.swift b/apple/Tether/Services/BonjourDiscovery.swift
index 4ffb690..cd59896 100644
--- a/apple/Tether/Services/BonjourDiscovery.swift
+++ b/apple/Tether/Services/BonjourDiscovery.swift
@@ -25,6 +25,9 @@ final class BonjourDiscovery {
/// Our own fingerprint, to filter ourselves out of the results.
var localFingerprint: String?
+ /// Our own device name, as a fallback filter if the TXT record hasn't arrived.
+ var localDeviceName: String?
+
/// Currently discovered hosts (updated live as services appear/disappear).
private(set) var hosts: [DiscoveredHost] = []
@@ -101,6 +104,10 @@ final class BonjourDiscovery {
return nil
}
+ if let localName = self.localDeviceName, !localName.isEmpty, name == localName {
+ return nil
+ }
+
return DiscoveredHost(
name: name,
endpoint: result.endpoint,
@@ -110,16 +117,20 @@ final class BonjourDiscovery {
onHostsChanged?(hosts)
}
- /// Extract the `fp=<sha256>` value from the Bonjour TXT record.
private func extractFingerprint(from metadata: NWBrowser.Result.Metadata) -> String {
guard case .bonjour(let txtRecord) = metadata else {
return ""
}
- if let fpEntry = txtRecord.getEntry(for: "fp"),
- case .string(let value) = fpEntry
- {
- return value
+ if let fpEntry = txtRecord.getEntry(for: "fp") {
+ switch fpEntry {
+ case .string(let value):
+ return value
+ case .data(let data):
+ return String(data: data, encoding: .utf8) ?? ""
+ @unknown default:
+ return ""
+ }
}
return ""
}
diff --git a/apple/Tether/Services/BonjourDiscovery.swift.patch b/apple/Tether/Services/BonjourDiscovery.swift.patch
new file mode 100644
index 0000000..74ec29e
--- /dev/null
+++ b/apple/Tether/Services/BonjourDiscovery.swift.patch
@@ -0,0 +1,10 @@
+--- Tether/Services/BonjourDiscovery.swift
++++ Tether/Services/BonjourDiscovery.swift
+@@ -97,6 +97,8 @@
+ let fingerprint = extractFingerprint(from: result.metadata)
+
++ print("BONJOUR: discovered name=\(name) fp=\(fingerprint) local=\(self.localFingerprint ?? "none")")
++
+ if let local = self.localFingerprint, !local.isEmpty, fingerprint == local {
+ return nil
+ }
diff --git a/apple/Tether/ViewModels/TetherViewModel.swift b/apple/Tether/ViewModels/TetherViewModel.swift
index c034e31..771e39e 100644
--- a/apple/Tether/ViewModels/TetherViewModel.swift
+++ b/apple/Tether/ViewModels/TetherViewModel.swift
@@ -140,6 +140,7 @@ final class TetherViewModel {
certificateManager.initialize()
discovery.localFingerprint = certificateManager.myFingerprint
+ discovery.localDeviceName = certificateManager.localDeviceName
setupConnectionHandlers()
setupServerHandlers()