remove unnecessary in resolver
This commit is contained in:
parent
7f278202c6
commit
a40d244bf5
|
@ -28,6 +28,8 @@ import java.util.Iterator;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||
import javax.net.ssl.SSLSession;
|
||||
|
@ -37,6 +39,7 @@ import javax.net.ssl.SSLSocketFactory;
|
|||
final class DNSSocket implements Closeable {
|
||||
|
||||
private static final int CONNECT_TIMEOUT = 5_000;
|
||||
public static final int QUERY_TIMEOUT = 5_000;
|
||||
|
||||
private final Semaphore semaphore = new Semaphore(1);
|
||||
private final Map<Integer, SettableFuture<DNSMessage>> inFlightQueries = new HashMap<>();
|
||||
|
@ -109,6 +112,7 @@ final class DNSSocket implements Closeable {
|
|||
new InetSocketAddress(dnsServer.inetAddress, dnsServer.port);
|
||||
final Socket socket = new Socket();
|
||||
socket.connect(socketAddress, CONNECT_TIMEOUT);
|
||||
socket.setSoTimeout(QUERY_TIMEOUT);
|
||||
return DNSSocket.of(socket);
|
||||
}
|
||||
|
||||
|
@ -120,9 +124,11 @@ final class DNSSocket implements Closeable {
|
|||
final SocketAddress socketAddress =
|
||||
new InetSocketAddress(dnsServer.inetAddress, dnsServer.port);
|
||||
sslSocket = (SSLSocket) factory.createSocket(dnsServer.inetAddress, dnsServer.port);
|
||||
sslSocket.connect(socketAddress, 5_000);
|
||||
sslSocket.connect(socketAddress, CONNECT_TIMEOUT);
|
||||
sslSocket.setSoTimeout(QUERY_TIMEOUT);
|
||||
} else {
|
||||
sslSocket = (SSLSocket) factory.createSocket(dnsServer.hostname, dnsServer.port);
|
||||
sslSocket.setSoTimeout(QUERY_TIMEOUT);
|
||||
final SSLSession session = sslSocket.getSession();
|
||||
final Certificate[] peerCertificates = session.getPeerCertificates();
|
||||
if (peerCertificates.length == 0 || !(peerCertificates[0] instanceof X509Certificate)) {
|
||||
|
@ -138,7 +144,7 @@ final class DNSSocket implements Closeable {
|
|||
|
||||
public DNSMessage query(final DNSMessage query) throws IOException, InterruptedException {
|
||||
try {
|
||||
return queryAsync(query).get();
|
||||
return queryAsync(query).get(QUERY_TIMEOUT, TimeUnit.MILLISECONDS);
|
||||
} catch (final ExecutionException e) {
|
||||
final Throwable cause = e.getCause();
|
||||
if (cause instanceof IOException) {
|
||||
|
@ -146,6 +152,8 @@ final class DNSSocket implements Closeable {
|
|||
} else {
|
||||
throw new IOException(e);
|
||||
}
|
||||
} catch (final TimeoutException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ public class NetworkDataSource extends DNSDataSource {
|
|||
} catch (final IOException e) {
|
||||
ioExceptions.add(e);
|
||||
} catch (final InterruptedException e) {
|
||||
return null;
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
MultipleIoException.throwIfRequired(ioExceptions);
|
||||
|
|
|
@ -6,6 +6,8 @@ import android.util.Log;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.Inet4Address;
|
||||
|
@ -113,7 +115,7 @@ public class Resolver {
|
|||
return port == 443 || port == 5223;
|
||||
}
|
||||
|
||||
public static List<Result> resolve(String domain) {
|
||||
public static List<Result> resolve(final String domain) {
|
||||
final List<Result> ipResults = fromIpAddress(domain);
|
||||
if (ipResults.size() > 0) {
|
||||
return ipResults;
|
||||
|
@ -127,8 +129,10 @@ public class Resolver {
|
|||
synchronized (results) {
|
||||
results.addAll(list);
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving SRV record (direct TLS)", throwable);
|
||||
} catch (final Throwable throwable) {
|
||||
if (!(Throwables.getRootCause(throwable) instanceof InterruptedException)) {
|
||||
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving SRV record (direct TLS)", throwable);
|
||||
}
|
||||
}
|
||||
});
|
||||
threads[1] = new Thread(() -> {
|
||||
|
@ -137,8 +141,10 @@ public class Resolver {
|
|||
synchronized (results) {
|
||||
results.addAll(list);
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving SRV record (STARTTLS)", throwable);
|
||||
} catch (final Throwable throwable) {
|
||||
if (!(Throwables.getRootCause(throwable) instanceof InterruptedException)) {
|
||||
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving SRV record (STARTTLS)", throwable);
|
||||
}
|
||||
}
|
||||
});
|
||||
threads[2] = new Thread(() -> {
|
||||
|
@ -261,8 +267,10 @@ public class Resolver {
|
|||
results.addAll(resolveNoSrvRecords(cname.name, false));
|
||||
}
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + "error resolving fallback records", throwable);
|
||||
} catch (final Throwable throwable) {
|
||||
if (!(Throwables.getRootCause(throwable) instanceof InterruptedException)) {
|
||||
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + "error resolving fallback records", throwable);
|
||||
}
|
||||
}
|
||||
results.add(Result.createDefault(dnsName));
|
||||
return results;
|
||||
|
|
Loading…
Reference in a new issue