Skip to content

Commit

Permalink
Dns adaptive upload (#69)
Browse files Browse the repository at this point in the history
* record add source property  &  dns manager add query error handler

* update version info
  • Loading branch information
YangSen-qn authored Jul 7, 2020
1 parent 335d89b commit 6337936
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 10 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
#Changelog
## 0.3.17 (2020-07-03)

### 修改
* qiniu record增加source, dns manager增加query error handler

## 0.3.16 (2020-05-07)

### 修改
* qiniu http dns 增加额外query接口

## 0.3.15 (2019-02-12)

Expand Down
2 changes: 1 addition & 1 deletion HappyDNS.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'HappyDNS'
s.version = '0.3.16'
s.version = '0.3.17'
s.summary = 'DNS library for iOS and Mac'
s.homepage = 'https://github.com/qiniu/happy-dns-objc'
s.social_media_url = 'http://weibo.com/qiniutek'
Expand Down
5 changes: 4 additions & 1 deletion HappyDNS/Common/QNDnsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ typedef void (^QNIpStatusCallback)(NSString *ip, int code, int ms);
@interface QNDnsManager : NSObject

/// 默认ttl值 单位:秒
@property(nonatomic, assign)int defalutTtl;
@property(nonatomic, assign)int defaultTtl;

/// 查询失败时抛出错误信息回调
@property(nonatomic, copy)void(^ queryErrorHandler)(NSError *error, NSString *host);

/**
* 解析域名
Expand Down
8 changes: 6 additions & 2 deletions HappyDNS/Common/QNDnsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ - (NSArray *)queryInternalWithDomain:(QNDomain *)domain needRecordInfo:(BOOL)nee
if (needRecordInfo) {
NSMutableArray *retP = [NSMutableArray array];
for (NSString *host in ret) {
QNRecord *record = [[QNRecord alloc] init:host ttl:self.defalutTtl type:kQNTypeA];
QNRecord *record = [[QNRecord alloc] init:host ttl:self.defaultTtl type:kQNTypeA source:QNRecordSourceUnknown];
[retP addObject:record];
}
return [retP copy];
Expand Down Expand Up @@ -189,6 +189,10 @@ - (NSArray *)queryInternalWithDomain:(QNDomain *)domain needRecordInfo:(BOOL)nee
if (tmp.code == kQNDomainNotOwnCode) {
continue;
}

if (self.queryErrorHandler) {
self.queryErrorHandler(error, domain.domain);
}
}

if (records == nil || records.count == 0) {
Expand All @@ -215,7 +219,7 @@ - (NSArray *)queryInternalWithDomain:(QNDomain *)domain needRecordInfo:(BOOL)nee
if (needRecordInfo) {
NSMutableArray *retP = [NSMutableArray array];
for (NSString *host in ret) {
QNRecord *record = [[QNRecord alloc] init:host ttl:self.defalutTtl type:kQNTypeA];
QNRecord *record = [[QNRecord alloc] init:host ttl:self.defaultTtl type:kQNTypeA source:QNRecordSourceUnknown];
[retP addObject:record];
}
return [retP copy];
Expand Down
13 changes: 12 additions & 1 deletion HappyDNS/Common/QNRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,26 @@ extern const int kQNTypeCname;
*/
extern const int kQNTypeTXT;

typedef NS_ENUM(NSUInteger, QNRecordSource) {
QNRecordSourceUnknown,
QNRecordSourceDnspodFree,
QNRecordSourceDnspodEnterprise,
QNRecordSourceSystem,
};

@interface QNRecord : NSObject

@property (nonatomic, strong, readonly) NSString *value;
@property (nonatomic, readonly) int ttl;
@property (nonatomic, readonly) int type;
@property (nonatomic, readonly) long long timeStamp;
@property (nonatomic, readonly) QNRecordSource source;

- (instancetype)init:(NSString *)value
ttl:(int)ttl
type:(int)type;
type:(int)type
source:(QNRecordSource)source;

- (BOOL)expired:(long long)time;

@end
4 changes: 3 additions & 1 deletion HappyDNS/Common/QNRecord.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
@implementation QNRecord
- (instancetype)init:(NSString *)value
ttl:(int)ttl
type:(int)type {
type:(int)type
source:(QNRecordSource)source {
if (self = [super init]) {
_value = value;
_type = type;
_ttl = ttl;
_source = source;
_timeStamp = [[NSDate date] timeIntervalSince1970];
}
return self;
Expand Down
2 changes: 1 addition & 1 deletion HappyDNS/Http/QNDnspodEnterprise.m
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ - (NSArray *)query:(QNDomain *)domain networkInfo:(QNNetworkInfo *)netInfo error
NSArray *ipArray = [ips componentsSeparatedByString:@";"];
NSMutableArray *ret = [[NSMutableArray alloc] initWithCapacity:ipArray.count];
for (int i = 0; i < ipArray.count; i++) {
QNRecord *record = [[QNRecord alloc] init:[ipArray objectAtIndex:i] ttl:ttl type:kQNTypeA];
QNRecord *record = [[QNRecord alloc] init:[ipArray objectAtIndex:i] ttl:ttl type:kQNTypeA source:QNRecordSourceDnspodEnterprise];
[ret addObject:record];
}
return ret;
Expand Down
2 changes: 1 addition & 1 deletion HappyDNS/Http/QNDnspodFree.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ - (NSArray *)query:(QNDomain *)domain networkInfo:(QNNetworkInfo *)netInfo error
NSArray *ipArray = [ips componentsSeparatedByString:@";"];
NSMutableArray *ret = [[NSMutableArray alloc] initWithCapacity:ipArray.count];
for (int i = 0; i < ipArray.count; i++) {
QNRecord *record = [[QNRecord alloc] init:[ipArray objectAtIndex:i] ttl:ttl type:kQNTypeA];
QNRecord *record = [[QNRecord alloc] init:[ipArray objectAtIndex:i] ttl:ttl type:kQNTypeA source:QNRecordSourceDnspodFree];
[ret addObject:record];
}
return ret;
Expand Down
2 changes: 1 addition & 1 deletion HappyDNS/Local/QNResolver.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ @interface QNResolver ()
} else {
continue;
}
QNRecord *record = [[QNRecord alloc] init:val ttl:ttl type:t];
QNRecord *record = [[QNRecord alloc] init:val ttl:ttl type:t source:QNRecordSourceSystem];
[array addObject:record];
}
res_ndestroy(res);
Expand Down
2 changes: 1 addition & 1 deletion HappyDNS/Local/QNTxtResolver.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ @interface QNTxtResolver ()
NSArray *ipArray = [val componentsSeparatedByString:@","];
NSMutableArray *ret = [[NSMutableArray alloc] initWithCapacity:ipArray.count];
for (int i = 0; i < ipArray.count; i++) {
QNRecord *record = [[QNRecord alloc] init:[ipArray objectAtIndex:i] ttl:ttl type:kQNTypeA];
QNRecord *record = [[QNRecord alloc] init:[ipArray objectAtIndex:i] ttl:ttl type:kQNTypeA source:QNRecordSourceSystem];
[ret addObject:record];
}

Expand Down

0 comments on commit 6337936

Please sign in to comment.