Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: v4.8.0 #27

Merged
merged 31 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1971554
feat: 修改ttl数据格式并赋值处理
lemondark Sep 27, 2023
1e38506
feat: ttl不序列化处理&ttl仅做计算过期时间使用,命中缓存结果不再处理ttl
lemondark Sep 28, 2023
12e7776
feat: 以requestname为基准来判断是否下发乐观dns的异步解析请求
lemondark Sep 28, 2023
eba10e4
fix: 代码质量管理
lemondark Oct 24, 2023
141eb9a
feat: 代码质量治理
lemondark Oct 26, 2023
40016d9
feat: 代码质量治理
lemondark Oct 26, 2023
484ab91
feat: 代码规范质量处理
lemondark Oct 27, 2023
37fd7f6
fix: 代码质量管理,包命名规范
lemondark Oct 27, 2023
0fee20c
fix: 代码质量管理
lemondark Oct 27, 2023
66df9e1
Merge remote-tracking branch 'fork/master' into feature/ttlChange
lemondark Nov 6, 2023
dafcf59
Merge branch 'fix/codecc' into feature/ttlChange
lemondark Nov 7, 2023
fa38c71
fix: fix merge error
lemondark Nov 8, 2023
23ae38c
feat: 缓存清除不再使用线程处理,采用expiredTime判断
lemondark Nov 8, 2023
e46bfad
feat: 后台接口请求成功但解析结果返回异常时,清除本地缓存。
lemondark Nov 20, 2023
5c03991
feat: 对于正常状态返回为空的值,需清除之前缓存值
lemondark Nov 20, 2023
adec83f
feat: 乐观DNS场景下,底层返回401或者200状态码且返回解析结果无效时,清除本地缓存。优化处理
lemondark Nov 21, 2023
068068c
feat: 代码质量规范调整
lemondark Nov 22, 2023
af74664
feat: 代码质量管理
lemondark Nov 23, 2023
7940e5f
feat: 代码质量管理
lemondark Nov 23, 2023
51cfcb9
feat: 代码质量管理
lemondark Nov 24, 2023
b741fda
feat: 代码质量管理
lemondark Nov 24, 2023
fcee365
feat: 圈复杂度处理-tryGetResultFromCache优化
lemondark Nov 24, 2023
2f170d1
feat: 代码质量管理
lemondark Nov 24, 2023
d7dbbc7
feat: https加密请求下,deskey为非必需
lemondark Nov 28, 2023
9a47801
feat: 圈复杂度优化
lemondark Dec 5, 2023
0b3e8af
feat:圈复杂度调整
lemondark Dec 5, 2023
c52dbf4
fix: 圈复杂度优化
lemondark Dec 5, 2023
01fa938
feat: lookup圈复杂度调整1
lemondark Dec 8, 2023
f182c5e
feat: 圈复杂度处理
lemondark Dec 11, 2023
71fb082
feat: 代码质量规范
lemondark Dec 11, 2023
7b7ca3a
fix: bug fix
lemondark Dec 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# 对外接口类
-keep public class com.tencent.msdk.dns.DnsService {*;}
-keep public class com.tencent.msdk.dns.core.IpSet {*;}
-keep public class com.tencent.msdk.dns.core.ipRank.IpRankItem {*;}
-keep public class com.tencent.msdk.dns.core.rank.IpRankItem {*;}
-keep public class com.tencent.msdk.dns.DnsConfig {*;}
-keep public class com.tencent.msdk.dns.HttpDnsResponseObserver {*;}
-keep public class com.tencent.msdk.dns.DnsConfig$Builder {*;}
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/com/tencent/msdk/dns/BackupResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ private BackupResolver() {
// 尝试切回主ip的间隔时间,默认为10分钟
private final long mInterval = 10 * 60 * 1000;

public static BackupResolver getInstance() {//静态get方法
public static BackupResolver getInstance() {
// 静态get方法
if (mBackupResolver == null) {
synchronized (BackupResolver.class) {
if (mBackupResolver == null) {
Expand All @@ -53,7 +54,7 @@ public static BackupResolver getInstance() {//静态get方法
public void init(DnsConfig dnsConfig) {
mConfig = dnsConfig;
mErrorCount = new AtomicInteger(0);
// http和https是两个IP
// http和https是两个IP
dnsIps = getBackUpIps();
}

Expand All @@ -66,9 +67,11 @@ public void getServerIps() {

private ArrayList getBackUpIps() {
if (Const.HTTPS_CHANNEL.equals(mConfig.channel) && !BuildConfig.HTTPS_TOLERANCE_SERVER.isEmpty()) {
return new ArrayList<String>(Arrays.asList(BuildConfig.HTTPS_INIT_SERVER, BuildConfig.HTTPS_TOLERANCE_SERVER));
return new ArrayList<String>(Arrays.asList(BuildConfig.HTTPS_INIT_SERVER,
BuildConfig.HTTPS_TOLERANCE_SERVER));
} else {
return new ArrayList<String>(Arrays.asList(BuildConfig.HTTP_INIT_SERVER, BuildConfig.HTTP_TOLERANCE_SERVER));
return new ArrayList<String>(Arrays.asList(BuildConfig.HTTP_INIT_SERVER,
BuildConfig.HTTP_TOLERANCE_SERVER));
}
}

Expand Down Expand Up @@ -97,12 +100,10 @@ public boolean getCanReport(int errorCount) {

/**
* 主IP故障,切换备份IP策略
* 1. 主备IP切换:在精确性、速度上折中处理,主IP解析的同时,会发起LocalDNS解析,若主IP首次解析不成功,立即返回 上次解析结果,如果没有上次解析结果,则返回LocalDNS解析结果,如果主IP 3次解析不成功,则切换到备份IP进行解析。
* <p>
* 2. 备份IP 切换 域名兜底:所有备份IP都经超过3次不通,切换到域名兜底解析。
* <p>
* 1. 主备IP切换:在精确性、速度上折中处理,主IP解析的同时,会发起LocalDNS解析,若主IP首次解析不成功,立即返回
* 上次解析结果,如果没有上次解析结果,则返回LocalDNS解析结果,如果主IP 3次解析不成功,则切换到备份IP进行解析。
* 2. 备份IP切换 域名兜底:所有备份IP都经超过3次不通,切换到域名兜底解析。
* 3. 恢复:每隔10min切回测试一次主IP(不主动探测主备IP是否恢复)
* <p>
* 4. 通过参数控制 切换策略的次数判断(默认3次)、恢复主IP策略的时间间隔(默认10min)
*/
public String getDnsIp() {
Expand Down Expand Up @@ -143,7 +144,8 @@ public void run() {
try {
String dnsIp = BackupResolver.getInstance().getDnsIp();
String domain = BuildConfig.DOMAIN_SERVICE_DOMAINS[0];
LookupExtra lookupExtra = new LookupExtra(BuildConfig.DOMAIN_SERVICE_ID, BuildConfig.DOMSIN_SERVICE_KEY, BuildConfig.DOMAIN_SERVICE_TOKEN);
LookupExtra lookupExtra = new LookupExtra(BuildConfig.DOMAIN_SERVICE_ID,
BuildConfig.DOMSIN_SERVICE_KEY, BuildConfig.DOMAIN_SERVICE_TOKEN);
LookupParameters lookupParameters = new LookupParameters.Builder<LookupExtra>()
.dnsIp(dnsIp)
.channel("DesHttp")
Expand Down
141 changes: 76 additions & 65 deletions src/main/java/com/tencent/msdk/dns/DnsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.tencent.msdk.dns.base.report.IReporter;
import com.tencent.msdk.dns.base.utils.CommonUtils;
import com.tencent.msdk.dns.core.Const;
import com.tencent.msdk.dns.core.ipRank.IpRankItem;
import com.tencent.msdk.dns.core.rank.IpRankItem;
import com.tencent.msdk.dns.core.rest.share.LookupExtra;

import java.util.ArrayList;
Expand Down Expand Up @@ -62,16 +62,13 @@ public final class DnsConfig {

public String routeIp;

private DnsConfig(int logLevel,
String appId, String userId, boolean initBuiltInReporters,
String dnsId, String dnsKey, String token,
int timeoutMills,
Set<WildcardDomain> protectedDomains,
Set<String> preLookupDomains, boolean enablePersistentCache, Set<String> persistentCacheDomains,
Set<IpRankItem> ipRankItems, String channel, boolean enableReport, boolean blockFirst,
private DnsConfig(int logLevel, String appId, String userId, boolean initBuiltInReporters, String dnsId,
String dnsKey, String token, int timeoutMills, Set<WildcardDomain> protectedDomains,
Set<String> preLookupDomains, boolean enablePersistentCache, Set<String> persistentCacheDomains
, Set<IpRankItem> ipRankItems, String channel, boolean enableReport, boolean blockFirst,
int customNetStack, DnsExecutors.ExecutorSupplier executorSupplier,
ILookedUpListener lookedUpListener, List<ILogNode> logNodes,
List<IReporter> reporters, boolean useExpiredIpEnable, boolean cachedIpEnable, String routeIp) {
ILookedUpListener lookedUpListener, List<ILogNode> logNodes, List<IReporter> reporters,
boolean useExpiredIpEnable, boolean cachedIpEnable, String routeIp) {
this.logLevel = logLevel;
this.appId = appId;
this.userId = userId;
Expand Down Expand Up @@ -114,30 +111,30 @@ boolean needProtect(/* @Nullable */String hostname) {

@Override
public String toString() {
return "DnsConfig{" +
"logLevel=" + logLevel +
", appId='" + appId + '\'' +
", userId='" + userId + '\'' +
", lookupExtra=" + lookupExtra +
", timeoutMills=" + timeoutMills +
", protectedDomains=" + CommonUtils.toString(protectedDomains) +
", preLookupDomains=" + CommonUtils.toString(preLookupDomains) +
", enablePersistentCache=" + enablePersistentCache +
", persistentCacheDomains=" + CommonUtils.toString(persistentCacheDomains) +
", IpRankItems=" + CommonUtils.toString(ipRankItems) +
", channel='" + channel + '\'' +
", enableReport='" + enableReport + '\'' +
", blockFirst=" + blockFirst +
", customNetStack=" + customNetStack +
", executorSupplier=" + executorSupplier +
", lookedUpListener=" + lookedUpListener +
", logNodes=" + CommonUtils.toString(logNodes) +
", reporters=" + CommonUtils.toString(reporters) +
", useExpiredIpEnable=" + useExpiredIpEnable +
", cachedIpEnable=" + cachedIpEnable +
", enableDomainServer=" + enableDomainServer +
", routeIp=" + routeIp +
'}';
return "DnsConfig{"
+ "logLevel=" + logLevel
+ ", appId='" + appId + '\''
+ ", userId='" + userId + '\''
+ ", lookupExtra=" + lookupExtra
+ ", timeoutMills=" + timeoutMills
+ ", protectedDomains=" + CommonUtils.toString(protectedDomains)
+ ", preLookupDomains=" + CommonUtils.toString(preLookupDomains)
+ ", enablePersistentCache=" + enablePersistentCache
+ ", persistentCacheDomains=" + CommonUtils.toString(persistentCacheDomains)
+ ", IpRankItems=" + CommonUtils.toString(ipRankItems)
+ ", channel='" + channel + '\''
+ ", enableReport='" + enableReport + '\''
+ ", blockFirst=" + blockFirst
+ ", customNetStack=" + customNetStack
+ ", executorSupplier=" + executorSupplier
+ ", lookedUpListener=" + lookedUpListener
+ ", logNodes=" + CommonUtils.toString(logNodes)
+ ", reporters=" + CommonUtils.toString(reporters)
+ ", useExpiredIpEnable=" + useExpiredIpEnable
+ ", cachedIpEnable=" + cachedIpEnable
+ ", enableDomainServer=" + enableDomainServer
+ ", routeIp=" + routeIp
+ '}';
}

/* @VisibleForTesting */
Expand Down Expand Up @@ -169,10 +166,10 @@ boolean contains(String hostname) {

@Override
public String toString() {
return "WildcardDomain{" +
"mIsWildcard=" + mIsWildcard +
", mNakedDomain='" + mNakedDomain + '\'' +
'}';
return "WildcardDomain{"
+ "mIsWildcard=" + mIsWildcard
+ ", mNakedDomain='" + mNakedDomain + '\''
+ '}';
}
}

Expand Down Expand Up @@ -232,14 +229,18 @@ public static final class Builder {
* SDK默认仅将日志通过logcat输出, tag统一使用HTTPDNS
* 不设置时, 默认输出<a href="https://developer.android.google.cn/reference/android/util/Log.html#WARN">WARN</a>及以上等级的日志
*
* @param logLevel 最低日志等级, 使用<a href="https://developer.android.google.cn/reference/android/util/Log">Log</a>类定义的常量, 可选值为
* @param logLevel 最低日志等级, 使用<a href="https://developer.android.google.cn/reference/android/util/Log">Log</a>
* 类定义的常量, 可选值为
* <a href="https://developer.android.google.cn/reference/android/util/Log.html#VERBOSE">VERBOSE</a>,
* <a href="https://developer.android.google.cn/reference/android/util/Log.html#DEBUG">DEBUG</a>,
* <a href="https://developer.android.google.cn/reference/android/util/Log.html#DEBUG">DEBUG</a>
* ,
* <a href="https://developer.android.google.cn/reference/android/util/Log.html#INFO">INFO</a>,
* <a href="https://developer.android.google.cn/reference/android/util/Log.html#WARN">WARN</a>,
* <a href="https://developer.android.google.cn/reference/android/util/Log.html#ERROR">ERROR</a>,
* <a href="https://developer.android.google.cn/reference/android/util/Log.html#ERROR">ERROR</a>
* ,
* <a href="https://developer.android.google.cn/reference/android/util/Log.html#ASSERT">ASSERT</a>,
* 其中<a href="https://developer.android.google.cn/reference/android/util/Log.html#ASSERT">ASSERT</a>即不输出任何日志
* 其中
* <a href="https://developer.android.google.cn/reference/android/util/Log.html#ASSERT">ASSERT</a>即不输出任何日志
* @return 当前Builder实例, 方便链式调用
*/
public Builder logLevel(int logLevel) {
Expand Down Expand Up @@ -280,7 +281,7 @@ public Builder userId(String userId) {
/**
* 启停缓存自动刷新功能, 默认开启
*
* @param enablePersistentCache, 启停缓存自动刷新功能
* @param enablePersistentCache 启停缓存自动刷新功能
* @return 当前Builder实例, 方便链式调用
*/
public Builder enablePersistentCache(boolean enablePersistentCache) {
Expand Down Expand Up @@ -342,12 +343,13 @@ public Builder dnsId(String dnsId) {
/**
* 设置DnsKey
*
* @param dnsKey dnsKey, 即HTTPDNS服务的授权Id对应的加密密钥, 从<a href="https://console.cloud.tencent.com/HttpDNS">腾讯云官网</a>申请获得
* @param dnsKey dnsKey, 即HTTPDNS服务的授权Id对应的加密密钥, 从<a href="https://console.cloud.tencent.com/HttpDNS">腾讯云官网</a>
* 申请获得
* @return 当前Builder实例, 方便链式调用
* @throws IllegalArgumentException dnsKey为空时抛出
*/
public Builder dnsKey(String dnsKey) {
if (TextUtils.isEmpty(dnsKey)) {
if (mChannel != Const.HTTPS_CHANNEL && TextUtils.isEmpty(dnsKey)) {
throw new IllegalArgumentException("dnsKey".concat(Const.EMPTY_TIPS));
}
mDnsKey = dnsKey;
Expand Down Expand Up @@ -391,8 +393,7 @@ public Builder timeoutMills(int timeoutMills) {
*/
public Builder maxNumOfPreLookupDomains(int maxNumOfPreLookupDomains) {
if (0 >= maxNumOfPreLookupDomains) {
throw new IllegalArgumentException(
"maxNumOfPreLookupDomains".concat(Const.LESS_THAN_0_TIPS));
throw new IllegalArgumentException("maxNumOfPreLookupDomains".concat(Const.LESS_THAN_0_TIPS));
}
mMaxNumOfPreLookupDomains = maxNumOfPreLookupDomains;
return this;
Expand Down Expand Up @@ -558,7 +559,8 @@ public Builder ipRankItems(List<IpRankItem> ipRankItems) {

public Builder channel(String channel) {
if (channel.equals(Const.HTTPS_CHANNEL) && BuildConfig.FLAVOR.equals("intl")) {
throw new IllegalArgumentException("httpdns-sdk-intl version still doesn't support " + Const.HTTPS_CHANNEL);
throw new IllegalArgumentException("httpdns-sdk-intl version still doesn't support "
+ Const.HTTPS_CHANNEL);
}
mChannel = channel;
return this;
Expand All @@ -576,7 +578,8 @@ public Builder desHttp() {

public Builder https() {
if (BuildConfig.FLAVOR.equals("intl")) {
throw new IllegalArgumentException("httpdns-sdk-intl version still doesn't support " + Const.HTTPS_CHANNEL);
throw new IllegalArgumentException("httpdns-sdk-intl version still doesn't support "
+ Const.HTTPS_CHANNEL);
}
mChannel = Const.HTTPS_CHANNEL;
return this;
Expand Down Expand Up @@ -618,16 +621,17 @@ public Builder nonBlockFirst() {

/**
* 设置{@link DnsExecutors.ExecutorSupplier}, 用于为SDK定制线程池
* 不设置时, 默认使用<a href="https://developer.android.com/reference/android/os/AsyncTask.html#THREAD_POOL_EXECUTOR">THREAD_POOL_EXECUTOR</a>作为SDK内部使用的线程池
* 不设置时, 默认使用
* <a href="https://developer.android.com/reference/android/os/AsyncTask.html#THREAD_POOL_EXECUTOR">THREAD_POOL_EXECUTOR</a>作为SDK内部使用的线程池
*
* @param executorSupplier {@link DnsExecutors.ExecutorSupplier}接口实现类实例, SDK通过{@link DnsExecutors.ExecutorSupplier#get()}获取SDK内部使用的线程池
* @param executorSupplier {@link DnsExecutors.ExecutorSupplier}接口实现类实例,
* SDK通过{@link DnsExecutors.ExecutorSupplier#get()}获取SDK内部使用的线程池
* @return 当前Builder实例, 方便链式调用
* @throws IllegalArgumentException executorSupplier为null时抛出
*/
public Builder executorSupplier(DnsExecutors.ExecutorSupplier executorSupplier) {
if (null == executorSupplier) {
throw new IllegalArgumentException(
"executorSupplier".concat(Const.NULL_POINTER_TIPS));
throw new IllegalArgumentException("executorSupplier".concat(Const.NULL_POINTER_TIPS));
}
mExecutorSupplier = executorSupplier;
return this;
Expand All @@ -642,8 +646,7 @@ public Builder executorSupplier(DnsExecutors.ExecutorSupplier executorSupplier)
*/
public Builder lookedUpListener(ILookedUpListener lookedUpListener) {
if (null == lookedUpListener) {
throw new IllegalArgumentException(
"lookedUpListener".concat(Const.NULL_POINTER_TIPS));
throw new IllegalArgumentException("lookedUpListener".concat(Const.NULL_POINTER_TIPS));
}
mLookedUpListener = lookedUpListener;
return this;
Expand Down Expand Up @@ -690,8 +693,10 @@ public Builder setCustomNetStack(int customNetStack) {
* 允许使用过期缓存
*
* @param useExpiredIpEnable 默认false,解析时先取未过期的缓存结果,不满足则等待解析请求完成后返回解析结果
* 设置为true时,会直接返回缓存的解析结果,没有缓存则返回0;0,用户可使用localdns(InetAddress)进行兜底。且在无缓存结果或缓存已过期时,会异步发起解析请求更新缓存。
* 因异步API(getAddrByNameAsync,getAddrsByNameAsync)逻辑在回调中始终返回未过期的解析结果,设置为true时,异步API不可使用。建议使用同步API (getAddrByName,getAddrsByName)
* 设置为true时,会直接返回缓存的解析结果,没有缓存则返回0;
* 0,用户可使用localdns(InetAddress)进行兜底。且在无缓存结果或缓存已过期时,会异步发起解析请求更新缓存。
* 因异步API(getAddrByNameAsync,getAddrsByNameAsync)逻辑在回调中始终返回未过期的解析结果,设置为true时,异步API
* 不可使用。建议使用同步API (getAddrByName,getAddrsByName)
* @return 当前Builder实例, 方便链式调用
*/
public Builder setUseExpiredIpEnable(boolean useExpiredIpEnable) {
Expand Down Expand Up @@ -728,14 +733,20 @@ public Builder routeIp(String routeIp) {
* @return DnsConfig实例
*/
public DnsConfig build() {
return new DnsConfig(mLogLevel,
mAppId, mUserId, mInitBuiltInReporters, mDnsId, mDnsKey, mToken,
mTimeoutMills,
mProtectedDomains, mPreLookupDomains, mEnablePersistentCache, mPersistentCacheDomains,
mIpRankItems, mChannel, mEnableReport, mBlockFirst,
mCustomNetStack, mExecutorSupplier,
mLookedUpListener, mLogNodes,
mReporters, mUseExpiredIpEnable, mCachedIpEnable, mRouteIp);
if (TextUtils.isEmpty(mDnsId)) {
throw new IllegalArgumentException("dnsId".concat(Const.EMPTY_TIPS));
}
if (mChannel != Const.HTTPS_CHANNEL && TextUtils.isEmpty(mDnsKey)) {
throw new IllegalArgumentException("dnsKey".concat(Const.EMPTY_TIPS));
}
if (mChannel == Const.HTTPS_CHANNEL && TextUtils.isEmpty(mToken)) {
throw new IllegalArgumentException("token".concat(Const.EMPTY_TIPS));
}
return new DnsConfig(mLogLevel, mAppId, mUserId, mInitBuiltInReporters, mDnsId, mDnsKey, mToken,
mTimeoutMills, mProtectedDomains, mPreLookupDomains, mEnablePersistentCache,
mPersistentCacheDomains, mIpRankItems, mChannel, mEnableReport, mBlockFirst, mCustomNetStack,
mExecutorSupplier, mLookedUpListener, mLogNodes, mReporters, mUseExpiredIpEnable, mCachedIpEnable
, mRouteIp);
}
}
}
Loading