Skip to content

Commit 5aacb6a

Browse files
authored
Merge pull request #430 from YangSen-qn/master
connect config support get from server
2 parents ccd2d72 + 347e330 commit 5aacb6a

27 files changed

+345
-103
lines changed

.github/workflows/ci-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ jobs:
2828
env:
2929
QINIU_TEST_ENV: travis
3030
run: |
31-
xcodebuild test -workspace QiniuSDK.xcworkspace -scheme QiniuSDK_iOS -configuration Debug -destination 'platform=iOS Simulator,name=iPhone 8 Plus' -enableCodeCoverage YES
31+
xcodebuild test -workspace QiniuSDK.xcworkspace -scheme QiniuSDK_iOS -configuration Debug -destination 'platform=iOS Simulator,name=iPhone 14 Pro' -enableCodeCoverage YES
3232
xcodebuild test -workspace QiniuSDK.xcworkspace -scheme QiniuSDK_Mac -configuration Debug -destination 'platform=macOS,arch=x86_64'
3333
bash <(curl -s https://codecov.io/bash)

QiniuDemo/Podfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ source 'https://github.com/CocoaPods/Specs.git'
33
target "QiniuDemo" do
44
platform :ios, "10.0"
55

6-
# pod 'Qiniu', '~> 8.3.2'
6+
# pod 'Qiniu', '~> 7.4.0'
7+
# pod 'Qiniu', '7.1.7'
78
pod 'Qiniu',:path => '../'
89
end
910

QiniuDemo/QiniuDemo.xcodeproj/project.pbxproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
93D230321C86D7F700434F6D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 93D230301C86D7F700434F6D /* LaunchScreen.storyboard */; };
1919
93D2303D1C86D7F700434F6D /* QiniuDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D2303C1C86D7F700434F6D /* QiniuDemoTests.m */; };
2020
93D230481C86D7F800434F6D /* QiniuDemoUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D230471C86D7F800434F6D /* QiniuDemoUITests.m */; };
21+
9C463550C07FFFC029A652B8 /* libPods-QiniuDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B9BC5A8D93F988C1240E05F /* libPods-QiniuDemo.a */; };
2122
/* End PBXBuildFile section */
2223

2324
/* Begin PBXContainerItemProxy section */
@@ -71,6 +72,7 @@
7172
isa = PBXFrameworksBuildPhase;
7273
buildActionMask = 2147483647;
7374
files = (
75+
9C463550C07FFFC029A652B8 /* libPods-QiniuDemo.a in Frameworks */,
7476
);
7577
runOnlyForDeploymentPostprocessing = 0;
7678
};
@@ -539,8 +541,8 @@
539541
PRODUCT_BUNDLE_IDENTIFIER = com.qiniu.demo;
540542
PRODUCT_NAME = "$(TARGET_NAME)";
541543
STRIP_SWIFT_SYMBOLS = YES;
542-
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
543-
SUPPORTS_MACCATALYST = NO;
544+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
545+
SUPPORTS_MACCATALYST = YES;
544546
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
545547
TARGETED_DEVICE_FAMILY = "1,2";
546548
};
@@ -560,8 +562,8 @@
560562
PRODUCT_BUNDLE_IDENTIFIER = com.qiniu.demo;
561563
PRODUCT_NAME = "$(TARGET_NAME)";
562564
STRIP_SWIFT_SYMBOLS = YES;
563-
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
564-
SUPPORTS_MACCATALYST = NO;
565+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
566+
SUPPORTS_MACCATALYST = YES;
565567
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
566568
TARGETED_DEVICE_FAMILY = "1,2";
567569
};

QiniuDemo/QiniuDemo/QiniuDemo.entitlements

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>com.apple.security.app-sandbox</key>
6+
<true/>
7+
<key>com.apple.security.device.audio-input</key>
8+
<true/>
9+
<key>com.apple.security.device.camera</key>
10+
<true/>
11+
<key>com.apple.security.network.client</key>
12+
<true/>
513
<key>com.apple.security.personal-information.photos-library</key>
614
<true/>
715
</dict>

QiniuDemo/QiniuDemo/ViewController.m

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
#endif
1414

1515
#import "ViewController.h"
16-
#import "QNTransactionManager.h"
16+
//#import "QNTransactionManager.h"
17+
#import <HappyDNS/HappyDNS.h>
1718
#import <Photos/Photos.h>
1819

