net.i2p.router.transport

## Class CommSystemFacadeImpl

- java.lang.Object
- - net.i2p.router.CommSystemFacade
  - - net.i2p.router.transport.CommSystemFacadeImpl

- All Implemented Interfaces:
    Service

      public class CommSystemFacadeImpl
      extends CommSystemFacade

  Primary implementation of the communication system facade for I2P network operations. This class provides the main interface between the router core and all transport protocols. It coordinates message sending, peer management, address configuration, and network monitoring while abstracting the underlying transport details. Core Responsibilities:
  - Message routing and delivery across all transports
  - Peer connection management and statistics
  - Network address discovery and configuration
  - Bandwidth allocation and monitoring
  - Transport lifecycle management (start/stop/restart)
  - Network reachability testing and reporting
  - Geographic IP filtering and country blocking
  - Communication system status and health monitoring
  Transport Integration:
  - Manages NTCP, UDP, and SSU transports
  - Handles transport selection and failover
  - Coordinates address updates across protocols
  - Provides unified API for router components
  Configuration Features:
  - Transport enable/disable controls
  - Country-based blocking and filtering
  - Proxy configuration and detection
  - Network monitoring and testing options
  - IPv4 and IPv6 addressing support
  Security Features:
  - Geographic IP filtering
  - Country-based access controls
  - Peer reputation and banlist management
  - Transport-specific security policies

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `CommSystemFacadeImpl.CacheEntry` Cache entry for IP address and hostname mappings.

    - ### Nested classes/interfaces inherited from class net.i2p.router.CommSystemFacade

      `CommSystemFacade.Status`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `PROP_BLOCK_MY_COUNTRY`
    `static String` | `PROP_IP_COUNTRY`

    - ### Fields inherited from class net.i2p.router.CommSystemFacade

      `ROUTER_BUNDLE_NAME, STATUS_DIFFERENT, STATUS_DISCONNECTED, STATUS_HOSED, STATUS_IPV4_DISABLED_IPV6_FIREWALLED, STATUS_IPV4_DISABLED_IPV6_OK, STATUS_IPV4_DISABLED_IPV6_UNKNOWN, STATUS_IPV4_FIREWALLED_IPV6_OK, STATUS_IPV4_FIREWALLED_IPV6_UNKNOWN, STATUS_IPV4_OK_IPV6_FIREWALLED, STATUS_IPV4_OK_IPV6_UNKNOWN, STATUS_IPV4_SNAT_IPV6_OK, STATUS_IPV4_SNAT_IPV6_UNKNOWN, STATUS_IPV4_UNKNOWN_IPV6_FIREWALLED, STATUS_IPV4_UNKNOWN_IPV6_OK, STATUS_OK, STATUS_REJECT_UNSOLICITED, STATUS_UNKNOWN`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CommSystemFacadeImpl(RouterContext context)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `countActivePeers()` How many peers are we currently connected to, that we have sent a message to or received a message from in the last minute.
    `int` | `countActiveSendPeers()` How many peers are we currently connected to, that we have sent a message to in the last minute.
    `static int` | `countRdnsCacheEntries()`
    `List<RouterAddress>` | `createAddresses()` Create router addresses for all configured transport protocols.
    `boolean` | `enableReverseLookups()`
    `boolean` | `enableWhoisLookups()`
    `void` | `exemptIncoming(Hash peer)` Exempt this router hash from any incoming throttles or rejections
    `void` | `forceDisconnect(Hash peer)` Tell the comm system to disconnect from this peer.
    `String` | `getCanonicalHostName(String ipAddress)` Returns the canonical hostname for the given IP address from cache or DNS.
    `String` | `getCanonicalHostNameSync(String ipAddress)`
    `static byte[]` | `getCompatibleIP(RouterInfo ri)` Return the first IP compatible with our outbound transports.
    `Map<String,String>` | `getCountries()` Provides country code mappings.
    `String` | `getCountry(Hash peer)` Uses the transport IP first because that lookup is fast, then the IP from the netDb.
    `String` | `getCountry(String ip)` Get country code for an IP address.
    `String` | `getCountryName(String c)` full name for a country code, or the code if we don't know the name
    `static String` | `getDomain(String hostname)`
    `List<Hash>` | `getEstablished()` Get all the peers we are connected to.
    `long` | `getFramedAveragePeerClockSkew(int percentToInclude)` Return framed average clock skew of connected peers in seconds, or null if we cannot answer.
    `byte[]` | `getIP(Hash peer)`
    `String` | `getLocalizedStatusString()` getStatus().toStatusString(), translated if available.
    `List<String>` | `getMostRecentErrorMessages()`
    `String` | `getOurCountry()`
    `static String` | `getRdnsCacheStats()` Get cache statistics for monitoring
    `CommSystemFacade.Status` | `getStatus()` Determine under what conditions we are remotely reachable.
    `SortedMap<String,Transport>` | `getTransports()`
    `static byte[]` | `getValidIP(RouterInfo ri)` Return first valid IP (v4 or v6) we find, any transport.
    `X25519KeyFactory` | `getXDHFactory()` Factory for making X25519 key pairs.
    `boolean` | `haveHighOutboundCapacity()`
    `boolean` | `haveInboundCapacity(int pct)`
    `boolean` | `haveOutboundCapacity(int pct)`
    `void` | `initGeoIP()` Router must call after netdb is initialized
    `boolean` | `isBacklogged(Hash peer)`
    `boolean` | `isDummy()` Is everything disabled for testing?
    `boolean` | `isEstablished(Hash peer)`
    `boolean` | `isExemptIncoming(String ip)` Is this IP exempt from any incoming throttles or rejections
    `boolean` | `isInStrictCountry()` Are we in a strict country
    `boolean` | `isInStrictCountry(Hash peer)` Are they in a strict country.
    `boolean` | `isInStrictCountry(RouterInfo ri)` Are they in a strict country
    `boolean` | `isRunning()`
    `void` | `mayDisconnect(Hash peer)` Tell the comm system that we may disconnect from this peer.
    `void` | `notifyRemoveAddress(boolean ipv6)` Tell other transports our address changed
    `void` | `notifyRemoveAddress(RouterAddress address)` Tell other transports our address changed
    `void` | `notifyReplaceAddress(RouterAddress udpAddr)` UDP changed addresses, tell NTCP and restart All the work moved to NTCPTransport.externalAddressReceived()
    `void` | `processMessage(OutNetMessage msg)` Process and route an outbound message through the transport system.
    `void` | `queueLookup(byte[] ip)`
    `static String` | `rdnsCacheSize()`
    `void` | `registerTransport(Transport t)` Pluggable transports.
    `void` | `removeExemption(String ip)` Remove this IP from the exemptions
    `String` | `renderPeerCaps(Hash peer, boolean inline)` Renders the peer's capability HTML block.
    `String` | `renderPeerFlag(Hash peer)`
    `String` | `renderPeerHTML(Hash peer, boolean extended)` Renders HTML for a peer with optional extended info.
    `void` | `renderStatusHTML(Writer out, String urlBase, int sortFlags)` As of 0.9.31, only outputs UPnP status Warning - blocking, very slow, queries the active UPnP router, will take many seconds if it has vanished.
    `void` | `restart()` Restart the communication system.
    `void` | `shutdown()` Gracefully shutdown the communication system.
    `void` | `startup()` Start the communication system and all transport protocols.
    `void` | `unregisterTransport(Transport t)` Pluggable transports.
    `boolean` | `wasUnreachable(Hash peer)`

    - ### Methods inherited from class net.i2p.router.CommSystemFacade

      `getMedianPeerClockSkew, renderStatusHTML`

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

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

