pull/8/head
Niels Andriesse 7 years ago
parent e6bfd56487
commit 294d8b5c11

@ -915,39 +915,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
return deviceMessages;
}
- (AnyPromise *)calculateProofOfWorkForDeviceMessages:(NSArray<NSDictionary *> *)deviceMessages
ttl:(NSNumber *)ttl
{
// Loki: Calculate the proof of work for each device message
NSMutableArray *promises = [NSMutableArray new];
for (NSDictionary<NSString *, id> *deviceMessage in deviceMessages) {
AnyPromise *promise = [AnyPromise promiseWithValue:deviceMessage]
.thenOn(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(NSDictionary<NSString *, id> *message) {
NSTimeInterval timestampInterval = [[NSDate new] timeIntervalSince1970];
NSNumber *timestamp = [NSNumber numberWithDouble:timestampInterval];
NSString *destination = message[@"destination"];
NSString *data = message[@"content"];
NSString *nonce = [ProofOfWork calculateWithData:data pubKey:destination timestamp:timestamp.unsignedIntegerValue ttl:ttl.integerValue];
// Return our timestamp along with the nonce
// These will help us identify which nonce belongs to which message
return @{
@"destination" : destination,
@"deviceId" : message[@"destinationDeviceId"],
@"timestamp" : timestamp,
@"nonce" : nonce
};
});
[promises addObject:promise];
}
// Wait for all the PoW calculations to finish
return PMKWhen(promises);
}
- (void)sendMessageToRecipient:(OWSMessageSend *)messageSend
{
OWSAssertDebug(messageSend);

@ -59,11 +59,6 @@ typedef NS_ENUM(NSUInteger, TSVerificationTransport) { TSVerificationTransportVo
captchaToken:(nullable NSString *)captchaToken
transport:(TSVerificationTransport)transport;
+ (TSRequest *)submitLokiMessageRequestWithRecipient:(NSString *)recipientId
messages:(NSArray *)messages
nonceArray:(NSArray *)nonceArray
ttl:(NSNumber *)ttl;
+ (TSRequest *)submitMessageRequestWithRecipient:(NSString *)recipientId
messages:(NSArray *)messages
timeStamp:(uint64_t)timeStamp

@ -354,60 +354,6 @@ NS_ASSUME_NONNULL_BEGIN
return [accountAttributes copy];
}
// Loki: Convert Signal JSON messages to Loki messages
// Refer to OWSMessageServiceParams for the Signal JSON params
+ (NSArray *)lokiMessagesFromMessages:(NSArray *)messages
nonceArray:(NSArray *)nonceArray
ttl:(NSNumber *)ttl {
NSMutableArray *modifiedMessages = [NSMutableArray new];
for (NSDictionary *message in messages) {
NSMutableDictionary *lokiMessage = [NSMutableDictionary new];
// Params for our message server
lokiMessage[@"pubKey"] = message[@"destination"];
lokiMessage[@"data"] = message[@"content"];
lokiMessage[@"ttl"] = [ttl stringValue];
NSDictionary *_Nullable nonce = [self getNonceFromArray:nonceArray forMessage:message];
if (nonce) {
lokiMessage[@"timestamp"] = nonce[@"timestmap"];
lokiMessage[@"nonce"] = nonce[@"nonce"];
}
[modifiedMessages addObject:lokiMessage];
}
return modifiedMessages;
}
+ (NSDictionary *_Nullable)getNonceFromArray:(NSArray *)nonceArray forMessage:(NSDictionary *)message {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"destination == %@ AND deviceId == %d", message[@"destination"], message[@"destinationDeviceId"]];
NSArray *filtered = [nonceArray filteredArrayUsingPredicate:predicate];
return filtered.count > 0 ? [filtered objectAtIndex:0] : nil;
}
// Loki: This is the function below with our changes
+ (TSRequest *)submitLokiMessageRequestWithRecipient:(NSString *)recipientId
messages:(NSArray *)messages
nonceArray:(NSArray *)nonceArray
ttl:(NSNumber *)ttl
{
// Messages may be empty; see comments in OWSDeviceManager.
// This doesn't apply to Loki since we don't have linked device support.
OWSAssertDebug(recipientId.length > 0);
OWSAssertDebug(messages.count > 0);
// Convert to Loki JSON format
NSArray *lokiMessages = [self lokiMessagesFromMessages:messages nonceArray:nonceArray ttl:ttl];
OWSAssertDebug(lokiMessages.count > 0);
// Loki: Just send the first message
NSString *path = [textSecureMessagesAPI stringByAppendingString:recipientId];
NSDictionary *parameters = [lokiMessages objectAtIndex:0];
return [TSRequest new]; // TODO: Just here to make things build
}
+ (TSRequest *)submitMessageRequestWithRecipient:(NSString *)recipientId
messages:(NSArray *)messages
timeStamp:(uint64_t)timeStamp

Loading…
Cancel
Save