Remove Obj-c proto parser.

This commit is contained in:
Matthew Chen 2018-08-07 12:57:48 -04:00
parent 39124190a6
commit a5ffbdebb3
23 changed files with 1105 additions and 108 deletions

View File

@ -9,10 +9,9 @@ def shared_pods
pod 'SQLCipher', :git => 'https://github.com/sqlcipher/sqlcipher.git', :commit => 'd5c2bec' pod 'SQLCipher', :git => 'https://github.com/sqlcipher/sqlcipher.git', :commit => 'd5c2bec'
# pod 'YapDatabase/SQLCipher', path: '../YapDatabase' # pod 'YapDatabase/SQLCipher', path: '../YapDatabase'
pod 'YapDatabase/SQLCipher', :git => 'https://github.com/signalapp/YapDatabase.git', branch: 'signal-release' pod 'YapDatabase/SQLCipher', :git => 'https://github.com/signalapp/YapDatabase.git', branch: 'signal-release'
# pod 'AxolotlKit', path: '../SignalProtocolKit'
pod 'SignalServiceKit', path: '.'
pod 'AxolotlKit', git: 'https://github.com/signalapp/SignalProtocolKit.git' pod 'AxolotlKit', git: 'https://github.com/signalapp/SignalProtocolKit.git'
# pod 'AxolotlKit', path: '../SignalProtocolKit' # pod 'AxolotlKit', path: '../SignalProtocolKit'
pod 'SignalServiceKit', path: '.'
pod 'HKDFKit', git: 'https://github.com/signalapp/HKDFKit.git' pod 'HKDFKit', git: 'https://github.com/signalapp/HKDFKit.git'
# pod 'HKDFKit', path: '../HKDFKit' # pod 'HKDFKit', path: '../HKDFKit'
pod 'Curve25519Kit', git: 'https://github.com/signalapp/Curve25519Kit' pod 'Curve25519Kit', git: 'https://github.com/signalapp/Curve25519Kit'

View File

@ -19,7 +19,7 @@ PODS:
- CocoaLumberjack - CocoaLumberjack
- Curve25519Kit (~> 2.1.0) - Curve25519Kit (~> 2.1.0)
- HKDFKit (~> 0.0.3) - HKDFKit (~> 0.0.3)
- ProtocolBuffers (~> 1.9.8) - SwiftProtobuf
- CocoaLumberjack (3.4.2): - CocoaLumberjack (3.4.2):
- CocoaLumberjack/Default (= 3.4.2) - CocoaLumberjack/Default (= 3.4.2)
- CocoaLumberjack/Extensions (= 3.4.2) - CocoaLumberjack/Extensions (= 3.4.2)
@ -44,7 +44,6 @@ PODS:
- PromiseKit/CorePromise - PromiseKit/CorePromise
- PromiseKit/UIKit (4.5.2): - PromiseKit/UIKit (4.5.2):
- PromiseKit/CorePromise - PromiseKit/CorePromise
- ProtocolBuffers (1.9.11)
- PureLayout (3.0.2) - PureLayout (3.0.2)
- Reachability (3.2) - Reachability (3.2)
- SAMKeychain (1.5.3) - SAMKeychain (1.5.3)
@ -161,7 +160,6 @@ SPEC REPOS:
- libPhoneNumber-iOS - libPhoneNumber-iOS
- Mantle - Mantle
- PromiseKit - PromiseKit
- ProtocolBuffers
- PureLayout - PureLayout
- Reachability - Reachability
- SAMKeychain - SAMKeychain
@ -192,7 +190,7 @@ EXTERNAL SOURCES:
CHECKOUT OPTIONS: CHECKOUT OPTIONS:
AxolotlKit: AxolotlKit:
:commit: 54d5f90558578bb96ebfa9688b3905093b489e31 :commit: 1fbdd114afe5ca981324892f22242d3a7a47794d
:git: https://github.com/signalapp/SignalProtocolKit.git :git: https://github.com/signalapp/SignalProtocolKit.git
Curve25519Kit: Curve25519Kit:
:commit: ced146699622ebd3d282bbfce3d492db4456e9aa :commit: ced146699622ebd3d282bbfce3d492db4456e9aa
@ -216,7 +214,7 @@ CHECKOUT OPTIONS:
SPEC CHECKSUMS: SPEC CHECKSUMS:
AFNetworking: b6f891fdfaed196b46c7a83cf209e09697b94057 AFNetworking: b6f891fdfaed196b46c7a83cf209e09697b94057
ATAppUpdater: a9f7027060959d47e58733d3b48f6b9a28cb8de1 ATAppUpdater: a9f7027060959d47e58733d3b48f6b9a28cb8de1
AxolotlKit: 7cfd2e71329b8dc398734e95b936450a2081fd60 AxolotlKit: 07bd978ea931d113939de88d3d2d354896680ceb
CocoaLumberjack: db7cc9e464771f12054c22ff6947c5a58d43a0fd CocoaLumberjack: db7cc9e464771f12054c22ff6947c5a58d43a0fd
Curve25519Kit: 76d0859ecb34704f7732847812363f83b23a6a59 Curve25519Kit: 76d0859ecb34704f7732847812363f83b23a6a59
GRKOpenSSLFramework: 8a3735ad41e7dc1daff460467bccd32ca5d6ae3e GRKOpenSSLFramework: 8a3735ad41e7dc1daff460467bccd32ca5d6ae3e
@ -224,7 +222,6 @@ SPEC CHECKSUMS:
libPhoneNumber-iOS: e444379ac18bbfbdefad571da735b2cd7e096caa libPhoneNumber-iOS: e444379ac18bbfbdefad571da735b2cd7e096caa
Mantle: 2fa750afa478cd625a94230fbf1c13462f29395b Mantle: 2fa750afa478cd625a94230fbf1c13462f29395b
PromiseKit: 743e497a5f505a470d3bbbf4ce0663c1268af0a4 PromiseKit: 743e497a5f505a470d3bbbf4ce0663c1268af0a4
ProtocolBuffers: d509225eb2ea43d9582a59e94348fcf86e2abd65
PureLayout: 4d550abe49a94f24c2808b9b95db9131685fe4cd PureLayout: 4d550abe49a94f24c2808b9b95db9131685fe4cd
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96 Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
SAMKeychain: 483e1c9f32984d50ca961e26818a534283b4cd5c SAMKeychain: 483e1c9f32984d50ca961e26818a534283b4cd5c
@ -236,6 +233,6 @@ SPEC CHECKSUMS:
YapDatabase: b418a4baa6906e8028748938f9159807fd039af4 YapDatabase: b418a4baa6906e8028748938f9159807fd039af4
YYImage: 1e1b62a9997399593e4b9c4ecfbbabbf1d3f3b54 YYImage: 1e1b62a9997399593e4b9c4ecfbbabbf1d3f3b54
PODFILE CHECKSUM: aa9ff0d7d6d50852127963f4b8aa60d8d1eff8d3 PODFILE CHECKSUM: 0c3d5978b54712391b5b90835b9554277b07fa23
COCOAPODS: 1.5.3 COCOAPODS: 1.5.3

