diff --git a/QiniuDemo/QiniuDemo.xcodeproj/project.pbxproj b/QiniuDemo/QiniuDemo.xcodeproj/project.pbxproj index 91559ff7..0995e5c6 100644 --- a/QiniuDemo/QiniuDemo.xcodeproj/project.pbxproj +++ b/QiniuDemo/QiniuDemo.xcodeproj/project.pbxproj @@ -8,7 +8,6 @@ /* Begin PBXBuildFile section */ 26F62ADDD5B6306E978C9A3F /* libPods-QiniuDemoTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 14CB2139715DD7B6FD5B146E /* libPods-QiniuDemoTests.a */; }; - 4545D3142BAD7D0C00932C3F /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 4545D3132BAD7D0C00932C3F /* PrivacyInfo.xcprivacy */; }; 4561F02C28D9A6F80098A697 /* UploadResource_14M.zip in Resources */ = {isa = PBXBuildFile; fileRef = 4561F02B28D9A6F80098A697 /* UploadResource_14M.zip */; }; 45E6080929ADD57100634200 /* UploadResource_1G.zip in Resources */ = {isa = PBXBuildFile; fileRef = 45E6080829ADD57100634200 /* UploadResource_1G.zip */; }; 93D230241C86D7F700434F6D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D230231C86D7F700434F6D /* main.m */; }; @@ -43,7 +42,6 @@ 14CB2139715DD7B6FD5B146E /* libPods-QiniuDemoTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuDemoTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 24EE530BBB100BED89B08A3D /* Pods-QiniuDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuDemo/Pods-QiniuDemo.release.xcconfig"; sourceTree = ""; }; 3189882026469145003CCA68 /* QiniuDemo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = QiniuDemo.entitlements; sourceTree = ""; }; - 4545D3132BAD7D0C00932C3F /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; 4561F02B28D9A6F80098A697 /* UploadResource_14M.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = UploadResource_14M.zip; sourceTree = ""; }; 4561F02F28D9AB090098A697 /* Configure.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Configure.h; sourceTree = ""; }; 45E6080829ADD57100634200 /* UploadResource_1G.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = UploadResource_1G.zip; sourceTree = ""; }; @@ -171,7 +169,6 @@ 93D230301C86D7F700434F6D /* LaunchScreen.storyboard */, 93D230331C86D7F700434F6D /* Info.plist */, 93D230221C86D7F700434F6D /* Supporting Files */, - 4545D3132BAD7D0C00932C3F /* PrivacyInfo.xcprivacy */, ); path = QiniuDemo; sourceTree = ""; @@ -309,7 +306,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 4545D3142BAD7D0C00932C3F /* PrivacyInfo.xcprivacy in Resources */, 93D230321C86D7F700434F6D /* LaunchScreen.storyboard in Resources */, 45E6080929ADD57100634200 /* UploadResource_1G.zip in Resources */, 4561F02C28D9A6F80098A697 /* UploadResource_14M.zip in Resources */, diff --git a/QiniuDemo/QiniuDemo/ViewController.m b/QiniuDemo/QiniuDemo/ViewController.m index 7530d18e..a8123463 100755 --- a/QiniuDemo/QiniuDemo/ViewController.m +++ b/QiniuDemo/QiniuDemo/ViewController.m @@ -151,7 +151,12 @@ - (void)uploadImageToQNFilePath:(NSString *)filePath complete:(dispatch_block_t) builder.resumeUploadVersion = QNResumeUploadVersionV2; builder.putThreshold = 4*1024*1024; builder.chunkSize = 1*1024*1024; -// builder.zone = [[QNFixedZone alloc] initWithUpDomainList:@[kUploadFixHost00, kUploadFixHost01]]; + builder.accelerateUploading = true; + builder.zone = [[QNFixedZone alloc] initWithAccUpDomainList:@[@"zone0-space.kodo-accelerate.cn-east-1.qiniucs.com"] + upList:@[kUploadFixHost00] + oldUpList:@[] + regionId:@"custom"]; + // [[QNFixedZone alloc] initWithUpDomainList:@[kUploadFixHost00, kUploadFixHost01]]; NSString *recorderPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; NSLog(@"== record path:%@", recorderPath); builder.recorder = [QNFileRecorder fileRecorderWithFolder:recorderPath error:nil]; diff --git a/QiniuSDK/Common/QNFixedZone.h b/QiniuSDK/Common/QNFixedZone.h index f1c74a2b..a2114afe 100644 --- a/QiniuSDK/Common/QNFixedZone.h +++ b/QiniuSDK/Common/QNFixedZone.h @@ -63,6 +63,21 @@ NS_ASSUME_NONNULL_BEGIN */ - (instancetype)initWithUpDomainList:(NSArray *)upList; + +/** + * Zone初始化方法 + * + * @param accUpList 加速上传服务器地址列表 + * @param upList 默认上传服务器地址列表 + * @param oldUpList 支持 SNI 的上传服务器地址列表 + * @param regionId 区域 ID + * @return Zone实例 + */ +- (instancetype)initWithAccUpDomainList:(NSArray *)accUpList + upList:(NSArray *)upList + oldUpList:(NSArray *)oldUpList + regionId:(NSString *)regionId; + /** * Zone初始化方法 * diff --git a/QiniuSDK/Common/QNFixedZone.m b/QiniuSDK/Common/QNFixedZone.m index 83b21d38..426f41fb 100644 --- a/QiniuSDK/Common/QNFixedZone.m +++ b/QiniuSDK/Common/QNFixedZone.m @@ -137,11 +137,21 @@ - (QNZonesInfo *)createZonesInfo:(NSArray *)upDomains - (QNZonesInfo *)createZonesInfo:(NSArray *)upDomains oldUpDomains:(NSArray *)oldUpDomains regionId:(NSString *)regionId { - if (!upDomains && upDomains.count == 0) { + return [self createZonesInfo:nil domains:upDomains oldDomains:oldUpDomains regionId:regionId]; +} + +- (QNZonesInfo *)createZonesInfo:(NSArray *)accDomains + domains:(NSArray *)domains + oldDomains:(NSArray *)oldDomains + regionId:(NSString *)regionId { + if ((!accDomains || accDomains.count == 0) && (!domains || domains.count == 0)) { return nil; } - QNZoneInfo *zoneInfo = [QNZoneInfo zoneInfoWithMainHosts:upDomains oldHosts:oldUpDomains regionId:regionId]; + QNZoneInfo *zoneInfo = [QNZoneInfo zoneInfoWithAccHosts:accDomains + mainHosts:domains + oldHosts:oldDomains + regionId:regionId]; QNZonesInfo *zonesInfo = [[QNZonesInfo alloc] initWithZonesInfo:@[zoneInfo]]; return zonesInfo; } @@ -167,6 +177,15 @@ - (instancetype)initWithUpDomainList:(NSArray *)upList } return self; } +- (instancetype)initWithAccUpDomainList:(NSArray *)accUpList + upList:(NSArray *)upList + oldUpList:(NSArray *)oldUpList + regionId:(NSString *)regionId { + if (self = [super init]) { + self.zonesInfo = [self createZonesInfo:accUpList domains:upList oldDomains:oldUpList regionId:regionId]; + } + return self; +} - (QNZonesInfo *)getZonesInfoWithToken:(QNUpToken *)token { return self.zonesInfo; diff --git a/QiniuSDK/Common/QNZoneInfo.m b/QiniuSDK/Common/QNZoneInfo.m index d78f0434..9c0c1002 100644 --- a/QiniuSDK/Common/QNZoneInfo.m +++ b/QiniuSDK/Common/QNZoneInfo.m @@ -73,7 +73,7 @@ + (QNZoneInfo *)zoneInfoWithAccHosts:(NSArray *)accHosts QNZoneInfo *zoneInfo = [QNZoneInfo zoneInfoFromDictionary:@{@"ttl" : @(-1), @"region" : regionId ?: QNZoneInfoEmptyRegionId, - @"up" : @{@"acc_domains" : mainHosts ?: @[], + @"up" : @{@"acc_domains" : accHosts ?: @[], @"domains" : mainHosts ?: @[], @"old" : oldHosts ?: @[]}, }]; diff --git a/QiniuSDK/Http/QNResponseInfo.h b/QiniuSDK/Http/QNResponseInfo.h index 85e51c8b..f021ee78 100755 --- a/QiniuSDK/Http/QNResponseInfo.h +++ b/QiniuSDK/Http/QNResponseInfo.h @@ -55,6 +55,8 @@ @property (nonatomic, readonly) BOOL isHostUnavailable; /// 在断点续上传过程中,ctx 信息已过期。 @property (nonatomic, readonly) BOOL isCtxExpiedError; +/// 是否是加速配置错误 +@property (nonatomic, readonly) BOOL isTransferAccelerationConfigureError; /// 是否为 七牛响应 @property (nonatomic, readonly, getter=isNotQiniu) BOOL notQiniu; diff --git a/QiniuSDK/Http/QNResponseInfo.m b/QiniuSDK/Http/QNResponseInfo.m index 407da5a7..879f41ff 100755 --- a/QiniuSDK/Http/QNResponseInfo.m +++ b/QiniuSDK/Http/QNResponseInfo.m @@ -257,6 +257,10 @@ - (BOOL)couldRegionRetry{ return YES; } + if ([self isTransferAccelerationConfigureError]) { + return YES; + } + if (self.isCancelled || _statusCode == 100 || (_statusCode > 300 && _statusCode < 500 && _statusCode != 406) @@ -276,6 +280,10 @@ - (BOOL)couldHostRetry{ return YES; } + if ([self isTransferAccelerationConfigureError]) { + return YES; + } + if (self.isCancelled || _statusCode == 100 || (_statusCode > 300 && _statusCode < 500 && _statusCode != 406) @@ -301,7 +309,8 @@ - (BOOL)canConnectToHost{ - (BOOL)isHostUnavailable{ // 基本不可恢复,注:会影响下次请求,范围太大可能会造成大量的timeout - if (_statusCode == 502 || _statusCode == 503 || _statusCode == 504 || _statusCode == 599) { + if ([self isTransferAccelerationConfigureError] || + _statusCode == 502 || _statusCode == 503 || _statusCode == 504 || _statusCode == 599) { return true; } else { return false; @@ -312,6 +321,11 @@ - (BOOL)isCtxExpiedError { return _statusCode == 701 || (_statusCode == 612 && [_message containsString:@"no such uploadId"]); } +- (BOOL)isTransferAccelerationConfigureError { + NSString *errorDesc = [NSString stringWithFormat:@"%@", self.error]; + return [errorDesc containsString:@"transfer acceleration is not configured on this bucket"]; +} + - (BOOL)isConnectionBroken { return _statusCode == kQNNetworkError || _statusCode == NSURLErrorNotConnectedToInternet; } diff --git a/QiniuSDK/Http/ServerRegion/QNUploadDomainRegion.h b/QiniuSDK/Http/ServerRegion/QNUploadDomainRegion.h index bcade144..8e8c5d00 100644 --- a/QiniuSDK/Http/ServerRegion/QNUploadDomainRegion.h +++ b/QiniuSDK/Http/ServerRegion/QNUploadDomainRegion.h @@ -10,8 +10,12 @@ NS_ASSUME_NONNULL_BEGIN +@class QNConfiguration; + @interface QNUploadDomainRegion : NSObject +- (instancetype)initWithConfig:(QNConfiguration *)config; + @end NS_ASSUME_NONNULL_END diff --git a/QiniuSDK/Http/ServerRegion/QNUploadDomainRegion.m b/QiniuSDK/Http/ServerRegion/QNUploadDomainRegion.m index a8271c69..daf72f12 100644 --- a/QiniuSDK/Http/ServerRegion/QNUploadDomainRegion.m +++ b/QiniuSDK/Http/ServerRegion/QNUploadDomainRegion.m @@ -271,28 +271,33 @@ - (void)updateIpListFormHost:(NSString *)host { BOOL accelerate = YES; @synchronized (self) { - if (self.enableAccelerateUpload && responseInfo.error != nil && - [[NSString stringWithFormat:@"%@", responseInfo.error] - containsString:@"transfer acceleration is not configured on this bucket"]) { - self.enableAccelerateUpload = true; + if (self.enableAccelerateUpload && responseInfo.isTransferAccelerationConfigureError) { + self.enableAccelerateUpload = NO; } accelerate = self.enableAccelerateUpload; } - NSArray *hostList = nil; - NSDictionary *domainInfo = nil; + NSMutableArray *hostList = [NSMutableArray array]; + NSMutableDictionary *domainInfo = [NSMutableDictionary dictionary]; if (requestState.isUseOldServer) { - hostList = self.oldDomainHostList; - domainInfo = self.oldDomainDictionary; + if (self.oldDomainHostList.count > 0 && self.oldDomainDictionary.count > 0) { + [hostList addObjectsFromArray:self.oldDomainHostList]; + [domainInfo addEntriesFromDictionary:self.oldDomainDictionary]; + } } else { + + // 优先使用 acc if (accelerate && self.accDomainHostList.count > 0 && self.accDomainDictionary.count > 0) { - hostList = self.accDomainHostList; - domainInfo = self.accDomainDictionary; - } else { - hostList = self.domainHostList; - domainInfo = self.domainDictionary; + [hostList addObjectsFromArray:self.accDomainHostList]; + [domainInfo addEntriesFromDictionary:self.accDomainDictionary]; + } + + if (self.domainHostList.count > 0 && + self.domainDictionary.count > 0){ + [hostList addObjectsFromArray:self.domainHostList]; + [domainInfo addEntriesFromDictionary:self.domainDictionary]; } } @@ -300,10 +305,6 @@ - (void)updateIpListFormHost:(NSString *)host { return nil; } - if (requestState.isUseOldServer && self.oldDomainHostList.count > 0 && self.oldDomainDictionary.count > 0) { - hostList = self.oldDomainHostList; - domainInfo = self.oldDomainDictionary; - } QNUploadServer *server = nil; // 1. 优先使用http3 diff --git a/QiniuSDK/Storage/QNBaseUpload.m b/QiniuSDK/Storage/QNBaseUpload.m index b6a3eca1..8d8ef1af 100644 --- a/QiniuSDK/Storage/QNBaseUpload.m +++ b/QiniuSDK/Storage/QNBaseUpload.m @@ -113,7 +113,7 @@ - (void)run { if (responseInfo != nil && responseInfo.isOK && zonesInfo) { if (![self setupRegions:zonesInfo]) { - responseInfo = [QNResponseInfo responseInfoWithInvalidArgument:[NSString stringWithFormat:@"origin response:%@", responseInfo]]; + responseInfo = [QNResponseInfo responseInfoWithInvalidArgument:[NSString stringWithFormat:@"setup regions host fail, origin response:%@", responseInfo]]; [self complete:responseInfo response:responseInfo.responseDictionary]; return; } @@ -221,7 +221,7 @@ - (BOOL)setupRegions:(QNZonesInfo *)zonesInfo{ NSMutableArray *defaultRegions = [NSMutableArray array]; NSArray *zoneInfos = zonesInfo.zonesInfo; for (QNZoneInfo *zoneInfo in zoneInfos) { - QNUploadDomainRegion *region = [[QNUploadDomainRegion alloc] init]; + QNUploadDomainRegion *region = [[QNUploadDomainRegion alloc] initWithConfig:self.config]; [region setupRegionData:zoneInfo]; if (region.isValid) { [defaultRegions addObject:region]; diff --git a/QiniuSDK/Storage/QNConfiguration.h b/QiniuSDK/Storage/QNConfiguration.h index 04a2c277..e5cb7f9e 100644 --- a/QiniuSDK/Storage/QNConfiguration.h +++ b/QiniuSDK/Storage/QNConfiguration.h @@ -224,7 +224,7 @@ typedef void (^QNConfigurationBuilderBlock)(QNConfigurationBuilder *builder); @property(nonatomic, copy) NSArray *dohIpv6Servers; /** - * Host全局冻结时间 单位:秒 默认:10 推荐范围:[5 ~ 30] + * Host全局冻结时间 单位:秒 默认:60 推荐范围:[30 ~ 120] * 当某个Host的上传失败后并且可能短时间无法恢复,会冻结该Host */ @property(nonatomic, assign)UInt32 globalHostFrozenTime; diff --git a/QiniuSDK/Storage/QNConfiguration.m b/QiniuSDK/Storage/QNConfiguration.m index 308dcfe9..7262a62d 100644 --- a/QiniuSDK/Storage/QNConfiguration.m +++ b/QiniuSDK/Storage/QNConfiguration.m @@ -111,7 +111,7 @@ - (void)setupData{ _udpDnsEnable = true; _defaultUdpDnsIpv4Servers = [self parseBase64Array:@"WyIyMjMuNS41LjUiLCAiMTE0LjExNC4xMTQuMTE0IiwgIjEuMS4xLjEiLCAiOC44LjguOCJd"]; - _globalHostFrozenTime = 10; + _globalHostFrozenTime = 60; _partialHostFrozenTime = 5*60; _connectCheckEnable = YES;