Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-1494] No connection serial #1714

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions Ably.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,6 @@
21276CC229F00BAA00107B5F /* ContinuousClockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21276CC129F00BAA00107B5F /* ContinuousClockTests.swift */; };
21276CC329F00BAA00107B5F /* ContinuousClockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21276CC129F00BAA00107B5F /* ContinuousClockTests.swift */; };
21276CC429F00BAA00107B5F /* ContinuousClockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21276CC129F00BAA00107B5F /* ContinuousClockTests.swift */; };
2132C20E29D20EEC000C4355 /* ARTResumeRequestResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 2132C20D29D20EEC000C4355 /* ARTResumeRequestResponse.h */; settings = {ATTRIBUTES = (Private, ); }; };
2132C20F29D20EEC000C4355 /* ARTResumeRequestResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 2132C20D29D20EEC000C4355 /* ARTResumeRequestResponse.h */; settings = {ATTRIBUTES = (Private, ); }; };
2132C21029D20EEC000C4355 /* ARTResumeRequestResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 2132C20D29D20EEC000C4355 /* ARTResumeRequestResponse.h */; settings = {ATTRIBUTES = (Private, ); }; };
2132C21229D20F05000C4355 /* ARTResumeRequestResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 2132C21129D20F05000C4355 /* ARTResumeRequestResponse.m */; };
2132C21329D20F05000C4355 /* ARTResumeRequestResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 2132C21129D20F05000C4355 /* ARTResumeRequestResponse.m */; };
2132C21429D20F05000C4355 /* ARTResumeRequestResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 2132C21129D20F05000C4355 /* ARTResumeRequestResponse.m */; };
2132C21629D20F69000C4355 /* ResumeRequestResponseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2132C21529D20F69000C4355 /* ResumeRequestResponseTests.swift */; };
2132C21729D20F69000C4355 /* ResumeRequestResponseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2132C21529D20F69000C4355 /* ResumeRequestResponseTests.swift */; };
2132C21829D20F69000C4355 /* ResumeRequestResponseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2132C21529D20F69000C4355 /* ResumeRequestResponseTests.swift */; };
2132C21A29D230CE000C4355 /* ARTErrorChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = 2132C21929D230AE000C4355 /* ARTErrorChecker.h */; settings = {ATTRIBUTES = (Private, ); }; };
2132C21B29D230CF000C4355 /* ARTErrorChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = 2132C21929D230AE000C4355 /* ARTErrorChecker.h */; settings = {ATTRIBUTES = (Private, ); }; };
2132C21C29D230D0000C4355 /* ARTErrorChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = 2132C21929D230AE000C4355 /* ARTErrorChecker.h */; settings = {ATTRIBUTES = (Private, ); }; };
Expand Down Expand Up @@ -1169,9 +1160,6 @@
21276CB929EF323100107B5F /* ARTContinuousClock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ARTContinuousClock.h; path = PrivateHeaders/Ably/ARTContinuousClock.h; sourceTree = "<group>"; };
21276CBD29EF34AE00107B5F /* ARTContinuousClock.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ARTContinuousClock.m; sourceTree = "<group>"; };
21276CC129F00BAA00107B5F /* ContinuousClockTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContinuousClockTests.swift; sourceTree = "<group>"; };
2132C20D29D20EEC000C4355 /* ARTResumeRequestResponse.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ARTResumeRequestResponse.h; path = PrivateHeaders/Ably/ARTResumeRequestResponse.h; sourceTree = "<group>"; };
2132C21129D20F05000C4355 /* ARTResumeRequestResponse.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ARTResumeRequestResponse.m; sourceTree = "<group>"; };
2132C21529D20F69000C4355 /* ResumeRequestResponseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResumeRequestResponseTests.swift; sourceTree = "<group>"; };
2132C21929D230AE000C4355 /* ARTErrorChecker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ARTErrorChecker.h; path = PrivateHeaders/Ably/ARTErrorChecker.h; sourceTree = "<group>"; };
2132C21D29D23196000C4355 /* ARTErrorChecker.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ARTErrorChecker.m; sourceTree = "<group>"; };
2132C22129D233EB000C4355 /* DefaultErrorCheckerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultErrorCheckerTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1729,7 +1717,6 @@
D72768201C9C19040022F8B2 /* RestClientPresenceTests.swift */,
853ED7C31B7A1A3C006F1C6F /* RestClientStatsTests.swift */,
D74CBC09212EC02C00D090E4 /* RestPaginatedTests.swift */,
2132C21529D20F69000C4355 /* ResumeRequestResponseTests.swift */,
217FCF3129D62460006E5F2D /* RetrySequenceTests.swift */,
851674EE1B7BA5CD00D35169 /* StatsTests.swift */,
D520C4DD2680A1E3000012B2 /* StringifiableTests.swift */,
Expand Down Expand Up @@ -1959,8 +1946,6 @@
EB89D4081C61C5ED007FA5B7 /* ARTRealtimeChannels.h */,
D7CEF12C1C8D821D004FB242 /* ARTRealtimeChannels+Private.h */,
EB89D40A1C61C6EA007FA5B7 /* ARTRealtimeChannels.m */,
2132C20D29D20EEC000C4355 /* ARTResumeRequestResponse.h */,
2132C21129D20F05000C4355 /* ARTResumeRequestResponse.m */,
2104EFAB2A4CC33300CC1184 /* ARTAttachRetryState.h */,
2104EFA72A4CC30C00CC1184 /* ARTAttachRetryState.m */,
21088DC22A5354F10033C722 /* ARTConnectRetryState.h */,
Expand Down Expand Up @@ -2246,7 +2231,6 @@
D7534C321D79E5C20054C182 /* Ably.h in Headers */,
D777EEE0206285CF002EBA03 /* ARTDeviceIdentityTokenDetails.h in Headers */,
2124B79F29DB14D000AD8361 /* ARTLogAdapter.h in Headers */,
2132C20E29D20EEC000C4355 /* ARTResumeRequestResponse.h in Headers */,
215F76032922C76C009E0E76 /* ARTClientInformation+Private.h in Headers */,
211A610329DA05C700D169C5 /* ARTAttachRequestMetadata.h in Headers */,
96BF615E1A35C1C8004CF2B3 /* ARTTypes.h in Headers */,
Expand Down Expand Up @@ -2552,7 +2536,6 @@
D5BB211026AA993C00AA5F3E /* ARTNSURL+ARTUtils.h in Headers */,
D710D60E21949DDB008F54AD /* ARTPaginatedResult.h in Headers */,
D710D4BF21949B6C008F54AD /* ARTNSMutableRequest+ARTRest.h in Headers */,
2132C20F29D20EEC000C4355 /* ARTResumeRequestResponse.h in Headers */,
2147F02E29E583AD0071CB94 /* ARTInternalLogCore.h in Headers */,
D710D5BE21949D4F008F54AD /* ARTBaseMessage+Private.h in Headers */,
D5BB20FE26A7F50000AA5F3E /* ARTSRPinningSecurityPolicy.h in Headers */,
Expand Down Expand Up @@ -2721,7 +2704,6 @@
D710D61821949DDC008F54AD /* ARTPaginatedResult.h in Headers */,
D5BB213B26AAA60500AA5F3E /* ARTNSError+ARTUtils.h in Headers */,
D710D4C121949B6D008F54AD /* ARTNSMutableRequest+ARTRest.h in Headers */,
2132C21029D20EEC000C4355 /* ARTResumeRequestResponse.h in Headers */,
2147F02F29E583AD0071CB94 /* ARTInternalLogCore.h in Headers */,
D710D5CE21949D50008F54AD /* ARTBaseMessage+Private.h in Headers */,
D5BB20FF26A7F50800AA5F3E /* ARTSRPinningSecurityPolicy.h in Headers */,
Expand Down Expand Up @@ -3074,7 +3056,6 @@
D510E4AB29F1659F00F77F43 /* Aspects.m in Sources */,
D74A17B81FA0D9A3006D27B5 /* PushAdminTests.swift in Sources */,
2110CC3A2A530D42007310D4 /* AttachRetryStateTests.swift in Sources */,
2132C21629D20F69000C4355 /* ResumeRequestResponseTests.swift in Sources */,
EB7913A81C6E54C3000ABF9B /* CryptoTests.swift in Sources */,
2132C22229D233EB000C4355 /* DefaultErrorCheckerTests.swift in Sources */,
21FD9F272A015BE400216482 /* Test.swift in Sources */,
Expand Down Expand Up @@ -3170,7 +3151,6 @@
D7D29B421BE3DEB300374295 /* ARTConnection.m in Sources */,
D74CBC08212EB5B900D090E4 /* ARTNSMutableURLRequest+ARTPaginated.m in Sources */,
96BF61711A35FB7C004CF2B3 /* ARTAuth.m in Sources */,
2132C21229D20F05000C4355 /* ARTResumeRequestResponse.m in Sources */,
96E408441A38939E00087F77 /* ARTProtocolMessage.m in Sources */,
D71966E51E5DF360000974DD /* ARTPushActivationStateMachine.m in Sources */,
EB9121401CA0AD8200BA0A40 /* ARTMsgPackEncoder.m in Sources */,
Expand Down Expand Up @@ -3261,7 +3241,6 @@
D798554923EB96C000946BE2 /* DeltaCodecTests.swift in Sources */,
2124B78829DB127900AD8361 /* MockVersion2Log.swift in Sources */,
D510E4AC29F1659F00F77F43 /* Aspects.m in Sources */,
2132C21729D20F69000C4355 /* ResumeRequestResponseTests.swift in Sources */,
21113B4A29DB60F800652C86 /* MockRetryDelayCalculator.swift in Sources */,
217FCF4329D626E4006E5F2D /* MockJitterCoefficientGenerator.swift in Sources */,
D7093C21219E466E00723F17 /* RestClientChannelsTests.swift in Sources */,
Expand Down Expand Up @@ -3320,7 +3299,6 @@
D798554A23EB96C000946BE2 /* DeltaCodecTests.swift in Sources */,
2124B78929DB127900AD8361 /* MockVersion2Log.swift in Sources */,
D510E4AD29F1659F00F77F43 /* Aspects.m in Sources */,
2132C21829D20F69000C4355 /* ResumeRequestResponseTests.swift in Sources */,
21113B4B29DB60F800652C86 /* MockRetryDelayCalculator.swift in Sources */,
217FCF4429D626E4006E5F2D /* MockJitterCoefficientGenerator.swift in Sources */,
D7093C74219EE26400723F17 /* AuthTests.swift in Sources */,
Expand Down Expand Up @@ -3414,7 +3392,6 @@
D710D49921949ACA008F54AD /* ARTAuth.m in Sources */,
D710D5D321949D78008F54AD /* ARTTokenParams.m in Sources */,
D710D53221949C54008F54AD /* ARTPushChannel.m in Sources */,
2132C21329D20F05000C4355 /* ARTResumeRequestResponse.m in Sources */,
D710D5D421949D78008F54AD /* ARTTokenDetails.m in Sources */,
D710D49B21949ACA008F54AD /* ARTRestChannels.m in Sources */,
D710D62E21949E03008F54AD /* ARTURLSessionServerTrust.m in Sources */,
Expand Down Expand Up @@ -3540,7 +3517,6 @@
D710D5F921949D79008F54AD /* ARTTokenParams.m in Sources */,
D710D54421949C55008F54AD /* ARTPushChannel.m in Sources */,
D710D5FA21949D79008F54AD /* ARTTokenDetails.m in Sources */,
2132C21429D20F05000C4355 /* ARTResumeRequestResponse.m in Sources */,
D710D4A521949ACB008F54AD /* ARTRestChannels.m in Sources */,
D710D63E21949E04008F54AD /* ARTURLSessionServerTrust.m in Sources */,
D710D65121949E77008F54AD /* ARTJsonEncoder.m in Sources */,
Expand Down
145 changes: 102 additions & 43 deletions Source/ARTConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#import "ARTRealtime+Private.h"
#import "ARTEventEmitter+Private.h"
#import "ARTQueuedDealloc.h"
#import "ARTRealtimeChannels+Private.h"
#import "ARTRealtimeChannel+Private.h"

