SSU: Rewrite isTooClose()

to use actual local IP rather than iterating through getCurrentAddresses(),
more efficient and works even when firewalled
This commit is contained in:
zzz
2022-12-17 11:56:12 -05:00
parent db459de0c6
commit f26c616fdc

View File

@@ -1049,17 +1049,15 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
boolean isTooClose(byte[] ip) {
if (allowLocal())
return false;
for (RouterAddress addr : getCurrentAddresses()) {
byte[] myip = addr.getIP();
if (myip == null || ip.length != myip.length)
continue;
if (ip.length == 4) {
if (DataHelper.eq(ip, 0, myip, 0, 2))
return true;
} else if (ip.length == 16) {
if (DataHelper.eq(ip, 0, myip, 0, 4))
return true;
}
byte[] myip = ip.length == 16 ? _lastOurIPv6 : _lastOurIPv4;
if (myip == null)
return false;
if (ip.length == 4) {
if (DataHelper.eq(ip, 0, myip, 0, 2))
return true;
} else if (ip.length == 16) {
if (DataHelper.eq(ip, 0, myip, 0, 4))
return true;
}
return false;
}