View File

@ -375,6 +375,11 @@ class MessageContext(BaseContext):
writer.push_context(self.proto_name, self.swift_name) writer.push_context(self.proto_name, self.swift_name)
if self.args.add_log_tag:
writer.add('fileprivate static let logTag = "%s"' % self.swift_name)
writer.add('fileprivate let logTag = "%s"' % self.swift_name)
writer.newline()
for child in self.enums: for child in self.enums:
child.generate(writer) child.generate(writer)
@ -606,6 +611,17 @@ public func serializedData() throws -> Data {
writer.pop_indent() writer.pop_indent()
writer.add('}') writer.add('}')
writer.newline() writer.newline()
# description
writer.add('@objc public override var description: String {')
writer.push_indent()
writer.add('var fields = [String]()')
for field in self.fields():
writer.add('fields.append("%s: \(proto.%s)")' % ( field.name_swift, field.name_swift, ) )
writer.add('return "[" + fields.joined(separator: ", ") + "]"')
writer.pop_indent()
writer.add('}')
writer.newline()
writer.pop_context() writer.pop_context()
@ -710,13 +726,24 @@ public func serializedData() throws -> Data {
writer.add('}') writer.add('}')
writer.newline() writer.newline()
# build() func # buildSerializedData() func
writer.add('@objc public func buildSerializedData() throws -> Data {') writer.add('@objc public func buildSerializedData() throws -> Data {')
writer.push_indent() writer.push_indent()
writer.add('return try %s.parseProto(proto).serializedData()' % self.swift_name) writer.add('return try %s.parseProto(proto).serializedData()' % self.swift_name)
writer.pop_indent() writer.pop_indent()
writer.add('}') writer.add('}')
writer.newline() writer.newline()
# description
writer.add('@objc public override var description: String {')
writer.push_indent()
writer.add('var fields = [String]()')
for field in self.fields():
writer.add('fields.append("%s: \(proto.%s)")' % ( field.name_swift, field.name_swift, ) )
writer.add('return "[" + fields.joined(separator: ", ") + "]"')
writer.pop_indent()
writer.add('}')
writer.newline()
writer.pop_context() writer.pop_context()
@ -1096,6 +1123,7 @@ if __name__ == "__main__":
parser.add_argument('--wrapper-prefix', help='name prefix for generated wrappers.') parser.add_argument('--wrapper-prefix', help='name prefix for generated wrappers.')
parser.add_argument('--proto-prefix', help='name prefix for proto bufs.') parser.add_argument('--proto-prefix', help='name prefix for proto bufs.')
parser.add_argument('--dst-dir', help='path to the destination directory.') parser.add_argument('--dst-dir', help='path to the destination directory.')
parser.add_argument('--add-log-tag', action='store_true', help='add log tag properties.')
parser.add_argument('--verbose', action='store_true', help='enables verbose logging') parser.add_argument('--verbose', action='store_true', help='enables verbose logging')
args = parser.parse_args() args = parser.parse_args()

View File

@ -3015,7 +3015,6 @@
"${BUILT_PRODUCTS_DIR}/HKDFKit/HKDFKit.framework", "${BUILT_PRODUCTS_DIR}/HKDFKit/HKDFKit.framework",
"${BUILT_PRODUCTS_DIR}/Mantle/Mantle.framework", "${BUILT_PRODUCTS_DIR}/Mantle/Mantle.framework",
"${BUILT_PRODUCTS_DIR}/PromiseKit/PromiseKit.framework", "${BUILT_PRODUCTS_DIR}/PromiseKit/PromiseKit.framework",
"${BUILT_PRODUCTS_DIR}/ProtocolBuffers/ProtocolBuffers.framework",
"${BUILT_PRODUCTS_DIR}/PureLayout/PureLayout.framework", "${BUILT_PRODUCTS_DIR}/PureLayout/PureLayout.framework",
"${BUILT_PRODUCTS_DIR}/Reachability/Reachability.framework", "${BUILT_PRODUCTS_DIR}/Reachability/Reachability.framework",
"${BUILT_PRODUCTS_DIR}/SAMKeychain/SAMKeychain.framework", "${BUILT_PRODUCTS_DIR}/SAMKeychain/SAMKeychain.framework",
@ -3039,7 +3038,6 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/HKDFKit.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/HKDFKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mantle.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mantle.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PromiseKit.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PromiseKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ProtocolBuffers.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PureLayout.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PureLayout.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SAMKeychain.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SAMKeychain.framework",
@ -3090,7 +3088,6 @@
"${BUILT_PRODUCTS_DIR}/HKDFKit/HKDFKit.framework", "${BUILT_PRODUCTS_DIR}/HKDFKit/HKDFKit.framework",
"${BUILT_PRODUCTS_DIR}/Mantle/Mantle.framework", "${BUILT_PRODUCTS_DIR}/Mantle/Mantle.framework",
"${BUILT_PRODUCTS_DIR}/PromiseKit/PromiseKit.framework", "${BUILT_PRODUCTS_DIR}/PromiseKit/PromiseKit.framework",
"${BUILT_PRODUCTS_DIR}/ProtocolBuffers/ProtocolBuffers.framework",
"${BUILT_PRODUCTS_DIR}/PureLayout/PureLayout.framework", "${BUILT_PRODUCTS_DIR}/PureLayout/PureLayout.framework",
"${BUILT_PRODUCTS_DIR}/Reachability/Reachability.framework", "${BUILT_PRODUCTS_DIR}/Reachability/Reachability.framework",
"${BUILT_PRODUCTS_DIR}/SAMKeychain/SAMKeychain.framework", "${BUILT_PRODUCTS_DIR}/SAMKeychain/SAMKeychain.framework",
@ -3112,7 +3109,6 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/HKDFKit.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/HKDFKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mantle.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mantle.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PromiseKit.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PromiseKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ProtocolBuffers.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PureLayout.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PureLayout.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SAMKeychain.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SAMKeychain.framework",

View File

@ -1,11 +1,6 @@
# See https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#runtime-suppressions # See https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#runtime-suppressions
# for details. # for details.
# protobuf lib
shift-base:CodedInputStream.m
# generated protos
bool:WhisperTextProtocol.pb.m
# YapDatabase # YapDatabase
bool:YapDatabaseAutoViewTransaction.m bool:YapDatabaseAutoViewTransaction.m

View File

@ -64,9 +64,12 @@ class ConversationConfigurationSyncOperation: OWSOperation {
identityManager: self.identityManager, identityManager: self.identityManager,
profileManager: self.profileManager) profileManager: self.profileManager)
var dataSource: DataSource? = nil var dataSource: DataSource?
self.dbConnection.readWrite { transaction in self.dbConnection.readWrite { transaction in
let messageData: Data = syncMessage.buildPlainTextAttachmentData(with: transaction) guard let messageData: Data = syncMessage.buildPlainTextAttachmentData(with: transaction) else {
owsFail("\(self.logTag) could not serialize sync contacts data")
return
}
dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData) dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData)
} }
@ -85,9 +88,12 @@ class ConversationConfigurationSyncOperation: OWSOperation {
// What does Android do? // What does Android do?
let syncMessage: OWSSyncGroupsMessage = OWSSyncGroupsMessage() let syncMessage: OWSSyncGroupsMessage = OWSSyncGroupsMessage()
var dataSource: DataSource? = nil var dataSource: DataSource?
self.dbConnection.read { transaction in self.dbConnection.read { transaction in
let messageData: Data = syncMessage.buildPlainTextAttachmentData(with: transaction) guard let messageData: Data = syncMessage.buildPlainTextAttachmentData(with: transaction) else {
owsFail("\(self.logTag) could not serialize sync groups data")
return
}
dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData) dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData)
} }

View File

@ -48,9 +48,13 @@ import SignalMessaging
identityManager: self.identityManager, identityManager: self.identityManager,
profileManager: self.profileManager) profileManager: self.profileManager)
var dataSource: DataSource? = nil var dataSource: DataSource?
self.editingDatabaseConnection.readWrite { transaction in self.editingDatabaseConnection.readWrite { transaction in
dataSource = DataSourceValue.dataSource(withSyncMessageData: syncContactsMessage.buildPlainTextAttachmentData(with: transaction)) guard let messageData: Data = syncContactsMessage.buildPlainTextAttachmentData(with: transaction) else {
owsFail("\(self.logTag) could not serialize sync contacts data")
return
}
dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData)
} }
guard let attachmentDataSource = dataSource else { guard let attachmentDataSource = dataSource else {

View File

@ -2,9 +2,95 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// //
#import <Curve25519Kit/Randomness.h>
#import <SignalServiceKit/ContactsManagerProtocol.h>
#import <SignalServiceKit/NSData+OWS.h>
#import <SignalServiceKit/OWSContactsOutputStream.h>
#import <SignalServiceKit/OWSGroupsOutputStream.h>
#import <SignalServiceKit/SignalAccount.h>
#import <SignalServiceKit/SignalServiceKit-Swift.h> #import <SignalServiceKit/SignalServiceKit-Swift.h>
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
NS_ASSUME_NONNULL_BEGIN
@class CNContact;
@interface TestContactsManager : NSObject <ContactsManagerProtocol>
@end
#pragma mark -
@implementation TestContactsManager
- (NSString *)displayNameForPhoneIdentifier:(NSString *_Nullable)phoneNumber
{
return phoneNumber;
}
- (NSArray<SignalAccount *> *)signalAccounts
{
return @[];
}
- (BOOL)isSystemContact:(NSString *)recipientId
{
return YES;
}
- (BOOL)isSystemContactWithSignalAccount:(NSString *)recipientId
{
return YES;
}
- (NSComparisonResult)compareSignalAccount:(SignalAccount *)left withSignalAccount:(SignalAccount *)right
{
return NSOrderedSame;
}
- (nullable CNContact *)cnContactWithId:(nullable NSString *)contactId
{
return nil;
}
- (nullable NSData *)avatarDataForCNContactId:(nullable NSString *)contactId
{
return nil;
}
- (nullable UIImage *)avatarImageForCNContactId:(nullable NSString *)contactId
{
return nil;
}
@end
#pragma mark -
@interface FakeContact : NSObject
@property (nullable, nonatomic) NSString *firstName;
@property (nullable, nonatomic) NSString *lastName;
@property (nonatomic) NSString *fullName;
@property (nonatomic) NSString *comparableNameFirstLast;
@property (nonatomic) NSString *comparableNameLastFirst;
@property (nonatomic) NSArray<PhoneNumber *> *parsedPhoneNumbers;
@property (nonatomic) NSArray<NSString *> *userTextPhoneNumbers;
@property (nonatomic) NSArray<NSString *> *emails;
@property (nonatomic) NSString *uniqueId;
@property (nonatomic) BOOL isSignalContact;
@property (nonatomic) NSString *cnContactId;
@end
#pragma mark -
@implementation FakeContact
@end
#pragma mark -
@interface ProtoParsingTest : XCTestCase @interface ProtoParsingTest : XCTestCase
@end @end
@ -31,4 +117,58 @@
XCTAssertNotNil(error); XCTAssertNotNil(error);
} }
- (void)testProtoStreams
{
NSArray<SignalAccount *> *signalAccounts = @[
[[SignalAccount alloc] initWithRecipientId:@"+13213214321"],
[[SignalAccount alloc] initWithRecipientId:@"+13213214322"],
[[SignalAccount alloc] initWithRecipientId:@"+13213214323"],
];
NSData *_Nullable streamData = [self dataForSyncingContacts:signalAccounts];
XCTAssertNotNil(streamData);
XCTAssertEqualObjects(streamData.hexadecimalString,
@"1b0a0c2b31333231333231343332311209416c69636520426f6240001b0a0c2b31333231333231343332321209416c69636520426f624"
@"0001b0a0c2b31333231333231343332331209416c69636520426f624000");
}
- (nullable NSData *)dataForSyncingContacts:(NSArray<SignalAccount *> *)signalAccounts
{
TestContactsManager *contactsManager = [TestContactsManager new];
NSOutputStream *dataOutputStream = [NSOutputStream outputStreamToMemory];
[dataOutputStream open];
OWSContactsOutputStream *contactsOutputStream =
[[OWSContactsOutputStream alloc] initWithOutputStream:dataOutputStream];
for (SignalAccount *signalAccount in signalAccounts) {
OWSRecipientIdentity *_Nullable recipientIdentity = nil;
// NSData *_Nullable profileKeyData = [Randomness generateRandomBytes:32];
NSData *_Nullable profileKeyData = nil;
OWSDisappearingMessagesConfiguration *_Nullable disappearingMessagesConfiguration = nil;
NSString *_Nullable conversationColorName = @"fake color name";
FakeContact *fakeContact = [FakeContact new];
fakeContact.cnContactId = @"123";
fakeContact.fullName = @"Alice Bob";
signalAccount.contact = (Contact *)fakeContact;
[contactsOutputStream writeSignalAccount:signalAccount
recipientIdentity:recipientIdentity
profileKeyData:profileKeyData
contactsManager:contactsManager
conversationColorName:conversationColorName
disappearingMessagesConfiguration:disappearingMessagesConfiguration];
}
[dataOutputStream close];
if (contactsOutputStream.hasError) {
return nil;
}
return [dataOutputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
}
@end @end
NS_ASSUME_NONNULL_END

View File

@ -124,14 +124,19 @@ NSString *const kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
identityManager:self.identityManager identityManager:self.identityManager
profileManager:self.profileManager]; profileManager:self.profileManager];
__block NSData *messageData; __block NSData *_Nullable messageData;
__block NSData *lastMessageData; __block NSData *_Nullable lastMessageData;
[self.editingDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { [self.editingDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
messageData = [syncContactsMessage buildPlainTextAttachmentDataWithTransaction:transaction]; messageData = [syncContactsMessage buildPlainTextAttachmentDataWithTransaction:transaction];
lastMessageData = [transaction objectForKey:kOWSPrimaryStorageOWSContactsSyncingLastMessageKey lastMessageData = [transaction objectForKey:kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
inCollection:kOWSPrimaryStorageOWSContactsSyncingCollection]; inCollection:kOWSPrimaryStorageOWSContactsSyncingCollection];
}]; }];
if (!messageData) {
OWSFail(@"%@ Failed to serialize contacts sync message.", self.logTag);
return;
}
if (lastMessageData && [lastMessageData isEqual:messageData]) { if (lastMessageData && [lastMessageData isEqual:messageData]) {
// Ignore redundant contacts sync message. // Ignore redundant contacts sync message.
return; return;

View File

@ -1,15 +1,21 @@
// Copyright © 2016 Open Whisper Systems. All rights reserved. //
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class PBCodedOutputStream;
@interface OWSChunkedOutputStream : NSObject @interface OWSChunkedOutputStream : NSObject
@property (nonatomic, readonly) PBCodedOutputStream *delegateStream; // Indicates whether any write failed.
@property (nonatomic, readonly) BOOL hasError;
+ (instancetype)streamWithOutputStream:(NSOutputStream *)output; - (instancetype)init NS_UNAVAILABLE;
- (void)flush;
- (instancetype)initWithOutputStream:(NSOutputStream *)outputStream;
// Returns NO on error.
- (BOOL)writeData:(NSData *)data;
- (BOOL)writeUInt32:(UInt32)value;
@end @end

View File

@ -1,34 +1,69 @@
// Copyright © 2016 Open Whisper Systems. All rights reserved. //
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSChunkedOutputStream.h" #import "OWSChunkedOutputStream.h"
#import <ProtocolBuffers/CodedOutputStream.h> #import "NSData+OWS.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@implementation OWSChunkedOutputStream @interface OWSChunkedOutputStream ()
+ (instancetype)streamWithOutputStream:(NSOutputStream *)output @property (nonatomic, readonly) NSOutputStream *outputStream;
{ @property (nonatomic) BOOL hasError;
return [[self alloc] initWithOutputStream:output];
} @end
#pragma mark -
@implementation OWSChunkedOutputStream
- (instancetype)initWithOutputStream:(NSOutputStream *)outputStream - (instancetype)initWithOutputStream:(NSOutputStream *)outputStream
{ {
self = [super init]; if (self = [super init]) {
if (!self) { OWSAssert(outputStream);
return self; _outputStream = outputStream;
} }
_delegateStream = [PBCodedOutputStream streamWithOutputStream:outputStream];
return self; return self;
} }
- (void)flush - (BOOL)writeByte:(uint8_t)value
{ {
[self.delegateStream flush]; NSInteger written = [self.outputStream write:&value maxLength:sizeof(value)];
if (written != sizeof(value)) {
OWSFail(@"%@ could not write to output stream.", self.logTag);
self.hasError = YES;
return NO;
}
return YES;
} }
- (BOOL)writeData:(NSData *)data
{
OWSAssert(data);
NSInteger written = [self.outputStream write:data.bytes maxLength:data.length];
if (written != data.length) {
OWSFail(@"%@ could not write to output stream.", self.logTag);
self.hasError = YES;
return NO;
}
return YES;
}
- (BOOL)writeUInt32:(UInt32)value
{
while (YES) {
if (value <= 0x7F) {
return [self writeByte:value];
} else {
if (![self writeByte:((value & 0x7F) | 0x80)]) {
return NO;
}
value >>= 7;
}
}
}
@end @end

View File

@ -7,13 +7,13 @@
#import "ContactsManagerProtocol.h" #import "ContactsManagerProtocol.h"
#import "Cryptography.h" #import "Cryptography.h"
#import "MIMETypeUtil.h" #import "MIMETypeUtil.h"
#import "NSData+OWS.h"
#import "NSData+keyVersionByte.h" #import "NSData+keyVersionByte.h"
#import "OWSBlockingManager.h" #import "OWSBlockingManager.h"
#import "OWSDisappearingMessagesConfiguration.h" #import "OWSDisappearingMessagesConfiguration.h"
#import "OWSRecipientIdentity.h" #import "OWSRecipientIdentity.h"
#import "SignalAccount.h" #import "SignalAccount.h"
#import "TSContactThread.h" #import "TSContactThread.h"
#import <ProtocolBuffers/CodedOutputStream.h>
#import <SignalServiceKit/SignalServiceKit-Swift.h> #import <SignalServiceKit/SignalServiceKit-Swift.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -96,11 +96,11 @@ disappearingMessagesConfiguration:(nullable OWSDisappearingMessagesConfiguration
} }
uint32_t contactDataLength = (uint32_t)contactData.length; uint32_t contactDataLength = (uint32_t)contactData.length;
[self.delegateStream writeRawVarint32:contactDataLength]; [self writeUInt32:contactDataLength];
[self.delegateStream writeRawData:contactData]; [self writeData:contactData];
if (avatarPng) { if (avatarPng) {
[self.delegateStream writeRawData:avatarPng]; [self writeData:avatarPng];
} }
} }

View File

@ -7,7 +7,6 @@
#import "OWSDisappearingMessagesConfiguration.h" #import "OWSDisappearingMessagesConfiguration.h"
#import "TSGroupModel.h" #import "TSGroupModel.h"
#import "TSGroupThread.h" #import "TSGroupThread.h"
#import <ProtocolBuffers/CodedOutputStream.h>
#import <SignalServiceKit/SignalServiceKit-Swift.h> #import <SignalServiceKit/SignalServiceKit-Swift.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -69,11 +68,11 @@ NS_ASSUME_NONNULL_BEGIN
uint32_t groupDataLength = (uint32_t)groupData.length; uint32_t groupDataLength = (uint32_t)groupData.length;
[self.delegateStream writeRawVarint32:groupDataLength]; [self writeUInt32:groupDataLength];
[self.delegateStream writeRawData:groupData]; [self writeData:groupData];
if (avatarPng) { if (avatarPng) {
[self.delegateStream writeRawData:avatarPng]; [self writeData:avatarPng];
} }
} }

View File

@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER; - (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
- (NSData *)buildPlainTextAttachmentDataWithTransaction:(YapDatabaseReadTransaction *)transaction; - (nullable NSData *)buildPlainTextAttachmentDataWithTransaction:(YapDatabaseReadTransaction *)transaction;
@end @end

View File

@ -79,7 +79,7 @@ NS_ASSUME_NONNULL_BEGIN
return syncMessageBuilder; return syncMessageBuilder;
} }
- (NSData *)buildPlainTextAttachmentDataWithTransaction:(YapDatabaseReadTransaction *)transaction - (nullable NSData *)buildPlainTextAttachmentDataWithTransaction:(YapDatabaseReadTransaction *)transaction
{ {
id<ContactsManagerProtocol> contactsManager = TextSecureKitEnv.sharedEnv.contactsManager; id<ContactsManagerProtocol> contactsManager = TextSecureKitEnv.sharedEnv.contactsManager;
@ -88,7 +88,8 @@ NS_ASSUME_NONNULL_BEGIN
// and uploading with streams). // and uploading with streams).
NSOutputStream *dataOutputStream = [NSOutputStream outputStreamToMemory]; NSOutputStream *dataOutputStream = [NSOutputStream outputStreamToMemory];
[dataOutputStream open]; [dataOutputStream open];
OWSContactsOutputStream *contactsOutputStream = [OWSContactsOutputStream streamWithOutputStream:dataOutputStream]; OWSContactsOutputStream *contactsOutputStream =
[[OWSContactsOutputStream alloc] initWithOutputStream:dataOutputStream];
for (SignalAccount *signalAccount in self.signalAccounts) { for (SignalAccount *signalAccount in self.signalAccounts) {
OWSRecipientIdentity *_Nullable recipientIdentity = OWSRecipientIdentity *_Nullable recipientIdentity =
@ -115,9 +116,13 @@ NS_ASSUME_NONNULL_BEGIN
disappearingMessagesConfiguration:disappearingMessagesConfiguration]; disappearingMessagesConfiguration:disappearingMessagesConfiguration];
} }
[contactsOutputStream flush];
[dataOutputStream close]; [dataOutputStream close];
if (contactsOutputStream.hasError) {
OWSFail(@"%@ Could not write contacts sync stream.", self.logTag);
return nil;
}
return [dataOutputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; return [dataOutputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
} }

