forked from I2P_Developers/i2p.i2p
Util: Speed up IP address validation by using Apache's implementation (ticket #1198)
This commit is contained in:
@@ -17,6 +17,8 @@ import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.http.conn.util.InetAddressUtils;
|
||||
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.DataStructureImpl;
|
||||
@@ -219,8 +221,8 @@ public class RouterAddress extends DataStructureImpl {
|
||||
if (host != null) {
|
||||
rv = Addresses.getIP(host);
|
||||
if (rv != null &&
|
||||
(host.replaceAll("[0-9\\.]", "").length() == 0 ||
|
||||
host.replaceAll("[0-9a-fA-F:]", "").length() == 0)) {
|
||||
(InetAddressUtils.isIPv4Address(host) ||
|
||||
InetAddressUtils.isIPv6Address(host))) {
|
||||
_ip = rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class RouterVersion {
|
||||
/** deprecated */
|
||||
public final static String ID = "Monotone";
|
||||
public final static String VERSION = CoreVersion.VERSION;
|
||||
public final static long BUILD = 11;
|
||||
public final static long BUILD = 12;
|
||||
|
||||
/** for example "-test" */
|
||||
public final static String EXTRA = "";
|
||||
|
||||
@@ -4,6 +4,8 @@ import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.conn.util.InetAddressUtils;
|
||||
|
||||
import net.i2p.data.Base64;
|
||||
import net.i2p.data.router.RouterAddress;
|
||||
import net.i2p.data.SessionKey;
|
||||
@@ -262,12 +264,9 @@ class UDPAddress {
|
||||
}
|
||||
if (rv == null) {
|
||||
try {
|
||||
boolean isIPv4 = host.replaceAll("[0-9\\.]", "").length() == 0;
|
||||
if (isIPv4 && host.replaceAll("[0-9]", "").length() != 3)
|
||||
return null;
|
||||
rv = InetAddress.getByName(host);
|
||||
if (isIPv4 ||
|
||||
host.replaceAll("[0-9a-fA-F:]", "").length() == 0) {
|
||||
if (InetAddressUtils.isIPv4Address(host) ||
|
||||
InetAddressUtils.isIPv6Address(host)) {
|
||||
synchronized (_inetAddressCache) {
|
||||
_inetAddressCache.put(host, rv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user