- - ### Field Detail

    - #### PROP_BLOCK_MY_COUNTRY

          public static final String PROP_BLOCK_MY_COUNTRY

      See Also:
        Constant Field Values

    - #### PROP_IP_COUNTRY

          public static final String PROP_IP_COUNTRY

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### CommSystemFacadeImpl

          public CommSystemFacadeImpl(RouterContext context)

  - ### Method Detail

    - #### countActivePeers

          public int countActivePeers()

      How many peers are we currently connected to, that we have sent a message to or received a message from in the last minute.
      Specified by:
        `countActivePeers` in class `CommSystemFacade`

    - #### countActiveSendPeers

          public int countActiveSendPeers()

      How many peers are we currently connected to, that we have sent a message to in the last minute. Unused for anything, to be removed.
      Specified by:
        `countActiveSendPeers` in class `CommSystemFacade`

    - #### countRdnsCacheEntries

          public static int countRdnsCacheEntries()

    - #### createAddresses

          public List<RouterAddress> createAddresses()

      Create router addresses for all configured transport protocols. This method generates RouterAddress objects for each transport protocol based on current configuration and network conditions. It handles address discovery, validation, and format conversion. Address Creation:
      - Iterates through all registered transports
      - Gets current addresses from each transport
      - Validates address format and consistency
      - Handles IPv4 and IPv6 address generation
      - Applies geographic and network filtering
      Overrides:
        `createAddresses` in class `CommSystemFacade`
      Returns:
        list of RouterAddress objects for all active transports, may be empty if no addresses available

    - #### enableReverseLookups

          public boolean enableReverseLookups()

    - #### enableWhoisLookups

          public boolean enableWhoisLookups()

    - #### exemptIncoming

          public void exemptIncoming(Hash peer)

      Exempt this router hash from any incoming throttles or rejections
      Overrides:
        `exemptIncoming` in class `CommSystemFacade`

    - #### forceDisconnect

          public void forceDisconnect(Hash peer)

      Tell the comm system to disconnect from this peer.
      Overrides:
        `forceDisconnect` in class `CommSystemFacade`

    - #### getCanonicalHostName

          public String getCanonicalHostName(String ipAddress)

      Returns the canonical hostname for the given IP address from cache or DNS. Falls back to a WHOIS lookup if DNS fails, returning "ip (whois info)" if available, or just the IP if WHOIS data is missing.
      Overrides:
        `getCanonicalHostName` in class `CommSystemFacade`
      Parameters:
        `ipAddress` - IP address to resolve, or null/"null" to return null
      Returns:
        hostname, IP with WHOIS info, just IP if no WHOIS, or null for invalid input

    - #### getCanonicalHostNameSync

          public String getCanonicalHostNameSync(String ipAddress)

      Overrides:
        `getCanonicalHostNameSync` in class `CommSystemFacade`

    - #### getCompatibleIP

          public static byte[] getCompatibleIP(RouterInfo ri)

      Return the first IP compatible with our outbound transports. If the peer has both IPv4 and IPv6 addresses, and we support both, prefer IPv4. If we only support one, return only that type. Falls back to any valid IP if no compatible one found.
      Returns:
        IP or null

    - #### getCountries

          public Map<String,String> getCountries()

      Provides country code mappings.
      Overrides:
        `getCountries` in class `CommSystemFacade`
      Returns:
        Unmodifiable map of lower-case country codes to untranslated names. Returns empty map if geoIP data is unavailable.

    - #### getCountry

          public String getCountry(Hash peer)

      Uses the transport IP first because that lookup is fast, then the IP from the netDb. Not recommended for our local router hash, as we may not be either in the cache or netdb, or may not be publishing an IP. As of 0.9.32, works only for literal IPs, returns null for hostnames.
      Overrides:
        `getCountry` in class `CommSystemFacade`
      Parameters:
        `peer` - not ourselves - use getOurCountry() for that
      Returns:
        two-letter lower-case country code or xx for non-banned peers, or null otherwise

    - #### getCountry

          public String getCountry(String ip)

      Get country code for an IP address.
      Overrides:
        `getCountry` in class `CommSystemFacade`
      Parameters:
        `ip` - IP address string (IPv4 or IPv6)
      Returns:
        two-letter lower-case country code or null if not found

    - #### getCountryName

          public String getCountryName(String c)

      full name for a country code, or the code if we don't know the name
      Overrides:
        `getCountryName` in class `CommSystemFacade`

    - #### getDomain

          public static String getDomain(String hostname)

      Returns:
        domain name only from reverse dns hostname lookups

    - #### getEstablished

          public List<Hash> getEstablished()

      Description copied from class: `CommSystemFacade`
      Get all the peers we are connected to. This should be more efficient than repeated calls to isEstablished() if you have to check a lot.
      Specified by:
        `getEstablished` in class `CommSystemFacade`
      Returns:
        a new list, may be modified

    - #### getFramedAveragePeerClockSkew

          public long getFramedAveragePeerClockSkew(int percentToInclude)

      Description copied from class: `CommSystemFacade`
      Return framed average clock skew of connected peers in seconds, or null if we cannot answer. CommSystemFacadeImpl overrides this.
      Overrides:
        `getFramedAveragePeerClockSkew` in class `CommSystemFacade`
      Parameters:
        `percentToInclude` - 1-100
      Returns:
        Framed average clock skew of connected peers in milliseconds, or the clock offset if we cannot answer. Average is calculated over the middle "percentToInclude" peers. A positive number means our clock is ahead of theirs. Todo: change List to milliseconds

    - #### getIP

          public byte[] getIP(Hash peer)

      Overrides:
        `getIP` in class `CommSystemFacade`

    - #### getLocalizedStatusString

          public String getLocalizedStatusString()

      getStatus().toStatusString(), translated if available.
      Overrides:
        `getLocalizedStatusString` in class `CommSystemFacade`

    - #### getMostRecentErrorMessages

          public List<String> getMostRecentErrorMessages()

      Overrides:
        `getMostRecentErrorMessages` in class `CommSystemFacade`

    - #### getOurCountry

          public String getOurCountry()

      Overrides:
        `getOurCountry` in class `CommSystemFacade`
      Returns:
        two-letter lower-case country code or null

    - #### getRdnsCacheStats

          public static String getRdnsCacheStats()

      Get cache statistics for monitoring
      Returns:
        formatted string with cache stats

    - #### getStatus

          public CommSystemFacade.Status getStatus()

      Description copied from class: `CommSystemFacade`
      Determine under what conditions we are remotely reachable.
      Overrides:
        `getStatus` in class `CommSystemFacade`

    - #### getTransports

          public SortedMap<String,Transport> getTransports()

      Overrides:
        `getTransports` in class `CommSystemFacade`
      Returns:
        SortedMap of style to Transport (a copy)

    - #### getValidIP

          public static byte[] getValidIP(RouterInfo ri)

      Return first valid IP (v4 or v6) we find, any transport. Local and other invalid IPs will not be returned. As of 0.9.32, works only for literal IPs, returns null for host names.
      Returns:
        IP or null

    - #### getXDHFactory

          public X25519KeyFactory getXDHFactory()

      Factory for making X25519 key pairs.
      Overrides:
        `getXDHFactory` in class `CommSystemFacade`

    - #### haveHighOutboundCapacity

          public boolean haveHighOutboundCapacity()

      Overrides:
        `haveHighOutboundCapacity` in class `CommSystemFacade`

    - #### haveInboundCapacity

          public boolean haveInboundCapacity(int pct)

      Overrides:
        `haveInboundCapacity` in class `CommSystemFacade`

    - #### haveOutboundCapacity

          public boolean haveOutboundCapacity(int pct)

      Overrides:
        `haveOutboundCapacity` in class `CommSystemFacade`

    - #### initGeoIP

          public void initGeoIP()

      Router must call after netdb is initialized
      Overrides:
        `initGeoIP` in class `CommSystemFacade`

    - #### isBacklogged

          public boolean isBacklogged(Hash peer)

      Overrides:
        `isBacklogged` in class `CommSystemFacade`

    - #### isDummy

          public boolean isDummy()

      Is everything disabled for testing?
      Overrides:
        `isDummy` in class `CommSystemFacade`

    - #### isEstablished

          public boolean isEstablished(Hash peer)

      Specified by:
        `isEstablished` in class `CommSystemFacade`

    - #### isExemptIncoming

          public boolean isExemptIncoming(String ip)

      Is this IP exempt from any incoming throttles or rejections
      Overrides:
        `isExemptIncoming` in class `CommSystemFacade`
      Parameters:
        `ip` - canonical string

    - #### isInStrictCountry

          public boolean isInStrictCountry()

      Are we in a strict country
      Overrides:
        `isInStrictCountry` in class `CommSystemFacade`

    - #### isInStrictCountry

          public boolean isInStrictCountry(Hash peer)

      Are they in a strict country. Not recommended for our local router hash, as we may not be either in the cache or netdb, or may not be publishing an IP.
      Overrides:
        `isInStrictCountry` in class `CommSystemFacade`
      Parameters:
        `peer` - non-null

    - #### isInStrictCountry

          public boolean isInStrictCountry(RouterInfo ri)

      Are they in a strict country
      Overrides:
        `isInStrictCountry` in class `CommSystemFacade`
      Parameters:
        `ri` - non-null

    - #### isRunning

          public boolean isRunning()

      Overrides:
        `isRunning` in class `CommSystemFacade`

    - #### mayDisconnect

          public void mayDisconnect(Hash peer)

      Tell the comm system that we may disconnect from this peer. This is advisory only.
      Overrides:
        `mayDisconnect` in class `CommSystemFacade`

    - #### notifyRemoveAddress

          public void notifyRemoveAddress(boolean ipv6)

      Tell other transports our address changed
      Overrides:
        `notifyRemoveAddress` in class `CommSystemFacade`

    - #### notifyRemoveAddress

          public void notifyRemoveAddress(RouterAddress address)

      Tell other transports our address changed
      Overrides:
        `notifyRemoveAddress` in class `CommSystemFacade`
      Parameters:
        `address` - may be null; or address's host/IP may be null

    - #### notifyReplaceAddress

          public void notifyReplaceAddress(RouterAddress udpAddr)

      UDP changed addresses, tell NTCP and restart All the work moved to NTCPTransport.externalAddressReceived()
      Overrides:
        `notifyReplaceAddress` in class `CommSystemFacade`
      Parameters:
        `udpAddr` - may be null; or udpAddr's host/IP may be null

    - #### processMessage

          public void processMessage(OutNetMessage msg)

      Process and route an outbound message through the transport system. This method is the central entry point for sending messages to other I2P peers. It selects appropriate transport, handles message queuing, and manages delivery tracking. Message Processing:
      - Transport selection based on destination
      - Message validation and filtering
      - Queueing and throttling
      - Delivery status tracking
      - Failure handling and retry logic
      - Callback execution for send completion
      Specified by:
        `processMessage` in class `CommSystemFacade`
      Parameters:
        `msg` - the outbound message to be processed and delivered

    - #### queueLookup

          public void queueLookup(byte[] ip)

      Overrides:
        `queueLookup` in class `CommSystemFacade`
      Parameters:
        `ip` - ipv4 or ipv6

    - #### rdnsCacheSize

          public static String rdnsCacheSize()

    - #### registerTransport

          public void registerTransport(Transport t)

      Pluggable transports. Not for NTCP or SSU. Do not call from transport constructor. Transport must be ready to be started. Following transport methods will be called: setListener() externalAddressReceived() (zero or more times, one for each known address) startListening();
      Overrides:
        `registerTransport` in class `CommSystemFacade`

    - #### removeExemption

          public void removeExemption(String ip)

      Remove this IP from the exemptions
      Overrides:
        `removeExemption` in class `CommSystemFacade`
      Parameters:
        `ip` - canonical string

    - #### renderPeerCaps

          public String renderPeerCaps(Hash peer,
                                       boolean inline)

      Renders the peer's capability HTML block. Caches data and removes unnecessary repeated computation.
      Overrides:
        `renderPeerCaps` in class `CommSystemFacade`
      Parameters:
        `peer` - Peer Hash
        `inline` - If true, render inline without table wrapper
      Returns:
        HTML snippet of peer capabilities

    - #### renderPeerFlag

          public String renderPeerFlag(Hash peer)

      Overrides:
        `renderPeerFlag` in class `CommSystemFacade`

    - #### renderPeerHTML

          public String renderPeerHTML(Hash peer,
                                       boolean extended)

      Renders HTML for a peer with optional extended info. Uses cached RouterInfo, country info, and reverse lookup cache.
      Overrides:
        `renderPeerHTML` in class `CommSystemFacade`
      Parameters:
        `peer` - Peer Hash
        `extended` - Whether to show extended capabilities
      Returns:
        HTML snippet representing peer

    - #### renderStatusHTML

          public void renderStatusHTML(Writer out,
                                       String urlBase,
                                       int sortFlags)
                                throws IOException

      As of 0.9.31, only outputs UPnP status Warning - blocking, very slow, queries the active UPnP router, will take many seconds if it has vanished.
      Overrides:
        `renderStatusHTML` in class `CommSystemFacade`
      Throws:
        `IOException`

    - #### restart

          public void restart()

      Restart the communication system. This method performs a complete restart of all transport protocols while preserving router state. It stops all transports, reinitializes system components, and restarts network operations. Restart Process:
      - Stop all transport protocols gracefully
      - Reinitialize system components
      - Restart transports with preserved state
      - Resume network operations and monitoring
      - Reconfigure address management
      Throws:
        `IllegalStateException` - if not running

    - #### shutdown

          public void shutdown()

      Gracefully shutdown the communication system. This method performs a clean shutdown of all transport protocols and network operations. It stops accepting new connections, closes existing ones, and performs cleanup of system resources. Shutdown Process:
      - Stop network monitoring
      - Stop all transport protocols
      - Close all active connections
      - Cleanup system resources and caches
      - Save final state and statistics
      Throws:
        `IllegalStateException` - if not running

    - #### startup

          public void startup()

      Start the communication system and all transport protocols. This method initializes the communication system, starts all configured transports, and begins network operations. It handles transport discovery, address configuration, and peer management setup. Startup Process:
      - Initialize geographic IP filtering
      - Start network monitoring
      - Register and start all configured transports
      - Begin peer discovery and connection attempts
      - Setup address change notifications
      Throws:
        `IllegalStateException` - if already running

    - #### unregisterTransport

          public void unregisterTransport(Transport t)

      Pluggable transports. Not for NTCP or SSU. Following transport methods will be called: setListener(null) stoptListening();
      Overrides:
        `unregisterTransport` in class `CommSystemFacade`

    - #### wasUnreachable

          public boolean wasUnreachable(Hash peer)

      Overrides:
        `wasUnreachable` in class `CommSystemFacade`