View File

@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)init NS_DESIGNATED_INITIALIZER; - (instancetype)init NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER; - (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
- (NSData *)buildPlainTextAttachmentDataWithTransaction:(YapDatabaseReadTransaction *)transaction; - (nullable NSData *)buildPlainTextAttachmentDataWithTransaction:(YapDatabaseReadTransaction *)transaction;
@end @end

View File

@ -57,14 +57,14 @@ NS_ASSUME_NONNULL_BEGIN
return syncMessageBuilder; return syncMessageBuilder;
} }
- (NSData *)buildPlainTextAttachmentDataWithTransaction:(YapDatabaseReadTransaction *)transaction - (nullable NSData *)buildPlainTextAttachmentDataWithTransaction:(YapDatabaseReadTransaction *)transaction
{ {
// TODO use temp file stream to avoid loading everything into memory at once // TODO use temp file stream to avoid loading everything into memory at once
// First though, we need to re-engineer our attachment process to accept streams (encrypting with stream, // First though, we need to re-engineer our attachment process to accept streams (encrypting with stream,
// and uploading with streams). // and uploading with streams).
NSOutputStream *dataOutputStream = [NSOutputStream outputStreamToMemory]; NSOutputStream *dataOutputStream = [NSOutputStream outputStreamToMemory];
[dataOutputStream open]; [dataOutputStream open];
OWSGroupsOutputStream *groupsOutputStream = [OWSGroupsOutputStream streamWithOutputStream:dataOutputStream]; OWSGroupsOutputStream *groupsOutputStream = [[OWSGroupsOutputStream alloc] initWithOutputStream:dataOutputStream];
[TSGroupThread [TSGroupThread
enumerateCollectionObjectsWithTransaction:transaction enumerateCollectionObjectsWithTransaction:transaction
@ -80,9 +80,13 @@ NS_ASSUME_NONNULL_BEGIN
[groupsOutputStream writeGroup:groupThread transaction:transaction]; [groupsOutputStream writeGroup:groupThread transaction:transaction];
}]; }];
[groupsOutputStream flush];
[dataOutputStream close]; [dataOutputStream close];
if (groupsOutputStream.hasError) {
OWSFail(@"%@ Could not write groups sync stream.", self.logTag);
return nil;
}
return [dataOutputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; return [dataOutputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
} }

