Skip to content

Commit f7e8511

Browse files
author
YangSen-qn
committed
support acc upload
1 parent da1929d commit f7e8511

File tree

12 files changed

+86
-30
lines changed

12 files changed

+86
-30
lines changed

QiniuDemo/QiniuDemo.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
/* Begin PBXBuildFile section */
1010
26F62ADDD5B6306E978C9A3F /* libPods-QiniuDemoTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 14CB2139715DD7B6FD5B146E /* libPods-QiniuDemoTests.a */; };
11-
4545D3142BAD7D0C00932C3F /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 4545D3132BAD7D0C00932C3F /* PrivacyInfo.xcprivacy */; };
1211
4561F02C28D9A6F80098A697 /* UploadResource_14M.zip in Resources */ = {isa = PBXBuildFile; fileRef = 4561F02B28D9A6F80098A697 /* UploadResource_14M.zip */; };
1312
45E6080929ADD57100634200 /* UploadResource_1G.zip in Resources */ = {isa = PBXBuildFile; fileRef = 45E6080829ADD57100634200 /* UploadResource_1G.zip */; };
1413
93D230241C86D7F700434F6D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D230231C86D7F700434F6D /* main.m */; };
@@ -43,7 +42,6 @@
4342
14CB2139715DD7B6FD5B146E /* libPods-QiniuDemoTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuDemoTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
4443
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 = "<group>"; };
4544
3189882026469145003CCA68 /* QiniuDemo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = QiniuDemo.entitlements; sourceTree = "<group>"; };
46-
4545D3132BAD7D0C00932C3F /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
4745
4561F02B28D9A6F80098A697 /* UploadResource_14M.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = UploadResource_14M.zip; sourceTree = "<group>"; };
4846
4561F02F28D9AB090098A697 /* Configure.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Configure.h; sourceTree = "<group>"; };
4947
45E6080829ADD57100634200 /* UploadResource_1G.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = UploadResource_1G.zip; sourceTree = "<group>"; };
@@ -171,7 +169,6 @@
171169
93D230301C86D7F700434F6D /* LaunchScreen.storyboard */,
172170
93D230331C86D7F700434F6D /* Info.plist */,
173171
93D230221C86D7F700434F6D /* Supporting Files */,
174-
4545D3132BAD7D0C00932C3F /* PrivacyInfo.xcprivacy */,
175172
);
176173
path = QiniuDemo;
177174
sourceTree = "<group>";
@@ -309,7 +306,6 @@
309306
isa = PBXResourcesBuildPhase;
310307
buildActionMask = 2147483647;
311308
files = (
312-
4545D3142BAD7D0C00932C3F /* PrivacyInfo.xcprivacy in Resources */,
313309
93D230321C86D7F700434F6D /* LaunchScreen.storyboard in Resources */,
314310
45E6080929ADD57100634200 /* UploadResource_1G.zip in Resources */,
315311
4561F02C28D9A6F80098A697 /* UploadResource_14M.zip in Resources */,

QiniuDemo/QiniuDemo/ViewController.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,12 @@ - (void)uploadImageToQNFilePath:(NSString *)filePath complete:(dispatch_block_t)
151151
builder.resumeUploadVersion = QNResumeUploadVersionV2;
152152
builder.putThreshold = 4*1024*1024;
153153
builder.chunkSize = 1*1024*1024;
154-
// builder.zone = [[QNFixedZone alloc] initWithUpDomainList:@[kUploadFixHost00, kUploadFixHost01]];
154+
builder.accelerateUploading = true;
155+
builder.zone = [[QNFixedZone alloc] initWithAccUpDomainList:@[@"zone0-space.kodo-accelerate.cn-east-1.qiniucs.com"]
156+
upList:@[kUploadFixHost00]
157+
oldUpList:@[]
158+
regionId:@"custom"];
159+
// [[QNFixedZone alloc] initWithUpDomainList:@[kUploadFixHost00, kUploadFixHost01]];
155160
NSString *recorderPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
156161
NSLog(@"== record path:%@", recorderPath);
157162
builder.recorder = [QNFileRecorder fileRecorderWithFolder:recorderPath error:nil];

QiniuSDK/Common/QNFixedZone.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ NS_ASSUME_NONNULL_BEGIN
6363
*/
6464
- (instancetype)initWithUpDomainList:(NSArray<NSString *> *)upList;
6565

66+
67+
/**
68+
* Zone初始化方法
69+
*
70+
* @param accUpList 加速上传服务器地址列表
71+
* @param upList 默认上传服务器地址列表
72+
* @param oldUpList 支持 SNI 的上传服务器地址列表
73+
* @param regionId 区域 ID
74+
* @return Zone实例
75+
*/
76+
- (instancetype)initWithAccUpDomainList:(NSArray<NSString *> *)accUpList
77+
upList:(NSArray<NSString *> *)upList
78+
oldUpList:(NSArray<NSString *> *)oldUpList
79+
regionId:(NSString *)regionId;
80+
6681
/**
6782
* Zone初始化方法
6883
*

QiniuSDK/Common/QNFixedZone.m

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,21 @@ - (QNZonesInfo *)createZonesInfo:(NSArray <NSString *> *)upDomains
137137
- (QNZonesInfo *)createZonesInfo:(NSArray <NSString *> *)upDomains
138138
oldUpDomains:(NSArray <NSString *> *)oldUpDomains
139139
regionId:(NSString *)regionId {
140-
if (!upDomains && upDomains.count == 0) {
140+
return [self createZonesInfo:nil domains:upDomains oldDomains:oldUpDomains regionId:regionId];
141+
}
142+
143+
- (QNZonesInfo *)createZonesInfo:(NSArray <NSString *> *)accDomains
144+
domains:(NSArray <NSString *> *)domains
145+
oldDomains:(NSArray <NSString *> *)oldDomains
146+
regionId:(NSString *)regionId {
147+
if ((!accDomains || accDomains.count == 0) && (!domains || domains.count == 0)) {
141148
return nil;
142149
}
143150

144-
QNZoneInfo *zoneInfo = [QNZoneInfo zoneInfoWithMainHosts:upDomains oldHosts:oldUpDomains regionId:regionId];
151+
QNZoneInfo *zoneInfo = [QNZoneInfo zoneInfoWithAccHosts:accDomains
152+
mainHosts:domains
153+
oldHosts:oldDomains
154+
regionId:regionId];
145155
QNZonesInfo *zonesInfo = [[QNZonesInfo alloc] initWithZonesInfo:@[zoneInfo]];
146156
return zonesInfo;
147157
}
@@ -167,6 +177,15 @@ - (instancetype)initWithUpDomainList:(NSArray<NSString *> *)upList
167177
}
168178
return self;
169179
}
180+
- (instancetype)initWithAccUpDomainList:(NSArray<NSString *> *)accUpList
181+
upList:(NSArray<NSString *> *)upList
182+
oldUpList:(NSArray<NSString *> *)oldUpList
183+
regionId:(NSString *)regionId {
184+
if (self = [super init]) {
185+
self.zonesInfo = [self createZonesInfo:accUpList domains:upList oldDomains:oldUpList regionId:regionId];
186+
}
187+
return self;
188+
}
170189

171190
- (QNZonesInfo *)getZonesInfoWithToken:(QNUpToken *)token {
172191
return self.zonesInfo;

QiniuSDK/Common/QNZoneInfo.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ + (QNZoneInfo *)zoneInfoWithAccHosts:(NSArray <NSString *> *)accHosts
7373

7474
QNZoneInfo *zoneInfo = [QNZoneInfo zoneInfoFromDictionary:@{@"ttl" : @(-1),
7575
@"region" : regionId ?: QNZoneInfoEmptyRegionId,
76-
@"up" : @{@"acc_domains" : mainHosts ?: @[],
76+
@"up" : @{@"acc_domains" : accHosts ?: @[],
7777
@"domains" : mainHosts ?: @[],
7878
@"old" : oldHosts ?: @[]},
7979
}];

QiniuSDK/Http/QNResponseInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
@property (nonatomic, readonly) BOOL isHostUnavailable;
5656
/// 在断点续上传过程中,ctx 信息已过期。
5757
@property (nonatomic, readonly) BOOL isCtxExpiedError;
58+
/// 是否是加速配置错误
59+
@property (nonatomic, readonly) BOOL isTransferAccelerationConfigureError;
5860
/// 是否为 七牛响应
5961
@property (nonatomic, readonly, getter=isNotQiniu) BOOL notQiniu;
6062

QiniuSDK/Http/QNResponseInfo.m

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ - (BOOL)couldRegionRetry{
257257
return YES;
258258
}
259259

260+
if ([self isTransferAccelerationConfigureError]) {
261+
return YES;
262+
}
263+
260264
if (self.isCancelled
261265
|| _statusCode == 100
262266
|| (_statusCode > 300 && _statusCode < 500 && _statusCode != 406)
@@ -276,6 +280,10 @@ - (BOOL)couldHostRetry{
276280
return YES;
277281
}
278282

283+
if ([self isTransferAccelerationConfigureError]) {
284+
return YES;
285+
}
286+
279287
if (self.isCancelled
280288
|| _statusCode == 100
281289
|| (_statusCode > 300 && _statusCode < 500 && _statusCode != 406)
@@ -301,7 +309,8 @@ - (BOOL)canConnectToHost{
301309

302310
- (BOOL)isHostUnavailable{
303311
// 基本不可恢复,注:会影响下次请求,范围太大可能会造成大量的timeout
304-
if (_statusCode == 502 || _statusCode == 503 || _statusCode == 504 || _statusCode == 599) {
312+
if ([self isTransferAccelerationConfigureError] ||
313+
_statusCode == 502 || _statusCode == 503 || _statusCode == 504 || _statusCode == 599) {
305314
return true;
306315
} else {
307316
return false;
@@ -312,6 +321,11 @@ - (BOOL)isCtxExpiedError {
312321
return _statusCode == 701 || (_statusCode == 612 && [_message containsString:@"no such uploadId"]);
313322
}
314323

324+
- (BOOL)isTransferAccelerationConfigureError {
325+
NSString *errorDesc = [NSString stringWithFormat:@"%@", self.error];
326+
return [errorDesc containsString:@"transfer acceleration is not configured on this bucket"];
327+
}
328+
315329
- (BOOL)isConnectionBroken {
316330
return _statusCode == kQNNetworkError || _statusCode == NSURLErrorNotConnectedToInternet;
317331
}

QiniuSDK/Http/ServerRegion/QNUploadDomainRegion.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010

1111
NS_ASSUME_NONNULL_BEGIN
1212

13+
@class QNConfiguration;
14+
1315
@interface QNUploadDomainRegion : NSObject <QNUploadRegion>
1416

17+
- (instancetype)initWithConfig:(QNConfiguration *)config;
18+
1519
@end
1620

1721
NS_ASSUME_NONNULL_END

QiniuSDK/Http/ServerRegion/QNUploadDomainRegion.m

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -271,39 +271,40 @@ - (void)updateIpListFormHost:(NSString *)host {
271271

272272
BOOL accelerate = YES;
273273
@synchronized (self) {
274-
if (self.enableAccelerateUpload && responseInfo.error != nil &&
275-
[[NSString stringWithFormat:@"%@", responseInfo.error]
276-
containsString:@"transfer acceleration is not configured on this bucket"]) {
277-
self.enableAccelerateUpload = true;
274+
if (self.enableAccelerateUpload && responseInfo.isTransferAccelerationConfigureError) {
275+
self.enableAccelerateUpload = NO;
278276
}
279277
accelerate = self.enableAccelerateUpload;
280278
}
281279

282-
NSArray *hostList = nil;
283-
NSDictionary *domainInfo = nil;
280+
NSMutableArray *hostList = [NSMutableArray array];
281+
NSMutableDictionary *domainInfo = [NSMutableDictionary dictionary];
284282
if (requestState.isUseOldServer) {
285-
hostList = self.oldDomainHostList;
286-
domainInfo = self.oldDomainDictionary;
283+
if (self.oldDomainHostList.count > 0 && self.oldDomainDictionary.count > 0) {
284+
[hostList addObjectsFromArray:self.oldDomainHostList];
285+
[domainInfo addEntriesFromDictionary:self.oldDomainDictionary];
286+
}
287287
} else {
288+
289+
// 优先使用 acc
288290
if (accelerate &&
289291
self.accDomainHostList.count > 0 &&
290292
self.accDomainDictionary.count > 0) {
291-
hostList = self.accDomainHostList;
292-
domainInfo = self.accDomainDictionary;
293-
} else {
294-
hostList = self.domainHostList;
295-
domainInfo = self.domainDictionary;
293+
[hostList addObjectsFromArray:self.accDomainHostList];
294+
[domainInfo addEntriesFromDictionary:self.accDomainDictionary];
295+
}
296+
297+
if (self.domainHostList.count > 0 &&
298+
self.domainDictionary.count > 0){
299+
[hostList addObjectsFromArray:self.domainHostList];
300+
[domainInfo addEntriesFromDictionary:self.domainDictionary];
296301
}
297302
}
298303

299304
if (hostList.count == 0 || domainInfo.count == 0) {
300305
return nil;
301306
}
302307

303-
if (requestState.isUseOldServer && self.oldDomainHostList.count > 0 && self.oldDomainDictionary.count > 0) {
304-
hostList = self.oldDomainHostList;
305-
domainInfo = self.oldDomainDictionary;
306-
}
307308

308309
QNUploadServer *server = nil;
309310
// 1. 优先使用http3

QiniuSDK/Storage/QNBaseUpload.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ - (void)run {
113113

114114
if (responseInfo != nil && responseInfo.isOK && zonesInfo) {
115115
if (![self setupRegions:zonesInfo]) {
116-
responseInfo = [QNResponseInfo responseInfoWithInvalidArgument:[NSString stringWithFormat:@"origin response:%@", responseInfo]];
116+
responseInfo = [QNResponseInfo responseInfoWithInvalidArgument:[NSString stringWithFormat:@"setup regions host fail, origin response:%@", responseInfo]];
117117
[self complete:responseInfo response:responseInfo.responseDictionary];
118118
return;
119119
}
@@ -221,7 +221,7 @@ - (BOOL)setupRegions:(QNZonesInfo *)zonesInfo{
221221
NSMutableArray *defaultRegions = [NSMutableArray array];
222222
NSArray *zoneInfos = zonesInfo.zonesInfo;
223223
for (QNZoneInfo *zoneInfo in zoneInfos) {
224-
QNUploadDomainRegion *region = [[QNUploadDomainRegion alloc] init];
224+
QNUploadDomainRegion *region = [[QNUploadDomainRegion alloc] initWithConfig:self.config];
225225
[region setupRegionData:zoneInfo];
226226
if (region.isValid) {
227227
[defaultRegions addObject:region];

QiniuSDK/Storage/QNConfiguration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ typedef void (^QNConfigurationBuilderBlock)(QNConfigurationBuilder *builder);
224224
@property(nonatomic, copy) NSArray <NSString *> *dohIpv6Servers;
225225

226226
/**
227-
* Host全局冻结时间 单位:秒 默认:10 推荐范围:[5 ~ 30]
227+
* Host全局冻结时间 单位:秒 默认:60 推荐范围:[30 ~ 120]
228228
* 当某个Host的上传失败后并且可能短时间无法恢复,会冻结该Host
229229
*/
230230
@property(nonatomic, assign)UInt32 globalHostFrozenTime;

QiniuSDK/Storage/QNConfiguration.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ - (void)setupData{
111111
_udpDnsEnable = true;
112112
_defaultUdpDnsIpv4Servers = [self parseBase64Array:@"WyIyMjMuNS41LjUiLCAiMTE0LjExNC4xMTQuMTE0IiwgIjEuMS4xLjEiLCAiOC44LjguOCJd"];
113113

114-
_globalHostFrozenTime = 10;
114+
_globalHostFrozenTime = 60;
115115
_partialHostFrozenTime = 5*60;
116116

117117
_connectCheckEnable = YES;

0 commit comments

Comments
 (0)