1920
typedef NS_ENUM(NSInteger, UploadState){
@@ -72,7 +73,7 @@ - (IBAction)uploadAction:(UIButton *)sender {
7273
path = [[NSBundle mainBundle] pathForResource:@"UploadResource_14M.zip" ofType:nil];
7374
// path = [[NSBundle mainBundle] pathForResource:@"UploadResource_9M.zip" ofType:nil];
7475
// path = [[NSBundle mainBundle] pathForResource:@"UploadResource_49M.zip" ofType:nil];
75-
// path = [[NSBundle mainBundle] pathForResource:@"UploadResource_1G.zip" ofType:nil];
76+
path = [[NSBundle mainBundle] pathForResource:@"UploadResource_1G.zip" ofType:nil];
7677

7778
// NSFileManager *manager = [NSFileManager defaultManager];
7879
// NSURL *desktopUrl = [manager URLsForDirectory:NSDesktopDirectory inDomains:NSUserDomainMask].firstObject;
@@ -126,21 +127,25 @@ - (void)uploadImageToQNFilePath:(NSString *)filePath complete:(dispatch_block_t)
126127

127128
// kQNGlobalConfiguration.isDnsOpen = NO;
128129
// kQNGlobalConfiguration.connectCheckEnable = false;
129-
kQNGlobalConfiguration.dnsCacheMaxTTL = 600;
130-
kQNGlobalConfiguration.partialHostFrozenTime = 20*60;
130+
// kQNGlobalConfiguration.dnsCacheMaxTTL = 600;
131+
// kQNGlobalConfiguration.partialHostFrozenTime = 20*60;
131132
// kQNGlobalConfiguration.dns = self;
132133

133134
// [QNServerConfigMonitor removeConfigCache];
134135

136+
kQNGlobalConfiguration.udpDnsIpv4Servers = @[@"223.5.5.5", @"114.114.114.114"];
137+
kQNGlobalConfiguration.dohIpv4Servers = @[@"https://223.6.6.6/dns-query"];
138+
135139
NSString *key = [NSString stringWithFormat:@"iOS_Demo_%@", [NSDate date]];
136140
key = @"iOS-Test";
137141
self.token = YourToken;
138-
142+
143+
139144
QNConfiguration *configuration = [QNConfiguration build:^(QNConfigurationBuilder *builder) {
140145
builder.timeoutInterval = 90;
141146
builder.retryMax = 1;
142147
// builder.useHttps = NO;
143-
148+
144149
builder.useConcurrentResumeUpload = false;
145150
builder.concurrentTaskCount = 10;
146151
builder.resumeUploadVersion = QNResumeUploadVersionV2;

QiniuSDK.xcodeproj/project.pbxproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@
358358
4551E56724D0065100447285 /* NSData+QNMD5.h in Headers */ = {isa = PBXBuildFile; fileRef = 4551E56524D0065100447285 /* NSData+QNMD5.h */; };
359359
4551E56824D0065100447285 /* NSData+QNMD5.m in Sources */ = {isa = PBXBuildFile; fileRef = 4551E56624D0065100447285 /* NSData+QNMD5.m */; };
360360
4551E56924D0065100447285 /* NSData+QNMD5.m in Sources */ = {isa = PBXBuildFile; fileRef = 4551E56624D0065100447285 /* NSData+QNMD5.m */; };
361+
45E0B28A2A1F0596009B1BC7 /* QNConfigurationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45E0B2892A1F0596009B1BC7 /* QNConfigurationTest.m */; };
362+
45E0B28B2A1F0596009B1BC7 /* QNConfigurationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45E0B2892A1F0596009B1BC7 /* QNConfigurationTest.m */; };
361363
8D0FB78D364BAEE65E20A604 /* libPods-QiniuSDK_iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F881668982449FAF2384327E /* libPods-QiniuSDK_iOS.a */; };
362364
C275A64FFBE81B9CE7DDC79E /* libPods-QiniuSDK_iOSTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F32D114A1227199BEC6DF5C /* libPods-QiniuSDK_iOSTests.a */; };
363365
CC25135C244C7EB3003F4C65 /* QNBaseUpload.h in Headers */ = {isa = PBXBuildFile; fileRef = CC25135A244C7EB3003F4C65 /* QNBaseUpload.h */; };
@@ -594,6 +596,7 @@
594596
4551E55E24CE81DA00447285 /* QNInetAddress.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNInetAddress.m; sourceTree = "<group>"; };
595597
4551E56524D0065100447285 /* NSData+QNMD5.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSData+QNMD5.h"; sourceTree = "<group>"; };
596598
4551E56624D0065100447285 /* NSData+QNMD5.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSData+QNMD5.m"; sourceTree = "<group>"; };
599+
45E0B2892A1F0596009B1BC7 /* QNConfigurationTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNConfigurationTest.m; sourceTree = "<group>"; };
597600
466E7AACB5F77BA0D4DE4070 /* Pods-QiniuSDK_MacTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuSDK_MacTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuSDK_MacTests/Pods-QiniuSDK_MacTests.debug.xcconfig"; sourceTree = "<group>"; };
598601
5F32D114A1227199BEC6DF5C /* libPods-QiniuSDK_iOSTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuSDK_iOSTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
599602
6663602DA8CC701EA3B11F04 /* Pods-QiniuSDK_iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuSDK_iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuSDK_iOS/Pods-QiniuSDK_iOS.debug.xcconfig"; sourceTree = "<group>"; };
@@ -1053,13 +1056,15 @@
10531056
3142419B2449547B00BD9A21 /* QNCFHttpClientTest.m */,
10541057
31A1840D246942E0001D6EEE /* QNComplexUploadSceneTest.m */,
10551058
CCF661052355C2C00018A41E /* QNConcurrentResumeUploadTest.m */,
1059+
45E0B2892A1F0596009B1BC7 /* QNConfigurationTest.m */,
10561060
31A6980C26D62DDE00D84ABC /* QNConnctCheckTest.m */,
10571061
DF293C9619DB865800799011 /* QNCrc32Test.m */,
10581062
316A4B822431C8BA007BF564 /* QNDnsPrefetcherTest.m */,
10591063
DFA9B63E19DFD8C900A15FD1 /* QNEtagTest.m */,
10601064
DFFE0E5F19E6575600D7A0FC /* QNFileRecorderTest.m */,
10611065
DF3C504619DD7BA6000F548F /* QNFormUploadTest.m */,
10621066
31259E3524E3D32700CF7531 /* QNGZipTest.m */,
1067+
31C30FAB2852EA7900BFD8F7 /* QNNetworkStatusTest.m */,
10631068
CC251374244EE717003F4C65 /* QNPipelineTest.m */,
10641069
DF3C504919DD7D9F000F548F /* QNResumeUploadTest.m */,
10651070
31FD09232487506300217848 /* QNRetryTest.m */,
@@ -1083,7 +1088,6 @@
10831088
31C2EEEB242DEF6A00713A33 /* QNUtilTest.m */,
10841089
3149445D24470B9E00386F16 /* XCTestCase+QNTest.h */,
10851090
3149445E24470B9E00386F16 /* XCTestCase+QNTest.m */,
1086-
31C30FAB2852EA7900BFD8F7 /* QNNetworkStatusTest.m */,
10871091
);
10881092
path = QiniuSDKTests;
10891093
sourceTree = SOURCE_ROOT;
@@ -1639,6 +1643,7 @@
16391643
31304CBC256767F0001034D2 /* QNUploadServerFreezeManagerTest.m in Sources */,
16401644
DF293C9719DB865800799011 /* QNCrc32Test.m in Sources */,
16411645
31A1841124694A3C001D6EEE /* QNUploadErrorTest.m in Sources */,
1646+
45E0B28A2A1F0596009B1BC7 /* QNConfigurationTest.m in Sources */,
16421647
CCF661062355C2C00018A41E /* QNConcurrentResumeUploadTest.m in Sources */,
16431648
DFF525391A64079B00D02BA1 /* QNSessionTest.m in Sources */,
16441649
FDEA88661DAC10D000D037E5 /* QNAutoZoneTest.m in Sources */,
@@ -1763,6 +1768,7 @@
17631768
31304CBD256767F0001034D2 /* QNUploadServerFreezeManagerTest.m in Sources */,
17641769
DF0A032B1B3BAC6E00E3778C /* QNEtagTest.m in Sources */,
17651770
31A1841224694A3C001D6EEE /* QNUploadErrorTest.m in Sources */,
1771+
45E0B28B2A1F0596009B1BC7 /* QNConfigurationTest.m in Sources */,
17661772
CCF661072355C4480018A41E /* QNConcurrentResumeUploadTest.m in Sources */,
17671773
DF0A032D1B3BAC6E00E3778C /* QNFileRecorderTest.m in Sources */,
17681774
FDEA88671DAC10D000D037E5 /* QNAutoZoneTest.m in Sources */,