View File

@ -661,9 +661,15 @@ NS_ASSUME_NONNULL_BEGIN
[[OWSSyncContactsMessage alloc] initWithSignalAccounts:self.contactsManager.signalAccounts [[OWSSyncContactsMessage alloc] initWithSignalAccounts:self.contactsManager.signalAccounts
identityManager:self.identityManager identityManager:self.identityManager
profileManager:self.profileManager]; profileManager:self.profileManager];
DataSource *dataSource = [DataSourceValue __block NSData *_Nullable syncData;
dataSourceWithSyncMessageData:[syncContactsMessage [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
buildPlainTextAttachmentDataWithTransaction:transaction]]; syncData = [syncContactsMessage buildPlainTextAttachmentDataWithTransaction:transaction];
}];
if (!syncData) {
OWSFail(@"%@ Failed to serialize contacts sync message.", self.logTag);
return;
}
DataSource *dataSource = [DataSourceValue dataSourceWithSyncMessageData:syncData];
[self.messageSender enqueueTemporaryAttachment:dataSource [self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeApplicationOctetStream contentType:OWSMimeTypeApplicationOctetStream
inMessage:syncContactsMessage inMessage:syncContactsMessage
@ -676,19 +682,31 @@ NS_ASSUME_NONNULL_BEGIN
}]; }];
}); });
} else if (syncMessage.request.type == SSKProtoSyncMessageRequestTypeGroups) { } else if (syncMessage.request.type == SSKProtoSyncMessageRequestTypeGroups) {
OWSSyncGroupsMessage *syncGroupsMessage = [[OWSSyncGroupsMessage alloc] init]; // We respond asynchronously.
DataSource *dataSource = [DataSourceValue //
dataSourceWithSyncMessageData:[syncGroupsMessage // In rare cases this means we won't respond to the sync request, but that's
buildPlainTextAttachmentDataWithTransaction:transaction]]; // acceptable.
[self.messageSender enqueueTemporaryAttachment:dataSource dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
contentType:OWSMimeTypeApplicationOctetStream OWSSyncGroupsMessage *syncGroupsMessage = [[OWSSyncGroupsMessage alloc] init];
inMessage:syncGroupsMessage __block NSData *_Nullable syncData;
success:^{ [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
DDLogInfo(@"%@ Successfully sent Groups response syncMessage.", self.logTag); syncData = [syncGroupsMessage buildPlainTextAttachmentDataWithTransaction:transaction];
}
failure:^(NSError *error) {
DDLogError(@"%@ Failed to send Groups response syncMessage with error: %@", self.logTag, error);
}]; }];
if (!syncData) {
OWSFail(@"%@ Failed to serialize groups sync message.", self.logTag);
return;
}
DataSource *dataSource = [DataSourceValue dataSourceWithSyncMessageData:syncData];
[self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeApplicationOctetStream
inMessage:syncGroupsMessage
success:^{
DDLogInfo(@"%@ Successfully sent Groups response syncMessage.", self.logTag);
}
failure:^(NSError *error) {
DDLogError(@"%@ Failed to send Groups response syncMessage with error: %@", self.logTag, error);
}];
});
} else if (syncMessage.request.type == SSKProtoSyncMessageRequestTypeBlocked) { } else if (syncMessage.request.type == SSKProtoSyncMessageRequestTypeBlocked) {
DDLogInfo(@"%@ Received request for block list", self.logTag); DDLogInfo(@"%@ Received request for block list", self.logTag);
[_blockingManager syncBlockedPhoneNumbers]; [_blockingManager syncBlockedPhoneNumbers];

View File

@ -43,6 +43,12 @@ public enum FingerprintProtoError: Error {
@objc public func buildSerializedData() throws -> Data { @objc public func buildSerializedData() throws -> Data {
return try FingerprintProtoLogicalFingerprint.parseProto(proto).serializedData() return try FingerprintProtoLogicalFingerprint.parseProto(proto).serializedData()
} }
@objc public override var description: String {
var fields = [String]()
fields.append("identityData: \(proto.identityData)")
return "[" + fields.joined(separator: ", ") + "]"
}
} }
fileprivate let proto: FingerprintProtos_LogicalFingerprint fileprivate let proto: FingerprintProtos_LogicalFingerprint
@ -88,6 +94,12 @@ public enum FingerprintProtoError: Error {
identityData: identityData) identityData: identityData)
return result return result
} }
@objc public override var description: String {
var fields = [String]()
fields.append("identityData: \(proto.identityData)")
return "[" + fields.joined(separator: ", ") + "]"
}
} }
// MARK: - FingerprintProtoLogicalFingerprints // MARK: - FingerprintProtoLogicalFingerprints
@ -130,6 +142,14 @@ public enum FingerprintProtoError: Error {
@objc public func buildSerializedData() throws -> Data { @objc public func buildSerializedData() throws -> Data {
return try FingerprintProtoLogicalFingerprints.parseProto(proto).serializedData() return try FingerprintProtoLogicalFingerprints.parseProto(proto).serializedData()
} }
@objc public override var description: String {
var fields = [String]()
fields.append("version: \(proto.version)")
fields.append("localFingerprint: \(proto.localFingerprint)")
fields.append("remoteFingerprint: \(proto.remoteFingerprint)")
return "[" + fields.joined(separator: ", ") + "]"
}
} }
fileprivate let proto: FingerprintProtos_LogicalFingerprints fileprivate let proto: FingerprintProtos_LogicalFingerprints
@ -195,4 +215,12 @@ public enum FingerprintProtoError: Error {
remoteFingerprint: remoteFingerprint) remoteFingerprint: remoteFingerprint)
return result return result
} }
@objc public override var description: String {
var fields = [String]()
fields.append("version: \(proto.version)")
fields.append("localFingerprint: \(proto.localFingerprint)")
fields.append("remoteFingerprint: \(proto.remoteFingerprint)")
return "[" + fields.joined(separator: ", ") + "]"
}
} }