#define IsInactiveConnectionState(state) (state == ARTRealtimeClosing || state == ARTRealtimeClosed || state == ARTRealtimeFailed || state == ARTRealtimeSuspended)

@implementation ARTConnection {
ARTQueuedDealloc *_dealloc;
Expand All @@ -20,12 +24,16 @@ - (NSString *)key {
return _internal.key;
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-implementations"
- (NSString *)recoveryKey {
return _internal.recoveryKey;
return [_internal createRecoveryKey];
}
#pragma GCC diagnostic pop

- (int64_t)serial {
return _internal.serial;
// RTN16g - recovery key as a JSON serialized version of [ARTConnectionRecoveryKey]
- (NSString *)createRecoveryKey {
return [_internal createRecoveryKey];
}

- (NSInteger)maxMessageSize {
Expand Down Expand Up @@ -96,7 +104,6 @@ @implementation ARTConnectionInternal {
NSString *_id;
NSString *_key;
NSInteger _maxMessageSize;
int64_t _serial;
ARTRealtimeConnectionState _state;
ARTErrorInfo *_errorReason;
}
Expand All @@ -106,7 +113,6 @@ - (instancetype)initWithRealtime:(ARTRealtimeInternal *)realtime logger:(ARTInte
_eventEmitter = [[ARTPublicEventEmitter alloc] initWithRest:realtime.rest logger:logger];
_realtime = realtime;
_queue = _realtime.rest.queue;
_serial = -1;
}
return self;
}
Expand Down Expand Up @@ -139,14 +145,6 @@ - (NSString *)key {
return ret;
}

- (int64_t)serial {
__block int64_t ret;
dispatch_sync(_queue, ^{
ret = [self serial_nosync];
});
return ret;
}

- (ARTRealtimeConnectionState)state {
__block ARTRealtimeConnectionState ret;
dispatch_sync(_queue, ^{
Expand Down Expand Up @@ -195,10 +193,6 @@ - (NSString *)key_nosync {
return _key;
}

- (int64_t)serial_nosync {
return _serial;
}

- (ARTRealtimeConnectionState)state_nosync {
return _state;
}
Expand All @@ -215,44 +209,22 @@ - (void)setKey:(NSString *)key {
_key = key;
}

- (void)setSerial:(int64_t)serial {
_serial = serial;
}

- (void)setMaxMessageSize:(NSInteger)maxMessageSize {
_maxMessageSize = maxMessageSize;
}

- (void)setState:(ARTRealtimeConnectionState)state {
_state = state;
if (IsInactiveConnectionState(state)) {
_id = nil; // RTN8c
_key = nil; // RTN9c
}
}

- (void)setErrorReason:(ARTErrorInfo *_Nullable)errorReason {
_errorReason = errorReason;
}

- (NSString *)recoveryKey {
__block NSString *ret;
dispatch_sync(_queue, ^{
ret = [self recoveryKey_nosync];
});
return ret;
}

- (NSString *)recoveryKey_nosync {
switch(self.state_nosync) {
case ARTRealtimeConnecting:
case ARTRealtimeConnected:
case ARTRealtimeDisconnected:
case ARTRealtimeSuspended: {
return [self.key_nosync stringByAppendingString:[NSString stringWithFormat:@":%ld:%ld", (long)self.serial_nosync, (long)_realtime.msgSerial]];
}
default: {
return nil;
}
}
}

- (ARTEventListener *)on:(ARTRealtimeConnectionEvent)event callback:(ARTConnectionStateCallback)cb {
return [_eventEmitter on:[ARTEvent newWithConnectionEvent:event] callback:cb];
}
Expand Down Expand Up @@ -284,6 +256,39 @@ - (void)off:(ARTEventListener *)listener {
[_eventEmitter off:listener];
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
- (NSString *)recoveryKey {
return [self createRecoveryKey];
}
#pragma clang diagnostic pop

- (NSString *)createRecoveryKey_nosync {
sacOO7 marked this conversation as resolved.
Show resolved Hide resolved
if (_key == nil || IsInactiveConnectionState(_state)) { // RTN16g2
return nil;
}

NSMutableDictionary<NSString *, NSString *> *channelSerials = [NSMutableDictionary new];
for (ARTRealtimeChannelInternal *const channel in _realtime.channels.nosyncIterable) {
lawrence-forooghian marked this conversation as resolved.
Show resolved Hide resolved
lawrence-forooghian marked this conversation as resolved.
Show resolved Hide resolved
if (channel.state_nosync == ARTRealtimeChannelAttached) {
sacOO7 marked this conversation as resolved.
Show resolved Hide resolved
channelSerials[channel.name] = channel.serial;
}
}

ARTConnectionRecoveryKey *const recoveryKey = [[ARTConnectionRecoveryKey alloc] initWithConnectionKey:_key
msgSerial:_realtime.msgSerial
channelSerials:channelSerials];
return [recoveryKey jsonString];
}

- (NSString *)createRecoveryKey {
__block NSString *ret;
dispatch_sync(_queue, ^{
ret = [self createRecoveryKey_nosync];
});
return ret;
}

- (void)emit:(ARTRealtimeConnectionEvent)event with:(ARTConnectionStateChange *)data {
[_eventEmitter emit:[ARTEvent newWithConnectionEvent:event] with:data];
}
Expand All @@ -303,3 +308,57 @@ + (instancetype)newWithConnectionEvent:(ARTRealtimeConnectionEvent)value {
}

@end

@implementation ARTConnectionRecoveryKey

- (instancetype)initWithConnectionKey:(NSString *)connectionKey
msgSerial:(int64_t)msgSerial
channelSerials:(NSDictionary<NSString *, NSString *> *)channelSerials {
self = [super init];
if (self) {
_connectionKey = connectionKey;
_msgSerial = msgSerial;
_channelSerials = channelSerials;
}
return self;
}

- (NSString *)jsonString {
NSError *error;
NSDictionary *const object = @{
@"msgSerial": @(_msgSerial),
@"connectionKey": _connectionKey,
@"channelSerials": _channelSerials
};

NSData *const jsonData = [NSJSONSerialization dataWithJSONObject:object
options:0
error:&error];
if (error) {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:[NSString stringWithFormat:@"%@: This JSON serialization should pass without errors.", self.class]
userInfo:nil];
}

return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}

+ (ARTConnectionRecoveryKey *)fromJsonString:(NSString *)json error:(NSError **)errorPtr {
NSData *const jsonData = [json dataUsingEncoding:NSUTF8StringEncoding];

NSError *error = nil;
NSDictionary *const object = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];

if (error) {
if (errorPtr) {
*errorPtr = error;
}
return nil;
}

return [[ARTConnectionRecoveryKey alloc] initWithConnectionKey:[object valueForKey:@"connectionKey"]
msgSerial:[[object valueForKey:@"msgSerial"] longLongValue]
channelSerials:[object valueForKey:@"channelSerials"]];
}

@end
2 changes: 1 addition & 1 deletion Source/ARTDefault.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#import "ARTNSArray+ARTFunctional.h"
#import "ARTClientInformation+Private.h"

static NSString *const ARTDefault_apiVersion = @"1.2";
static NSString *const ARTDefault_apiVersion = @"2"; // CSV2

NSString *const ARTDefaultProduction = @"production";

Expand Down
4 changes: 0 additions & 4 deletions Source/ARTJsonLikeEncoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -719,10 +719,6 @@ - (ARTProtocolMessage *)protocolMessageFromDictionary:(NSDictionary *)input {
message.channel = [input artString:@"channel"];
message.channelSerial = [input artString:@"channelSerial"];
message.connectionId = [input artString:@"connectionId"];
NSNumber * serial = [input artNumber:@"connectionSerial"];
if (serial != nil) {
message.connectionSerial = [serial longLongValue];
}
message.id = [input artString:@"id"];
message.msgSerial = [input artNumber:@"msgSerial"];
message.timestamp = [input artTimestamp:@"timestamp"];
Expand Down
Loading
Loading