IOS Companion for @LimesKey/Serviceberry (on github)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix mDNS discovery: use nil domain, add retry logic for DefunctConnection errors

+21 -6
+21 -6
serviceberry/Services/MDNSDiscovery.swift
··· 12 12 @Published var isSearching = false 13 13 @Published var lastError: Error? 14 14 @Published var debugState: String = "idle" 15 + private var retryCount = 0 16 + private let maxRetries = 3 15 17 16 18 /// Start browsing for Serviceberry servers 17 19 func startBrowsing() { 20 + retryCount = 0 21 + startBrowsingInternal() 22 + } 23 + 24 + private func startBrowsingInternal() { 18 25 stopBrowsing() 19 26 discoveredServers = [] 20 27 isSearching = true 21 28 debugState = "starting" 22 29 23 - // Use "local." domain with trailing dot (standard DNS format) 30 + // Use nil domain to search all local domains 24 31 let descriptor = NWBrowser.Descriptor.bonjour( 25 32 type: Constants.bonjourServiceType, 26 - domain: Constants.bonjourDomain 33 + domain: nil 27 34 ) 28 35 29 - // Configure parameters for local network discovery 36 + // Use default parameters for mDNS browsing 30 37 let parameters = NWParameters() 31 - parameters.allowLocalEndpointReuse = true 32 - parameters.acceptLocalOnly = true 33 - parameters.allowFastOpen = true 38 + parameters.includePeerToPeer = true 34 39 35 40 print("[mDNS] Creating browser for type: \(Constants.bonjourServiceType)") 36 41 browser = NWBrowser(for: descriptor, using: parameters) ··· 48 53 self.debugState = "failed: \(error.localizedDescription)" 49 54 self.lastError = error 50 55 self.isSearching = false 56 + // Auto-retry after 2 seconds on failure (up to maxRetries) 57 + if self.retryCount < self.maxRetries { 58 + self.retryCount += 1 59 + self.debugState = "retrying (\(self.retryCount)/\(self.maxRetries))..." 60 + Task { 61 + try? await Task.sleep(nanoseconds: 2_000_000_000) 62 + print("[mDNS] Auto-retrying (\(self.retryCount)/\(self.maxRetries))...") 63 + self.startBrowsingInternal() 64 + } 65 + } 51 66 case .cancelled: 52 67 print("[mDNS] Browser cancelled") 53 68 self.debugState = "cancelled"