diff --git a/SignalServiceKit/Network/SgxWebsocketConnection/SgxWebsocketConnection.swift b/SignalServiceKit/Network/SgxWebsocketConnection/SgxWebsocketConnection.swift index 93ac6ce47e..5731b061b8 100644 --- a/SignalServiceKit/Network/SgxWebsocketConnection/SgxWebsocketConnection.swift +++ b/SignalServiceKit/Network/SgxWebsocketConnection/SgxWebsocketConnection.swift @@ -34,11 +34,6 @@ public class SgxWebsocketConnection { fatalError("Concrete subclass must implement") } - // Subclasses must implement. - func sendRequestAndReadAllResponses(_ request: Configurator.Request) async throws -> [Configurator.Response] { - fatalError("Concrete subclass must implement") - } - // Subclasses must implement. func disconnect(code: URLSessionWebSocketTask.CloseCode?) { fatalError("Concrete subclass must implement") @@ -131,17 +126,6 @@ public class SgxWebsocketConnectionImpl: return try Configurator.Response(serializedBytes: data) } - override public func sendRequestAndReadAllResponses( - _ request: Configurator.Request, - ) async throws -> [Configurator.Response] { - try self.encryptAndSendRequest(request.serializedData()) - let encryptedResponses = try await self.webSocket.waitForAllResponses().awaitable() - return try encryptedResponses.map { - let data = try self.decryptResponse($0) - return try Configurator.Response(serializedBytes: data) - } - } - private func encryptAndSendRequest(_ request: Data) throws { let encryptedRequest = try client.establishedSend(request) webSocket.send(data: encryptedRequest) @@ -184,14 +168,6 @@ public class MockSgxWebsocketConnection: try await onSendRequestAndReadResponse!(request).awaitable() } - public var onSendRequestAndReadAllResponses: ((Configurator.Request) -> Promise<[Configurator.Response]>)? - - override public func sendRequestAndReadAllResponses( - _ request: Configurator.Request, - ) async throws -> [Configurator.Response] { - try await onSendRequestAndReadAllResponses!(request).awaitable() - } - public var onDisconnect: (() -> Void)? override public func disconnect(code: URLSessionWebSocketTask.CloseCode?) { diff --git a/SignalServiceKit/Network/WebSocketPromise.swift b/SignalServiceKit/Network/WebSocketPromise.swift index 5f30d95c84..87234ba5ab 100644 --- a/SignalServiceKit/Network/WebSocketPromise.swift +++ b/SignalServiceKit/Network/WebSocketPromise.swift @@ -34,7 +34,7 @@ final class WebSocketPromise: SSKWebSocketDelegate { /// Initialize a WebSocketPromise & try to connect. /// /// If an error occurs while connecting, it'll be reported on the first - /// invocation of `waitForResponse`/`waitForAllResponses`. + /// invocation of `waitForResponse`. init(webSocket: SSKWebSocket) { self.webSocket = webSocket webSocket.delegate = self @@ -55,7 +55,6 @@ final class WebSocketPromise: SSKWebSocketDelegate { private enum WaitingState { case waitingForResponse(Future) - case waitingForAllResponses(Future<[Data]>) } private struct State { @@ -79,9 +78,9 @@ final class WebSocketPromise: SSKWebSocketDelegate { /// If a connection failure or write error occurred, it will be reported /// here in lieu of the next message. /// - /// The caller must ensure that `waitForResponse` and `waitForAllResponses` - /// are called sequentially. After calling one of these methods, the caller - /// must wait until the Promise is resolved before calling either method. + /// The caller must ensure that `waitForResponse` invocations happen + /// sequentially. After calling this method, the caller must wait until the + /// Promise is resolved before calling the method again. func waitForResponse() -> Promise { let (promise, future) = Promise.pending() updateState { state in @@ -91,28 +90,6 @@ final class WebSocketPromise: SSKWebSocketDelegate { return promise } - /// Read all remaining messages from the underlying web socket. - /// - /// If a connection failure or write error occurred, it will be reported - /// here in lieu of the next message. - /// - /// The caller must ensure that `waitForResponse` and `waitForAllResponses` - /// are called sequentially. After calling one of these methods, the caller - /// must wait until the Promise is resolved before calling either method. - /// - /// - Returns: - /// All remaining messages if the web socket is closed with the - /// `WebSocketError.normalClosure` code. Otherwise, rejects the promise - /// with the error that prevented the socket from closing normally. - func waitForAllResponses() -> Promise<[Data]> { - let (promise, future) = Promise<[Data]>.pending() - updateState { state in - owsPrecondition(state.waitingState == nil) - state.waitingState = .waitingForAllResponses(future) - } - return promise - } - private func updateState(updateBlock: (inout State) -> Void) { var resolveBlock: (() -> Void)? state.map { oldState in @@ -150,23 +127,6 @@ final class WebSocketPromise: SSKWebSocketDelegate { } // Keep waiting until we receive a message or an error. return nil - case .waitingForAllResponses(let future): - switch state.socketError { - case .some(WebSocketError.closeError(statusCode: WebSocketError.normalClosure, closeReason: _)): - // On iOS 13 & 14, we expect exactly one message. If we notice "!= 1" - // results on well-behaved platforms, surface it as an error since it's - // probably leading to incorrect behavior on iOS 13 & 14. - owsAssertDebug(state.receivedMessages.count == 1, "Must be exactly one message.") - let receivedMessages = state.receivedMessages - state.receivedMessages = [] - return { future.resolve(receivedMessages) } - case .some(let socketError): - return { future.reject(socketError) } - case .none: - break - } - // Keep waiting until the socket is closed. - return nil } }