Skip to content

Commit b3eacba

Browse files
committed
optimize cf client
1 parent 81b49f8 commit b3eacba

File tree

4 files changed

+19
-65
lines changed

4 files changed

+19
-65
lines changed

QiniuDemo/QiniuDemo/ViewController.m

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ @interface ViewController () <UINavigationControllerDelegate, UIImagePickerContr
4141

4242
@implementation ViewController
4343

44+
#define kUploadFixHost00 @"up-z0.qbox.me"
45+
#define kUploadFixHost01 @"upload.qbox.me"
46+
4447
- (void)viewDidLoad {
4548
[super viewDidLoad];
4649
[QNLogUtil setLogLevel:QNLogLevelInfo];
@@ -62,15 +65,15 @@ - (IBAction)uploadAction:(UIButton *)sender {
6265
path = [[NSBundle mainBundle] pathForResource:@"image.png" ofType:nil];
6366
path = [[NSBundle mainBundle] pathForResource:@"image.jpg" ofType:nil];
6467
path = [[NSBundle mainBundle] pathForResource:@"UploadResource_6M.zip" ofType:nil];
65-
path = [[NSBundle mainBundle] pathForResource:@"UploadResource_9M.zip" ofType:nil];
68+
// path = [[NSBundle mainBundle] pathForResource:@"UploadResource_9M.zip" ofType:nil];
6669
// path = [[NSBundle mainBundle] pathForResource:@"UploadResource_49M.zip" ofType:nil];
6770
// path = [[NSBundle mainBundle] pathForResource:@"UploadResource_1.44G.zip" ofType:nil];
6871

6972
// NSFileManager *manager = [NSFileManager defaultManager];
7073
// NSURL *desktopUrl = [manager URLsForDirectory:NSDesktopDirectory inDomains:NSUserDomainMask].firstObject;
7174
// path = [desktopUrl URLByAppendingPathComponent:@"pycharm.dmg"].path;
7275

73-
[self uploadImageToQNFilePath:path index:0];
76+
// [self uploadImageToQNFilePath:path index:0];
7477
[self uploadImageToQNFilePath:path complete:nil];
7578
[self changeUploadState:UploadStateUploading];
7679
#else
@@ -116,7 +119,7 @@ - (void)uploadImageToQNFilePath:(NSString *)filePath index:(NSInteger)index {
116119

117120
- (void)uploadImageToQNFilePath:(NSString *)filePath complete:(dispatch_block_t)complete {
118121

119-
kQNGlobalConfiguration.isDnsOpen = NO;
122+
// kQNGlobalConfiguration.isDnsOpen = NO;
120123
// kQNGlobalConfiguration.connectCheckEnable = false;
121124
kQNGlobalConfiguration.dnsCacheMaxTTL = 600;
122125
kQNGlobalConfiguration.partialHostFrozenTime = 20*60;
@@ -130,14 +133,14 @@ - (void)uploadImageToQNFilePath:(NSString *)filePath complete:(dispatch_block_t)
130133
QNConfiguration *configuration = [QNConfiguration build:^(QNConfigurationBuilder *builder) {
131134
builder.timeoutInterval = 90;
132135
builder.retryMax = 1;
133-
builder.useHttps = NO;
136+
// builder.useHttps = NO;
134137

135138
builder.useConcurrentResumeUpload = true;
136-
// builder.concurrentTaskCount = 6;
139+
builder.concurrentTaskCount = 3;
137140
builder.resumeUploadVersion = QNResumeUploadVersionV1;
138141
builder.putThreshold = 4*1024*1024;
139-
// builder.chunkSize = 1*1024*1024;
140-
// builder.zone = [[QNFixedZone alloc] initWithUpDomainList:@[@"up-z0.qbox.me", /*@"upload.qbox.me"*/]];
142+
builder.chunkSize = 1*1024*1024;
143+
builder.zone = [[QNFixedZone alloc] initWithUpDomainList:@[kUploadFixHost00, kUploadFixHost01]];
141144
builder.recorder = [QNFileRecorder fileRecorderWithFolder:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] error:nil];
142145
}];
143146

@@ -310,9 +313,15 @@ - (void)alertMessage:(NSString *)message{
310313
item.ipValue = @"180.101.136.19";
311314
item.sourceValue = @"custom";
312315
[array addObject:item];
313-
} else if ([host containsString:@"up-z0.qbox.me"]) {
316+
} else if ([host containsString:kUploadFixHost00]) {
314317
DnsItem *item = [[DnsItem alloc] init];
315318
item.hostValue = host;
319+
item.ipValue = @"220.181.38.148";
320+
item.sourceValue = @"custom";
321+
[array addObject:item];
322+
323+
item = [[DnsItem alloc] init];
324+
item.hostValue = host;
316325
item.ipValue = @"180.101.136.28";
317326
item.sourceValue = @"custom";
318327
[array addObject:item];

QiniuSDK/Http/Request/HttpClient/CFNetwork/QNCFHttpClient.m

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ - (void)request:(NSURLRequest *)request
7777
[self.requestMetrics start];
7878

7979
self.responseData = [NSMutableData data];
80-
self.httpClient = [QNCFHttpClientInner client:request connectionProxy:connectionProxy];
80+
self.httpClient = [QNCFHttpClientInner client:self.request connectionProxy:connectionProxy];
8181
self.httpClient.delegate = self;
8282
[self.httpClient performSelector:@selector(main)
8383
onThread:self.thread
@@ -126,31 +126,6 @@ - (void)didLoadData:(nonnull NSData *)data {
126126
[self.responseData appendData:data];
127127
}
128128

129-
- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust forDomain:(NSString *)domain {
130-
131-
NSMutableArray *policies = [NSMutableArray array];
132-
if (domain) {
133-
[policies addObject:(__bridge_transfer id)SecPolicyCreateSSL(true, (__bridge CFStringRef)domain)];
134-
} else {
135-
[policies addObject:(__bridge_transfer id)SecPolicyCreateBasicX509()];
136-
}
137-
138-
SecTrustSetPolicies(serverTrust, (__bridge CFArrayRef)policies);
139-
140-
SecTrustResultType result = kSecTrustResultInvalid;
141-
142-
OSStatus status = SecTrustEvaluate(serverTrust, &result);
143-
if (status != errSecSuccess) {
144-
return NO;
145-
}
146-
147-
if (result == kSecTrustResultUnspecified || result == kSecTrustResultProceed) {
148-
return YES;
149-
} else {
150-
return NO;
151-
}
152-
}
153-
154129
- (void)onError:(nonnull NSError *)error {
155130
[self completeAction:error];
156131
}

QiniuSDK/Http/Request/HttpClient/CFNetwork/QNCFHttpClientInner.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ NS_ASSUME_NONNULL_BEGIN
1515
- (void)redirectedToRequest:(NSURLRequest *)request
1616
redirectResponse:(NSURLResponse *)redirectResponse;
1717

18-
- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust
19-
forDomain:(NSString *)domain;
20-
2118
- (void)onError:(NSError *)error;
2219

2320
- (void)didSendBodyData:(int64_t)bytesSent

QiniuSDK/Http/Request/HttpClient/CFNetwork/QNCFHttpClientInner.m

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,6 @@ - (BOOL)shouldEvaluateInputStreamServerTrust{
158158
}
159159
}
160160

161-
- (void)evaluateInputStreamServerTrust{
162-
if (self.isInputStreamEvaluated) {
163-
return;
164-
}
165-
166-
SecTrustRef trust = (__bridge SecTrustRef) [self.inputStream propertyForKey:(__bridge NSString *) kCFStreamPropertySSLPeerTrust];
167-
NSString *host = [self.request allHTTPHeaderFields][@"host"];
168-
if ([self delegate_evaluateServerTrust:trust forDomain:host]) {
169-
self.isInputStreamEvaluated = YES;
170-
} else {
171-
[self delegate_onError:[self createError:NSURLErrorSecureConnectionFailed errorDescription:@"SSLHandshake failed"]];
172-
}
173-
}
174-
175161
- (void)inputStreamGetAndNotifyHttpResponse{
176162
@synchronized (self) {
177163
if (self.isReadResponseHeader) {
@@ -298,10 +284,6 @@ - (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode{
298284
@autoreleasepool {
299285
switch (eventCode) {
300286
case NSStreamEventHasBytesAvailable:{
301-
if ([self shouldEvaluateInputStreamServerTrust]) {
302-
[self evaluateInputStreamServerTrust];
303-
}
304-
305287
if (![self isInputStreamHttpResponseHeaderComplete]) {
306288
break;
307289
}
@@ -315,7 +297,7 @@ - (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode{
315297
case NSStreamEventErrorOccurred:{
316298
[self releaseResource];
317299
[self endProgress: YES];
318-
[self delegate_onError:[self translateCFNetworkErrorIntoUrlError:[self.inputStream streamError]]];
300+
[self delegate_onError:[self translateCFNetworkErrorIntoUrlError:[aStream streamError]]];
319301
}
320302
break;
321303
case NSStreamEventEndEncountered:{
@@ -816,15 +798,6 @@ - (void)delegate_redirectedToRequest:(NSURLRequest *)request
816798
}
817799
}
818800

819-
- (BOOL)delegate_evaluateServerTrust:(SecTrustRef)serverTrust
820-
forDomain:(NSString *)domain{
821-
if ([self.delegate respondsToSelector:@selector(evaluateServerTrust:forDomain:)]) {
822-
return [self.delegate evaluateServerTrust:serverTrust forDomain:domain];
823-
} else {
824-
return NO;
825-
}
826-
}
827-
828801
- (void)delegate_onError:(NSError *)error{
829802
@synchronized (self) {
830803
if (self.isCallFinishOrError) {

0 commit comments

Comments
 (0)