Skip to content

Commit

Permalink
Merge pull request #38 from HuYuee/feature/dynamicIP
Browse files Browse the repository at this point in the history
Feature/v1.11.0
  • Loading branch information
HuYuee authored Nov 6, 2024
2 parents 0324b10 + 95665c3 commit 2fcffb4
Show file tree
Hide file tree
Showing 9 changed files with 280 additions and 117 deletions.
16 changes: 8 additions & 8 deletions MSDKDns.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@
LINK_WITH_STANDARD_LIBRARIES = NO;
MACH_O_TYPE = mh_object;
MACOSX_DEPLOYMENT_TARGET = "";
MARKETING_VERSION = 1.10.5;
MARKETING_VERSION = 1.11.0;
ONLY_ACTIVE_ARCH = NO;
OTHER_CFLAGS = "-fembed-bitcode";
OTHER_LDFLAGS = (
Expand Down Expand Up @@ -1104,7 +1104,7 @@
LINK_WITH_STANDARD_LIBRARIES = NO;
MACH_O_TYPE = mh_object;
MACOSX_DEPLOYMENT_TARGET = "";
MARKETING_VERSION = 1.10.5;
MARKETING_VERSION = 1.11.0;
OTHER_CFLAGS = "-fembed-bitcode";
OTHER_LDFLAGS = (
"-ObjC",
Expand Down Expand Up @@ -1147,7 +1147,7 @@
LINK_WITH_STANDARD_LIBRARIES = NO;
MACH_O_TYPE = mh_object;
MACOSX_DEPLOYMENT_TARGET = "";
MARKETING_VERSION = 1.10.5;
MARKETING_VERSION = 1.11.0;
ONLY_ACTIVE_ARCH = NO;
OTHER_CFLAGS = "-fembed-bitcode";
OTHER_LDFLAGS = (
Expand Down Expand Up @@ -1189,7 +1189,7 @@
LINK_WITH_STANDARD_LIBRARIES = NO;
MACH_O_TYPE = mh_object;
MACOSX_DEPLOYMENT_TARGET = "";
MARKETING_VERSION = 1.10.5;
MARKETING_VERSION = 1.11.0;
OTHER_CFLAGS = "-fembed-bitcode";
OTHER_LDFLAGS = (
"-ObjC",
Expand Down Expand Up @@ -1238,7 +1238,7 @@
LINK_WITH_STANDARD_LIBRARIES = NO;
MACH_O_TYPE = mh_object;
MACOSX_DEPLOYMENT_TARGET = "";
MARKETING_VERSION = 1.10.5;
MARKETING_VERSION = 1.11.0;
ONLY_ACTIVE_ARCH = NO;
OTHER_CFLAGS = "-fembed-bitcode";
OTHER_LDFLAGS = (
Expand Down Expand Up @@ -1286,7 +1286,7 @@
LINK_WITH_STANDARD_LIBRARIES = NO;
MACH_O_TYPE = mh_object;
MACOSX_DEPLOYMENT_TARGET = "";
MARKETING_VERSION = 1.10.5;
MARKETING_VERSION = 1.11.0;
OTHER_CFLAGS = "-fembed-bitcode";
OTHER_LDFLAGS = (
"-ObjC",
Expand Down Expand Up @@ -1324,7 +1324,7 @@
LINK_WITH_STANDARD_LIBRARIES = NO;
MACH_O_TYPE = mh_object;
MACOSX_DEPLOYMENT_TARGET = "";
MARKETING_VERSION = 1.10.5;
MARKETING_VERSION = 1.11.0;
ONLY_ACTIVE_ARCH = NO;
OTHER_CFLAGS = "-fembed-bitcode";
OTHER_LDFLAGS = (
Expand Down Expand Up @@ -1364,7 +1364,7 @@
LINK_WITH_STANDARD_LIBRARIES = NO;
MACH_O_TYPE = mh_object;
MACOSX_DEPLOYMENT_TARGET = "";
MARKETING_VERSION = 1.10.5;
MARKETING_VERSION = 1.11.0;
OTHER_CFLAGS = "-fembed-bitcode";
OTHER_LDFLAGS = (
"-ObjC",
Expand Down
1 change: 0 additions & 1 deletion MSDKDns/CacheManager/MSDKDnsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ typedef enum {

- (NSString *)currentDnsServer;
- (void)switchDnsServer;
- (void)switchToMainServer;

// 添加domain进入延迟记录字典里面
- (void)msdkDnsAddDomainOpenDelayDispatch: (NSString *)domain;
Expand Down
349 changes: 267 additions & 82 deletions MSDKDns/CacheManager/MSDKDnsManager.m

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions MSDKDns/CacheManager/MSDKDnsNetworkManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ - (instancetype)init
}
//对保活域名发送解析请求
[self getHostsByKeepAliveDomains];
//重置ip指针
[[MSDKDnsManager shareInstance] switchToMainServer];

BOOL enableDetectHostServer = [[MSDKDnsParamsManager shareInstance] msdkDnsGetEnableDetectHostServer];
if (enableDetectHostServer) {
Expand Down
3 changes: 0 additions & 3 deletions MSDKDns/CacheManager/MSDKDnsParamsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
- (void)msdkDnsSetHttpOnly:(BOOL)httpOnly;
// 设置切换ip之前重试次数
- (void)msdkDnsSetRetryTimesBeforeSwitchServer:(NSUInteger)times;
// 设置切回主ip间隔时长
- (void)msdkDnsSetMinutesBeforeSwitchToMain:(NSUInteger)minutes;
// 设置备份ip
- (void)msdkDnsSetBackupServerIps: (NSArray *)ips;
- (void)msdkDnsSetEnableReport: (BOOL)enableReport;
Expand All @@ -47,7 +45,6 @@
- (BOOL)msdkDnsGetHttpOnly;
- (NSArray *)msdkDnsGetServerIps;
- (NSUInteger)msdkDnsGetRetryTimesBeforeSwitchServer;
- (NSUInteger)msdkDnsGetMinutesBeforeSwitchToMain;
- (BOOL)msdkDnsGetEnableReport;
- (BOOL)msdkDnsGetEnableDetectHostServer;
- (NSArray *)msdkDnsGetPreResolvedDomains;
Expand Down
13 changes: 0 additions & 13 deletions MSDKDns/CacheManager/MSDKDnsParamsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ @interface MSDKDnsParamsManager()
@property (assign, nonatomic, readwrite) BOOL httpOnly;
@property (strong, nonatomic, readwrite) NSArray* serverArray;
@property (assign, nonatomic, readwrite) NSUInteger retryTimesBeforeSwitchServer;
@property (assign, nonatomic, readwrite) NSUInteger minutesBeforeSwitchToMain;
@property (strong, nonatomic, readwrite) NSArray * backupServerIps;
@property (assign, nonatomic, readwrite) BOOL enableReport;
@property (strong, nonatomic, readwrite) NSArray* preResolvedDomains;
Expand Down Expand Up @@ -58,7 +57,6 @@ - (id) init {
_msdkDnsOpenId = HTTP_DNS_UNKNOWN_STR;
_msdkDnsAppId = HTTP_DNS_UNKNOWN_STR;
_retryTimesBeforeSwitchServer = 3;
_minutesBeforeSwitchToMain = 10;
_enableReport = NO;
_msdkAddressType = HttpDnsAddressTypeAuto;
_enableKeepDomainsAlive = YES;
Expand Down Expand Up @@ -114,13 +112,6 @@ - (void)msdkDnsSetRetryTimesBeforeSwitchServer:(NSUInteger)times {
});
}

// 设置切回主ip间隔时长
- (void)msdkDnsSetMinutesBeforeSwitchToMain:(NSUInteger)minutes {
dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{
self.minutesBeforeSwitchToMain = minutes;
});
}

// 设置备份ip
- (void)msdkDnsSetBackupServerIps: (NSArray *)ips {
dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{
Expand Down Expand Up @@ -253,10 +244,6 @@ - (NSUInteger)msdkDnsGetRetryTimesBeforeSwitchServer {
return _retryTimesBeforeSwitchServer;
}

- (NSUInteger)msdkDnsGetMinutesBeforeSwitchToMain {
return _minutesBeforeSwitchToMain;
}

- (BOOL)msdkDnsGetEnableReport {
return _enableReport;
}
Expand Down
4 changes: 2 additions & 2 deletions MSDKDns/MSDKDns.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef __MSDKDns_H__
#define __MSDKDns_H__

#define MSDKDns_Version @"1.10.5"
#define MSDKDns_Version @"1.11.0"

#import <Foundation/Foundation.h>

Expand Down Expand Up @@ -35,7 +35,7 @@ typedef struct DnsConfigStruct {
NSString* routeIp; // 可选,DNS 请求的 ECS(EDNS-Client-Subnet)值,默认情况下 HTTPDNS 服务器会查询客户端出口 IP 为 DNS 线路查询 IP,可以指定线路 IP 地址。支持 IPv4/IPv6 地址传入
BOOL httpOnly;// 可选,是否仅返回 httpDns 解析结果。默认 false,即当 httpDns 解析失败时会返回 localDns 解析结果,设置为 true 时,仅返回 httpDns 的解析结果
NSUInteger retryTimesBeforeSwitchServer; // 可选,切换ip之前重试次数, 默认3次
NSUInteger minutesBeforeSwitchToMain; // 可选,设置切回主ip间隔时长,默认10分钟
NSUInteger minutesBeforeSwitchToMain __attribute__((deprecated("v1.11.0及以上不支持该设置"))); // 可选,设置切回主ip间隔时长,默认10分钟
BOOL enableReport; // 是否开启解析异常上报,默认NO,不上报
BOOL enableExperimentalBugly; // 实验性参数,仅提供给内部特定团队使用,请勿启用
} DnsConfig;
Expand Down
4 changes: 0 additions & 4 deletions MSDKDns/MSDKDns.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ - (BOOL) initConfig:(DnsConfig *)config {
if (config->retryTimesBeforeSwitchServer) {
[[MSDKDnsParamsManager shareInstance] msdkDnsSetRetryTimesBeforeSwitchServer: config->retryTimesBeforeSwitchServer];
}
if (config->minutesBeforeSwitchToMain) {
[[MSDKDnsParamsManager shareInstance] msdkDnsSetMinutesBeforeSwitchToMain:config->minutesBeforeSwitchToMain];
}
[[MSDKDnsParamsManager shareInstance] msdkDnsSetEnableReport:config->enableReport];
[[MSDKDnsManager shareInstance] fetchConfig:config->dnsId encryptType:config->encryptType dnsKey:config->dnsKey token:config->token];
MSDKDNSLOG(@"MSDKDns init success.");
Expand Down Expand Up @@ -110,7 +107,6 @@ - (BOOL) initConfigWithDictionary:(NSDictionary *)config {
conf->timeout = [[config objectForKey:@"timeout"] intValue];
conf->httpOnly = [[config objectForKey:@"httpOnly"] boolValue];
conf->retryTimesBeforeSwitchServer = [[config objectForKey:@"retryTimesBeforeSwitchServer"] intValue];
conf->minutesBeforeSwitchToMain = [[config objectForKey:@"minutesBeforeSwitchToMain"] intValue];
conf->enableReport = [[config objectForKey:@"enableReport"] boolValue];
conf->addressType = (HttpDnsAddressType)[[config objectForKey:@"addressType"] intValue];
return [self initConfig:conf];
Expand Down
5 changes: 3 additions & 2 deletions MSDKDns/MSDKDnsInfoTool.m
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,11 @@ + (NSString *)buildUrlStringWithDomain:(NSString *)domainEncrypStr domain:(NSStr
NSString *serviceIp = [[MSDKDnsManager shareInstance] currentDnsServer];
NSString *routeIp = [[MSDKDnsParamsManager shareInstance] msdkDnsGetRouteIp];
NSString *protocol = encryptType == HttpDnsEncryptTypeHTTPS ? @"https" : @"http";

NSString *sdkVersion = @"2_x.x.x";
BOOL isHTTPDNSDomain = NO;

#ifdef httpdnsIps_h
sdkVersion = [NSString stringWithFormat:@"2_%@", MSDKDns_Version];
#if IS_INTL
if ([MSDKDnsServerDomain_INTL isEqualToString:domain]){
isHTTPDNSDomain = YES;
Expand All @@ -475,7 +476,7 @@ + (NSString *)buildUrlStringWithDomain:(NSString *)domainEncrypStr domain:(NSStr
if (!httpServer || httpServer.length == 0) {
httpServer = serviceIp;
}
NSString *urlStr = [NSString stringWithFormat:@"%@://%@/d?dn=%@&clientip=1&ttl=1&query=1&id=%d", protocol, httpServer, domainEncrypStr, dnsId];
NSString *urlStr = [NSString stringWithFormat:@"%@://%@/d?dn=%@&clientip=1&ttl=1&query=1&id=%d&sdk=%@", protocol, httpServer, domainEncrypStr, dnsId, sdkVersion];
if (ipType == HttpDnsTypeIPv6) {
urlStr = [urlStr stringByAppendingString:@"&type=aaaa"];
}else if (ipType == HttpDnsTypeDual) {
Expand Down

0 comments on commit 2fcffb4

Please sign in to comment.