net.i2p.router.transport

## Class TransportUtil

- java.lang.Object
- - net.i2p.router.transport.TransportUtil

-     public abstract class TransportUtil
      extends Object

  Utility class providing common transport operations and configurations. 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 Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `TransportUtil.IPv6Config` IPv6 configuration options for transports.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static TransportUtil.IPv6Config` | `DEFAULT_IPV6_CONFIG`
    `static String` | `NTCP_IPV6_CONFIG`
    `static String` | `PROP_IPV4_FIREWALLED`
    `static String` | `PROP_IPV6_FIREWALLED`
    `static String` | `SSU_IPV6_CONFIG`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TransportUtil()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static TransportUtil.IPv6Config` | `getIPv6Config(RouterContext ctx, String transportStyle)`
    `static TransportUtil.IPv6Config` | `getIPv6Config(String cfg)`
    `static AddressType` | `getType(byte[] ip)`
    `static AddressType` | `getType(RouterAddress addr)`
    `static AddressType` | `getType(String host)`
    `static boolean` | `isIPv4Firewalled(RouterContext ctx, String transportStyle)` This returns true if the force-firewalled setting is configured, false otherwise.
    `static boolean` | `isIPv6(RouterAddress addr)` Addresses without a host (i.e.
    `static boolean` | `isIPv6Firewalled(RouterContext ctx, String transportStyle)` This returns true if the force-firewalled setting is configured, false otherwise.
    `static boolean` | `isPubliclyRoutable(byte[] addr, boolean allowIPv6)`
    `static boolean` | `isPubliclyRoutable(byte[] addr, boolean allowIPv4, boolean allowIPv6)` Ref: RFC 5735
    `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
    `static boolean` | `isYggdrasil(RouterAddress addr)`
    `static void` | `logInvalidPort(Log log, String transportStyle, int port)` log an error
    `static int` | `selectRandomPort(RouterContext ctx, String transportStyle)` Pick a random port between the configured boundaries

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_IPV6_CONFIG

          public static final TransportUtil.IPv6Config DEFAULT_IPV6_CONFIG

    - #### NTCP_IPV6_CONFIG

          public static final String NTCP_IPV6_CONFIG

      See Also:
        Constant Field Values

    - #### PROP_IPV4_FIREWALLED

          public static final String PROP_IPV4_FIREWALLED

      See Also:
        Constant Field Values

    - #### PROP_IPV6_FIREWALLED

          public static final String PROP_IPV6_FIREWALLED

      See Also:
        Constant Field Values

    - #### SSU_IPV6_CONFIG

          public static final String SSU_IPV6_CONFIG

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### TransportUtil

          public TransportUtil()

  - ### Method Detail

    - #### getIPv6Config

          public static TransportUtil.IPv6Config getIPv6Config(RouterContext ctx,
                                                               String transportStyle)

    - #### getIPv6Config

          public static TransportUtil.IPv6Config getIPv6Config(String cfg)

    - #### getType

          public static AddressType getType(byte[] ip)

      Returns:
        null if unknown

    - #### getType

          public static AddressType getType(RouterAddress addr)

      Returns:
        null if unknown

    - #### getType

          public static AddressType getType(String host)

      Returns:
        null if unknown

    - #### isIPv4Firewalled

          public static boolean isIPv4Firewalled(RouterContext ctx,
                                                 String transportStyle)

      This returns true if the force-firewalled setting is configured, false otherwise.
      Parameters:
        `transportStyle` - ignored

    - #### isIPv6

          public static boolean isIPv6(RouterAddress addr)

      Addresses without a host (i.e. w/introducers) are assumed to be IPv4 unless a '6' cap is present
      Parameters:
        `addr` - non-null

    - #### isIPv6Firewalled

          public static boolean isIPv6Firewalled(RouterContext ctx,
                                                 String transportStyle)

      This returns true if the force-firewalled setting is configured, false otherwise.
      Parameters:
        `transportStyle` - ignored

    - #### isPubliclyRoutable

          public static boolean isPubliclyRoutable(byte[] addr,
                                                   boolean allowIPv6)

      Parameters:
        `addr` - non-null

    - #### isPubliclyRoutable

          public static boolean isPubliclyRoutable(byte[] addr,
                                                   boolean allowIPv4,
                                                   boolean allowIPv6)

      Ref: RFC 5735
      Parameters:
        `addr` - non-null

    - #### 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

    - #### isYggdrasil

          public static boolean isYggdrasil(RouterAddress addr)

    - #### logInvalidPort

          public static void logInvalidPort(Log log,
                                            String transportStyle,
                                            int port)

      log an error

    - #### selectRandomPort

          public static int selectRandomPort(RouterContext ctx,
                                             String transportStyle)

      Pick a random port between the configured boundaries