Package net.i2p.util

Class PortMapper

java.lang.Object
net.i2p.util.PortMapper

public class PortMapper extends Object
Map services to internal or external application ports for this context. Not intended for the router's NTCP or SSU ports.
Since:
0.8.12
  • Field Details

  • Constructor Details

    • PortMapper

      public PortMapper(I2PAppContext context)
      Parameters:
      context - unused for now
  • Method Details

    • register

      public boolean register(String service, int port)
      Add the service
      Parameters:
      port - > 0
      Returns:
      success, false if already registered
    • register

      public boolean register(String service, String host, int port)
      Add the service. If service is SVC_EEPSITE or SVC_HTTPS_EEPSITE, the URL will be included in getEepsites()
      Parameters:
      port - > 0
      Returns:
      success, false if already registered
      Since:
      0.9.21
    • isRegistered

      public boolean isRegistered(String service)
      Is the service registered?
      Since:
      0.9.34
    • unregister

      public void unregister(String service)
      Remove the service
    • unregister

      public void unregister(String service, int port)
      Remove the service, only if it is registered with the supplied port. If service is SVC_EEPSITE or SVC_HTTPS_EEPSITE, the URL will be removed from getEepsites()
      Since:
      0.9.34
    • getPort

      public int getPort(String service)
      Get the registered port for a service
      Returns:
      -1 if not registered
    • getPort

      public int getPort(String service, int def)
      Get the registered port for a service
      Parameters:
      def - default
      Returns:
      def if not registered
    • getHost

      public String getHost(String service, String def)
      Get the registered host for a service. Will return "127.0.0.1" if the service was registered without a host.
      Parameters:
      def - default
      Returns:
      def if not registered
      Since:
      0.9.21
    • getActualHost

      public String getActualHost(String service, String def)
      Get the actual host for a service. Will return "127.0.0.1" if the service was registered without a host. If the service was registered with the host "0.0.0.0", "::", or "0:0:0:0:0:0:0:0", it will return a public IP if we have one, else a local IP if we have one, else def. If it was not registered with a wildcard address, it will return the registered host.
      Parameters:
      def - default
      Returns:
      def if not registered
      Since:
      0.9.24
    • getConsoleURL

      public String getConsoleURL()
      If PROP_PREFER_HTTPS is true or unset, return https URL unless console is http only. Default https://127.0.0.1:7667/ If PROP_PREFER_HTTPS is set to false, return http URL unless console is https only. Default http://127.0.0.1:7657/
      Since:
      0.9.33 consolidated from i2ptunnel and desktopgui
    • getConsoleURL

      public String getConsoleURL(boolean preferHTTPS)
      If preferHTTPS is true, return https URL unless console is http only. Default https://127.0.0.1:7667/ If preferHTTPS is false, return http URL unless console is https only. Default http://127.0.0.1:7657/
      Since:
      0.9.34
    • getEepsiteURLs

      public List<String> getEepsiteURLs()
      Returns:
      unsorted, non-empty, or null if none
      Since:
      0.9.50
    • renderStatusHTML

      public void renderStatusHTML(Writer out) throws IOException
      For debugging only
      Throws:
      IOException
      Since:
      0.9.20