All Implemented Interfaces:
Runnable, EventDispatcher

public class I2Pingextends I2PTunnelClientBase
I2P ping utility for CLI use.

Warning: Not stable API. Sample code for I2PTunnel CLI only. Not for external use.

  • Field Details

    • PROP_COMMAND

      public static final String PROP_COMMAND
      Config key for the ping command string.
      See Also:
    • PING_COUNT

      private static final int PING_COUNT
      Pings sent to a tunnel peer.
      See Also:
    • CPING_COUNT

      private static final int CPING_COUNT
      Pings sent to a client destination.
      See Also:
    • PING_TIMEOUT

      private static final int PING_TIMEOUT
      Time allowed for one ping reply.
      See Also:
    • finished

      private volatile boolean finished
      True once the ping run is over.
    • fromList

      private boolean fromList
      True if the destination came from the local list.
  • Constructor Details

    • I2Ping

      public I2Ping(Logging l, boolean ownDest, EventDispatcher notifyThis, I2PTunnel tunnel)
      Construct a ping tunnel client over an existing command.

      The command line to run must be carried in tunnel.getOptions as "command".

      Parameters:
      l - the logging instance
      ownDest - whether to use an owned destination
      notifyThis - the event dispatcher for notifications
      tunnel - the I2PTunnel instance whose client options carry the command
      Throws:
      IllegalArgumentException - if it doesn't
  • Method Details

    • run

      public void run()
      Overrides super. No client ServerSocket is created.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class I2PTunnelClientBase
    • runCommand

      public void runCommand(String cmd) throws InterruptedException, IOException
      Parse the command line options, then ping each requested host.
      Parameters:
      cmd - the command line arguments, as a single space-separated string
      Throws:
      InterruptedException - if the calling thread is interrupted while pinging
      IOException - if the destination keys cannot be read or a ping cannot be sent
    • usage

      public static String usage()
      Return the command line usage text.
      Returns:
      the usage and option list, for display to the user
    • close

      public boolean close(boolean forced)
      Close the tunnel, warning if pings were still running.
      Overrides:
      close in class I2PTunnelClientBase
      Parameters:
      forced - true to close without waiting for the pings to finish
      Returns:
      true if the tunnel was closed or was already closed
    • ping

      private I2Ping.PingResult ping(Destination dest, int fromPort, int toPort, long timeout)
      Attempts to "ping" by opening an I2P socket to the destination. The result reports whether the connection succeeded within the timeout.
      Parameters:
      dest - the destination to ping
      fromPort - the local port to open the socket on
      toPort - the destination port to connect to
      timeout - how long to wait for the connection, in ms
      Returns:
      the ping result with success state and round-trip time
    • clientConnectionRun

      protected void clientConnectionRun(Socket s)
      Handle one accepted connection; a ping tunnel accepts none, so this does nothing.
      Specified by:
      clientConnectionRun in class I2PTunnelClientBase
      Parameters:
      s - the accepted connection