From 320cd0ca7e95041d9245871f2f0a65f733f8dbfb Mon Sep 17 00:00:00 2001 From: Max Radermacher Date: Fri, 25 Oct 2024 13:10:57 -0500 Subject: [PATCH] Remove missingDevicesCache --- SignalServiceKit/Messages/MessageSender.swift | 57 ------------------- 1 file changed, 57 deletions(-) diff --git a/SignalServiceKit/Messages/MessageSender.swift b/SignalServiceKit/Messages/MessageSender.swift index 0b3238bdf2..712f1d6041 100644 --- a/SignalServiceKit/Messages/MessageSender.swift +++ b/SignalServiceKit/Messages/MessageSender.swift @@ -115,14 +115,6 @@ public class MessageSender { ) async throws -> SignalServiceKit.PreKeyBundle { Logger.info("serviceId: \(serviceId).\(deviceId)") - if deviceRecentlyReportedMissing(serviceId: serviceId, deviceId: deviceId) { - // We don't want to retry prekey requests if we've recently gotten a "404 - // missing device" for the same recipient/device. Fail immediately as - // though we hit the "404 missing device" error again. - Logger.info("Skipping prekey request to avoid missing device error.") - throw MessageSenderError.missingDevice - } - // As an optimization, skip the request if an error is guaranteed. if willDefinitelyHaveUntrustedIdentityError(for: serviceId) { Logger.info("Skipping prekey request due to untrusted identity.") @@ -171,7 +163,6 @@ public class MessageSender { } catch { switch error.httpStatusCode { case 404: - self.reportMissingDeviceError(serviceId: serviceId, deviceId: deviceId) throw MessageSenderError.missingDevice case 429: throw MessageSenderError.prekeyRateLimit @@ -392,54 +383,6 @@ public class MessageSender { return true } - // MARK: - Missing Devices - - private struct CacheKey: Hashable { - let serviceId: ServiceId - let deviceId: UInt32 - } - - private let missingDevicesCache = AtomicDictionary(lock: .init()) - - private func reportMissingDeviceError(serviceId: ServiceId, deviceId: UInt32) { - assert(!Thread.isMainThread) - - guard deviceId == OWSDevice.primaryDeviceId else { - // For now, only bother ignoring primary devices. HTTP 404s should cause - // the recipient's device list to be updated, so linked devices shouldn't - // be a problem. - return - } - - let cacheKey = CacheKey(serviceId: serviceId, deviceId: deviceId) - missingDevicesCache[cacheKey] = Date() - } - - private func deviceRecentlyReportedMissing(serviceId: ServiceId, deviceId: UInt32) -> Bool { - assert(!Thread.isMainThread) - - // Prekey rate limits are strict. Therefore, we want to avoid requesting - // prekey bundles that are missing on the service (404). - - let cacheKey = CacheKey(serviceId: serviceId, deviceId: deviceId) - let recentlyReportedMissingDate = missingDevicesCache[cacheKey] - - guard let recentlyReportedMissingDate else { - return false - } - - // If the "missing device" was recorded more than N minutes ago, try - // another prekey fetch. It's conceivable that the recipient has - // registered (in the primary device case) or linked to the device (in the - // secondary device case). - let missingDeviceLifetime = kMinuteInterval * 1 - guard abs(recentlyReportedMissingDate.timeIntervalSinceNow) < missingDeviceLifetime else { - return false - } - - return true - } - // MARK: - Sending Attachments public func sendTransientContactSyncAttachment(