opt http dns

This commit is contained in:
tongchenfei
2020-12-29 11:19:33 +08:00
parent 539d5a78c2
commit ed309f942b
7 changed files with 40 additions and 13 deletions

View File

@@ -484,6 +484,7 @@ dependencies {
implementation rootProject.ext.dependencies.moduleextensions
implementation rootProject.ext.dependencies.modulemap
implementation rootProject.ext.dependencies.moduleSmallMap
implementation rootProject.ext.dependencies.httpdnsmogo
} else {
implementation project(':foudations:mogo-commons')
implementation project(':foudations:mogo-base-websocket-sdk')
@@ -501,6 +502,7 @@ dependencies {
implementation project(':modules:mogo-module-extensions')
implementation project(':modules:mogo-module-map')
implementation project(':modules:mogo-module-smp')
implementation project(':foudations:httpdns-mogo')
}
apply from: "./functions/basedmap.gradle"
@@ -513,7 +515,7 @@ dependencies {
apply from: "./functions/crashreport.gradle"
apply from: "./functions/widgets.gradle"
apply from: "./functions/tts.gradle"
apply from: "./functions/httpdns.gradle"
// apply from: "./functions/httpdns.gradle"
apply from: "./functions/backwidget.gradle"
apply from: "./functions/mediaui.gradle"
apply from: "./functions/bizguide.gradle"

View File

@@ -6,8 +6,8 @@ project.dependencies {
demoImplementation rootProject.ext.dependencies.httpdnsnoop
onlineImplementation rootProject.ext.dependencies.httpdnsmogo
} else {
qaImplementation project(':foudations:httpdns-noop')
demoImplementation project(':foudations:httpdns-noop')
qaImplementation project(':foudations:httpdns-mogo')
demoImplementation project(':foudations:httpdns-mogo')
onlineImplementation project(':foudations:httpdns-mogo')
}
}

View File

@@ -32,7 +32,7 @@ dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation rootProject.ext.dependencies.arouter
annotationProcessor rootProject.ext.dependencies.aroutercompiler
implementation 'com.mogo.httpdns:httpdns-helper:1.0.7'
implementation 'com.mogo.httpdns:httpdns-helper:1.0.8'
if (Boolean.valueOf(RELEASE)) {
implementation rootProject.ext.dependencies.httpdnsbase

View File

@@ -25,6 +25,7 @@ import com.mogo.utils.network.HttpDns;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -49,6 +50,12 @@ public class MogoHttpDns implements IMogoHttpDns, HttpDns, OnAddressChangedListe
@Override
public void getHttpDnsIp(String host, int type, boolean useCache, IHttpDnsCallback callback) {
Logger.d("MogoHttpDns", "host: " + host + " type: " + type);
Logger.d("MogoHttpDns","all host: ");
Map<String,String> map = httpDnsHelper.getAllAddress();
for (String key : map.keySet()) {
Logger.d("MogoHttpDns","key: "+key+" value: "+map.get(key));
}
if (useCache) {
String address = httpDnsHelper.getHttpDnsCachedAddress(type, host);
if (address != null) {
@@ -61,17 +68,20 @@ public class MogoHttpDns implements IMogoHttpDns, HttpDns, OnAddressChangedListe
}
}
private final Map<String, IHttpDnsTtlCallback> ttlCallbackMap = new ArrayMap<>();
private final Map<String, List<IHttpDnsTtlCallback>> ttlCallbackMap = new ArrayMap<>();
@Override
public void addHttpDnsTtlCallback(String host, int type, IHttpDnsTtlCallback callback) {
ttlCallbackMap.put(type + "-" + host, callback);
if (ttlCallbackMap.get(type + "-" + host) == null) {
ttlCallbackMap.put(type + "-" + host, new ArrayList<IHttpDnsTtlCallback>());
}
ttlCallbackMap.get(type + "-" + host).add(callback);
}
@Override
public void removeHttpDnsTtlCallback(String host, int type) {
ttlCallbackMap.remove(type + "-" + host);
// 先不实现
// ttlCallbackMap.remove(type + "-" + host);
}
@Override
@@ -94,6 +104,15 @@ public class MogoHttpDns implements IMogoHttpDns, HttpDns, OnAddressChangedListe
public List<InetAddress> lookup(String hostname) throws UnknownHostException {
String cacheIp = httpDnsHelper.getHttpDnsCachedAddress(HTTP_DNS_ADDRESS_TYPE_HTTP, hostname);
if (cacheIp == null || TextUtils.isEmpty(cacheIp)) {
cacheIp = httpDnsHelper.getHttpDnsAddress(HttpDnsHelper.HTTP_DNS_TYPE_HTTP, hostname);
if(!TextUtils.isEmpty(cacheIp)){
String[] info = cacheIp.split(":");
if (info.length > 1) {
return Arrays.asList(InetAddress.getAllByName(info[0]));
} else {
return Arrays.asList(InetAddress.getAllByName(cacheIp));
}
}
return Collections.emptyList();
}
String[] info = cacheIp.split(":");
@@ -108,10 +127,11 @@ public class MogoHttpDns implements IMogoHttpDns, HttpDns, OnAddressChangedListe
public void onAddressChanged(@org.jetbrains.annotations.Nullable Map<String, String> map) {
if (map != null) {
for (String key : map.keySet()) {
IHttpDnsTtlCallback callback = ttlCallbackMap.get(key);
Logger.d("MogoHttpDns", "onAddressChanged key: " + key);
if (callback != null) {
callback.onTtl();
if (ttlCallbackMap.get(key) != null) {
Logger.d("MogoHttpDns", "onAddressChanged key: " + key);
for(IHttpDnsTtlCallback callback : ttlCallbackMap.get(key)){
callback.onTtl();
}
}else{
Logger.d("MogoHttpDns", "callback is null: " + key);
}

View File

@@ -3,6 +3,7 @@ package com.mogo.base.websocket;
import com.alibaba.android.arouter.launcher.ARouter;
import com.mogo.httpdns.HttpDnsConst;
import com.mogo.httpdns.IMogoHttpDns;
import com.mogo.httpdns.MogoHttpDnsHandler;
import com.mogo.utils.ThreadPoolService;
import com.mogo.utils.logger.Logger;

View File

@@ -1,5 +1,7 @@
package com.mogo.utils.network;
import com.mogo.utils.logger.Logger;
import java.net.InetAddress;
import java.util.List;
import java.util.Set;
@@ -54,8 +56,10 @@ public final class OkHttpFactory {
builder.dns( hostname -> {
List< InetAddress > addresses = httpDns.lookup( hostname );
if ( addresses != null && !addresses.isEmpty() ) {
Logger.d("OkHttpFactory","look up hostname: "+hostname+" address: "+addresses.get(0).getHostAddress());
return addresses;
}
Logger.d("OkHttpFactory","hostname: "+hostname+" no address");
return Dns.SYSTEM.lookup( hostname );
} );
}

View File

@@ -134,7 +134,7 @@ MOGO_MODULES_SMALL_MAP=1.0.0
# httpdns
HTTPDNS_TENCENT_VERSION = 2.0.12
HTTPDNS_MOGO_VERSION=2.0.12
HTTPDNS_BASE_VERSION = 2.0.12
HTTPDNS_BASE_VERSION = 2.0.13
HTTPDNS_NOOP_VERSION = 2.0.12
######## 外部依赖引用