Util: Add AddressType enum

This commit is contained in:
zzz
2022-03-01 05:48:20 -05:00
parent 50ce3c2856
commit ce53714ba1
2 changed files with 29 additions and 1 deletions

View File

@@ -0,0 +1,8 @@
package net.i2p.util;
/**
* @since 0.9.54
*/
public enum AddressType {
IPV4, IPV6, YGG
}

View File

@@ -54,6 +54,26 @@ public abstract class Addresses {
private static final Set<String> _macCache = new HashSet<String>();
private static final boolean TEST_IPV6_ONLY = false;
/**
* Do we have any address of this type?
* Warning, very slow on Windows, appx. 200ms + 50ms/interface
*
* @since 0.9.54
*/
public static boolean isConnected(AddressType type) {
switch(type) {
case IPV6:
return isConnectedIPv6();
case YGG:
return getYggdrasilAddress() != null;
case IPV4:
default:
return isConnected();
}
}
/**
* Do we have any non-loop, non-wildcard IPv4 address at all?
* Warning, very slow on Windows, appx. 200ms + 50ms/interface
@@ -266,7 +286,7 @@ public abstract class Addresses {
/**
* Warning, very slow on Windows. Caller should cache.
*
* @return the IPv6 address with prefix 02xx: or 03xx:
* @return the IPv6 address with prefix 02xx: or 03xx:, or null
* @since 0.9.49
*/
public static byte[] getYggdrasilAddress() {