java.lang.Object
net.i2p.addressbook.HostPing

public class HostPingextends Object
Simple command-line ping tool Provides I2PIng-compatible functionality with direct I2PSocketManager usage.
  • Field Details

    • _context

      private final I2PAppContext _context
      The app context.
    • _namingService

      private final NamingService _namingService
      Resolver of the local destination names.
    • DEFAULT_COUNT

      private static final int DEFAULT_COUNT
      Pings sent by default.
      See Also:
    • DEFAULT_TIMEOUT

      private static final int DEFAULT_TIMEOUT
      Time allowed for one reply, in ms.
      See Also:
    • DEFAULT_LEASESET_TYPE

      private static final String DEFAULT_LEASESET_TYPE
      Default lease set encryption types to try.
      See Also:
    • DEST_PATTERN

      private static final Pattern DEST_PATTERN
      Matches a full destination in a command line argument.
    • B32_PATTERN

      private static final Pattern B32_PATTERN
      Matches a base32 address in a command line argument.
    • HOSTNAME_PATTERN

      private static final Pattern HOSTNAME_PATTERN
      Matches a hostname to resolve in a command line argument.
    • EQUALS_SPLIT

      private static final Pattern EQUALS_SPLIT
      Splits a command line argument on the equals sign.
    • _count

      private int _count
      Number of pings to send.
    • _timeout

      private int _timeout
      Time allowed for one reply, in ms.
    • _leaseSetType

      private String _leaseSetType
      The lease set encryption types to try.
    • _consecutiveMode

      private boolean _consecutiveMode
      True to send the pings one after another.
    • _debug

      private boolean _debug
      True to print the debug detail.
  • Constructor Details

    • HostPing

      public HostPing()
      Default constructor, uses global context.
  • Method Details

    • pingDestination

      public int pingDestination(String destination)
      Ping a single destination.
      Parameters:
      destination - the .i2p hostname, b32, or b64 address
      Returns:
      0 if all pings succeeded, 1 otherwise
    • pingMultiple

      private int pingMultiple(String destination)
      Multiple ping mode like I2PIng's default behavior.
      Parameters:
      destination - the destination to ping, in any naming service format
      Returns:
      0 if at least one ping got a pong, 1 if all of them failed
    • pingConsecutive

      private int pingConsecutive(String destination)
      Consecutive mode - requires 5 consecutive successes.
      Parameters:
      destination - the destination to ping, in any naming service format
      Returns:
      0 once 5 consecutive pings succeeded, 1 if the attempt budget ran out first
    • pingSingle

      private long pingSingle(String hostname)
      Single ping attempt using I2PSocketManager.
      Parameters:
      hostname - the destination to look up and ping
      Returns:
      the response time in ms, or -1 if the lookup, connect or pong failed
    • printSummary

      private void printSummary(String destination, int successCount, int totalCount, List<Long> responseTimes)
      Print summary in I2PIng format.
      Parameters:
      destination - the destination name printed in the summary
      successCount - the number of pings that got a pong
      totalCount - the number of pings attempted
      responseTimes - the response times in ms of the successful pings
    • pingFromFile

      public int pingFromFile(String filename)
      Ping all destinations listed in a file (one per line).
      Parameters:
      filename - path to the file
      Returns:
      0 if at least one destination was reachable, 1 otherwise
    • readDestinationsFromFile

      private List<String> readDestinationsFromFile(String filename)
      Read destinations from file.
      Parameters:
      filename - the file to read, one destination per line
      Returns:
      the valid destinations extracted from the lines, empty if the file is missing; on a read error, only those read so far
    • isValidDestination

      private boolean isValidDestination(String dest)
      Validate destination format (B64, B32, or .i2p).
      Parameters:
      dest - the destination string to check, null or empty is invalid
      Returns:
      whether valid destination
    • main

      public static void main(String[] args)
      Command line interface.
      Parameters:
      args - the command line: -n count, -t timeoutMs, -ls leaseSetType, -c, -d, -h or -l hostsFile, --help, plus any bare .b32.i2p destinations to ping
    • printHelp

      private static void printHelp()
      Print help message.