Try secondary ip4 addresses first when ip4 preferred

pull/214/head
M66B 11 months ago
parent 01383680d2
commit 6ad580827e

@ -67,6 +67,7 @@ import java.security.cert.X509Certificate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -617,6 +618,8 @@ public class EmailService implements AutoCloseable {
crumb.put("port", Integer.toString(port)); crumb.put("port", Integer.toString(port));
crumb.put("auth", Integer.toString(auth)); crumb.put("auth", Integer.toString(auth));
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
InetAddress main = null; InetAddress main = null;
boolean require_id = (purpose == PURPOSE_CHECK && boolean require_id = (purpose == PURPOSE_CHECK &&
auth == AUTH_TYPE_OAUTH && auth == AUTH_TYPE_OAUTH &&
@ -627,8 +630,6 @@ public class EmailService implements AutoCloseable {
// throw new MailConnectException( // throw new MailConnectException(
// new SocketConnectException("Debug", new IOException("Test"), host, port, 0)); // new SocketConnectException("Debug", new IOException("Test"), host, port, 0));
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String key = "dns." + host; String key = "dns." + host;
try { try {
main = DnsHelper.getByName(context, host, dnssec); main = DnsHelper.getByName(context, host, dnssec);
@ -748,6 +749,15 @@ public class EmailService implements AutoCloseable {
" ip4=" + ip4 + " max4=" + MAX_IPV4 + " has4=" + has46[0] + " ip4=" + ip4 + " max4=" + MAX_IPV4 + " has4=" + has46[0] +
" ip6=" + ip6 + " max6=" + MAX_IPV6 + " has6=" + has46[1]); " ip6=" + ip6 + " max6=" + MAX_IPV6 + " has6=" + has46[1]);
boolean prefer_ip4 = prefs.getBoolean("prefer_ip4", true);
if (prefer_ip4)
Arrays.sort(iaddrs, new Comparator<InetAddress>() {
@Override
public int compare(InetAddress a1, InetAddress a2) {
return -Boolean.compare(a1 instanceof Inet4Address, a2 instanceof Inet4Address);
}
});
for (InetAddress iaddr : iaddrs) { for (InetAddress iaddr : iaddrs) {
EntityLog.log(context, EntityLog.Type.Network, "Address resolved=" + iaddr); EntityLog.log(context, EntityLog.Type.Network, "Address resolved=" + iaddr);

Loading…
Cancel
Save