Skip to content

Commit 6337936

Browse files
authored
Dns adaptive upload (#69)
* record add source property & dns manager add query error handler * update version info
1 parent 335d89b commit 6337936

File tree

10 files changed

+39
-10
lines changed

10 files changed

+39
-10
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
#Changelog
2+
## 0.3.17 (2020-07-03)
3+
4+
### 修改
5+
* qiniu record增加source, dns manager增加query error handler
6+
7+
## 0.3.16 (2020-05-07)
8+
9+
### 修改
10+
* qiniu http dns 增加额外query接口
211

312
## 0.3.15 (2019-02-12)
413

HappyDNS.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'HappyDNS'
3-
s.version = '0.3.16'
3+
s.version = '0.3.17'
44
s.summary = 'DNS library for iOS and Mac'
55
s.homepage = 'https://github.com/qiniu/happy-dns-objc'
66
s.social_media_url = 'http://weibo.com/qiniutek'

HappyDNS/Common/QNDnsManager.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ typedef void (^QNIpStatusCallback)(NSString *ip, int code, int ms);
5050
@interface QNDnsManager : NSObject
5151

5252
/// 默认ttl值 单位:秒
53-
@property(nonatomic, assign)int defalutTtl;
53+
@property(nonatomic, assign)int defaultTtl;
54+
55+
/// 查询失败时抛出错误信息回调
56+
@property(nonatomic, copy)void(^ queryErrorHandler)(NSError *error, NSString *host);
5457

5558
/**
5659
* 解析域名

HappyDNS/Common/QNDnsManager.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ - (NSArray *)queryInternalWithDomain:(QNDomain *)domain needRecordInfo:(BOOL)nee
135135
if (needRecordInfo) {
136136
NSMutableArray *retP = [NSMutableArray array];
137137
for (NSString *host in ret) {
138-
QNRecord *record = [[QNRecord alloc] init:host ttl:self.defalutTtl type:kQNTypeA];
138+
QNRecord *record = [[QNRecord alloc] init:host ttl:self.defaultTtl type:kQNTypeA source:QNRecordSourceUnknown];
139139
[retP addObject:record];
140140
}
141141
return [retP copy];
@@ -189,6 +189,10 @@ - (NSArray *)queryInternalWithDomain:(QNDomain *)domain needRecordInfo:(BOOL)nee
189189
if (tmp.code == kQNDomainNotOwnCode) {
190190
continue;
191191
}
192+
193+
if (self.queryErrorHandler) {
194+
self.queryErrorHandler(error, domain.domain);
195+
}
192196
}
193197

194198
if (records == nil || records.count == 0) {
@@ -215,7 +219,7 @@ - (NSArray *)queryInternalWithDomain:(QNDomain *)domain needRecordInfo:(BOOL)nee
215219
if (needRecordInfo) {
216220
NSMutableArray *retP = [NSMutableArray array];
217221
for (NSString *host in ret) {
218-
QNRecord *record = [[QNRecord alloc] init:host ttl:self.defalutTtl type:kQNTypeA];
222+
QNRecord *record = [[QNRecord alloc] init:host ttl:self.defaultTtl type:kQNTypeA source:QNRecordSourceUnknown];
219223
[retP addObject:record];
220224
}
221225
return [retP copy];

HappyDNS/Common/QNRecord.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,26 @@ extern const int kQNTypeCname;
2828
*/
2929
extern const int kQNTypeTXT;
3030

31+
typedef NS_ENUM(NSUInteger, QNRecordSource) {
32+
QNRecordSourceUnknown,
33+
QNRecordSourceDnspodFree,
34+
QNRecordSourceDnspodEnterprise,
35+
QNRecordSourceSystem,
36+
};
37+
3138
@interface QNRecord : NSObject
39+
3240
@property (nonatomic, strong, readonly) NSString *value;
3341
@property (nonatomic, readonly) int ttl;
3442
@property (nonatomic, readonly) int type;
3543
@property (nonatomic, readonly) long long timeStamp;
44+
@property (nonatomic, readonly) QNRecordSource source;
3645

3746
- (instancetype)init:(NSString *)value
3847
ttl:(int)ttl
39-
type:(int)type;
48+
type:(int)type
49+
source:(QNRecordSource)source;
4050

4151
- (BOOL)expired:(long long)time;
52+
4253
@end

HappyDNS/Common/QNRecord.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
@implementation QNRecord
1717
- (instancetype)init:(NSString *)value
1818
ttl:(int)ttl
19-
type:(int)type {
19+
type:(int)type
20+
source:(QNRecordSource)source {
2021
if (self = [super init]) {
2122
_value = value;
2223
_type = type;
2324
_ttl = ttl;
25+
_source = source;
2426
_timeStamp = [[NSDate date] timeIntervalSince1970];
2527
}
2628
return self;

HappyDNS/Http/QNDnspodEnterprise.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ - (NSArray *)query:(QNDomain *)domain networkInfo:(QNNetworkInfo *)netInfo error
120120
NSArray *ipArray = [ips componentsSeparatedByString:@";"];
121121
NSMutableArray *ret = [[NSMutableArray alloc] initWithCapacity:ipArray.count];
122122
for (int i = 0; i < ipArray.count; i++) {
123-
QNRecord *record = [[QNRecord alloc] init:[ipArray objectAtIndex:i] ttl:ttl type:kQNTypeA];
123+
QNRecord *record = [[QNRecord alloc] init:[ipArray objectAtIndex:i] ttl:ttl type:kQNTypeA source:QNRecordSourceDnspodEnterprise];
124124
[ret addObject:record];
125125
}
126126
return ret;

HappyDNS/Http/QNDnspodFree.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ - (NSArray *)query:(QNDomain *)domain networkInfo:(QNNetworkInfo *)netInfo error
6666
NSArray *ipArray = [ips componentsSeparatedByString:@";"];
6767
NSMutableArray *ret = [[NSMutableArray alloc] initWithCapacity:ipArray.count];
6868
for (int i = 0; i < ipArray.count; i++) {
69-
QNRecord *record = [[QNRecord alloc] init:[ipArray objectAtIndex:i] ttl:ttl type:kQNTypeA];
69+
QNRecord *record = [[QNRecord alloc] init:[ipArray objectAtIndex:i] ttl:ttl type:kQNTypeA source:QNRecordSourceDnspodFree];
7070
[ret addObject:record];
7171
}
7272
return ret;

HappyDNS/Local/QNResolver.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ @interface QNResolver ()
7171
} else {
7272
continue;
7373
}
74-
QNRecord *record = [[QNRecord alloc] init:val ttl:ttl type:t];
74+
QNRecord *record = [[QNRecord alloc] init:val ttl:ttl type:t source:QNRecordSourceSystem];
7575
[array addObject:record];
7676
}
7777
res_ndestroy(res);

HappyDNS/Local/QNTxtResolver.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ @interface QNTxtResolver ()
6767
NSArray *ipArray = [val componentsSeparatedByString:@","];
6868
NSMutableArray *ret = [[NSMutableArray alloc] initWithCapacity:ipArray.count];
6969
for (int i = 0; i < ipArray.count; i++) {
70-
QNRecord *record = [[QNRecord alloc] init:[ipArray objectAtIndex:i] ttl:ttl type:kQNTypeA];
70+
QNRecord *record = [[QNRecord alloc] init:[ipArray objectAtIndex:i] ttl:ttl type:kQNTypeA source:QNRecordSourceSystem];
7171
[ret addObject:record];
7272
}
7373

0 commit comments

Comments
 (0)