Skip to content

Commit

Permalink
Made things consistent re:compression and encoding.
Browse files Browse the repository at this point in the history
Incorporated review feedback.

Removed the "backwards compatibility" config option.
  • Loading branch information
pmarkowsky committed Apr 21, 2023
1 parent f5dc560 commit dea0e8e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 40 deletions.
8 changes: 4 additions & 4 deletions Source/common/SNTCommonEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ typedef NS_ENUM(NSInteger, SNTSyncStatusType) {
SNTSyncStatusTypeUnknown,
};

typedef NS_ENUM(NSInteger, SNTSyncCompressionEncoding) {
SNTSyncCompressionEncodingNone,
SNTSyncCompressionEncodingZlib,
SNTSyncCompressionEncodingGzip,
typedef NS_ENUM(NSInteger, SNTSyncContentEncoding) {
SNTSyncContentEncodingNone,
SNTSyncContentEncodingZlib,
SNTSyncContentEncodingGzip,
};

typedef NS_ENUM(NSInteger, SNTMetricFormatType) {
Expand Down
4 changes: 2 additions & 2 deletions Source/common/SNTConfigurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,9 @@

///
/// If set, "santactl sync" will use the supplied "Content-Encoding", possible
/// settings include gzip, deflate, none.
/// settings include "gzip", "deflate", "none". If empty defaults to "deflate".
///
@property(readonly, nonatomic) SNTSyncCompressionEncoding syncClientContentEncoding;
@property(readonly, nonatomic) SNTSyncContentEncoding syncClientContentEncoding;

///
/// Contains the FCM project name.
Expand Down
22 changes: 5 additions & 17 deletions Source/common/SNTConfigurator.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ @implementation SNTConfigurator
static NSString *const kIgnoreOtherEndpointSecurityClients = @"IgnoreOtherEndpointSecurityClients";
static NSString *const kEnableDebugLogging = @"EnableDebugLogging";

static NSString *const kEnableBackwardsCompatibleContentEncoding =
@"EnableBackwardsCompatibleContentEncoding";
static NSString *const kClientContentEncoding = @"SyncClientContentEncoding";

static NSString *const kFCMProject = @"FCMProject";
Expand Down Expand Up @@ -223,7 +221,6 @@ - (instancetype)init {
kEnableForkAndExitLogging : number,
kIgnoreOtherEndpointSecurityClients : number,
kEnableDebugLogging : number,
kEnableBackwardsCompatibleContentEncoding : number,
kFCMProject : string,
kFCMEntity : string,
kFCMAPIKey : string,
Expand Down Expand Up @@ -465,10 +462,6 @@ + (NSSet *)keyPathsForValuesAffectingEnableDebugLogging {
return [self configStateSet];
}

+ (NSSet *)keyPathsForValuesAffectingEnableBackwardsCompatibleContentEncoding {
return [self configStateSet];
}

+ (NSSet *)keyPathsForValuesAffectingFcmProject {
return [self configStateSet];
}
Expand Down Expand Up @@ -717,17 +710,17 @@ - (NSString *)syncClientAuthCertificateIssuer {
return self.configState[kClientAuthCertificateIssuerKey];
}

- (SNTSyncCompressionEncoding)syncClientContentEncoding {
- (SNTSyncContentEncoding)syncClientContentEncoding {
NSString *contentEncoding = [self.configState[kClientContentEncoding] lowercaseString];
if ([contentEncoding isEqualToString:@"deflate"]) {
return SNTSyncCompressionEncodingZlib;
return SNTSyncContentEncodingZlib;
} else if ([contentEncoding isEqualToString:@"gzip"]) {
return SNTSyncCompressionEncodingGzip;
return SNTSyncContentEncodingGzip;
} else if ([contentEncoding isEqualToString:@"none"]) {
return SNTSyncCompressionEncodingNone;
return SNTSyncContentEncodingNone;
} else {
// Ensure we have the same default zlib behavior Santa's always had otherwise.
return SNTSyncCompressionEncodingZlib;
return SNTSyncContentEncodingZlib;
}
}

Expand Down Expand Up @@ -904,11 +897,6 @@ - (BOOL)enableDebugLogging {
return [number boolValue] || self.debugFlag;
}

- (BOOL)enableBackwardsCompatibleContentEncoding {
NSNumber *number = self.configState[kEnableBackwardsCompatibleContentEncoding];
return number ? [number boolValue] : NO;
}

- (NSString *)fcmProject {
return self.configState[kFCMProject];
}
Expand Down
6 changes: 1 addition & 5 deletions Source/santasyncservice/SNTSyncManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,7 @@ - (SNTSyncState *)createSyncStateWithStatus:(SNTSyncStatusType *)status {

syncState.session = [authURLSession session];
syncState.daemonConn = self.daemonConn;
syncState.compressionEncoding = config.syncClientContentEncoding;

syncState.compressedContentEncoding =
config.enableBackwardsCompatibleContentEncoding ? @"zlib" : @"deflate";

syncState.contentEncoding = config.syncClientContentEncoding;
syncState.pushNotificationsToken = self.pushNotifications.token;

return syncState;
Expand Down
12 changes: 6 additions & 6 deletions Source/santasyncservice/SNTSyncStage.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ - (NSMutableURLRequest *)requestWithDictionary:(NSDictionary *)dictionary {
NSData *compressed;
NSString *contentEncodingHeader;

switch (self.syncState.compressionEncoding) {
case SNTSyncCompressionEncodingNone: break;
case SNTSyncCompressionEncodingGzip:
switch (self.syncState.contentEncoding) {
case SNTSyncContentEncodingNone: break;
case SNTSyncContentEncodingGzip:
compressed = [requestBody gzipCompressed];
contentEncodingHeader = @"gzip";
break;
case SNTSyncCompressionEncodingZlib:
case SNTSyncContentEncodingZlib:
compressed = [requestBody zlibCompressed];
contentEncodingHeader = @"deflate";
break;
default:
compressed = [requestBody zlibCompressed];
contentEncodingHeader = self.syncState.compressedContentEncoding;
// This would be a programming error.
LOGD(@"Unexpected value for content encoding %ld", self.syncState.contentEncoding);
}

if (compressed) {
Expand Down
8 changes: 2 additions & 6 deletions Source/santasyncservice/SNTSyncState.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@
/// Array of bundle IDs to find binaries for.
@property NSArray *bundleBinaryRequests;

/// The header value for ContentEncoding when sending compressed content.
/// Either "deflate" (default) or "zlib".
@property(copy) NSString *compressedContentEncoding;

/// The compression type to use for the sync session.
@property SNTSyncCompressionEncoding compressionEncoding;
/// The content-encoding to use for the client uploads during the sync session.
@property SNTSyncContentEncoding contentEncoding;

@end

0 comments on commit dea0e8e

Please sign in to comment.