This class contains static methods and constants used throughout the transport system for address validation, port management, IPv6 configuration, and network utility functions.
Key Features:
- IPv4 and IPv6 address validation and parsing
- Port range validation and assignment
- IPv6 configuration options for transports
- Firewall and NAT detection utilities
- Geographic IP filtering and validation
- Transport-specific constants and defaults
IPv6 Support:
- Configuration options for NTCP and SSU transports
- Address format validation for IPv6
- Port assignment and range checking
- Compatibility helpers for mixed IPv4/IPv6 environments
Network Utilities:
- Port assignment strategies (random vs. configured)
- Firewall detection and bypass methods
- Transport protocol constants and defaults
- Address type detection and validation
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumIPv6 configuration options for transports.Field Summary
Modifier and TypeFieldDescriptionprivate static final Map<String, TransportUtil.IPv6Config> The IPv6 modes, by config value.static final TransportUtil.IPv6ConfigDEFAULT_IPV6_CONFIG.private static final intHighest port chosen by the random picker.private static final int8998 is monotone, and 31000 is the wrapper outbound, so let's stay between those Was 9111, increase to skip Tor browser at 9050.static final StringNTCP_IPV6_CONFIG.static final StringPROP_IPV4_FIREWALLED.static final StringIf true, this router believes its IPv6 address is firewalled.private static final StringSuffix of a transport's maximum-port property.private static final StringSuffix of a transport's minimum-port property.private static final StringConfig keys for the data port range and minimums.static final StringSSU_IPV6_CONFIG.private static final PatternMatches an address on the Yggdrasil network.Constructor Summary
ConstructorsConstructorDescriptionConstructor for subclasses; the operations in this base class are static.Method Summary
All MethodsModifier and TypeMethodDescriptionstatic TransportUtil.IPv6ConfiggetIPv6Config(String cfg) The IPv6 config for the given config string.static TransportUtil.IPv6ConfiggetIPv6Config(RouterContext ctx, String transportStyle) The IPv6 config for the given transport style.static AddressTypegetType(byte[] ip) Address type of the given IP address.static AddressTypeAddress type of the given host string.static AddressTypegetType(RouterAddress addr) Address type of the given RouterAddress.static booleanDoes this RouterInfo carry at least one address we could still send to?static booleanThis returns true if the force-firewalled setting is configured, false otherwise.static booleanisIPv6(RouterAddress addr) Addresses without a host (i.e.static booleanThis returns true if the force-firewalled setting is configured, false otherwise.static booleanisPubliclyRoutable(byte[] addr, boolean allowIPv6) Whether the address is publicly routable, optionally allowing IPv6.static booleanisPubliclyRoutable(byte[] addr, boolean allowIPv4, boolean allowIPv6) Ref: RFC 5735.static booleanIs the RouterAddress usable for tunnel building?static booleanisValidPort(int port) Is this a valid port for us or a remote router?static booleanisYggdrasil(RouterAddress addr) Whether the address is an in-network Yggdrasil address.static voidlogInvalidPort(Log log, String transportStyle, int port) Logs an error for an invalid port.static intselectRandomPort(RouterContext ctx, String transportStyle) Pick a random port between the configured boundaries.
Field Details
NTCP_IPV6_CONFIG
SSU_IPV6_CONFIG
PROP_IPV4_FIREWALLED
PROP_IPV6_FIREWALLED
If true, this router believes its IPv6 address is firewalled.- See Also:
PROP_PORT_PFX
Config keys for the data port range and minimums.- See Also:
PROP_MIN_PORT_SFX
Suffix of a transport's minimum-port property.- See Also:
PROP_MAX_PORT_SFX
Suffix of a transport's maximum-port property.- See Also:
MIN_RANDOM_PORT
private static final int MIN_RANDOM_PORT8998 is monotone, and 31000 is the wrapper outbound, so let's stay between those Was 9111, increase to skip Tor browser at 9050.- See Also:
MAX_RANDOM_PORT
private static final int MAX_RANDOM_PORTHighest port chosen by the random picker.- See Also:
YGGDRASIL_PATTERN
Matches an address on the Yggdrasil network.BY_NAME
The IPv6 modes, by config value.DEFAULT_IPV6_CONFIG
DEFAULT_IPV6_CONFIG.
Constructor Details
TransportUtil
public TransportUtil()Constructor for subclasses; the operations in this base class are static.
Method Details
getIPv6Config
The IPv6 config for the given transport style.- Parameters:
ctx- the router contexttransportStyle- the transport to read the config for, NTCP or SSU- Returns:
- the IPv6 config
getIPv6Config
The IPv6 config for the given config string.- Parameters:
cfg- the config string to look up- Returns:
- the IPv6 config
isIPv4Firewalled
This returns true if the force-firewalled setting is configured, false otherwise.- Parameters:
ctx- the router context- Returns:
- whether i pv4 firewalled
isIPv6Firewalled
This returns true if the force-firewalled setting is configured, false otherwise.- Parameters:
ctx- the router context- Returns:
- whether IPv6 firewalled
isIPv6
Addresses without a host (i.e. w/introducers) are assumed to be IPv4 unless a '6' cap is present.- Parameters:
addr- non-null- Returns:
- whether IPv6
isUsableRouterAddress
Is the RouterAddress usable for tunnel building?SSU requires protocol v2 plus a valid IP/port or an introduction; SSU2 requires a valid IP/port or an introduction; NTCP/NTCP2 require a valid IP/port.
Lives here rather than in
TunnelPeerSelectorbecause both the tunnel selectors andProfileOrganizerneed it, and the latter must not reach intotunnel.pool— that package already depends onpeermanager, so the reverse edge would close a cycle.Pure decision: no context access, safe for unit tests.
- Parameters:
ra- the router address to check (non-null)- Returns:
- true if the address is usable
hasUsableTransportAddress
Does this RouterInfo carry at least one address we could still send to?A peer whose addresses have all expired or become unusable cannot be selected for a build and cannot be pre-connected to, so admitting it to a selection tier only produces a candidate that is guaranteed to fail. Gate promotion on this.
Pure decision: takes the RouterInfo rather than consulting the netdb, so callers holding an entry do not pay for a second lookup.
- Parameters:
ri- the router info to check (non-null)- Returns:
- true if at least one address is usable
isYggdrasil
Whether the address is an in-network Yggdrasil address.- Parameters:
addr- the address to classify- Returns:
- true if the host string matches the Yggdrasil overlay pattern
getType
Address type of the given RouterAddress.- Parameters:
addr- the address to classify- Returns:
- null if unknown
getType
Address type of the given host string.- Parameters:
host- the host string to classify- Returns:
- null if unknown
getType
Address type of the given IP address.- Parameters:
ip- the raw 4 or 16 byte address to classify- Returns:
- null if unknown
isPubliclyRoutable
public static boolean isPubliclyRoutable(byte[] addr, boolean allowIPv6) Whether the address is publicly routable, optionally allowing IPv6.- Parameters:
addr- non-nullallowIPv6- true to treat global IPv6 addresses as routable- Returns:
- whether publicly routable
isPubliclyRoutable
public static boolean isPubliclyRoutable(byte[] addr, boolean allowIPv4, boolean allowIPv6) Ref: RFC 5735.- Parameters:
addr- non-nullallowIPv4- true to treat global IPv4 addresses as routableallowIPv6- true to treat global IPv6 addresses as routable- Returns:
- whether publicly routable
isValidPort
public static boolean isValidPort(int port) Is this a valid port for us or a remote router?ref: http://i2p-projekt.i2p/en/docs/ports ref: https://cs.chromium.org/chromium/src/net/base/port_util.cc
- Parameters:
port- the port to test- Returns:
- whether valid port
logInvalidPort
selectRandomPort
Pick a random port between the configured boundaries.- Parameters:
ctx- the router contexttransportStyle- the transport the port is for, NTCP or SSU- Returns:
- the port chosen