QiniuSDK/Http/ConnectCheck/QNConnectChecker.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ + (void)checkAllHosts:(void (^)(QNUploadSingleRequestMetrics *metrics))complete
7676
__block BOOL isCompleted = false;
7777
kQNWeakSelf;
7878
NSArray *allHosts = [kQNGlobalConfiguration.connectCheckURLStrings copy];
79+
if (allHosts.count == 0) {
80+
QNUploadSingleRequestMetrics *metrics = [QNUploadSingleRequestMetrics emptyMetrics];
81+
[metrics start];
82+
[metrics end];
83+
metrics.error = [NSError errorWithDomain:@"com.qiniu.NetworkCheck" code:NSURLErrorUnsupportedURL userInfo:@{@"user_info":@"check host is empty"}];
84+
complete(metrics);
85+
return;
86+
}
87+
7988
for (NSString *host in allHosts) {
8089
[self checkHost:host complete:^(QNUploadSingleRequestMetrics *metrics) {
8190
kQNStrongSelf;

QiniuSDK/Http/Dns/QNDnsCacheFile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
1818

1919
/// 构造方法 路径不存在,或进行创建,创建失败返回为nil
2020
/// @param directory 路径
21-
/// @param perror 构造错误时,会有值
21+
/// @param error 构造错误时,会有值
2222
+ (instancetype _Nullable)dnsCacheFile:(NSString *)directory
2323
error:(NSError **)error;
2424

QiniuSDK/Http/Dns/QNDnsPrefetch.m

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -392,17 +392,19 @@ - (NSString *)prefetchHostBySafeDns:(NSString *)host error:(NSError * __autorele
392392
return nil;
393393
}
394394

395-
QNDohResolver *dohResolver = [QNDohResolver resolverWithServers:kQNGlobalConfiguration.dohIpv4Servers recordType:kQNTypeA timeout:kQNGlobalConfiguration.dnsResolveTimeout];
396-
QNInternalDns *doh = [QNInternalDns dnsWithResolver:dohResolver];
397-
nextFetchHosts = [self preFetchHosts:nextFetchHosts dns:doh error:&err];
398-
if (nextFetchHosts.count == 0) {
399-
return [self getInetAddressByHost:host].firstObject.sourceValue;
400-
}
401-
if (error != nil && err) {
402-
*error = err;
395+
if (kQNGlobalConfiguration.dohIpv4Servers && [kQNGlobalConfiguration.dohIpv4Servers count] > 0) {
396+
QNDohResolver *dohResolver = [QNDohResolver resolverWithServers:kQNGlobalConfiguration.dohIpv4Servers recordType:kQNTypeA timeout:kQNGlobalConfiguration.dnsResolveTimeout];
397+
QNInternalDns *doh = [QNInternalDns dnsWithResolver:dohResolver];
398+
nextFetchHosts = [self preFetchHosts:nextFetchHosts dns:doh error:&err];
399+
if (nextFetchHosts.count == 0) {
400+
return [self getInetAddressByHost:host].firstObject.sourceValue;
401+
}
402+
if (error != nil && err) {
403+
*error = err;
404+
}
403405
}
404406

405-
if ([QNIP isIpV6FullySupported]) {
407+
if ([QNIP isIpV6FullySupported] && kQNGlobalConfiguration.dohIpv6Servers && [kQNGlobalConfiguration.dohIpv6Servers count] > 0) {
406408
QNDohResolver *dohResolver = [QNDohResolver resolverWithServers:kQNGlobalConfiguration.dohIpv6Servers recordType:kQNTypeA timeout:kQNGlobalConfiguration.dnsResolveTimeout];
407409
QNInternalDns *doh = [QNInternalDns dnsWithResolver:dohResolver];
408410
nextFetchHosts = [self preFetchHosts:nextFetchHosts dns:doh error:&err];
@@ -462,14 +464,16 @@ - (void)preFetchHosts:(NSArray <NSString *> *)fetchHosts error:(NSError **)error
462464

463465
// doh
464466
if (kQNGlobalConfiguration.dohEnable) {
465-
QNDohResolver *dohResolver = [QNDohResolver resolverWithServers:kQNGlobalConfiguration.dohIpv4Servers recordType:kQNTypeA timeout:kQNGlobalConfiguration.dnsResolveTimeout];
466-
QNInternalDns *doh = [QNInternalDns dnsWithResolver:dohResolver];
467-
nextFetchHosts = [self preFetchHosts:nextFetchHosts dns:doh error:error];
468-
if (nextFetchHosts.count == 0) {
469-
return;
467+
if (kQNGlobalConfiguration.dohIpv4Servers && [kQNGlobalConfiguration.dohIpv4Servers count] > 0) {
468+
QNDohResolver *dohResolver = [QNDohResolver resolverWithServers:kQNGlobalConfiguration.dohIpv4Servers recordType:kQNTypeA timeout:kQNGlobalConfiguration.dnsResolveTimeout];
469+
QNInternalDns *doh = [QNInternalDns dnsWithResolver:dohResolver];
470+
nextFetchHosts = [self preFetchHosts:nextFetchHosts dns:doh error:error];
471+
if (nextFetchHosts.count == 0) {
472+
return;
473+
}
470474
}
471475

472-
if ([QNIP isIpV6FullySupported]) {
476+
if ([QNIP isIpV6FullySupported] && kQNGlobalConfiguration.dohIpv6Servers && [kQNGlobalConfiguration.dohIpv6Servers count] > 0) {
473477
QNDohResolver *dohResolver = [QNDohResolver resolverWithServers:kQNGlobalConfiguration.dohIpv6Servers recordType:kQNTypeA timeout:kQNGlobalConfiguration.dnsResolveTimeout];
474478
QNInternalDns *doh = [QNInternalDns dnsWithResolver:dohResolver];
475479
nextFetchHosts = [self preFetchHosts:nextFetchHosts dns:doh error:error];
@@ -481,11 +485,13 @@ - (void)preFetchHosts:(NSArray <NSString *> *)fetchHosts error:(NSError **)error
481485

482486
// udp
483487
if (kQNGlobalConfiguration.udpDnsEnable) {
484-
QNDnsUdpResolver *udpDnsResolver = [QNDnsUdpResolver resolverWithServerIPs:kQNGlobalConfiguration.udpDnsIpv4Servers recordType:kQNTypeA timeout:kQNGlobalConfiguration.dnsResolveTimeout];
485-
QNInternalDns *udpDns = [QNInternalDns dnsWithResolver:udpDnsResolver];
486-
[self preFetchHosts:nextFetchHosts dns:udpDns error:error];
488+
if (kQNGlobalConfiguration.udpDnsIpv4Servers && [kQNGlobalConfiguration.udpDnsIpv4Servers count] > 0) {
489+
QNDnsUdpResolver *udpDnsResolver = [QNDnsUdpResolver resolverWithServerIPs:kQNGlobalConfiguration.udpDnsIpv4Servers recordType:kQNTypeA timeout:kQNGlobalConfiguration.dnsResolveTimeout];
490+
QNInternalDns *udpDns = [QNInternalDns dnsWithResolver:udpDnsResolver];
491+
[self preFetchHosts:nextFetchHosts dns:udpDns error:error];
492+
}
487493

488-
if ([QNIP isIpV6FullySupported]) {
494+
if ([QNIP isIpV6FullySupported] && kQNGlobalConfiguration.udpDnsIpv6Servers && [kQNGlobalConfiguration.udpDnsIpv6Servers count] > 0) {
489495
QNDnsUdpResolver *udpDnsResolver = [QNDnsUdpResolver resolverWithServerIPs:kQNGlobalConfiguration.udpDnsIpv6Servers recordType:kQNTypeA timeout:kQNGlobalConfiguration.dnsResolveTimeout];
490496
QNInternalDns *udpDns = [QNInternalDns dnsWithResolver:udpDnsResolver];
491497
[self preFetchHosts:nextFetchHosts dns:udpDns error:error];

QiniuSDK/Http/Request/QNHttpSingleRequest.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ - (void)retryRequest:(NSURLRequest *)request
182182
}
183183

184184
- (BOOL)shouldCheckConnect:(QNResponseInfo *)responseInfo {
185-
if (!kQNGlobalConfiguration.connectCheckEnable) {
185+
if (!kQNGlobalConfiguration.connectCheckEnable || [kQNGlobalConfiguration.connectCheckURLStrings count] == 0) {
186186
return NO;
187187
}
188188

0 commit comments

Comments
 (0)