添加资源http-dns实现

This commit is contained in:
tongchenfei
2020-12-24 20:30:54 +08:00
parent 7653f28a54
commit a96dcf19e0
20 changed files with 338 additions and 103 deletions

View File

@@ -19,6 +19,9 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static com.mogo.httpdns.HttpDnsConst.HTTP_DNS_ADDRESS_TYPE_IM;
import static com.mogo.httpdns.HttpDnsConst.HTTP_DNS_ADDRESS_TYPE_WS;
public
/**
* @author congtaowang
@@ -50,8 +53,13 @@ class TencentHttpDns implements IMogoHttpDns, HttpDns {
}
@Override
public String getCachedHttpDnsIps( String host ) {
return HttpDnsIpsCache.getHttpDnsIps( host );
public String getCachedHttpDnsIps( String host,int type ) {
String ip = HttpDnsIpsCache.getHttpDnsIps(host);
if (ip == null) {
return null;
} else {
return tailPort(ip, type);
}
}
private String getCacheOrParseIpIfNecessary( String host ) {
@@ -66,7 +74,7 @@ class TencentHttpDns implements IMogoHttpDns, HttpDns {
}
@Override
public void getHttpDnsIp( String host, boolean useCache, IHttpDnsCallback callback ) {
public void getHttpDnsIp( String host,int type, boolean useCache, IHttpDnsCallback callback ) {
String cacheIp = null;
if ( useCache ) {
cacheIp = getCacheOrParseIpIfNecessary( host );
@@ -78,7 +86,7 @@ class TencentHttpDns implements IMogoHttpDns, HttpDns {
}
if ( !TextUtils.isEmpty( cacheIp ) ) {
if ( callback != null ) {
callback.onParsed( cacheIp );
callback.onParsed( tailPort(cacheIp,type) );
return;
}
}
@@ -88,12 +96,12 @@ class TencentHttpDns implements IMogoHttpDns, HttpDns {
}
@Override
public void addHttpDnsTtlCallback( String host, IHttpDnsTtlCallback callback ) {
public void addHttpDnsTtlCallback( String host,int type, IHttpDnsTtlCallback callback ) {
HttpDnsIpsCache.addHttpDnsTtlCallback( host, callback );
}
@Override
public void removeHttpDnsTtlCallback( String host ) {
public void removeHttpDnsTtlCallback( String host,int type ) {
HttpDnsIpsCache.removeHttpDnsTtlCallback( host );
}
@@ -113,4 +121,15 @@ class TencentHttpDns implements IMogoHttpDns, HttpDns {
HttpDnsIpsCache.loopDnsParse();
sInited = true;
}
private String tailPort(String ip, int type) {
switch (type) {
case HTTP_DNS_ADDRESS_TYPE_WS:
return ip + ":4003";
case HTTP_DNS_ADDRESS_TYPE_IM:
return ip + ":4002";
default:
return ip;
}
}
}