diff --git a/Signal/src/Signal-Bridging-Header.h b/Signal/src/Signal-Bridging-Header.h index 2f44a68a3..f6bb3b18f 100644 --- a/Signal/src/Signal-Bridging-Header.h +++ b/Signal/src/Signal-Bridging-Header.h @@ -84,7 +84,6 @@ #import #import #import -#import #import #import #import diff --git a/Signal/src/call/CallService.swift b/Signal/src/call/CallService.swift index d5670ee89..335de2a36 100644 --- a/Signal/src/call/CallService.swift +++ b/Signal/src/call/CallService.swift @@ -78,7 +78,7 @@ public enum CallError: Error { case externalError(underlyingError: Error) case timeout(description: String) case obsoleteCall(description: String) - case protoErro(description: String) + case fatalError(description: String) } // Should be roughly synced with Android client for consistency @@ -417,7 +417,7 @@ private class SignalCallData: NSObject { return self.messageSender.sendPromise(message: callMessage) } catch { owsFail("Couldn't build proto in \(#function)") - throw CallError.protoErro(description: "Couldn't build proto in \(#function)") + throw CallError.fatalError(description: "Couldn't build proto in \(#function)") } } }.then { @@ -722,7 +722,7 @@ private class SignalCallData: NSObject { return self.messageSender.sendPromise(message: callAnswerMessage) } catch { owsFail("Couldn't build proto in \(#function)") - throw CallError.protoErro(description: "Couldn't build proto in \(#function)") + throw CallError.fatalError(description: "Couldn't build proto in \(#function)") } }.then { guard self.call == newCall else { @@ -841,12 +841,38 @@ private class SignalCallData: NSObject { return } - let iceUpdateMessage = OWSCallIceUpdateMessage(callId: call.signalingId, sdp: iceCandidate.sdp, sdpMLineIndex: iceCandidate.sdpMLineIndex, sdpMid: iceCandidate.sdpMid) + guard let sdpMid = iceCandidate.sdpMid else { + owsFail("Missing sdpMid in \(#function)") + throw CallError.fatalError(description: "Missing sdpMid in \(#function)") + } + + guard iceCandidate.sdpMLineIndex < UINT32_MAX else { + owsFail("Invalid sdpMLineIndex in \(#function)") + throw CallError.fatalError(description: "Invalid sdpMLineIndex in \(#function)") + } Logger.info("\(self.logTag) in \(#function) sending ICE Candidate \(call.identifiersForLogs).") - let callMessage = OWSOutgoingCallMessage(thread: call.thread, iceUpdateMessage: iceUpdateMessage) - let sendPromise = self.messageSender.sendPromise(message: callMessage) - sendPromise.retainUntilComplete() + + /** + * Sent by both parties out of band of the RTC calling channels, as part of setting up those channels. The messages + * include network accessibility information from the perspective of each client. Once compatible ICEUpdates have been + * exchanged, the clients can connect directly. + */ + let iceUpdateBuilder = SSKProtoCallMessageIceUpdate.SSKProtoCallMessageIceUpdateBuilder() + iceUpdateBuilder.setId(call.signalingId) + iceUpdateBuilder.setSdp(iceCandidate.sdp) + iceUpdateBuilder.setSdpMlineIndex(UInt32(iceCandidate.sdpMLineIndex)) + iceUpdateBuilder.setSdpMid(sdpMid) + do { + let iceUpdate = try iceUpdateBuilder.build() + + let callMessage = OWSOutgoingCallMessage(thread: call.thread, iceUpdateMessage: iceUpdate) + let sendPromise = self.messageSender.sendPromise(message: callMessage) + sendPromise.retainUntilComplete() + } catch { + owsFail("Couldn't build proto in \(#function)") + throw CallError.fatalError(description: "Couldn't build proto in \(#function)") + } }.catch { error in OWSProdInfo(OWSAnalyticsEvents.callServiceErrorHandleLocalAddedIceCandidate(), file: #file, function: #function, line: #line) Logger.error("\(self.logTag) in \(#function) waitUntilReadyToSendIceUpdates failed with error: \(error)") diff --git a/SignalServiceKit/src/Messages/OWSCallIceUpdateMessage.h b/SignalServiceKit/src/Messages/OWSCallIceUpdateMessage.h deleted file mode 100644 index a21dd55c6..000000000 --- a/SignalServiceKit/src/Messages/OWSCallIceUpdateMessage.h +++ /dev/null @@ -1,30 +0,0 @@ -// -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. -// - -NS_ASSUME_NONNULL_BEGIN - -@class SSKProtoCallMessageIceUpdate; - -/** - * Sent by both parties out of band of the RTC calling channels, as part of setting up those channels. The messages - * include network accessability information from the perspective of each client. Once compatible ICEUpdates have been - * exchanged, the clients can connect directly. - */ -@interface OWSCallIceUpdateMessage : NSObject - -- (instancetype)initWithCallId:(UInt64)callId - sdp:(NSString *)sdp - sdpMLineIndex:(SInt32)sdpMLineIndex - sdpMid:(nullable NSString *)sdpMid; - -@property (nonatomic, readonly) UInt64 callId; -@property (nonatomic, readonly, copy) NSString *sdp; -@property (nonatomic, readonly) SInt32 sdpMLineIndex; -@property (nullable, nonatomic, readonly, copy) NSString *sdpMid; - -- (nullable SSKProtoCallMessageIceUpdate *)asProtobuf; - -@end - -NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Messages/OWSCallIceUpdateMessage.m b/SignalServiceKit/src/Messages/OWSCallIceUpdateMessage.m deleted file mode 100644 index 373dd9192..000000000 --- a/SignalServiceKit/src/Messages/OWSCallIceUpdateMessage.m +++ /dev/null @@ -1,47 +0,0 @@ -// -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. -// - -#import "OWSCallIceUpdateMessage.h" -#import - -@implementation OWSCallIceUpdateMessage - -- (instancetype)initWithCallId:(UInt64)callId - sdp:(NSString *)sdp - sdpMLineIndex:(SInt32)sdpMLineIndex - sdpMid:(nullable NSString *)sdpMid -{ - self = [super init]; - if (!self) { - return self; - } - - _callId = callId; - _sdp = sdp; - _sdpMLineIndex = sdpMLineIndex; - _sdpMid = sdpMid; - - return self; -} - -- (nullable SSKProtoCallMessageIceUpdate *)asProtobuf -{ - SSKProtoCallMessageIceUpdateBuilder *builder = - [SSKProtoCallMessageIceUpdateBuilder new]; - - [builder setId:self.callId]; - [builder setSdp:self.sdp]; - [builder setSdpMlineIndex:self.sdpMLineIndex]; - [builder setSdpMid:self.sdpMid]; - - NSError *error; - SSKProtoCallMessageIceUpdate *_Nullable result = [builder buildAndReturnError:&error]; - if (error || !result) { - OWSFail(@"%@ could not build protobuf: %@", self.logTag, error); - return nil; - } - return result; -} - -@end diff --git a/SignalServiceKit/src/Messages/OWSOutgoingCallMessage.h b/SignalServiceKit/src/Messages/OWSOutgoingCallMessage.h index 6d911e52f..b0baca371 100644 --- a/SignalServiceKit/src/Messages/OWSOutgoingCallMessage.h +++ b/SignalServiceKit/src/Messages/OWSOutgoingCallMessage.h @@ -8,8 +8,8 @@ NS_ASSUME_NONNULL_BEGIN @class OWSCallBusyMessage; @class OWSCallHangupMessage; -@class OWSCallIceUpdateMessage; @class SSKProtoCallMessageAnswer; +@class SSKProtoCallMessageIceUpdate; @class SSKProtoCallMessageOffer; @class TSThread; @@ -31,15 +31,15 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithThread:(TSThread *)thread offerMessage:(SSKProtoCallMessageOffer *)offerMessage; - (instancetype)initWithThread:(TSThread *)thread answerMessage:(SSKProtoCallMessageAnswer *)answerMessage; -- (instancetype)initWithThread:(TSThread *)thread iceUpdateMessage:(OWSCallIceUpdateMessage *)iceUpdateMessage; +- (instancetype)initWithThread:(TSThread *)thread iceUpdateMessage:(SSKProtoCallMessageIceUpdate *)iceUpdateMessage; - (instancetype)initWithThread:(TSThread *)thread - iceUpdateMessages:(NSArray *)iceUpdateMessage; + iceUpdateMessages:(NSArray *)iceUpdateMessage; - (instancetype)initWithThread:(TSThread *)thread hangupMessage:(OWSCallHangupMessage *)hangupMessage; - (instancetype)initWithThread:(TSThread *)thread busyMessage:(OWSCallBusyMessage *)busyMessage; @property (nullable, nonatomic, readonly) SSKProtoCallMessageOffer *offerMessage; @property (nullable, nonatomic, readonly) SSKProtoCallMessageAnswer *answerMessage; -@property (nullable, nonatomic, readonly) NSArray *iceUpdateMessages; +@property (nullable, nonatomic, readonly) NSArray *iceUpdateMessages; @property (nullable, nonatomic, readonly) OWSCallHangupMessage *hangupMessage; @property (nullable, nonatomic, readonly) OWSCallBusyMessage *busyMessage; diff --git a/SignalServiceKit/src/Messages/OWSOutgoingCallMessage.m b/SignalServiceKit/src/Messages/OWSOutgoingCallMessage.m index b3ee69a71..57296f53b 100644 --- a/SignalServiceKit/src/Messages/OWSOutgoingCallMessage.m +++ b/SignalServiceKit/src/Messages/OWSOutgoingCallMessage.m @@ -6,7 +6,6 @@ #import "NSDate+OWS.h" #import "OWSCallBusyMessage.h" #import "OWSCallHangupMessage.h" -#import "OWSCallIceUpdateMessage.h" #import "ProtoUtils.h" #import "SignalRecipient.h" #import "TSContactThread.h" @@ -61,7 +60,7 @@ NS_ASSUME_NONNULL_BEGIN return self; } -- (instancetype)initWithThread:(TSThread *)thread iceUpdateMessage:(OWSCallIceUpdateMessage *)iceUpdateMessage +- (instancetype)initWithThread:(TSThread *)thread iceUpdateMessage:(SSKProtoCallMessageIceUpdate *)iceUpdateMessage { self = [self initWithThread:thread]; if (!self) { @@ -74,7 +73,7 @@ NS_ASSUME_NONNULL_BEGIN } - (instancetype)initWithThread:(TSThread *)thread - iceUpdateMessages:(NSArray *)iceUpdateMessages + iceUpdateMessages:(NSArray *)iceUpdateMessages { self = [self initWithThread:thread]; if (!self) { @@ -152,14 +151,8 @@ NS_ASSUME_NONNULL_BEGIN [builder setAnswer:self.answerMessage]; } - if (self.iceUpdateMessages) { - for (OWSCallIceUpdateMessage *iceUpdateMessage in self.iceUpdateMessages) { - SSKProtoCallMessageIceUpdate *_Nullable proto = [iceUpdateMessage asProtobuf]; - if (!proto) { - return nil; - } - [builder addIceUpdate:proto]; - } + if (self.iceUpdateMessages.count > 0) { + [builder setIceUpdate:self.iceUpdateMessages]; } if (self.hangupMessage) {