View File

@ -47,6 +47,13 @@ public enum ProvisioningProtoError: Error {
@objc public func buildSerializedData() throws -> Data { @objc public func buildSerializedData() throws -> Data {
return try ProvisioningProtoProvisionEnvelope.parseProto(proto).serializedData() return try ProvisioningProtoProvisionEnvelope.parseProto(proto).serializedData()
} }
@objc public override var description: String {
var fields = [String]()
fields.append("publicKey: \(proto.publicKey)")
fields.append("body: \(proto.body)")
return "[" + fields.joined(separator: ", ") + "]"
}
} }
fileprivate let proto: ProvisioningProtos_ProvisionEnvelope fileprivate let proto: ProvisioningProtos_ProvisionEnvelope
@ -102,6 +109,13 @@ public enum ProvisioningProtoError: Error {
body: body) body: body)
return result return result
} }
@objc public override var description: String {
var fields = [String]()
fields.append("publicKey: \(proto.publicKey)")
fields.append("body: \(proto.body)")
return "[" + fields.joined(separator: ", ") + "]"
}
} }
// MARK: - ProvisioningProtoProvisionMessage // MARK: - ProvisioningProtoProvisionMessage
@ -160,6 +174,18 @@ public enum ProvisioningProtoError: Error {
@objc public func buildSerializedData() throws -> Data { @objc public func buildSerializedData() throws -> Data {
return try ProvisioningProtoProvisionMessage.parseProto(proto).serializedData() return try ProvisioningProtoProvisionMessage.parseProto(proto).serializedData()
} }
@objc public override var description: String {
var fields = [String]()
fields.append("identityKeyPublic: \(proto.identityKeyPublic)")
fields.append("identityKeyPrivate: \(proto.identityKeyPrivate)")
fields.append("number: \(proto.number)")
fields.append("provisioningCode: \(proto.provisioningCode)")
fields.append("userAgent: \(proto.userAgent)")
fields.append("profileKey: \(proto.profileKey)")
fields.append("readReceipts: \(proto.readReceipts)")
return "[" + fields.joined(separator: ", ") + "]"
}
} }
fileprivate let proto: ProvisioningProtos_ProvisionMessage fileprivate let proto: ProvisioningProtos_ProvisionMessage
@ -265,4 +291,16 @@ public enum ProvisioningProtoError: Error {
readReceipts: readReceipts) readReceipts: readReceipts)
return result return result
} }
@objc public override var description: String {
var fields = [String]()
fields.append("identityKeyPublic: \(proto.identityKeyPublic)")
fields.append("identityKeyPrivate: \(proto.identityKeyPrivate)")
fields.append("number: \(proto.number)")
fields.append("provisioningCode: \(proto.provisioningCode)")
fields.append("userAgent: \(proto.userAgent)")
fields.append("profileKey: \(proto.profileKey)")
fields.append("readReceipts: \(proto.readReceipts)")
return "[" + fields.joined(separator: ", ") + "]"
}
} }

File diff suppressed because it is too large Load Diff

View File

@ -77,6 +77,13 @@ public enum SignalIOSProtoError: Error {
@objc public func buildSerializedData() throws -> Data { @objc public func buildSerializedData() throws -> Data {
return try SignalIOSProtoBackupSnapshotBackupEntity.parseProto(proto).serializedData() return try SignalIOSProtoBackupSnapshotBackupEntity.parseProto(proto).serializedData()
} }
@objc public override var description: String {
var fields = [String]()
fields.append("type: \(proto.type)")
fields.append("entityData: \(proto.entityData)")
return "[" + fields.joined(separator: ", ") + "]"
}
} }
fileprivate let proto: IOSProtos_BackupSnapshot.BackupEntity fileprivate let proto: IOSProtos_BackupSnapshot.BackupEntity
@ -132,6 +139,13 @@ public enum SignalIOSProtoError: Error {
entityData: entityData) entityData: entityData)
return result return result
} }
@objc public override var description: String {
var fields = [String]()
fields.append("type: \(proto.type)")
fields.append("entityData: \(proto.entityData)")
return "[" + fields.joined(separator: ", ") + "]"
}
} }
// MARK: - SignalIOSProtoBackupSnapshot // MARK: - SignalIOSProtoBackupSnapshot
@ -172,6 +186,12 @@ public enum SignalIOSProtoError: Error {
@objc public func buildSerializedData() throws -> Data { @objc public func buildSerializedData() throws -> Data {
return try SignalIOSProtoBackupSnapshot.parseProto(proto).serializedData() return try SignalIOSProtoBackupSnapshot.parseProto(proto).serializedData()
} }
@objc public override var description: String {
var fields = [String]()
fields.append("entity: \(proto.entity)")
return "[" + fields.joined(separator: ", ") + "]"
}
} }
fileprivate let proto: IOSProtos_BackupSnapshot fileprivate let proto: IOSProtos_BackupSnapshot
@ -215,4 +235,10 @@ public enum SignalIOSProtoError: Error {
entity: entity) entity: entity)
return result return result
} }
@objc public override var description: String {
var fields = [String]()
fields.append("entity: \(proto.entity)")
return "[" + fields.joined(separator: ", ") + "]"
}
} }

