diff --git a/MSDKDns.xcodeproj/project.pbxproj b/MSDKDns.xcodeproj/project.pbxproj index 3b2f28c..460c6e3 100644 --- a/MSDKDns.xcodeproj/project.pbxproj +++ b/MSDKDns.xcodeproj/project.pbxproj @@ -959,7 +959,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 = 11.0; MACOSX_DEPLOYMENT_TARGET = ""; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = NO; @@ -1010,7 +1010,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MACOSX_DEPLOYMENT_TARGET = ""; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; @@ -1039,7 +1039,7 @@ GCC_INPUT_FILETYPE = sourcecode.cpp.objcpp; INFOPLIST_FILE = MSDKDns/Info.plist; INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)"; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(SYSTEM_LIBRARY_DIR)/Tcl/sqlite3", @@ -1047,7 +1047,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.8.1; + MARKETING_VERSION = 1.9.0; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1086,7 +1086,7 @@ GCC_INPUT_FILETYPE = sourcecode.cpp.objcpp; INFOPLIST_FILE = MSDKDns/Info.plist; INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)"; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(SYSTEM_LIBRARY_DIR)/Tcl/sqlite3", @@ -1094,7 +1094,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.8.1; + MARKETING_VERSION = 1.9.0; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", @@ -1133,11 +1133,11 @@ ); INFOPLIST_FILE = MSDKDns/Info.plist; INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)"; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.8.1; + MARKETING_VERSION = 1.9.0; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1175,11 +1175,11 @@ GCC_PREPROCESSOR_DEFINITIONS = "IS_INTL=1"; INFOPLIST_FILE = MSDKDns/Info.plist; INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)"; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.8.1; + MARKETING_VERSION = 1.9.0; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", @@ -1220,7 +1220,7 @@ ); INFOPLIST_FILE = MSDKDns/Info.plist; INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)"; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(SYSTEM_LIBRARY_DIR)/Tcl/sqlite3", @@ -1228,7 +1228,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.8.1; + MARKETING_VERSION = 1.9.0; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1268,7 +1268,7 @@ GCC_PREPROCESSOR_DEFINITIONS = "IS_INTL=1"; INFOPLIST_FILE = MSDKDns/Info.plist; INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)"; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(SYSTEM_LIBRARY_DIR)/Tcl/sqlite3", @@ -1276,7 +1276,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.8.1; + MARKETING_VERSION = 1.9.0; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", @@ -1310,11 +1310,11 @@ GCC_INPUT_FILETYPE = sourcecode.cpp.objcpp; INFOPLIST_FILE = MSDKDns/Info.plist; INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)"; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.8.1; + MARKETING_VERSION = 1.9.0; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1350,11 +1350,11 @@ GCC_INPUT_FILETYPE = sourcecode.cpp.objcpp; INFOPLIST_FILE = MSDKDns/Info.plist; INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)"; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.8.1; + MARKETING_VERSION = 1.9.0; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", diff --git a/MSDKDns/CacheManager/MSDKDnsManager.h b/MSDKDns/CacheManager/MSDKDnsManager.h index 94c2129..7ddfe59 100644 --- a/MSDKDns/CacheManager/MSDKDnsManager.h +++ b/MSDKDns/CacheManager/MSDKDnsManager.h @@ -30,7 +30,7 @@ typedef enum { - (void)dnsHasDone:(MSDKDnsService *)service; - (void)cacheDomainInfo:(NSDictionary *)domainInfo Domain:(NSString *)domain; - (void)clearCacheForDomain:(NSString *)domain; -- (void)clearCacheForDomains:(NSArray *)domains; +- (void)clearCacheForDomains:(NSArray *)domains; - (void)clearAllCache; - (NSDictionary *)getDnsDetail:(NSString *)domain; diff --git a/MSDKDns/CacheManager/MSDKDnsManager.m b/MSDKDns/CacheManager/MSDKDnsManager.m index 0f028bb..54cd45f 100644 --- a/MSDKDns/CacheManager/MSDKDnsManager.m +++ b/MSDKDns/CacheManager/MSDKDnsManager.m @@ -29,6 +29,7 @@ @interface MSDKDnsManager () @property (nonatomic, assign, readwrite) HttpDnsSdkStatus sdkStatus; @property (nonatomic, strong, readwrite) NSArray * dnsServers; @property (strong, nonatomic) NSMutableURLRequest *request; +@property (strong, nonatomic, readwrite) NSMutableDictionary * cacheDomainCountDict; @end @@ -43,6 +44,10 @@ - (void)dealloc { [self.serviceArray removeAllObjects]; [self setServiceArray:nil]; } + if (_cacheDomainCountDict) { + [self.cacheDomainCountDict removeAllObjects]; + [self setCacheDomainCountDict:nil]; + } } #pragma mark - init @@ -64,6 +69,7 @@ - (instancetype) init { _serviceArray = [[NSMutableArray alloc] init]; _sdkStatus = net_undetected; _dnsServers = [self defaultServers]; + _cacheDomainCountDict = [[NSMutableDictionary alloc] init]; } return self; } @@ -200,6 +206,55 @@ - (NSDictionary *)getHostsByNamesEnableExpired:(NSArray *)domains verbose:(BOOL) NSDictionary * result = verbose? [self fullResultDictionaryEnableExpired:domains fromCache:cacheDomainDict toEmpty:toEmptyDomains] : [self resultDictionaryEnableExpired:domains fromCache:cacheDomainDict toEmpty:toEmptyDomains]; + // 当开启乐观DNS之后,如果结果为0则上报errorCode=3,要所有结果都为0 + BOOL needReport = NO; + if (verbose) { + for (int i = 0; i < [domains count]; i++) { + NSString *domain = [domains objectAtIndex:i]; + NSDictionary *domainData = result[domain]; + if (domainData && domainData.count > 0) { + needReport = NO; + break; + } else { + needReport = YES; + } + } + } else { + for (int i = 0; i < [domains count]; i++) { + NSString *domain = [domains objectAtIndex:i]; + NSArray *domainResArray = result[domain]; + if (domainResArray && domainResArray.count > 0) { + if ([domainResArray[0] isEqualToString:@"0"] && [domainResArray[1] isEqualToString:@"0"]) { + needReport = YES; + } else { + needReport = NO; + break; + } + } else { + needReport = YES; + } + } + } + if (needReport && domains) { + for (int i = 0; i < [domains count]; i++) { + NSString *domain = [domains objectAtIndex:i]; + [[AttaReport sharedInstance] reportEvent:@{ + MSDKDns_ErrorCode: MSDKDns_NoData, + @"eventName": MSDKDnsEventHttpDnsCached, + @"dnsIp": [[MSDKDnsManager shareInstance] currentDnsServer], + @"req_dn": domain, + @"req_type": @"a", + @"req_timeout": @0, + @"req_ttl": @0, + @"req_query": @0, + @"req_ip": @"", + @"spend": @0, + @"statusCode": @0, + @"count": @1, + @"isCache": @1, + }]; + } + } return result; } @@ -566,14 +621,16 @@ - (void)clearCacheForDomain:(NSString *)domain { - (void)clearCacheForDomains:(NSArray *)domains { for(int i = 0; i < [domains count]; i++) { - NSString* domain = [domains objectAtIndex:i]; - [self clearCacheForDomain:domain]; + if ([[domains objectAtIndex:i] isKindOfClass:[NSString class]]) { + NSString* domain = [domains objectAtIndex:i]; + [self clearCacheForDomain:domain]; + } } } - (void)clearAllCache { dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ - MSDKDNSLOG(@"MSDKDns clearCache"); + MSDKDNSLOG(@"MSDKDns cleared all caches!"); if (self.domainDict) { [self.domainDict removeAllObjects]; self.domainDict = nil; @@ -583,26 +640,43 @@ - (void)clearAllCache { #pragma mark - uploadReport - (void)hitCacheAttaUploadReport:(NSString *)domain { - static int count = 0; - count ++; - if ([[MSDKDnsParamsManager shareInstance] msdkDnsGetEnableReport] && [[AttaReport sharedInstance] shoulReportDnsSpend]) { - [[AttaReport sharedInstance] reportEvent:@{ - MSDKDns_ErrorCode: MSDKDns_Success, - @"eventName": MSDKDnsEventHttpDnsCached, - @"dnsIp": [[MSDKDnsManager shareInstance] currentDnsServer], - @"req_dn": domain, - @"req_type": @"a", - @"req_timeout": @0, - @"req_ttl": @0, - @"req_query": @0, - @"req_ip": @"", - @"spend": @0, - @"statusCode": @0, - @"count":[NSString stringWithFormat:@"%d", count], - @"isCache": @1, - }]; - count = 0; - } + // 检查控制台解析监控上报开关是否开启 + if ([[MSDKDnsParamsManager shareInstance] msdkDnsGetEnableReport]) { + if (self.cacheDomainCountDict) { + NSNumber *num = self.cacheDomainCountDict[domain]; + if (num) { + int numInt = num.intValue + 1; + [self.cacheDomainCountDict setValue:[NSNumber numberWithInt:numInt] forKey:domain]; + } else { + [self.cacheDomainCountDict setValue:[NSNumber numberWithInt:1] forKey:domain]; + } + + if ([[AttaReport sharedInstance] shoulReportDnsSpend]) { + NSArray *dictKey = [self.cacheDomainCountDict allKeys]; + NSInteger length = [dictKey count]; + for (int i = 0; i < length; i++) { + id domainKey = [dictKey objectAtIndex:i]; + NSNumber *cacheCount = [self.cacheDomainCountDict objectForKey:domainKey]; + [[AttaReport sharedInstance] reportEvent:@{ + MSDKDns_ErrorCode: MSDKDns_Success, + @"eventName": MSDKDnsEventHttpDnsCached, + @"dnsIp": [[MSDKDnsManager shareInstance] currentDnsServer], + @"req_dn": domainKey, + @"req_type": @"a", + @"req_timeout": @0, + @"req_ttl": @0, + @"req_query": @0, + @"req_ip": @"", + @"spend": @0, + @"statusCode": @0, + @"count": cacheCount, + @"isCache": @1, + }]; + } + [self.cacheDomainCountDict removeAllObjects]; + } + } + } } - (void)uploadReport:(BOOL)isFromCache Domain:(NSString *)domain NetStack:(msdkdns::MSDKDNS_TLocalIPStack)netStack { @@ -1205,7 +1279,7 @@ - (void)switchToMainServer { - (void)resetDnsServers:(NSArray *)servers { self.waitToSwitch = YES; - dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ + dispatch_barrier_async([MSDKDnsInfoTool msdkdns_resolver_queue], ^{ NSMutableArray *array = [[NSMutableArray alloc] init]; if (servers && [servers count] > 0) { [array addObjectsFromArray: servers]; diff --git a/MSDKDns/MSDKDns.h b/MSDKDns/MSDKDns.h index 89b4b41..cc06fcf 100644 --- a/MSDKDns/MSDKDns.h +++ b/MSDKDns/MSDKDns.h @@ -5,7 +5,7 @@ #ifndef __MSDKDns_H__ #define __MSDKDns_H__ -#define MSDKDns_Version @"1.8.1" +#define MSDKDns_Version @"1.9.0" #import @@ -192,6 +192,11 @@ typedef struct DnsConfigStruct { */ - (void)clearCache; +/** + 需要清除的host域名数组。如果需要清空全部数据,传nil或者空数组即可 +*/ +- (void)clearHostCache:(NSArray *)hostArray; + #pragma mark-查询网络栈支持情况 /** 查询网络栈支持情况 diff --git a/MSDKDns/MSDKDns.m b/MSDKDns/MSDKDns.m index ab895ac..0fd9556 100644 --- a/MSDKDns/MSDKDns.m +++ b/MSDKDns/MSDKDns.m @@ -85,7 +85,7 @@ - (BOOL) initConfigWithDictionary:(NSDictionary *)config { conf->minutesBeforeSwitchToMain = [[config objectForKey:@"minutesBeforeSwitchToMain"] intValue]; conf->enableReport = [[config objectForKey:@"enableReport"] boolValue]; conf->addressType = (HttpDnsAddressType)[[config objectForKey:@"addressType"] intValue]; - return [self initConfig:conf]; + return [self initConfig:conf]; } #pragma mark - setting @@ -408,4 +408,12 @@ - (void)clearCache { [[MSDKDnsManager shareInstance] clearAllCache]; } +- (void)clearHostCache:(NSArray *)hostArray { + if (hostArray == nil || ([hostArray isKindOfClass:[NSArray class]] && hostArray.count == 0)) { + [[MSDKDnsManager shareInstance] clearAllCache]; + }else if ([hostArray isKindOfClass:[NSArray class]] && hostArray.count > 0){ + [[MSDKDnsManager shareInstance] clearCacheForDomains:hostArray]; + } +} + @end diff --git a/MSDKDns/MSDKDnsService.m b/MSDKDns/MSDKDnsService.m index ceddf3f..b792c71 100644 --- a/MSDKDns/MSDKDnsService.m +++ b/MSDKDns/MSDKDnsService.m @@ -135,7 +135,9 @@ - (void)startCheck:(float)timeOut DnsId:(int)dnsId DnsKey:(NSString *)dnsKey enc } BOOL httpOnly = [[MSDKDnsParamsManager shareInstance] msdkDnsGetHttpOnly]; - if (!httpOnly) { + BOOL expiredIPEnabled = [[MSDKDnsParamsManager shareInstance] msdkDnsGetExpiredIPEnabled]; + // 设置httpOnly为YES,或者开启了expiredIPEnabled过期IP的情况下,就不下发LocalDns请求 + if (!httpOnly && !expiredIPEnabled) { dispatch_async([MSDKDnsInfoTool msdkdns_resolver_queue], ^{ [self startLocalDns:timeOut DnsId:dnsId DnsKey:dnsKey]; }); @@ -302,67 +304,6 @@ - (void)resolver:(MSDKDnsResolver *)resolver didGetDomainInfo:(NSDictionary *)do } }]; - // 正常解析结果上报,上报解析耗时 - if ([[MSDKDnsParamsManager shareInstance] msdkDnsGetEnableReport]) { - NSDictionary *domainDic = [domainInfo objectForKey:[self.toCheckDomains firstObject]]; - NSString* routeip = [[MSDKDnsParamsManager shareInstance] msdkDnsGetRouteIp]; - if (!routeip) { - routeip = @""; - } - HttpsDnsResolver *httpResolver = (HttpsDnsResolver *)resolver; - NSString *timeConsuming = @""; - if (domainDic) { - if(resolver == self.httpDnsResolver_BOTH){ - NSDictionary *ipv4CacheValue = [domainDic objectForKey:@"ipv4"]; - NSDictionary *ipv6CacheValue = [domainDic objectForKey:@"ipv6"]; - if (ipv4CacheValue) { - timeConsuming = [ipv4CacheValue objectForKey:kDnsTimeConsuming]; - } - if (ipv6CacheValue) { - timeConsuming = [ipv6CacheValue objectForKey:kDnsTimeConsuming]; - } - }else{ - timeConsuming = [domainDic objectForKey:kDnsTimeConsuming]; - } - } - NSString *req_type = @"a"; - if (resolver == self.httpDnsResolver_4A) { - req_type = @"aaaa"; - }else if (resolver == self.httpDnsResolver_BOTH) { - req_type = @"addrs"; - } - - NSDictionary * dnsIPs = [self getDomainsDNSFromCache:self.toCheckDomains]; - NSString *localDnsIPs = [dnsIPs valueForKey:kMSDKDnsLDNS_IP]; - NSString *httpDnsIP_A = [dnsIPs valueForKey:kMSDKDns_A_IP]; - NSString *httpDnsIP_4A = [dnsIPs valueForKey:kMSDKDns_4A_IP]; - NSString *httpdnsIPs = @""; - - if ([httpDnsIP_A length] > 0 && [httpDnsIP_4A length] > 0) { - httpdnsIPs = [NSString stringWithFormat:@"%@,%@", httpDnsIP_A, httpDnsIP_4A]; - } else if ([httpDnsIP_A length] > 0) { - httpdnsIPs = [NSString stringWithFormat:@"%@", httpDnsIP_A]; - } else if ([httpDnsIP_4A length] > 0) { - httpdnsIPs = [NSString stringWithFormat:@"%@", httpDnsIP_4A]; - } - [[AttaReport sharedInstance] reportEvent:@{ - MSDKDns_ErrorCode: MSDKDns_Success, - @"eventName": self.origin, - @"dnsIp": [[MSDKDnsManager shareInstance] currentDnsServer], - @"req_dn": [self.toCheckDomains componentsJoinedByString:@","], - @"req_type": req_type, - @"req_timeout": @(self.timeOut * 1000), - @"req_ttl": @1, - @"req_query": @1, - @"req_ip": routeip, - @"spend": timeConsuming, - @"statusCode": @(httpResolver.statusCode), - @"count": @1, - @"isCache": @0, - @"ldns": localDnsIPs, - @"hdns": httpdnsIPs, - }]; - } } if (resolver == self.httpDnsResolver_A || resolver == self.httpDnsResolver_BOTH) { @@ -540,7 +481,6 @@ - (void)resolver:(MSDKDnsResolver *)resolver getDomainError:(NSString *)error re }; [self callBack:resolver Info:info]; }); - [self dnsTimeoutAttaUpload:resolver]; } } @@ -622,7 +562,7 @@ - (void) retryHttpDns:(MSDKDnsResolver *)resolver { }; [self callBack:resolver Info:info]; }); - [self dnsTimeoutAttaUpload:resolver]; +// [self dnsTimeoutAttaUpload:resolver]; [[MSDKDnsManager shareInstance] switchDnsServer]; } } @@ -684,6 +624,116 @@ - (void)callBack:(MSDKDnsResolver *)resolver Info:(NSDictionary *)info { [self callNotify]; } } + //LocalHttp 和 HttpDns均完成,则返回结果 + if (httpOnly || self.localDnsResolver.isFinished) { + if (self.httpDnsResolver_A && self.httpDnsResolver_4A) { + if (self.httpDnsResolver_A.isFinished && self.httpDnsResolver_4A.isFinished) { + [self reportDataTransform]; + } + } else if (self.httpDnsResolver_A && !self.httpDnsResolver_4A) { + if (self.httpDnsResolver_A.isFinished) { + [self reportDataTransform]; + } + } else if (!self.httpDnsResolver_A && self.httpDnsResolver_4A) { + if (self.httpDnsResolver_4A.isFinished) { + [self reportDataTransform]; + } + } else if (self.httpDnsResolver_BOTH) { + if (self.httpDnsResolver_BOTH.isFinished) { + [self reportDataTransform]; + } + } + } +} + +- (void)reportDataTransform { + + BOOL httpOnly = [[MSDKDnsParamsManager shareInstance] msdkDnsGetHttpOnly]; + NSDictionary * tempDict = [[MSDKDnsManager shareInstance] domainDict]; + + // 当开启上报服务时 + if ([[MSDKDnsParamsManager shareInstance] msdkDnsGetEnableReport]) { + NSDictionary *domainDic = [tempDict objectForKey:[self.toCheckDomains firstObject]]; + NSString* routeip = [[MSDKDnsParamsManager shareInstance] msdkDnsGetRouteIp]; + if (!routeip) { + routeip = @""; + } + NSString *timeConsuming = @""; + if (domainDic) { + NSDictionary *ipv4CacheValue = [domainDic objectForKey:kMSDKHttpDnsCache_A]; + NSDictionary *ipv6CacheValue = [domainDic objectForKey:kMSDKHttpDnsCache_4A]; + if (ipv4CacheValue) { + timeConsuming = [ipv4CacheValue objectForKey:kDnsTimeConsuming]; + } + if (ipv6CacheValue) { + timeConsuming = [ipv6CacheValue objectForKey:kDnsTimeConsuming]; + } + } + NSString *req_type = @"a"; + NSNumber *status = @0; + if (self.httpDnsResolver_A) { + status = @(self.httpDnsResolver_A.statusCode); + }else if (self.httpDnsResolver_4A) { + req_type = @"aaaa"; + status = @(self.httpDnsResolver_4A.statusCode); + }else if (self.httpDnsResolver_BOTH) { + req_type = @"addrs"; + status = @(self.httpDnsResolver_BOTH.statusCode); + } + + NSDictionary * dnsIPs = [self getDomainsDNSFromCache:self.toCheckDomains]; + NSString *localDnsIPs = [dnsIPs valueForKey:kMSDKDnsLDNS_IP]; + NSString *httpDnsIP_A = [dnsIPs valueForKey:kMSDKDns_A_IP]; + NSString *httpDnsIP_4A = [dnsIPs valueForKey:kMSDKDns_4A_IP]; + NSString *httpdnsIPs = @""; + + if ([httpDnsIP_A length] > 0 && [httpDnsIP_4A length] > 0) { + httpdnsIPs = [NSString stringWithFormat:@"%@,%@", httpDnsIP_A, httpDnsIP_4A]; + } else if ([httpDnsIP_A length] > 0) { + httpdnsIPs = [NSString stringWithFormat:@"%@", httpDnsIP_A]; + } else if ([httpDnsIP_4A length] > 0) { + httpdnsIPs = [NSString stringWithFormat:@"%@", httpDnsIP_4A]; + } + + NSNumber *localDNSSpend = [NSNumber numberWithInt:-1]; + // 当httpOnly未开启时,对localDNS时延进行上报。否则上报-1来区分 + if (!httpOnly) { + for(int i = 0; i < [self.toCheckDomains count]; i++) { + NSString *domain = [self.toCheckDomains objectAtIndex:i]; + NSDictionary * domainData = [tempDict objectForKey:domain]; + + if (domainData) { + NSDictionary *localDNSData = [domainData objectForKey:kMSDKLocalDnsCache]; + if (localDNSData) { + int spend = [[localDNSData objectForKey:kDnsTimeConsuming] intValue]; + // 针对批量解析,localDNS解析时延取最大值 + if (spend > 0 && [localDNSSpend intValue] < spend) { + localDNSSpend = @(spend); + } + } + } + } + } + + [[AttaReport sharedInstance] reportEvent:@{ + MSDKDns_ErrorCode: MSDKDns_Success, + @"eventName": self.origin, + @"dnsIp": [[MSDKDnsManager shareInstance] currentDnsServer], + @"req_dn": [self.toCheckDomains componentsJoinedByString:@","], + @"req_type": req_type, + @"req_timeout": @(self.timeOut * 1000), + @"req_ttl": @1, + @"req_query": @1, + @"req_ip": routeip, + @"spend": timeConsuming, + @"ldns_spend": localDNSSpend, + @"statusCode": status, + @"count": @1, + @"isCache": @0, + @"ldns": localDnsIPs, + @"hdns": httpdnsIPs, + }]; + } } - (void)callNotify {