Sort SRV records on priority and weight

This commit is contained in:
M66B 2024-01-04 08:24:50 +01:00
parent 705197efbf
commit a55337ea09
1 changed files with 17 additions and 0 deletions

View File

@ -56,6 +56,8 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Set;
@ -302,6 +304,21 @@ public class DnsHelper {
record.authentic = data.isAuthenticData();
}
if ("srv".equals(type))
Collections.sort(result, new Comparator<DnsRecord>() {
@Override
public int compare(DnsRecord d1, DnsRecord d2) {
int o = Integer.compare(
d1.priority == null ? 0 : d1.priority,
d2.priority == null ? 0 : d2.priority);
if (o == 0)
o = Integer.compare(
d1.weight == null ? 0 : d1.weight,
d2.weight == null ? 0 : d2.weight);
return o;
}
});
return result.toArray(new DnsRecord[0]);
} catch (Throwable ex) {
if (ex instanceof DnssecValidationFailedException ||