I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Unverified Commit 7cf98959 authored by zzz's avatar zzz
Browse files

Transport: Add util methods for AddressType

WIP, not hooked in
parent d41c39a4
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@ import java.util.regex.Pattern;
import net.i2p.I2PAppContext;
import net.i2p.data.router.RouterAddress;
import net.i2p.util.AddressType;
import net.i2p.util.Log;
import net.i2p.router.RouterContext;
......@@ -145,6 +146,49 @@ public abstract class TransportUtil {
return host != null && YGGDRASIL_PATTERN.matcher(host).matches();
}
/**
* @return null if unknown
* @since 0.9.54
*/
public static AddressType getType(RouterAddress addr) {
String host = addr.getHost();
return getType(host);
}
/**
* @return null if unknown
* @since 0.9.54
*/
public static AddressType getType(String host) {
if (host == null)
return null;
if (host.indexOf('.') > 0)
return AddressType.IPV4;
if (host.indexOf(':') >= 0) {
if (YGGDRASIL_PATTERN.matcher(host).matches())
return AddressType.YGG;
return AddressType.IPV6;
}
return null;
}
/**
* @return null if unknown
* @since 0.9.54
*/
public static AddressType getType(byte[] ip) {
if (ip == null)
return null;
if (ip.length == 4)
return AddressType.IPV4;
if (ip.length == 16) {
if (ip[0] == 2 || ip[0] == 3)
return AddressType.YGG;
return AddressType.IPV6;
}
return null;
}
/**
* @param addr non-null
* @since IPv6 moved from TransportImpl
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment