From 561ac8702fb02f51a7960b30c9f702a75ee227ce Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Thu, 11 Aug 2022 19:33:06 +0800 Subject: [PATCH 01/10] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E8=BF=94=E5=9B=9ETTL=E8=BF=87=E6=9C=9F=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns/CacheManager/MSDKDnsParamsManager.h | 2 ++ MSDKDns/CacheManager/MSDKDnsParamsManager.m | 10 ++++++++++ MSDKDns/MSDKDns.h | 5 +++++ MSDKDns/MSDKDns.m | 4 ++++ 4 files changed, 21 insertions(+) diff --git a/MSDKDns/CacheManager/MSDKDnsParamsManager.h b/MSDKDns/CacheManager/MSDKDnsParamsManager.h index 873b916..c975b97 100644 --- a/MSDKDns/CacheManager/MSDKDnsParamsManager.h +++ b/MSDKDns/CacheManager/MSDKDnsParamsManager.h @@ -30,6 +30,7 @@ - (void)msdkDnsSetKeepAliveDomains: (NSArray *)domains; - (void)msdkDnsSetIPRankData: (NSDictionary *)IPRankData; - (void)msdkDnsSetEnableKeepDomainsAlive: (BOOL)enableKeepDomainsAlive; +- (void)msdkDnsSetExpiredIPEnabled: (BOOL)enable; - (NSString *) msdkDnsGetMDnsIp; - (NSString *) msdkDnsGetMOpenId; @@ -50,4 +51,5 @@ - (NSArray *)msdkDnsGetKeepAliveDomains; - (NSDictionary *)msdkDnsGetIPRankData; - (BOOL)msdkDnsGetEnableKeepDomainsAlive; +- (BOOL)msdkDnsGetExpiredIPEnabled; @end diff --git a/MSDKDns/CacheManager/MSDKDnsParamsManager.m b/MSDKDns/CacheManager/MSDKDnsParamsManager.m index 47c42b9..0c89971 100644 --- a/MSDKDns/CacheManager/MSDKDnsParamsManager.m +++ b/MSDKDns/CacheManager/MSDKDnsParamsManager.m @@ -35,6 +35,7 @@ @interface MSDKDnsParamsManager() @property (strong, nonatomic, readwrite) NSArray* keepAliveDomains; @property (strong, nonatomic, readwrite) NSDictionary* IPRankData; @property (assign, nonatomic, readwrite) BOOL enableKeepDomainsAlive; +@property (assign, nonatomic, readwrite) BOOL expiredIPEnabled; @end @@ -59,6 +60,7 @@ - (id) init { _enableReport = NO; _msdkAddressType = HttpDnsAddressTypeAuto; _enableKeepDomainsAlive = YES; + _expiredIPEnabled = NO; } return self; } @@ -179,6 +181,11 @@ - (void)msdkDnsSetEnableKeepDomainsAlive: (BOOL)enableKeepDomainsAlive { }); } +- (void)msdkDnsSetExpiredIPEnabled: (BOOL)enable { + dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ + self.expiredIPEnabled = enable; + }); +} #pragma mark - getter @@ -265,5 +272,8 @@ - (BOOL)msdkDnsGetEnableKeepDomainsAlive { return _enableKeepDomainsAlive; } +- (BOOL)msdkDnsGetExpiredIPEnabled { + return _expiredIPEnabled; +} @end diff --git a/MSDKDns/MSDKDns.h b/MSDKDns/MSDKDns.h index 02fe72d..66ea87f 100644 --- a/MSDKDns/MSDKDns.h +++ b/MSDKDns/MSDKDns.h @@ -94,6 +94,11 @@ typedef struct DnsConfigStruct { */ - (void) WGSetEnableKeepDomainsAlive: (BOOL)enableKeepDomainsAlive; +/** + * 设置允许返回TTL过期域名的IP,默认关闭 + */ +- (void) WGSetExpiredIPEnabled:(BOOL)enable; + #pragma mark - 域名解析接口,按需调用 /** 域名同步解析(通用接口) diff --git a/MSDKDns/MSDKDns.m b/MSDKDns/MSDKDns.m index e73c0d8..4a5abf0 100644 --- a/MSDKDns/MSDKDns.m +++ b/MSDKDns/MSDKDns.m @@ -128,6 +128,10 @@ - (void) WGSetNoHijackDomainArray:(NSArray *)noHijackDomainArray { } } +- (void) WGSetExpiredIPEnabled:(BOOL)enable { + [[MSDKDnsParamsManager shareInstance] msdkDnsSetExpiredIPEnabled:enable]; +} + #pragma mark - get host by name - (NSArray *) WGGetHostByName:(NSString *)domain { From b35cd36809d53c784859c4aabf227c1a454e033f Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Thu, 18 Aug 2022 15:21:54 +0800 Subject: [PATCH 02/10] =?UTF-8?q?feat:=E6=8F=90=E9=AB=98=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E5=91=BD=E4=B8=AD=E7=8E=87=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns/CacheManager/MSDKDnsManager.h | 1 + MSDKDns/CacheManager/MSDKDnsManager.m | 161 +++++++++++++++++++ MSDKDns/CacheManager/MSDKDnsNetworkManager.m | 18 ++- MSDKDns/CacheManager/MSDKDnsParamsManager.m | 3 + MSDKDns/MSDKDns.h | 24 +++ MSDKDns/MSDKDns.m | 86 ++++++++++ MSDKDns/MSDKDnsPrivate.h | 5 + 7 files changed, 292 insertions(+), 6 deletions(-) diff --git a/MSDKDns/CacheManager/MSDKDnsManager.h b/MSDKDns/CacheManager/MSDKDnsManager.h index 1846906..a64427e 100644 --- a/MSDKDns/CacheManager/MSDKDnsManager.h +++ b/MSDKDns/CacheManager/MSDKDnsManager.h @@ -26,6 +26,7 @@ - (void)getHostsByNames:(NSArray *)domains verbose:(BOOL)verbose returnIps:(void (^)(NSDictionary * ipsDict))handler; - (NSDictionary *)getHostsByNames:(NSArray *)domains verbose:(BOOL)verbose; +- (NSDictionary *)getHostsByNamesEnableExpired:(NSArray *)domains verbose:(BOOL)verbose; - (void)refreshCacheDelay:(NSArray *)domains clearDispatchTag:(BOOL)needClear; - (void)preResolveDomains; - (void)dnsHasDone:(MSDKDnsService *)service; diff --git a/MSDKDns/CacheManager/MSDKDnsManager.m b/MSDKDns/CacheManager/MSDKDnsManager.m index 251a310..5bd282a 100644 --- a/MSDKDns/CacheManager/MSDKDnsManager.m +++ b/MSDKDns/CacheManager/MSDKDnsManager.m @@ -135,6 +135,67 @@ - (NSDictionary *)getHostsByNames:(NSArray *)domains verbose:(BOOL)verbose { return result; } +// +- (NSDictionary *)getHostsByNamesEnableExpired:(NSArray *)domains verbose:(BOOL)verbose { + // 获取当前ipv4/ipv6/双栈网络环境 + msdkdns::MSDKDNS_TLocalIPStack netStack = [self detectAddressType]; + __block float timeOut = 2.0; + __block NSDictionary * cacheDomainDict = nil; + dispatch_sync([MSDKDnsInfoTool msdkdns_queue], ^{ + if (domains && [domains count] > 0 && _domainDict) { + cacheDomainDict = [[NSDictionary alloc] initWithDictionary:_domainDict]; + } + timeOut = [[MSDKDnsParamsManager shareInstance] msdkDnsGetMTimeOut]; + }); + // 待查询数组 + NSMutableArray *toCheckDomains = [NSMutableArray array]; + // 需要排除结果的域名数组 + NSMutableArray *toEmptyDomains = [NSMutableArray array]; + // 查找缓存,不存在或者ttl超时则放入待查询数组,ttl超时还放入排除结果的数组以便如果禁用返回ttl过期的解析结果则进行排除结果 + for (int i = 0; i < [domains count]; i++) { + NSString *domain = [domains objectAtIndex:i]; + if ([[self domianCache:cacheDomainDict check:domain] isEqualToString:MSDKDnsDomainCacheEmpty]) { + [toCheckDomains addObject:domain]; + } else if ([[self domianCache:cacheDomainDict check:domain] isEqualToString:MSDKDnsDomainCacheExpired]) { + [toCheckDomains addObject:domain]; + [toEmptyDomains addObject:domain]; + } else { + MSDKDNSLOG(@"%@ TTL has not expiried,return result from cache directly!", domain); + dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ + [self uploadReport:YES Domain:domain NetStack:netStack]; + }); + } + } + // 当待查询数组中存在数据的时候,就开启异步线程执行解析操作,并且更新缓存 + if (toCheckDomains && [toCheckDomains count] != 0) { + dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ + if (!_serviceArray) { + self.serviceArray = [[NSMutableArray alloc] init]; + } + int dnsId = [[MSDKDnsParamsManager shareInstance] msdkDnsGetMDnsId]; + NSString * dnsKey = [[MSDKDnsParamsManager shareInstance] msdkDnsGetMDnsKey]; + HttpDnsEncryptType encryptType = [[MSDKDnsParamsManager shareInstance] msdkDnsGetEncryptType]; + MSDKDnsService * dnsService = [[MSDKDnsService alloc] init]; + [self.serviceArray addObject:dnsService]; + __weak __typeof__(self) weakSelf = self; + //进行httpdns请求 + [dnsService getHostsByNames:toCheckDomains TimeOut:timeOut DnsId:dnsId DnsKey:dnsKey NetStack:netStack encryptType:encryptType returnIps:^() { + __strong __typeof(self) strongSelf = weakSelf; + if (strongSelf) { + [toCheckDomains enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + [strongSelf uploadReport:NO Domain:obj NetStack:netStack]; + }]; + [strongSelf dnsHasDone:dnsService]; + } + }]; + }); + } + NSDictionary * result = verbose? + [self fullResultDictionaryEnableExpired:domains fromCache:cacheDomainDict toEmpty:toEmptyDomains] : + [self resultDictionaryEnableExpired:domains fromCache:cacheDomainDict toEmpty:toEmptyDomains]; + return result; +} + #pragma mark async - (void)getHostsByNames:(NSArray *)domains @@ -345,6 +406,83 @@ - (NSDictionary *)fullResultDictionary: (NSArray *)domains fromCache:(NSDictiona return resultDict; } +- (NSDictionary *)resultDictionaryEnableExpired: (NSArray *)domains fromCache:(NSDictionary *)domainDict toEmpty:(NSArray *)emptyDomains { + NSMutableDictionary *resultDict = [NSMutableDictionary dictionary]; + BOOL expiredIPEnabled = [[MSDKDnsParamsManager shareInstance] msdkDnsGetExpiredIPEnabled]; + for (int i = 0; i < [domains count]; i++) { + NSString *domain = [domains objectAtIndex:i]; + NSArray *arr = [self resultArray:domain fromCache:domainDict]; + BOOL domainNeedEmpty = [emptyDomains containsObject:domain]; + // 缓存过期,并且没有开启使用过期缓存 + if (domainNeedEmpty && !expiredIPEnabled) { + [resultDict setObject:@[@0,@0] forKey:domain]; + } else { + [resultDict setObject:arr forKey:domain]; + } + } + return resultDict; +} + +- (NSDictionary *)fullResultDictionaryEnableExpired: (NSArray *)domains fromCache:(NSDictionary *)domainDict toEmpty:(NSArray *)emptyDomains { + NSMutableDictionary *resultDict = [NSMutableDictionary dictionary]; + BOOL expiredIPEnabled = [[MSDKDnsParamsManager shareInstance] msdkDnsGetExpiredIPEnabled]; + for (int i = 0; i < [domains count]; i++) { + NSString *domain = [domains objectAtIndex:i]; + BOOL domainNeedEmpty = [emptyDomains containsObject:domain]; + NSMutableDictionary * ipResult = [NSMutableDictionary dictionary]; + BOOL httpOnly = [[MSDKDnsParamsManager shareInstance] msdkDnsGetHttpOnly]; + if (domainDict) { + NSDictionary * cacheDict = domainDict[domain]; + if (cacheDict && [cacheDict isKindOfClass:[NSDictionary class]]) { + + NSDictionary * hresultDict_A = cacheDict[kMSDKHttpDnsCache_A]; + NSDictionary * hresultDict_4A = cacheDict[kMSDKHttpDnsCache_4A]; + + if (!httpOnly) { + NSDictionary * lresultDict = cacheDict[kMSDKLocalDnsCache]; + if (lresultDict && [lresultDict isKindOfClass:[NSDictionary class]]) { + NSArray *ipsArray = [lresultDict[kIP] mutableCopy]; + if (ipsArray.count == 2) { + // 缓存过期,并且没有开启使用过期缓存 + if (domainNeedEmpty && !expiredIPEnabled) { + [ipResult setObject:@[@0] forKey:@"ipv4"]; + [ipResult setObject:@[@0] forKey:@"ipv6"]; + } else { + [ipResult setObject:@[ipsArray[0]] forKey:@"ipv4"]; + [ipResult setObject:@[ipsArray[1]] forKey:@"ipv6"]; + } + } + } + } + if (hresultDict_A && [hresultDict_A isKindOfClass:[NSDictionary class]]) { + NSArray * ipsArray = hresultDict_A[kIP]; + if (ipsArray && [ipsArray isKindOfClass:[NSArray class]] && ipsArray.count > 0) { + // 缓存过期,并且没有开启使用过期缓存 + if (domainNeedEmpty && !expiredIPEnabled) { + [ipResult setObject:@[@0] forKey:@"ipv4"]; + } else { + [ipResult setObject:ipsArray forKey:@"ipv4"]; + } + } + } + if (hresultDict_4A && [hresultDict_4A isKindOfClass:[NSDictionary class]]) { + NSArray * ipsArray = hresultDict_4A[kIP]; + if (ipsArray && [ipsArray isKindOfClass:[NSArray class]] && ipsArray.count > 0) { + // 缓存过期,并且没有开启使用过期缓存 + if (domainNeedEmpty && !expiredIPEnabled) { + [ipResult setObject:@[@0] forKey:@"ipv6"]; + } else { + [ipResult setObject:ipsArray forKey:@"ipv6"]; + } + } + } + } + } + [resultDict setObject:ipResult forKey:domain]; + } + return resultDict; +} + - (void)dnsHasDone:(MSDKDnsService *)service { NSArray * tmpArray = [NSArray arrayWithArray:self.serviceArray]; NSMutableArray * tmp = [[NSMutableArray alloc] init]; @@ -685,6 +823,29 @@ - (BOOL) domianCache:(NSDictionary *)cache hit:(NSString *)domain { } return NO; } + +# pragma mark - check caches +// 检查缓存状态 +- (NSString *) domianCache:(NSDictionary *)cache check:(NSString *)domain { + NSDictionary * domainInfo = cache[domain]; + if (domainInfo && [domainInfo isKindOfClass:[NSDictionary class]]) { + NSDictionary * cacheDict = domainInfo[kMSDKHttpDnsCache_A]; + if (!cacheDict || ![cacheDict isKindOfClass:[NSDictionary class]]) { + cacheDict = domainInfo[kMSDKHttpDnsCache_4A]; + } + if (cacheDict && [cacheDict isKindOfClass:[NSDictionary class]]) { + NSString * ttlExpried = cacheDict[kTTLExpired]; + double timeInterval = [[NSDate date] timeIntervalSince1970]; + if (timeInterval <= ttlExpried.doubleValue) { + return MSDKDnsDomainCacheHit; + } else { + return MSDKDnsDomainCacheExpired; + } + } + } + return MSDKDnsDomainCacheEmpty; +} + # pragma mark - detect address type - (msdkdns::MSDKDNS_TLocalIPStack)detectAddressType { msdkdns::MSDKDNS_TLocalIPStack netStack = msdkdns::MSDKDNS_ELocalIPStack_None; diff --git a/MSDKDns/CacheManager/MSDKDnsNetworkManager.m b/MSDKDns/CacheManager/MSDKDnsNetworkManager.m index 24d2693..39ff4a2 100644 --- a/MSDKDns/CacheManager/MSDKDnsNetworkManager.m +++ b/MSDKDns/CacheManager/MSDKDnsNetworkManager.m @@ -69,9 +69,12 @@ - (instancetype)init queue:nil usingBlock:^(NSNotification *note) { - MSDKDNSLOG(@"Network did changed,clear MSDKDns cache"); - //网络状态发生变化时清除缓存 - [[MSDKDnsManager shareInstance] clearAllCache]; + BOOL expiredIPEnabled = [[MSDKDnsParamsManager shareInstance] msdkDnsGetExpiredIPEnabled]; + if (!expiredIPEnabled) { + MSDKDNSLOG(@"Network did changed,clear MSDKDns cache"); + //网络状态发生变化时清除缓存 + [[MSDKDnsManager shareInstance] clearAllCache]; + } //对保活域名发送解析请求 [self getHostsByKeepAliveDomains]; //重置ip指针 @@ -83,9 +86,12 @@ - (instancetype)init queue:nil usingBlock:^(NSNotification *note) { - MSDKDNSLOG(@"Application did enter background,clear MSDKDns cache"); - //进入后台时清除缓存,暂停网络监测 - [[MSDKDnsManager shareInstance] clearAllCache]; + BOOL expiredIPEnabled = [[MSDKDnsParamsManager shareInstance] msdkDnsGetExpiredIPEnabled]; + if (!expiredIPEnabled) { + MSDKDNSLOG(@"Application did enter background,clear MSDKDns cache"); + //进入后台时清除缓存,暂停网络监测 + [[MSDKDnsManager shareInstance] clearAllCache]; + } [self.reachability stopNotifier]; }]; diff --git a/MSDKDns/CacheManager/MSDKDnsParamsManager.m b/MSDKDns/CacheManager/MSDKDnsParamsManager.m index 0c89971..663cd59 100644 --- a/MSDKDns/CacheManager/MSDKDnsParamsManager.m +++ b/MSDKDns/CacheManager/MSDKDnsParamsManager.m @@ -182,6 +182,9 @@ - (void)msdkDnsSetEnableKeepDomainsAlive: (BOOL)enableKeepDomainsAlive { } - (void)msdkDnsSetExpiredIPEnabled: (BOOL)enable { + if (_expiredIPEnabled == enable) { + return; + } dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ self.expiredIPEnabled = enable; }); diff --git a/MSDKDns/MSDKDns.h b/MSDKDns/MSDKDns.h index fcc4101..2290c59 100644 --- a/MSDKDns/MSDKDns.h +++ b/MSDKDns/MSDKDns.h @@ -151,6 +151,30 @@ typedef struct DnsConfigStruct { */ - (void)WGGetAllHostsByNamesAsync:(NSArray *)domains returnIps:(void (^)(NSDictionary * ipsDictionary))handler; +/** + 域名解析乐观DNS(通用接口) + + @param domain 域名 + @param handler 返回缓存中查询到的IP数组,若不存在会返回[0,0]并且进行异步域名解析更新缓存 + */ +- (NSArray *) WGGetHostByNameEnableExpired:(NSString *)domain; + +/** + 域名解析乐观DNS(通用接口) + + @param domains 域名数组 + @param handler 返回缓存中查询到的IP数组,若不存在会返回[0,0]并且进行异步域名解析更新缓存 + */ +- (NSDictionary *) WGGetHostsByNamesEnableExpired:(NSArray *)domains; + +/** + 域名解析乐观DNS(通用接口) + + @param domains 域名数组 + @param handler 返回缓存中查询到的IP数组,若不存在会返回[0,0]并且进行异步域名解析更新缓存 + */ +- (NSDictionary *) WGGetAllHostsByNamesEnableExpired:(NSArray *)domains; + #pragma mark - SNI场景,仅调用一次即可,请勿多次调用 /** SNI场景下设置需要拦截的域名列表 diff --git a/MSDKDns/MSDKDns.m b/MSDKDns/MSDKDns.m index 4a5abf0..5504be6 100644 --- a/MSDKDns/MSDKDns.m +++ b/MSDKDns/MSDKDns.m @@ -344,6 +344,92 @@ - (void)WGGetAllHostsByNamesAsync:(NSArray *)domains returnIps:(void (^)(NSDicti } } +- (NSArray *) WGGetHostByNameEnableExpired:(NSString *)domain { + @synchronized(self) { + NSArray * dnsResult = @[@"0", @"0"]; + MSDKDNSLOG(@"GetHostByNameEnableExpired:%@",domain); + if (!domain || domain.length == 0) { + //请求域名为空,返回空 + MSDKDNSLOG(@"MSDKDns Result is Empty!"); + return dnsResult; + } + [[MSDKDnsParamsManager shareInstance] msdkDnsSetExpiredIPEnabled:YES]; + // 转换成小写 + domain = [domain lowercaseString]; + NSDate * date = [NSDate date]; + //进行httpdns请求 + NSDictionary *res = [[MSDKDnsManager shareInstance] getHostsByNamesEnableExpired:@[domain] verbose:NO]; + dnsResult = [res objectForKey:domain]; + NSTimeInterval time_consume = [[NSDate date] timeIntervalSinceDate:date] * 1000; + MSDKDNSLOG(@"MSDKDns WGGetHostByNameEnableExpired Total Time Consume is %.1fms", time_consume); + NSMutableString * ipsStr = [NSMutableString stringWithString:@""]; + for (int i = 0; i < dnsResult.count; i++) { + NSString * ip = dnsResult[i]; + [ipsStr appendFormat:@"%@,",ip]; + } + MSDKDNSLOG(@"%@, MSDKDns Result is:%@",domain, ipsStr); + return dnsResult; + } +} + +- (NSDictionary *) WGGetHostsByNamesEnableExpired:(NSArray *)domains { + @synchronized(self) { + NSDictionary * dnsResult = @{}; + MSDKDNSLOG(@"GetHostsByNamesEnableExpired:%@",domains); + if (!domains || [domains count] == 0) { + //请求域名为空,返回空 + MSDKDNSLOG(@"MSDKDns Result is Empty!"); + return dnsResult; + } + [[MSDKDnsParamsManager shareInstance] msdkDnsSetExpiredIPEnabled:YES]; + // 转换成小写 + NSMutableArray *lowerCaseArray = [NSMutableArray array]; + for(int i = 0; i < [domains count]; i++) { + NSString *d = [domains objectAtIndex:i]; + if (d && d.length > 0) { + [lowerCaseArray addObject:[d lowercaseString]]; + } + } + domains = lowerCaseArray; + NSDate * date = [NSDate date]; + //进行httpdns请求 + dnsResult = [[MSDKDnsManager shareInstance] getHostsByNamesEnableExpired:domains verbose:NO]; + NSTimeInterval time_consume = [[NSDate date] timeIntervalSinceDate:date] * 1000; + MSDKDNSLOG(@"%@, MSDKDns Result is:%@",domains, dnsResult); + MSDKDNSLOG(@"MSDKDns WGGetHostsByNamesEnableExpired Total Time Consume is %.1fms", time_consume); + return dnsResult; + } +} + +- (NSDictionary *) WGGetAllHostsByNamesEnableExpired:(NSArray *)domains { + @synchronized(self) { + NSDictionary * dnsResult = @{}; + MSDKDNSLOG(@"GetAllHostsByNamesEnableExpired:%@",domains); + if (!domains || [domains count] == 0) { + //请求域名为空,返回空 + MSDKDNSLOG(@"MSDKDns Result is Empty!"); + return dnsResult; + } + [[MSDKDnsParamsManager shareInstance] msdkDnsSetExpiredIPEnabled:YES]; + // 转换成小写 + NSMutableArray *lowerCaseArray = [NSMutableArray array]; + for(int i = 0; i < [domains count]; i++) { + NSString *d = [domains objectAtIndex:i]; + if (d && d.length > 0) { + [lowerCaseArray addObject:[d lowercaseString]]; + } + } + domains = lowerCaseArray; + NSDate * date = [NSDate date]; + //进行httpdns请求 + dnsResult = [[MSDKDnsManager shareInstance] getHostsByNamesEnableExpired:domains verbose:YES]; + NSTimeInterval time_consume = [[NSDate date] timeIntervalSinceDate:date] * 1000; + MSDKDNSLOG(@"%@, MSDKDns Result is:%@",domains, dnsResult); + MSDKDNSLOG(@"MSDKDns WGGetAllHostsByNamesEnableExpired Total Time Consume is %.1fms", time_consume); + return dnsResult; + } +} + - (NSDictionary *) WGGetDnsDetail:(NSString *) domain { return [[MSDKDnsManager shareInstance] getDnsDetail:domain]; } diff --git a/MSDKDns/MSDKDnsPrivate.h b/MSDKDns/MSDKDnsPrivate.h index 29329f2..096b0fc 100644 --- a/MSDKDns/MSDKDnsPrivate.h +++ b/MSDKDns/MSDKDnsPrivate.h @@ -69,4 +69,9 @@ static NSString * const MSDKDns_Success = @"0"; // 成功 static NSString * const MSDKDnsEventHttpDnsfail = @"HttpDnsfail"; static NSString * const MSDKDnsEventHttpDnsSpend = @"HttpDnsSpend"; +//命中缓存的状态 +static NSString * const MSDKDnsDomainCacheHit = @"domainCacheHit"; //命中缓存 +static NSString * const MSDKDnsDomainCacheExpired = @"domainCacheExpired"; //缓存过期 +static NSString * const MSDKDnsDomainCacheEmpty = @"domainCacheEmpty"; //没有缓存 + #endif From 82aebb845471bfdd73faef3f9e3025ca46cc90d5 Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Fri, 19 Aug 2022 10:54:56 +0800 Subject: [PATCH 03/10] =?UTF-8?q?feat:=E8=A7=A3=E5=86=B3=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E9=A2=84=E8=A7=A3=E6=9E=90=E4=B8=8D=E7=94=9F=E6=95=88=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns/CacheManager/MSDKDnsParamsManager.m | 5 +---- MSDKDns/MSDKDns.m | 3 --- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/MSDKDns/CacheManager/MSDKDnsParamsManager.m b/MSDKDns/CacheManager/MSDKDnsParamsManager.m index 663cd59..6e594dc 100644 --- a/MSDKDns/CacheManager/MSDKDnsParamsManager.m +++ b/MSDKDns/CacheManager/MSDKDnsParamsManager.m @@ -182,11 +182,8 @@ - (void)msdkDnsSetEnableKeepDomainsAlive: (BOOL)enableKeepDomainsAlive { } - (void)msdkDnsSetExpiredIPEnabled: (BOOL)enable { - if (_expiredIPEnabled == enable) { - return; - } dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ - self.expiredIPEnabled = enable; + self.expiredIPEnabled = enable; }); } diff --git a/MSDKDns/MSDKDns.m b/MSDKDns/MSDKDns.m index 5504be6..867e6c2 100644 --- a/MSDKDns/MSDKDns.m +++ b/MSDKDns/MSDKDns.m @@ -353,7 +353,6 @@ - (NSArray *) WGGetHostByNameEnableExpired:(NSString *)domain { MSDKDNSLOG(@"MSDKDns Result is Empty!"); return dnsResult; } - [[MSDKDnsParamsManager shareInstance] msdkDnsSetExpiredIPEnabled:YES]; // 转换成小写 domain = [domain lowercaseString]; NSDate * date = [NSDate date]; @@ -381,7 +380,6 @@ - (NSDictionary *) WGGetHostsByNamesEnableExpired:(NSArray *)domains { MSDKDNSLOG(@"MSDKDns Result is Empty!"); return dnsResult; } - [[MSDKDnsParamsManager shareInstance] msdkDnsSetExpiredIPEnabled:YES]; // 转换成小写 NSMutableArray *lowerCaseArray = [NSMutableArray array]; for(int i = 0; i < [domains count]; i++) { @@ -410,7 +408,6 @@ - (NSDictionary *) WGGetAllHostsByNamesEnableExpired:(NSArray *)domains { MSDKDNSLOG(@"MSDKDns Result is Empty!"); return dnsResult; } - [[MSDKDnsParamsManager shareInstance] msdkDnsSetExpiredIPEnabled:YES]; // 转换成小写 NSMutableArray *lowerCaseArray = [NSMutableArray array]; for(int i = 0; i < [domains count]; i++) { From 362b561ba071b1a36e5236ece7b3c1f8da72f19c Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Mon, 29 Aug 2022 16:21:26 +0800 Subject: [PATCH 04/10] feat:add persistent cache --- MSDKDns.xcodeproj/project.pbxproj | 84 +++++++- .../xcshareddata/xcschemes/MSDKDns.xcscheme | 2 +- .../xcschemes/MSDKDns_C11.xcscheme | 2 +- MSDKDns/CacheManager/MSDKDnsManager.h | 1 + MSDKDns/CacheManager/MSDKDnsManager.m | 13 +- MSDKDns/CacheManager/MSDKDnsParamsManager.h | 2 + MSDKDns/CacheManager/MSDKDnsParamsManager.m | 11 ++ MSDKDns/MSDKDns.h | 5 + MSDKDns/MSDKDns.m | 5 + MSDKDns/MSDKDnsPrivate.h | 9 + MSDKDns/MSDKDnsService.m | 5 + MSDKDns/WCDB/HTTPDNSORM+WCTTableCoding.h | 29 +++ MSDKDns/WCDB/HTTPDNSORM.h | 26 +++ MSDKDns/WCDB/HTTPDNSORM.m | 39 ++++ MSDKDns/WCDB/MSDKDnsDB.h | 18 ++ MSDKDns/WCDB/MSDKDnsDB.m | 185 ++++++++++++++++++ 16 files changed, 425 insertions(+), 11 deletions(-) create mode 100644 MSDKDns/WCDB/HTTPDNSORM+WCTTableCoding.h create mode 100644 MSDKDns/WCDB/HTTPDNSORM.h create mode 100644 MSDKDns/WCDB/HTTPDNSORM.m create mode 100644 MSDKDns/WCDB/MSDKDnsDB.h create mode 100644 MSDKDns/WCDB/MSDKDnsDB.m diff --git a/MSDKDns.xcodeproj/project.pbxproj b/MSDKDns.xcodeproj/project.pbxproj index 9abe592..2542d01 100644 --- a/MSDKDns.xcodeproj/project.pbxproj +++ b/MSDKDns.xcodeproj/project.pbxproj @@ -38,6 +38,16 @@ 54EA82232760890B005F68A9 /* AttaReport.m in Sources */ = {isa = PBXBuildFile; fileRef = 54EA82212760890B005F68A9 /* AttaReport.m */; }; 54EA822427608A55005F68A9 /* AttaReport.h in Headers */ = {isa = PBXBuildFile; fileRef = 54EA82202760890B005F68A9 /* AttaReport.h */; }; 54EA822527608A58005F68A9 /* AttaReport.m in Sources */ = {isa = PBXBuildFile; fileRef = 54EA82212760890B005F68A9 /* AttaReport.m */; }; + 5F1E288028B72A7D00AD0D9F /* HTTPDNSORM.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F1E287B28B72A7D00AD0D9F /* HTTPDNSORM.m */; }; + 5F1E288128B72A7D00AD0D9F /* HTTPDNSORM.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F1E287B28B72A7D00AD0D9F /* HTTPDNSORM.m */; }; + 5F1E288228B72A7D00AD0D9F /* HTTPDNSORM.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F1E287C28B72A7D00AD0D9F /* HTTPDNSORM.h */; }; + 5F1E288328B72A7D00AD0D9F /* HTTPDNSORM.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F1E287C28B72A7D00AD0D9F /* HTTPDNSORM.h */; }; + 5F1E288428B72A7D00AD0D9F /* MSDKDnsDB.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F1E287D28B72A7D00AD0D9F /* MSDKDnsDB.m */; }; + 5F1E288528B72A7D00AD0D9F /* MSDKDnsDB.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F1E287D28B72A7D00AD0D9F /* MSDKDnsDB.m */; }; + 5F1E288628B72A7D00AD0D9F /* HTTPDNSORM+WCTTableCoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F1E287E28B72A7D00AD0D9F /* HTTPDNSORM+WCTTableCoding.h */; }; + 5F1E288728B72A7D00AD0D9F /* HTTPDNSORM+WCTTableCoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F1E287E28B72A7D00AD0D9F /* HTTPDNSORM+WCTTableCoding.h */; }; + 5F1E288828B72A7D00AD0D9F /* MSDKDnsDB.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F1E287F28B72A7D00AD0D9F /* MSDKDnsDB.h */; }; + 5F1E288928B72A7D00AD0D9F /* MSDKDnsDB.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F1E287F28B72A7D00AD0D9F /* MSDKDnsDB.h */; }; 5F5DAF4E28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F5DAF4B28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.h */; }; 5F5DAF4F28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F5DAF4B28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.h */; }; 5F5DAF5028A525E300BF5B79 /* MSDKDnsTCPSpeedTester.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F5DAF4C28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.m */; }; @@ -110,6 +120,12 @@ 54EA81F1275478D1005F68A9 /* httpdnsIps.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = httpdnsIps.h; sourceTree = ""; }; 54EA82202760890B005F68A9 /* AttaReport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AttaReport.h; sourceTree = ""; }; 54EA82212760890B005F68A9 /* AttaReport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AttaReport.m; sourceTree = ""; }; + 5F1E287B28B72A7D00AD0D9F /* HTTPDNSORM.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HTTPDNSORM.m; sourceTree = ""; }; + 5F1E287C28B72A7D00AD0D9F /* HTTPDNSORM.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTTPDNSORM.h; sourceTree = ""; }; + 5F1E287D28B72A7D00AD0D9F /* MSDKDnsDB.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MSDKDnsDB.m; sourceTree = ""; }; + 5F1E287E28B72A7D00AD0D9F /* HTTPDNSORM+WCTTableCoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "HTTPDNSORM+WCTTableCoding.h"; sourceTree = ""; }; + 5F1E287F28B72A7D00AD0D9F /* MSDKDnsDB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MSDKDnsDB.h; sourceTree = ""; }; + 5F1E288F28B86DFD00AD0D9F /* WCDB.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WCDB.framework; path = ../WCDB.framework; sourceTree = ""; }; 5F5DAF4B28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MSDKDnsTCPSpeedTester.h; sourceTree = ""; }; 5F5DAF4C28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MSDKDnsTCPSpeedTester.m; sourceTree = ""; }; 5F5DAF4D28A525E300BF5B79 /* MSDKDnsSpeedTester.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MSDKDnsSpeedTester.h; sourceTree = ""; }; @@ -179,6 +195,7 @@ 5F5DAF4C28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.m */, C8EBE7D1256664C400BEFEEC /* aes.h */, C8EBE7D2256664C500BEFEEC /* aes.mm */, + 5F85CBA828B4B3B1003D20D1 /* WCDB */, 54EA821F2760890B005F68A9 /* Reporter */, 501001EB215E1F1D003288A5 /* Network */, 445B363D1CBBBFAF00BD4345 /* Manager */, @@ -251,9 +268,22 @@ path = Reporter; sourceTree = ""; }; + 5F85CBA828B4B3B1003D20D1 /* WCDB */ = { + isa = PBXGroup; + children = ( + 5F1E287C28B72A7D00AD0D9F /* HTTPDNSORM.h */, + 5F1E287B28B72A7D00AD0D9F /* HTTPDNSORM.m */, + 5F1E287E28B72A7D00AD0D9F /* HTTPDNSORM+WCTTableCoding.h */, + 5F1E287F28B72A7D00AD0D9F /* MSDKDnsDB.h */, + 5F1E287D28B72A7D00AD0D9F /* MSDKDnsDB.m */, + ); + path = WCDB; + sourceTree = ""; + }; C8EBE7D92566675800BEFEEC /* Frameworks */ = { isa = PBXGroup; children = ( + 5F1E288F28B86DFD00AD0D9F /* WCDB.framework */, C8EBE7DA2566675800BEFEEC /* libc++.tbd */, ); name = Frameworks; @@ -266,7 +296,9 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 5F1E288228B72A7D00AD0D9F /* HTTPDNSORM.h in Headers */, 44BFE2481CA59D9800D7FE87 /* MSDKDnsReachability.h in Headers */, + 5F1E288828B72A7D00AD0D9F /* MSDKDnsDB.h in Headers */, 504F543A1ECAF89F001BD7A9 /* MSDKDnsHttpMessageTools.h in Headers */, 445B36691CBD1D4700BD4345 /* MSDKDnsNetworkManager.h in Headers */, C8EBE7D3256664C500BEFEEC /* aes.h in Headers */, @@ -278,6 +310,7 @@ 5F5DAF4E28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.h in Headers */, 448EE4E81B329899004A2131 /* MSDKDnsResolver.h in Headers */, 54EA82222760890B005F68A9 /* AttaReport.h in Headers */, + 5F1E288628B72A7D00AD0D9F /* HTTPDNSORM+WCTTableCoding.h in Headers */, 5F5DAF5228A525E300BF5B79 /* MSDKDnsSpeedTester.h in Headers */, 44BFE2371CA58C3A00D7FE87 /* MSDKDnsInfoTool.h in Headers */, 502422EC2140073F0094403C /* MSDKDnsParamsManager.h in Headers */, @@ -291,7 +324,9 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 5F1E288328B72A7D00AD0D9F /* HTTPDNSORM.h in Headers */, DD43F4A6231CC36D0000A89F /* MSDKDnsReachability.h in Headers */, + 5F1E288928B72A7D00AD0D9F /* MSDKDnsDB.h in Headers */, DD43F4A7231CC36D0000A89F /* MSDKDnsHttpMessageTools.h in Headers */, DD43F4A8231CC36D0000A89F /* MSDKDnsNetworkManager.h in Headers */, 2FBE52E825E77AFE0012A0DF /* aes.h in Headers */, @@ -303,6 +338,7 @@ 5F5DAF4F28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.h in Headers */, DD43F4AE231CC36D0000A89F /* MSDKDnsResolver.h in Headers */, 54EA822427608A55005F68A9 /* AttaReport.h in Headers */, + 5F1E288728B72A7D00AD0D9F /* HTTPDNSORM+WCTTableCoding.h in Headers */, 5F5DAF5328A525E300BF5B79 /* MSDKDnsSpeedTester.h in Headers */, DD43F4AF231CC36D0000A89F /* MSDKDnsInfoTool.h in Headers */, DD43F4B0231CC36D0000A89F /* MSDKDnsParamsManager.h in Headers */, @@ -363,7 +399,7 @@ 44224FB81B312DD6003497C4 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0730; + LastUpgradeCheck = 1340; ORGANIZATIONNAME = Tencent; TargetAttributes = { 44224FBF1B312DD6003497C4 = { @@ -506,9 +542,11 @@ 445B366B1CBD1D4700BD4345 /* MSDKDnsNetworkManager.m in Sources */, 4497F8BA1B4628F000D51391 /* MSDKDnsLog.m in Sources */, 504F543C1ECAF89F001BD7A9 /* MSDKDnsHttpMessageTools.m in Sources */, + 5F1E288428B72A7D00AD0D9F /* MSDKDnsDB.m in Sources */, 448EE4E91B329899004A2131 /* MSDKDnsResolver.m in Sources */, 54EA82232760890B005F68A9 /* AttaReport.m in Sources */, 4455D15F1B3A5B90005BF126 /* MSDKDns.m in Sources */, + 5F1E288028B72A7D00AD0D9F /* HTTPDNSORM.m in Sources */, 448EE4E71B329899004A2131 /* LocalDnsResolver.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -529,9 +567,11 @@ DD43F49D231CC36D0000A89F /* MSDKDnsNetworkManager.m in Sources */, DD43F49E231CC36D0000A89F /* MSDKDnsLog.m in Sources */, DD43F49F231CC36D0000A89F /* MSDKDnsHttpMessageTools.m in Sources */, + 5F1E288528B72A7D00AD0D9F /* MSDKDnsDB.m in Sources */, DD43F4A0231CC36D0000A89F /* MSDKDnsResolver.m in Sources */, 54EA822527608A58005F68A9 /* AttaReport.m in Sources */, DD43F4A1231CC36D0000A89F /* MSDKDns.m in Sources */, + 5F1E288128B72A7D00AD0D9F /* HTTPDNSORM.m in Sources */, DD43F4A2231CC36D0000A89F /* LocalDnsResolver.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -548,13 +588,24 @@ CLANG_CXX_LIBRARY = "compiler-default"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; @@ -595,13 +646,24 @@ CLANG_CXX_LIBRARY = "compiler-default"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; @@ -617,7 +679,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 5.1; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; MACOSX_DEPLOYMENT_TARGET = ""; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; @@ -638,11 +700,14 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; ENABLE_BITCODE = YES; - FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + FRAMEWORK_SEARCH_PATHS = ( + "$(PROJECT_DIR)/../**", + "$(inherited)", + ); GCC_INPUT_FILETYPE = sourcecode.cpp.objcpp; INFOPLIST_FILE = MSDKDns/Info.plist; INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)"; - IPHONEOS_DEPLOYMENT_TARGET = 6.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; @@ -677,11 +742,14 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; ENABLE_BITCODE = YES; - FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + FRAMEWORK_SEARCH_PATHS = ( + "$(PROJECT_DIR)/../**", + "$(inherited)", + ); GCC_INPUT_FILETYPE = sourcecode.cpp.objcpp; INFOPLIST_FILE = MSDKDns/Info.plist; INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)"; - IPHONEOS_DEPLOYMENT_TARGET = 6.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; @@ -714,7 +782,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; ENABLE_BITCODE = YES; - FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/../**"; GCC_INPUT_FILETYPE = sourcecode.cpp.objcpp; INFOPLIST_FILE = MSDKDns/Info.plist; INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)"; @@ -753,7 +821,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; ENABLE_BITCODE = YES; - FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/../**"; GCC_INPUT_FILETYPE = sourcecode.cpp.objcpp; INFOPLIST_FILE = MSDKDns/Info.plist; INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)"; diff --git a/MSDKDns.xcodeproj/xcshareddata/xcschemes/MSDKDns.xcscheme b/MSDKDns.xcodeproj/xcshareddata/xcschemes/MSDKDns.xcscheme index 9bba7e2..4cfa5da 100644 --- a/MSDKDns.xcodeproj/xcshareddata/xcschemes/MSDKDns.xcscheme +++ b/MSDKDns.xcodeproj/xcshareddata/xcschemes/MSDKDns.xcscheme @@ -1,6 +1,6 @@ = 201103L + #import + #import "HTTPDNSORM.h" + @interface HTTPDNSORM (WCTTableCoding) + + WCDB_PROPERTY(domain) + + WCDB_PROPERTY(httpDnsIPV4Channel) + WCDB_PROPERTY(httpDnsIPV4ClientIP) + WCDB_PROPERTY(httpDnsIPV4IPs) + WCDB_PROPERTY(httpDnsIPV4TimeConsuming) + WCDB_PROPERTY(httpDnsIPV4TTL) + WCDB_PROPERTY(httpDnsIPV4TTLExpried) + + WCDB_PROPERTY(httpDnsIPV6Channel) + WCDB_PROPERTY(httpDnsIPV6ClientIP) + WCDB_PROPERTY(httpDnsIPV6IPs) + WCDB_PROPERTY(httpDnsIPV6TimeConsuming) + WCDB_PROPERTY(httpDnsIPV6TTL) + WCDB_PROPERTY(httpDnsIPV6TTLExpried) + + @end + +#endif + diff --git a/MSDKDns/WCDB/HTTPDNSORM.h b/MSDKDns/WCDB/HTTPDNSORM.h new file mode 100644 index 0000000..27a811e --- /dev/null +++ b/MSDKDns/WCDB/HTTPDNSORM.h @@ -0,0 +1,26 @@ +/** + * Copyright (c) Tencent. All rights reserved. + */ + +#import + +@interface HTTPDNSORM : NSObject + +@property(retain) NSString *domain; + +@property(retain) NSString *httpDnsIPV4Channel; +@property(retain) NSString *httpDnsIPV4ClientIP; +@property(retain) NSArray *httpDnsIPV4IPs; +@property(retain) NSString *httpDnsIPV4TimeConsuming; +@property(retain) NSString *httpDnsIPV4TTL; +@property(retain) NSString *httpDnsIPV4TTLExpried; + +@property(retain) NSString *httpDnsIPV6Channel; +@property(retain) NSString *httpDnsIPV6ClientIP; +@property(retain) NSArray *httpDnsIPV6IPs; +@property(retain) NSString *httpDnsIPV6TimeConsuming; +@property(retain) NSString *httpDnsIPV6TTL; +@property(retain) NSString *httpDnsIPV6TTLExpried; + + +@end diff --git a/MSDKDns/WCDB/HTTPDNSORM.m b/MSDKDns/WCDB/HTTPDNSORM.m new file mode 100644 index 0000000..88935f4 --- /dev/null +++ b/MSDKDns/WCDB/HTTPDNSORM.m @@ -0,0 +1,39 @@ +/** + * Copyright (c) Tencent. All rights reserved. + */ + +#if __cplusplus >= 201103L + + #import + #import "HTTPDNSORM.h" + #import "HTTPDNSORM+WCTTableCoding.h" + + + @implementation HTTPDNSORM + + WCDB_IMPLEMENTATION(HTTPDNSORM) + + WCDB_SYNTHESIZE(HTTPDNSORM, domain) + + WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV4Channel) + WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV4ClientIP) + WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV4IPs) + WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV4TimeConsuming) + WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV4TTL) + WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV4TTLExpried) + + WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV6Channel) + WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV6ClientIP) + WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV6IPs) + WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV6TimeConsuming) + WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV6TTL) + WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV6TTLExpried) + + WCDB_PRIMARY(HTTPDNSORM, domain) + + WCDB_INDEX(HTTPDNSORM, "_index", domain) + + @end + +#endif + diff --git a/MSDKDns/WCDB/MSDKDnsDB.h b/MSDKDns/WCDB/MSDKDnsDB.h new file mode 100644 index 0000000..cbf4342 --- /dev/null +++ b/MSDKDns/WCDB/MSDKDnsDB.h @@ -0,0 +1,18 @@ +// Created by eric hu on 2022/8/23. +// Copyright © 2022 Tencent. All rights reserved. +// + +#import + +@interface MSDKDnsDB : NSObject + +//@property (strong, nonatomic, readonly) WCTDatabase *database; + ++ (instancetype)shareInstance; + +- (void)insertOrReplaceDomainInfo:(NSDictionary *)domainInfo Domain:(NSString *)domain; + +- (NSDictionary *)getDataFromDB; + +@end + diff --git a/MSDKDns/WCDB/MSDKDnsDB.m b/MSDKDns/WCDB/MSDKDnsDB.m new file mode 100644 index 0000000..7f6f059 --- /dev/null +++ b/MSDKDns/WCDB/MSDKDnsDB.m @@ -0,0 +1,185 @@ +// Created by eric hu on 2022/8/23. +// Copyright © 2022 Tencent. All rights reserved. +// + +#import "MSDKDnsDB.h" +#import "MSDKDnsLog.h" +#import "MSDKDnsPrivate.h" + +#if __cplusplus >= 201103L + #import + #import "HTTPDNSORM.h" + #import "HTTPDNSORM+WCTTableCoding.h" +#endif + +@interface MSDKDnsDB () + +@property (strong, nonatomic, readwrite) id database; +@property (strong, nonatomic, readwrite) NSString *tableName; + +@end + +@implementation MSDKDnsDB + +#pragma mark - init + +static MSDKDnsDB * _sharedInstance = nil; ++ (instancetype)shareInstance { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + _sharedInstance = [[MSDKDnsDB alloc] init]; + }); + return _sharedInstance; +} + +- (instancetype) init { + if (self = [super init]) { + _tableName = @"HttpDNSTable"; + // 获取WCTDatabase类 + Class databaseClass = NSClassFromString(@"WCTDatabase"); + // 获取HTTPDNSORM类 + Class HTTPDNSORMClass = NSClassFromString(@"HTTPDNSORM"); + if (databaseClass == 0x0) { + MSDKDNSLOG(@"WCTDatabase framework is not imported"); + } else if (HTTPDNSORMClass == 0x0) { + MSDKDNSLOG(@"MSDKDns does not support persistent cache, we recommend using MSDKDns_C11"); + } else { + @try { + NSTimeInterval time1 = [[NSDate date] timeIntervalSince1970]; + _database = [[databaseClass alloc] initWithPath:@"/Users/erichu/Library/HttpDNSTable"]; + // 获取方法编号 + SEL createTableAndIndexesOfNameSEL = NSSelectorFromString(@"createTableAndIndexesOfName:withClass:"); + // 调用WCTDatabase类的方法 + if (_database && [_database respondsToSelector:createTableAndIndexesOfNameSEL] ) { + IMP imp = [_database methodForSelector:createTableAndIndexesOfNameSEL]; + using connectDatabase = BOOL (*)(id, SEL, NSString *, Class); + BOOL success = ((connectDatabase) imp)(_database, createTableAndIndexesOfNameSEL, _tableName, HTTPDNSORMClass.class); + if (!success) { + MSDKDNSLOG(@"database connection failed"); + } + } + NSTimeInterval time2 = [[NSDate date] timeIntervalSince1970]; + NSLog(@"===创建数据库==本次耗时=====:%fms", (time2 - time1) * 1000); + } @catch (NSException *exception) { + MSDKDNSLOG(@"database connection failed"); + } + } + } + return self; +} + +- (void)insertOrReplaceDomainInfo:(NSDictionary *)domainInfo Domain:(NSString *)domain { + + NSDictionary * hresultDict_A = domainInfo[kMSDKHttpDnsCache_A]; + NSDictionary * hresultDict_4A = domainInfo[kMSDKHttpDnsCache_4A]; + + // 获取HTTPDNSORM类 + Class HTTPDNSORMClass = NSClassFromString(@"HTTPDNSORM"); + + if (HTTPDNSORMClass == 0x0) { + MSDKDNSLOG(@"MSDKDns does not support persistent cache, we recommend using MSDKDns_C11"); + return; + } + + id httpDnsData = [[HTTPDNSORMClass alloc] init]; + + [httpDnsData setValue:[domain copy] forKey:@"domain"]; + + if (hresultDict_A){ + [httpDnsData setValue:hresultDict_A[kChannel] forKey:@"httpDnsIPV4Channel"]; + [httpDnsData setValue:hresultDict_A[kClientIP] forKey:@"httpDnsIPV4ClientIP"]; + [httpDnsData setValue:hresultDict_A[kIP] forKey:@"httpDnsIPV4IPs"]; + [httpDnsData setValue:hresultDict_A[kDnsTimeConsuming] forKey:@"httpDnsIPV4TimeConsuming"]; + [httpDnsData setValue:hresultDict_A[kTTL] forKey:@"httpDnsIPV4TTL"]; + [httpDnsData setValue:hresultDict_A[kTTLExpired] forKey:@"httpDnsIPV4TTLExpried"]; + } + + if (hresultDict_4A) { + [httpDnsData setValue:hresultDict_4A[kChannel] forKey:@"httpDnsIPV6Channel"]; + [httpDnsData setValue:hresultDict_4A[kClientIP] forKey:@"httpDnsIPV6ClientIP"]; + [httpDnsData setValue:hresultDict_4A[kIP] forKey:@"httpDnsIPV6IPs"]; + [httpDnsData setValue:hresultDict_4A[kDnsTimeConsuming] forKey:@"httpDnsIPV6TimeConsuming"]; + [httpDnsData setValue:hresultDict_4A[kTTL] forKey:@"httpDnsIPV6TTL"]; + [httpDnsData setValue:hresultDict_4A[kTTLExpired] forKey:@"httpDnsIPV6TTLExpried"]; + } + // 获取方法编号 + SEL insertOrReplaceObjectSEL = NSSelectorFromString(@"insertOrReplaceObject:into:"); + + if (_database && [_database respondsToSelector:insertOrReplaceObjectSEL] ) { + NSTimeInterval time1 = [[NSDate date] timeIntervalSince1970]; + + @try { + IMP imp = [_database methodForSelector:insertOrReplaceObjectSEL]; + using insertData = BOOL (*)(id, SEL, id, NSString *); + BOOL success = ((insertData) imp)(_database, insertOrReplaceObjectSEL, httpDnsData, _tableName); + if (!success) { + MSDKDNSLOG(@"Failed to insert data into database"); + } + } @catch (NSException *exception) { + MSDKDNSLOG(@"Failed to insert data into database"); + } + + NSTimeInterval time2 = [[NSDate date] timeIntervalSince1970]; + NSLog(@"===插入数据库==本次耗时=====:%fms", (time2 - time1) * 1000); + + NSDictionary *result = [self getDataFromDB]; + NSLog(@"loadDB domainInfo = %@",result); + } +} + +- (NSDictionary *)getDataFromDB { + // 获取HTTPDNSORM类 + Class HTTPDNSORMClass = NSClassFromString(@"HTTPDNSORM"); + SEL getAllObjectsOfClassSEL = NSSelectorFromString(@"getAllObjectsOfClass:fromTable:"); + + NSMutableDictionary *newResult = [[NSMutableDictionary alloc] init]; + + if (HTTPDNSORMClass == 0x0) { + MSDKDNSLOG(@"MSDKDns does not support persistent cache, we recommend using MSDKDns_C11"); + } + + if (_database && [_database respondsToSelector:getAllObjectsOfClassSEL] && HTTPDNSORMClass != 0x0) { + NSTimeInterval time1 = [[NSDate date] timeIntervalSince1970]; + @try { + IMP imp = [_database methodForSelector:getAllObjectsOfClassSEL]; + using GetAllData = NSArray* (*)(id, SEL, Class, NSString *); + NSArray *result = ((GetAllData) imp)(_database, getAllObjectsOfClassSEL, HTTPDNSORMClass.class, _tableName); + if (!result) { + MSDKDNSLOG(@"Failed to insert data into database"); + } + for (id item in result) { + NSMutableDictionary *domainInfo = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *httpDnsIPV4Info = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *httpDnsIPV6Info = [[NSMutableDictionary alloc] init]; + + [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4Channel"] forKey:kChannel]; + [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4ClientIP"] forKey:kClientIP]; + [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4IPs"] forKey:kIP]; + [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4TimeConsuming"] forKey:kDnsTimeConsuming]; + [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4TTL"] forKey:kTTL]; + [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4TTLExpried"] forKey:kTTLExpired]; + + [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6Channel"] forKey:kChannel]; + [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6ClientIP"] forKey:kClientIP]; + [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6IPs"] forKey:kIP]; + [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6TimeConsuming"] forKey:kDnsTimeConsuming]; + [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6TTL"] forKey:kTTL]; + [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6TTLExpried"] forKey:kTTLExpired]; + + [domainInfo setObject:httpDnsIPV4Info forKey:kMSDKHttpDnsCache_A]; + [domainInfo setObject:httpDnsIPV6Info forKey:kMSDKHttpDnsCache_4A]; + + [newResult setObject:domainInfo forKey:[item valueForKey:@"domain"]]; + } + } @catch (NSException *exception) { + MSDKDNSLOG(@"Failed to insert data into database"); + } + + NSTimeInterval time2 = [[NSDate date] timeIntervalSince1970]; + NSLog(@"===读取数据库==本次耗时=====:%fms", (time2 - time1) * 1000); + } + return newResult; +} + + +@end From 8c465383c9c09ca2c75635d0c46168b23fd89e91 Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Mon, 29 Aug 2022 19:08:01 +0800 Subject: [PATCH 05/10] =?UTF-8?q?feat:=E5=90=88=E5=B9=B6=E4=B9=90=E8=A7=82?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns/MSDKDns.h | 24 ------------------------ MSDKDns/MSDKDns.m | 46 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 27 deletions(-) diff --git a/MSDKDns/MSDKDns.h b/MSDKDns/MSDKDns.h index 0f8acdb..b87aa18 100644 --- a/MSDKDns/MSDKDns.h +++ b/MSDKDns/MSDKDns.h @@ -156,30 +156,6 @@ typedef struct DnsConfigStruct { */ - (void)WGGetAllHostsByNamesAsync:(NSArray *)domains returnIps:(void (^)(NSDictionary * ipsDictionary))handler; -/** - 域名解析乐观DNS(通用接口) - - @param domain 域名 - @param handler 返回缓存中查询到的IP数组,若不存在会返回[0,0]并且进行异步域名解析更新缓存 - */ -- (NSArray *) WGGetHostByNameEnableExpired:(NSString *)domain; - -/** - 域名解析乐观DNS(通用接口) - - @param domains 域名数组 - @param handler 返回缓存中查询到的IP数组,若不存在会返回[0,0]并且进行异步域名解析更新缓存 - */ -- (NSDictionary *) WGGetHostsByNamesEnableExpired:(NSArray *)domains; - -/** - 域名解析乐观DNS(通用接口) - - @param domains 域名数组 - @param handler 返回缓存中查询到的IP数组,若不存在会返回[0,0]并且进行异步域名解析更新缓存 - */ -- (NSDictionary *) WGGetAllHostsByNamesEnableExpired:(NSArray *)domains; - #pragma mark - SNI场景,仅调用一次即可,请勿多次调用 /** SNI场景下设置需要拦截的域名列表 diff --git a/MSDKDns/MSDKDns.m b/MSDKDns/MSDKDns.m index 30c942b..1383441 100644 --- a/MSDKDns/MSDKDns.m +++ b/MSDKDns/MSDKDns.m @@ -153,7 +153,13 @@ - (NSArray *) WGGetHostByName:(NSString *)domain { //进行httpdns请求 NSDate * date = [NSDate date]; //进行httpdns请求 - NSDictionary *res = [[MSDKDnsManager shareInstance] getHostsByNames:@[domain] verbose:NO]; + NSDictionary * res = @{}; + BOOL expiredIPEnabled = [[MSDKDnsParamsManager shareInstance] msdkDnsGetExpiredIPEnabled]; + if (expiredIPEnabled) { + res = [[MSDKDnsManager shareInstance] getHostsByNamesEnableExpired:@[domain] verbose:NO]; + } else { + res = [[MSDKDnsManager shareInstance] getHostsByNames:@[domain] verbose:NO]; + } dnsResult = [res objectForKey:domain]; NSTimeInterval time_consume = [[NSDate date] timeIntervalSinceDate:date] * 1000; MSDKDNSLOG(@"MSDKDns WGGetHostByName Total Time Consume is %.1fms", time_consume); @@ -188,7 +194,12 @@ - (NSDictionary *) WGGetHostsByNames:(NSArray *)domains { //进行httpdns请求 NSDate * date = [NSDate date]; //进行httpdns请求 - dnsResult = [[MSDKDnsManager shareInstance] getHostsByNames:domains verbose:NO]; + BOOL expiredIPEnabled = [[MSDKDnsParamsManager shareInstance] msdkDnsGetExpiredIPEnabled]; + if (expiredIPEnabled) { + dnsResult = [[MSDKDnsManager shareInstance] getHostsByNamesEnableExpired:domains verbose:NO]; + } else { + dnsResult = [[MSDKDnsManager shareInstance] getHostsByNames:domains verbose:NO]; + } NSTimeInterval time_consume = [[NSDate date] timeIntervalSinceDate:date] * 1000; MSDKDNSLOG(@"%@, MSDKDns Result is:%@",domains, dnsResult); MSDKDNSLOG(@"MSDKDns WGGetHostByName Total Time Consume is %.1fms", time_consume); @@ -217,7 +228,12 @@ - (NSDictionary *) WGGetAllHostsByNames:(NSArray *)domains { //进行httpdns请求 NSDate * date = [NSDate date]; //进行httpdns请求 - dnsResult = [[MSDKDnsManager shareInstance] getHostsByNames:domains verbose:YES]; + BOOL expiredIPEnabled = [[MSDKDnsParamsManager shareInstance] msdkDnsGetExpiredIPEnabled]; + if (expiredIPEnabled) { + dnsResult = [[MSDKDnsManager shareInstance] getHostsByNamesEnableExpired:domains verbose:YES]; + } else { + dnsResult = [[MSDKDnsManager shareInstance] getHostsByNames:domains verbose:YES]; + } NSTimeInterval time_consume = [[NSDate date] timeIntervalSinceDate:date] * 1000; MSDKDNSLOG(@"%@, MSDKDns Result is:%@",domains, dnsResult); MSDKDNSLOG(@"MSDKDns WGGetHostByName Total Time Consume is %.1fms", time_consume); @@ -227,6 +243,14 @@ - (NSDictionary *) WGGetAllHostsByNames:(NSArray *)domains { - (void)WGGetHostByNameAsync:(NSString *)domain returnIps:(void (^)(NSArray *))handler { @synchronized(self) { + BOOL expiredIPEnabled = [[MSDKDnsParamsManager shareInstance] msdkDnsGetExpiredIPEnabled]; + if (expiredIPEnabled) { + //开启了使用过期缓存功能,给出提示建议使用同步接口进行解析 + @throw [NSException exceptionWithName:@"MSDKDns wrong use of api" + reason:@"WGGetHostByNameAsync cannot be used when useExpiredIpEnable is set to true, it is recommended to switch to the WGGetHostByName" + userInfo:nil]; + return; + } MSDKDNSLOG(@"GetHostByNameAsync:%@",domain); if (!domain || domain.length == 0) { //请求域名为空,返回空 @@ -267,6 +291,14 @@ - (void)WGGetHostByNameAsync:(NSString *)domain returnIps:(void (^)(NSArray *))h - (void)WGGetHostsByNamesAsync:(NSArray *)domains returnIps:(void (^)(NSDictionary *))handler { @synchronized(self) { + BOOL expiredIPEnabled = [[MSDKDnsParamsManager shareInstance] msdkDnsGetExpiredIPEnabled]; + if (expiredIPEnabled) { + //开启了使用过期缓存功能,给出提示建议使用同步接口进行解析 + @throw [NSException exceptionWithName:@"MSDKDns wrong use of api" + reason:@"WGGetHostsByNamesAsync cannot be used when useExpiredIpEnable is set to true, it is recommended to switch to the WGGetHostsByNames" + userInfo:nil]; + return; + } MSDKDNSLOG(@"GetHostByNameAsync:%@",domains); if (!domains || [domains count] == 0) { //请求域名为空,返回空 @@ -309,6 +341,14 @@ - (void)WGGetHostsByNamesAsync:(NSArray *)domains returnIps:(void (^)(NSDictiona - (void)WGGetAllHostsByNamesAsync:(NSArray *)domains returnIps:(void (^)(NSDictionary *))handler { @synchronized(self) { + BOOL expiredIPEnabled = [[MSDKDnsParamsManager shareInstance] msdkDnsGetExpiredIPEnabled]; + if (expiredIPEnabled) { + //开启了使用过期缓存功能,给出提示建议使用同步接口进行解析 + @throw [NSException exceptionWithName:@"MSDKDns wrong use of api" + reason:@"WGGetAllHostsByNamesAsync cannot be used when useExpiredIpEnable is set to true, it is recommended to switch to the WGGetAllHostsByNames" + userInfo:nil]; + return; + } MSDKDNSLOG(@"GetHostByNameAsync:%@",domains); if (!domains || [domains count] == 0) { //请求域名为空,返回空 From 437beda09d93a4834e8795a59fad5aadaf2ca843 Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Thu, 1 Sep 2022 16:54:58 +0800 Subject: [PATCH 06/10] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=8C=81=E4=B9=85=E5=8C=96=E8=BF=87=E6=9C=9F=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns/CacheManager/MSDKDnsManager.m | 33 +++++++- MSDKDns/WCDB/MSDKDnsDB.h | 2 + MSDKDns/WCDB/MSDKDnsDB.m | 106 ++++++++++++++++++++++---- 3 files changed, 124 insertions(+), 17 deletions(-) diff --git a/MSDKDns/CacheManager/MSDKDnsManager.m b/MSDKDns/CacheManager/MSDKDnsManager.m index 024ce5e..438a854 100644 --- a/MSDKDns/CacheManager/MSDKDnsManager.m +++ b/MSDKDns/CacheManager/MSDKDnsManager.m @@ -850,13 +850,44 @@ - (void)loadIPsFromPersistCacheAsync { dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ NSDictionary *result = [[MSDKDnsDB shareInstance] getDataFromDB]; NSLog(@"loadDB domainInfo = %@",result); + NSMutableArray *expiredDomains = [[NSMutableArray alloc] init]; for (NSString *domain in result) { - NSDictionary *domainInfo = result[domain]; + NSDictionary *domainInfo = [result valueForKey:domain]; + if ([self isDomainCacheExpired:domainInfo]) { + [expiredDomains addObject:domain]; + } [self cacheDomainInfo:domainInfo Domain:domain]; } + // 删除本地持久化缓存中过期缓存 + if (expiredDomains && expiredDomains.count > 0){ + [[MSDKDnsDB shareInstance] deleteDBData:expiredDomains]; + } }); } +- (BOOL)isDomainCacheExpired: (NSDictionary *)domainInfo { + NSDictionary *httpDnsIPV4Info = [domainInfo valueForKey:kMSDKHttpDnsCache_A]; + NSDictionary *httpDnsIPV6Info = [domainInfo valueForKey:kMSDKHttpDnsCache_4A]; + NSMutableString *expiredTime = [[NSMutableString alloc] init]; + double nowTime = [[NSDate date] timeIntervalSince1970]; + if (httpDnsIPV4Info) { + NSString *ipv4ExpiredTime = [httpDnsIPV4Info valueForKey:kTTLExpired]; + if (ipv4ExpiredTime) { + expiredTime = [[NSMutableString alloc]initWithString:ipv4ExpiredTime]; + } + } + if (httpDnsIPV6Info) { + NSString *ipv6ExpiredTime = [httpDnsIPV6Info valueForKey:kTTLExpired]; + if (ipv6ExpiredTime) { + expiredTime = [[NSMutableString alloc]initWithString:ipv6ExpiredTime]; + } + } + if (expiredTime && nowTime <= expiredTime.doubleValue) { + return false; + } + return true; +} + # pragma mark - detect address type - (msdkdns::MSDKDNS_TLocalIPStack)detectAddressType { msdkdns::MSDKDNS_TLocalIPStack netStack = msdkdns::MSDKDNS_ELocalIPStack_None; diff --git a/MSDKDns/WCDB/MSDKDnsDB.h b/MSDKDns/WCDB/MSDKDnsDB.h index cbf4342..9086e20 100644 --- a/MSDKDns/WCDB/MSDKDnsDB.h +++ b/MSDKDns/WCDB/MSDKDnsDB.h @@ -14,5 +14,7 @@ - (NSDictionary *)getDataFromDB; +- (void)deleteDBData: (NSArray *)domains; + @end diff --git a/MSDKDns/WCDB/MSDKDnsDB.m b/MSDKDns/WCDB/MSDKDnsDB.m index 7f6f059..116bed5 100644 --- a/MSDKDns/WCDB/MSDKDnsDB.m +++ b/MSDKDns/WCDB/MSDKDnsDB.m @@ -5,6 +5,7 @@ #import "MSDKDnsDB.h" #import "MSDKDnsLog.h" #import "MSDKDnsPrivate.h" +#import #if __cplusplus >= 201103L #import @@ -46,7 +47,15 @@ - (instancetype) init { } else { @try { NSTimeInterval time1 = [[NSDate date] timeIntervalSince1970]; - _database = [[databaseClass alloc] initWithPath:@"/Users/erichu/Library/HttpDNSTable"]; + NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); + + NSString *baseDirectory = [documentPaths objectAtIndex:0]; + + NSString *path = [baseDirectory stringByAppendingPathComponent:_tableName]; + + NSLog(@"path =========== %@", path); + + _database = [[databaseClass alloc] initWithPath:path]; // 获取方法编号 SEL createTableAndIndexesOfNameSEL = NSSelectorFromString(@"createTableAndIndexesOfName:withClass:"); // 调用WCTDatabase类的方法 @@ -136,9 +145,10 @@ - (NSDictionary *)getDataFromDB { if (HTTPDNSORMClass == 0x0) { MSDKDNSLOG(@"MSDKDns does not support persistent cache, we recommend using MSDKDns_C11"); + return newResult; } - if (_database && [_database respondsToSelector:getAllObjectsOfClassSEL] && HTTPDNSORMClass != 0x0) { + if (_database && [_database respondsToSelector:getAllObjectsOfClassSEL]) { NSTimeInterval time1 = [[NSDate date] timeIntervalSince1970]; @try { IMP imp = [_database methodForSelector:getAllObjectsOfClassSEL]; @@ -152,20 +162,21 @@ - (NSDictionary *)getDataFromDB { NSMutableDictionary *httpDnsIPV4Info = [[NSMutableDictionary alloc] init]; NSMutableDictionary *httpDnsIPV6Info = [[NSMutableDictionary alloc] init]; - [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4Channel"] forKey:kChannel]; - [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4ClientIP"] forKey:kClientIP]; - [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4IPs"] forKey:kIP]; - [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4TimeConsuming"] forKey:kDnsTimeConsuming]; - [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4TTL"] forKey:kTTL]; - [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4TTLExpried"] forKey:kTTLExpired]; - - [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6Channel"] forKey:kChannel]; - [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6ClientIP"] forKey:kClientIP]; - [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6IPs"] forKey:kIP]; - [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6TimeConsuming"] forKey:kDnsTimeConsuming]; - [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6TTL"] forKey:kTTL]; - [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6TTLExpried"] forKey:kTTLExpired]; - + @try { + [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4Channel"] forKey:kChannel]; + [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4ClientIP"] forKey:kClientIP]; + [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4IPs"] forKey:kIP]; + [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4TimeConsuming"] forKey:kDnsTimeConsuming]; + [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4TTL"] forKey:kTTL]; + [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4TTLExpried"] forKey:kTTLExpired]; + + [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6Channel"] forKey:kChannel]; + [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6ClientIP"] forKey:kClientIP]; + [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6IPs"] forKey:kIP]; + [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6TimeConsuming"] forKey:kDnsTimeConsuming]; + [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6TTL"] forKey:kTTL]; + [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6TTLExpried"] forKey:kTTLExpired]; + } @catch (NSException *exception) {} [domainInfo setObject:httpDnsIPV4Info forKey:kMSDKHttpDnsCache_A]; [domainInfo setObject:httpDnsIPV6Info forKey:kMSDKHttpDnsCache_4A]; @@ -181,5 +192,68 @@ - (NSDictionary *)getDataFromDB { return newResult; } +- (void)deleteDBData: (NSArray *)domains { + // 获取HTTPDNSORM类 + Class HTTPDNSORMClass = NSClassFromString(@"HTTPDNSORM"); + SEL deleteObjectsFromTableSEL = NSSelectorFromString(@"deleteObjectsFromTable:where:"); + + if (HTTPDNSORMClass == 0x0) { + MSDKDNSLOG(@"MSDKDns does not support persistent cache, we recommend using MSDKDns_C11"); + return; + } + + if (_database && [_database respondsToSelector:deleteObjectsFromTableSEL]) { + NSTimeInterval time1 = [[NSDate date] timeIntervalSince1970]; + @try { + IMP imp = [_database methodForSelector:deleteObjectsFromTableSEL]; + using deleteData = BOOL (*)(id, SEL, NSString *, WCTExpr); + +// _database meth + +// //初始化HTTPDNSORM对象 + id httpDnsData = [[HTTPDNSORM alloc] init]; +// +// // 获取HTTPDNSORM.domain +// SEL domainSEL = NSSelectorFromString(@"domain"); +// IMP domainImp = [httpDnsData methodForSelector:domainSEL]; +// using getDomainData = id (*)(id, SEL); +// id domainData = ((getDomainData) domainImp)(httpDnsData, domainSEL); +// +// // 获取HTTPDNSORM.domain.in(domains) +// SEL inSEL = NSSelectorFromString(@"in:"); +// IMP inImp = [domainData methodForSelector:inSEL]; +// using inData = id (*)(id, SEL, NSArray *); +// id condition = ((inData) inImp)(domainData, inSEL, domains); + +// BOOL success = [_database deleteObjectsFromTable:_tableName where:HTTPDNSORM.domain.in(domains)]; +// [HTTPDNSORM.domain in(domains)] + + + // 删除表数据 + +// BOOL success = ((deleteData) imp)(_database, deleteObjectsFromTableSEL, _tableName, [[HTTPDNSORMClass performSelector:@selector(@"domain")] performSelector:@selector(@"in:") withObject:domains]); +// NSLog(@"%@",objc_getClass("HTTPDNSORM")); + const WCTProperty & domainFunc = ((const WCTProperty &(*)(id, SEL))objc_msgSend)(objc_getClass("HTTPDNSORM"), NSSelectorFromString(@"domain")); + + WCTExpr condition = ((WCTExpr (*)(const WCTProperty &, SEL, id))objc_msgSend)(domainFunc, NSSelectorFromString(@"in"), domains); + + +// HTTPDNSORM.domain.in + +// objc_msgSend(objc_getClass("LGStudent"), sel_registerName("sayNB")) + BOOL success = ((deleteData) imp)(_database, deleteObjectsFromTableSEL, _tableName, HTTPDNSORM.domain.in(domains)); +// BOOL success = ((deleteData) imp)(_database, deleteObjectsFromTableSEL, _tableName, condition); + if (!success) { + MSDKDNSLOG(@"Failed to delete data into database"); + } + } @catch (NSException *exception) { + MSDKDNSLOG(@"Failed to delete data into database"); + } + + NSTimeInterval time2 = [[NSDate date] timeIntervalSince1970]; + NSLog(@"===删除数据库==本次耗时=====:%fms", (time2 - time1) * 1000); + } +} + @end From c14dc118face97c24e46817f093fd817bfaa3976 Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Thu, 1 Sep 2022 17:03:05 +0800 Subject: [PATCH 07/10] =?UTF-8?q?feat:=E5=88=A0=E9=99=A4=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns/CacheManager/MSDKDnsManager.m | 2 +- MSDKDns/WCDB/MSDKDnsDB.m | 56 --------------------------- 2 files changed, 1 insertion(+), 57 deletions(-) diff --git a/MSDKDns/CacheManager/MSDKDnsManager.m b/MSDKDns/CacheManager/MSDKDnsManager.m index 438a854..472bc8d 100644 --- a/MSDKDns/CacheManager/MSDKDnsManager.m +++ b/MSDKDns/CacheManager/MSDKDnsManager.m @@ -849,7 +849,7 @@ - (NSString *) domianCache:(NSDictionary *)cache check:(NSString *)domain { - (void)loadIPsFromPersistCacheAsync { dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ NSDictionary *result = [[MSDKDnsDB shareInstance] getDataFromDB]; - NSLog(@"loadDB domainInfo = %@",result); + MSDKDNSLOG(@"loadDB domainInfo = %@",result); NSMutableArray *expiredDomains = [[NSMutableArray alloc] init]; for (NSString *domain in result) { NSDictionary *domainInfo = [result valueForKey:domain]; diff --git a/MSDKDns/WCDB/MSDKDnsDB.m b/MSDKDns/WCDB/MSDKDnsDB.m index 116bed5..9d5f876 100644 --- a/MSDKDns/WCDB/MSDKDnsDB.m +++ b/MSDKDns/WCDB/MSDKDnsDB.m @@ -5,7 +5,6 @@ #import "MSDKDnsDB.h" #import "MSDKDnsLog.h" #import "MSDKDnsPrivate.h" -#import #if __cplusplus >= 201103L #import @@ -46,15 +45,10 @@ - (instancetype) init { MSDKDNSLOG(@"MSDKDns does not support persistent cache, we recommend using MSDKDns_C11"); } else { @try { - NSTimeInterval time1 = [[NSDate date] timeIntervalSince1970]; NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); - NSString *baseDirectory = [documentPaths objectAtIndex:0]; - NSString *path = [baseDirectory stringByAppendingPathComponent:_tableName]; - NSLog(@"path =========== %@", path); - _database = [[databaseClass alloc] initWithPath:path]; // 获取方法编号 SEL createTableAndIndexesOfNameSEL = NSSelectorFromString(@"createTableAndIndexesOfName:withClass:"); @@ -67,8 +61,6 @@ - (instancetype) init { MSDKDNSLOG(@"database connection failed"); } } - NSTimeInterval time2 = [[NSDate date] timeIntervalSince1970]; - NSLog(@"===创建数据库==本次耗时=====:%fms", (time2 - time1) * 1000); } @catch (NSException *exception) { MSDKDNSLOG(@"database connection failed"); } @@ -115,8 +107,6 @@ - (void)insertOrReplaceDomainInfo:(NSDictionary *)domainInfo Domain:(NSString *) SEL insertOrReplaceObjectSEL = NSSelectorFromString(@"insertOrReplaceObject:into:"); if (_database && [_database respondsToSelector:insertOrReplaceObjectSEL] ) { - NSTimeInterval time1 = [[NSDate date] timeIntervalSince1970]; - @try { IMP imp = [_database methodForSelector:insertOrReplaceObjectSEL]; using insertData = BOOL (*)(id, SEL, id, NSString *); @@ -127,10 +117,6 @@ - (void)insertOrReplaceDomainInfo:(NSDictionary *)domainInfo Domain:(NSString *) } @catch (NSException *exception) { MSDKDNSLOG(@"Failed to insert data into database"); } - - NSTimeInterval time2 = [[NSDate date] timeIntervalSince1970]; - NSLog(@"===插入数据库==本次耗时=====:%fms", (time2 - time1) * 1000); - NSDictionary *result = [self getDataFromDB]; NSLog(@"loadDB domainInfo = %@",result); } @@ -149,7 +135,6 @@ - (NSDictionary *)getDataFromDB { } if (_database && [_database respondsToSelector:getAllObjectsOfClassSEL]) { - NSTimeInterval time1 = [[NSDate date] timeIntervalSince1970]; @try { IMP imp = [_database methodForSelector:getAllObjectsOfClassSEL]; using GetAllData = NSArray* (*)(id, SEL, Class, NSString *); @@ -185,9 +170,6 @@ - (NSDictionary *)getDataFromDB { } @catch (NSException *exception) { MSDKDNSLOG(@"Failed to insert data into database"); } - - NSTimeInterval time2 = [[NSDate date] timeIntervalSince1970]; - NSLog(@"===读取数据库==本次耗时=====:%fms", (time2 - time1) * 1000); } return newResult; } @@ -203,55 +185,17 @@ - (void)deleteDBData: (NSArray *)domains { } if (_database && [_database respondsToSelector:deleteObjectsFromTableSEL]) { - NSTimeInterval time1 = [[NSDate date] timeIntervalSince1970]; @try { IMP imp = [_database methodForSelector:deleteObjectsFromTableSEL]; using deleteData = BOOL (*)(id, SEL, NSString *, WCTExpr); - -// _database meth - -// //初始化HTTPDNSORM对象 - id httpDnsData = [[HTTPDNSORM alloc] init]; -// -// // 获取HTTPDNSORM.domain -// SEL domainSEL = NSSelectorFromString(@"domain"); -// IMP domainImp = [httpDnsData methodForSelector:domainSEL]; -// using getDomainData = id (*)(id, SEL); -// id domainData = ((getDomainData) domainImp)(httpDnsData, domainSEL); -// -// // 获取HTTPDNSORM.domain.in(domains) -// SEL inSEL = NSSelectorFromString(@"in:"); -// IMP inImp = [domainData methodForSelector:inSEL]; -// using inData = id (*)(id, SEL, NSArray *); -// id condition = ((inData) inImp)(domainData, inSEL, domains); - -// BOOL success = [_database deleteObjectsFromTable:_tableName where:HTTPDNSORM.domain.in(domains)]; -// [HTTPDNSORM.domain in(domains)] - - // 删除表数据 - -// BOOL success = ((deleteData) imp)(_database, deleteObjectsFromTableSEL, _tableName, [[HTTPDNSORMClass performSelector:@selector(@"domain")] performSelector:@selector(@"in:") withObject:domains]); -// NSLog(@"%@",objc_getClass("HTTPDNSORM")); - const WCTProperty & domainFunc = ((const WCTProperty &(*)(id, SEL))objc_msgSend)(objc_getClass("HTTPDNSORM"), NSSelectorFromString(@"domain")); - - WCTExpr condition = ((WCTExpr (*)(const WCTProperty &, SEL, id))objc_msgSend)(domainFunc, NSSelectorFromString(@"in"), domains); - - -// HTTPDNSORM.domain.in - -// objc_msgSend(objc_getClass("LGStudent"), sel_registerName("sayNB")) BOOL success = ((deleteData) imp)(_database, deleteObjectsFromTableSEL, _tableName, HTTPDNSORM.domain.in(domains)); -// BOOL success = ((deleteData) imp)(_database, deleteObjectsFromTableSEL, _tableName, condition); if (!success) { MSDKDNSLOG(@"Failed to delete data into database"); } } @catch (NSException *exception) { MSDKDNSLOG(@"Failed to delete data into database"); } - - NSTimeInterval time2 = [[NSDate date] timeIntervalSince1970]; - NSLog(@"===删除数据库==本次耗时=====:%fms", (time2 - time1) * 1000); } } From b234a89073924d9ca8f8f168a3536bb086555525 Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Fri, 2 Sep 2022 10:16:29 +0800 Subject: [PATCH 08/10] =?UTF-8?q?feat:=E5=85=BC=E5=AE=B998=E7=89=88?= =?UTF-8?q?=E6=9C=ACsdk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns.xcodeproj/project.pbxproj | 4 ++-- MSDKDns/WCDB/MSDKDnsDB.m | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/MSDKDns.xcodeproj/project.pbxproj b/MSDKDns.xcodeproj/project.pbxproj index 2542d01..df68200 100644 --- a/MSDKDns.xcodeproj/project.pbxproj +++ b/MSDKDns.xcodeproj/project.pbxproj @@ -782,7 +782,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; ENABLE_BITCODE = YES; - FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/../**"; + FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/.."; GCC_INPUT_FILETYPE = sourcecode.cpp.objcpp; INFOPLIST_FILE = MSDKDns/Info.plist; INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)"; @@ -821,7 +821,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; ENABLE_BITCODE = YES; - FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/../**"; + FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/.."; GCC_INPUT_FILETYPE = sourcecode.cpp.objcpp; INFOPLIST_FILE = MSDKDns/Info.plist; INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)"; diff --git a/MSDKDns/WCDB/MSDKDnsDB.m b/MSDKDns/WCDB/MSDKDnsDB.m index 9d5f876..76734a0 100644 --- a/MSDKDns/WCDB/MSDKDnsDB.m +++ b/MSDKDns/WCDB/MSDKDnsDB.m @@ -186,6 +186,7 @@ - (void)deleteDBData: (NSArray *)domains { if (_database && [_database respondsToSelector:deleteObjectsFromTableSEL]) { @try { +#if __cplusplus >= 201103L IMP imp = [_database methodForSelector:deleteObjectsFromTableSEL]; using deleteData = BOOL (*)(id, SEL, NSString *, WCTExpr); // 删除表数据 @@ -193,6 +194,7 @@ - (void)deleteDBData: (NSArray *)domains { if (!success) { MSDKDNSLOG(@"Failed to delete data into database"); } +#endif } @catch (NSException *exception) { MSDKDNSLOG(@"Failed to delete data into database"); } From 3a23730d112765c32ecbea2e886b2824a6f063a4 Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Tue, 6 Sep 2022 10:16:42 +0800 Subject: [PATCH 09/10] =?UTF-8?q?feat:=E6=96=B0=E5=A2=9E1.6.0=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns.xcodeproj/project.pbxproj | 8 ++++---- MSDKDns/MSDKDns.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/MSDKDns.xcodeproj/project.pbxproj b/MSDKDns.xcodeproj/project.pbxproj index df68200..67b28f9 100644 --- a/MSDKDns.xcodeproj/project.pbxproj +++ b/MSDKDns.xcodeproj/project.pbxproj @@ -711,7 +711,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.5.0; + MARKETING_VERSION = 1.6.0; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -753,7 +753,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.5.0; + MARKETING_VERSION = 1.6.0; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", @@ -790,7 +790,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.5.0; + MARKETING_VERSION = 1.6.0; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -829,7 +829,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.5.0; + MARKETING_VERSION = 1.6.0; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", diff --git a/MSDKDns/MSDKDns.h b/MSDKDns/MSDKDns.h index b87aa18..dff0d13 100644 --- a/MSDKDns/MSDKDns.h +++ b/MSDKDns/MSDKDns.h @@ -5,7 +5,7 @@ #ifndef __MSDKDns_H__ #define __MSDKDns_H__ -#define MSDKDns_Version @"1.5.0" +#define MSDKDns_Version @"1.6.0" #import From e576b5a5a40838edc034c05a4b4c0c82a3e05916 Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Wed, 7 Sep 2022 16:45:32 +0800 Subject: [PATCH 10/10] =?UTF-8?q?feat:=E5=8E=BB=E9=99=A4log=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns/CacheManager/MSDKDnsParamsManager.h | 1 + MSDKDns/MSDKDnsService.m | 4 ++-- MSDKDns/WCDB/MSDKDnsDB.m | 2 -- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/MSDKDns/CacheManager/MSDKDnsParamsManager.h b/MSDKDns/CacheManager/MSDKDnsParamsManager.h index e064a63..08bec4a 100644 --- a/MSDKDns/CacheManager/MSDKDnsParamsManager.h +++ b/MSDKDns/CacheManager/MSDKDnsParamsManager.h @@ -53,5 +53,6 @@ - (NSDictionary *)msdkDnsGetIPRankData; - (BOOL)msdkDnsGetEnableKeepDomainsAlive; - (BOOL)msdkDnsGetExpiredIPEnabled; +- (BOOL)msdkDnsGetPersistCacheIPEnabled; @end diff --git a/MSDKDns/MSDKDnsService.m b/MSDKDns/MSDKDnsService.m index 7c23cd3..b6d313a 100644 --- a/MSDKDns/MSDKDnsService.m +++ b/MSDKDns/MSDKDnsService.m @@ -539,9 +539,9 @@ - (void)cacheDomainInfo:(MSDKDnsResolver *)resolver { } if (cacheDict && domain) { - NSLog(@"cacheDict = %@", cacheDict); [[MSDKDnsManager shareInstance] cacheDomainInfo:cacheDict Domain:domain]; - if (resolver && resolver != self.localDnsResolver){ + BOOL persistCacheIPEnabled = [[MSDKDnsParamsManager shareInstance] msdkDnsGetPersistCacheIPEnabled]; + if (resolver && resolver != self.localDnsResolver && persistCacheIPEnabled){ [[MSDKDnsDB shareInstance] insertOrReplaceDomainInfo:cacheDict Domain:domain]; } } diff --git a/MSDKDns/WCDB/MSDKDnsDB.m b/MSDKDns/WCDB/MSDKDnsDB.m index 76734a0..7d5427b 100644 --- a/MSDKDns/WCDB/MSDKDnsDB.m +++ b/MSDKDns/WCDB/MSDKDnsDB.m @@ -117,8 +117,6 @@ - (void)insertOrReplaceDomainInfo:(NSDictionary *)domainInfo Domain:(NSString *) } @catch (NSException *exception) { MSDKDNSLOG(@"Failed to insert data into database"); } - NSDictionary *result = [self getDataFromDB]; - NSLog(@"loadDB domainInfo = %@",result); } }