Skip to content

Commit

Permalink
feat: 增加线路IP配置参数
Browse files Browse the repository at this point in the history
  • Loading branch information
Vastness committed May 17, 2021
1 parent 623ba08 commit 2efe331
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
8 changes: 4 additions & 4 deletions MSDKDns.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions MSDKDns/CacheManager/MSDKDnsParamsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- (void)msdkDnsSetMAppId:(NSString *) mdnsAppId MTimeOut:(int)mdnsTimeOut MEncryptType:(HttpDnsEncryptType)mdnsEncryptType;
- (void)msdkDnsSetMAppId:(NSString *) mdnsAppId MToken:(NSString* )mdnsToken MTimeOut:(int)mdnsTimeOut MEncryptType:(HttpDnsEncryptType)mdnsEncryptType;
- (void)msdkDnsSetMDnsId:(int) mdnsId MDnsKey:(NSString *)mdnsKey;
- (void)msdkDnsSetRouteIp:(NSString *)routeIp;

- (NSString *) msdkDnsGetMDnsIp;
- (NSString *) msdkDnsGetMOpenId;
Expand All @@ -27,4 +28,5 @@
- (float) msdkDnsGetMTimeOut;
- (HttpDnsEncryptType)msdkDnsGetEncryptType;
- (NSString *)msdkDnsGetMToken;
- (NSString *)msdkDnsGetRouteIp;
@end
11 changes: 11 additions & 0 deletions MSDKDns/CacheManager/MSDKDnsParamsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ @interface MSDKDnsParamsManager()
@property (strong, nonatomic, readwrite) NSString * msdkDnsKey;
@property (assign, nonatomic, readwrite) int msdkDnsTimeOut;
@property (assign, nonatomic, readwrite) HttpDnsEncryptType msdkEncryptType;
@property (strong, nonatomic, readwrite) NSString *msdkDnsRouteIp;

@end

Expand Down Expand Up @@ -83,6 +84,12 @@ - (void)msdkDnsSetMDnsId:(int) mdnsId MDnsKey:(NSString *)mdnsKey {
});
}

- (void)msdkDnsSetRouteIp:(NSString *)routeIp {
dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{
self.msdkDnsRouteIp = routeIp;
});
}

- (NSString *) msdkDnsGetMDnsIp {
return [_msdkDnsIp copy];
}
Expand Down Expand Up @@ -122,4 +129,8 @@ - (HttpDnsEncryptType)msdkDnsGetEncryptType
return _msdkEncryptType;
}

- (NSString *)msdkDnsGetRouteIp {
return _msdkDnsRouteIp;
}

@end
2 changes: 1 addition & 1 deletion MSDKDns/MSDKDns.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct DnsConfig {
BOOL debug; // 是否开启Debug日志,YES:开启,NO:关闭。建议联调阶段开启,正式上线前关闭
int timeout; // 超时时间,单位ms,如设置0,则设置为默认值2000ms
HttpDnsEncryptType encryptType; // 控制加密方式
NSString* routeIp; // 线路IP地址
NSString* routeIp; // 查询线路IP地址
};

@interface MSDKDns : NSObject
Expand Down
1 change: 1 addition & 0 deletions MSDKDns/MSDKDns.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ - (BOOL) initConfig:(DnsConfig *)config {
[[MSDKDnsParamsManager shareInstance] msdkDnsSetMAppId:config->appId MToken:config->token MTimeOut:config->timeout MEncryptType:config->encryptType];
[[MSDKDnsParamsManager shareInstance] msdkDnsSetMDnsId:config->dnsId MDnsKey:config->dnsKey];
[[MSDKDnsParamsManager shareInstance] msdkDnsSetMDnsIp:config->dnsIp];
[[MSDKDnsParamsManager shareInstance] msdkDnsSetRouteIp: config->routeIp];
return YES;
}

Expand Down
5 changes: 5 additions & 0 deletions MSDKDns/MSDKDnsInfoTool.m
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ + (NSURL *) httpsUrlWithDomain:(NSString *)domain DnsId:(int)dnsId DnsKey:(NSStr
}

NSString *serviceIp = [[MSDKDnsParamsManager shareInstance] msdkDnsGetMDnsIp];
NSString *routeIp = [[MSDKDnsParamsManager shareInstance] msdkDnsGetRouteIp];

if (domainEncrypStr && domainEncrypStr.length > 0) {
NSString * httpServer = [self getIPv6:[serviceIp UTF8String]];
if (!httpServer || httpServer.length == 0) {
Expand All @@ -432,6 +434,9 @@ + (NSURL *) httpsUrlWithDomain:(NSString *)domain DnsId:(int)dnsId DnsKey:(NSStr
} else if (encryptType == HttpDnsEncryptTypeHTTPS) {
urlStr = [urlStr stringByAppendingFormat:@"&token=%@", token];
}
if (routeIp && routeIp.length > 0) {
urlStr = [urlStr stringByAppendingFormat:@"&ip=%@", routeIp];
}
NSURL * url = [NSURL URLWithString:urlStr];
MSDKDNSLOG(@"httpdns service url: %@",url);
return url;
Expand Down

0 comments on commit 2efe331

Please sign in to comment.