View File

@ -65,6 +65,16 @@ public enum WebSocketProtoError: Error {
@objc public func buildSerializedData() throws -> Data { @objc public func buildSerializedData() throws -> Data {
return try WebSocketProtoWebSocketRequestMessage.parseProto(proto).serializedData() return try WebSocketProtoWebSocketRequestMessage.parseProto(proto).serializedData()
} }
@objc public override var description: String {
var fields = [String]()
fields.append("verb: \(proto.verb)")
fields.append("path: \(proto.path)")
fields.append("body: \(proto.body)")
fields.append("headers: \(proto.headers)")
fields.append("requestID: \(proto.requestID)")
return "[" + fields.joined(separator: ", ") + "]"
}
} }
fileprivate let proto: WebSocketProtos_WebSocketRequestMessage fileprivate let proto: WebSocketProtos_WebSocketRequestMessage
@ -144,6 +154,16 @@ public enum WebSocketProtoError: Error {
requestID: requestID) requestID: requestID)
return result return result
} }
@objc public override var description: String {
var fields = [String]()
fields.append("verb: \(proto.verb)")
fields.append("path: \(proto.path)")
fields.append("body: \(proto.body)")
fields.append("headers: \(proto.headers)")
fields.append("requestID: \(proto.requestID)")
return "[" + fields.joined(separator: ", ") + "]"
}
} }
// MARK: - WebSocketProtoWebSocketResponseMessage // MARK: - WebSocketProtoWebSocketResponseMessage
@ -200,6 +220,16 @@ public enum WebSocketProtoError: Error {
@objc public func buildSerializedData() throws -> Data { @objc public func buildSerializedData() throws -> Data {
return try WebSocketProtoWebSocketResponseMessage.parseProto(proto).serializedData() return try WebSocketProtoWebSocketResponseMessage.parseProto(proto).serializedData()
} }
@objc public override var description: String {
var fields = [String]()
fields.append("requestID: \(proto.requestID)")
fields.append("status: \(proto.status)")
fields.append("message: \(proto.message)")
fields.append("headers: \(proto.headers)")
fields.append("body: \(proto.body)")
return "[" + fields.joined(separator: ", ") + "]"
}
} }
fileprivate let proto: WebSocketProtos_WebSocketResponseMessage fileprivate let proto: WebSocketProtos_WebSocketResponseMessage
@ -279,6 +309,16 @@ public enum WebSocketProtoError: Error {
status: status) status: status)
return result return result
} }
@objc public override var description: String {
var fields = [String]()
fields.append("requestID: \(proto.requestID)")
fields.append("status: \(proto.status)")
fields.append("message: \(proto.message)")
fields.append("headers: \(proto.headers)")
fields.append("body: \(proto.body)")
return "[" + fields.joined(separator: ", ") + "]"
}
} }
// MARK: - WebSocketProtoWebSocketMessage // MARK: - WebSocketProtoWebSocketMessage
@ -345,6 +385,14 @@ public enum WebSocketProtoError: Error {
@objc public func buildSerializedData() throws -> Data { @objc public func buildSerializedData() throws -> Data {
return try WebSocketProtoWebSocketMessage.parseProto(proto).serializedData() return try WebSocketProtoWebSocketMessage.parseProto(proto).serializedData()
} }
@objc public override var description: String {
var fields = [String]()
fields.append("type: \(proto.type)")
fields.append("request: \(proto.request)")
fields.append("response: \(proto.response)")
return "[" + fields.joined(separator: ", ") + "]"
}
} }
fileprivate let proto: WebSocketProtos_WebSocketMessage fileprivate let proto: WebSocketProtos_WebSocketMessage
@ -396,12 +444,12 @@ public enum WebSocketProtoError: Error {
} }
let type = WebSocketProtoWebSocketMessageTypeWrap(proto.type) let type = WebSocketProtoWebSocketMessageTypeWrap(proto.type)
var request: WebSocketProtoWebSocketRequestMessage? = nil var request: WebSocketProtoWebSocketRequestMessage?
if proto.hasRequest { if proto.hasRequest {
request = try WebSocketProtoWebSocketRequestMessage.parseProto(proto.request) request = try WebSocketProtoWebSocketRequestMessage.parseProto(proto.request)
} }
var response: WebSocketProtoWebSocketResponseMessage? = nil var response: WebSocketProtoWebSocketResponseMessage?
if proto.hasResponse { if proto.hasResponse {
response = try WebSocketProtoWebSocketResponseMessage.parseProto(proto.response) response = try WebSocketProtoWebSocketResponseMessage.parseProto(proto.response)
} }
@ -416,4 +464,12 @@ public enum WebSocketProtoError: Error {
response: response) response: response)
return result return result
} }
@objc public override var description: String {
var fields = [String]()
fields.append("type: \(proto.type)")
fields.append("request: \(proto.request)")
fields.append("response: \(proto.response)")
return "[" + fields.joined(separator: ", ") + "]"
}
} }