Fix crash

This commit is contained in:
nielsandriesse 2020-12-14 09:00:50 +11:00
parent 7ca3b73fd8
commit 9ebb448b5f
2 changed files with 11 additions and 7 deletions

View File

@ -349,11 +349,11 @@ public enum OnionRequestAPI {
public static func sendOnionRequest(with payload: JSON, to destination: Destination, isJSONRequired: Bool = true) -> Promise<JSON> {
let (promise, seal) = Promise<JSON>.pending()
var guardSnode: Snode!
var guardSnode: Snode?
Threading.workQueue.async { // Avoid race conditions on `guardSnodes` and `paths`
buildOnion(around: payload, targetedAt: destination).done2 { intermediate in
guardSnode = intermediate.guardSnode
let url = "\(guardSnode.address):\(guardSnode.port)/onion_req/v2"
let url = "\(guardSnode!.address):\(guardSnode!.port)/onion_req/v2"
let finalEncryptionResult = intermediate.finalEncryptionResult
let onion = finalEncryptionResult.ciphertext
if case Destination.server = destination, Double(onion.count) > 0.75 * Double(maxFileSize) {

View File

@ -970,12 +970,16 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
result = [self profileNameForRecipientWithID:recipientID transaction:transaction];
}];
NSString *shortID = [recipientID substringWithRange:NSMakeRange(recipientID.length - 8, 8)];
NSString *suffix = [NSString stringWithFormat:@" (...%@)", shortID];
if ([result hasSuffix:suffix]) {
return [result substringToIndex:result.length - suffix.length];
if (recipientID.length > 8) {
NSString *shortID = [recipientID substringWithRange:NSMakeRange(recipientID.length - 8, 8)];
NSString *suffix = [NSString stringWithFormat:@" (...%@)", shortID];
if ([result hasSuffix:suffix]) {
return [result substringToIndex:result.length - suffix.length];
} else {
return result;
}
} else {
return result;
return result; // Should never occur
}
} else {
return recipientID;