java.lang.Object
net.i2p.addressbook.HostPing
Simple command-line ping tool Provides I2PIng-compatible functionality with direct I2PSocketManager usage.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanTrue to send the pings one after another.private final I2PAppContextThe app context.private intNumber of pings to send.private booleanTrue to print the debug detail.private StringThe lease set encryption types to try.private final NamingServiceResolver of the local destination names.private intTime allowed for one reply, in ms.private static final PatternMatches a base32 address in a command line argument.private static final intPings sent by default.private static final StringDefault lease set encryption types to try.private static final intTime allowed for one reply, in ms.private static final PatternMatches a full destination in a command line argument.private static final PatternSplits a command line argument on the equals sign.private static final PatternMatches a hostname to resolve in a command line argument.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionprivate booleanisValidDestination(String dest) Validate destination format (B64, B32, or .i2p).static voidCommand line interface.private intpingConsecutive(String destination) Consecutive mode - requires 5 consecutive successes.intpingDestination(String destination) Ping a single destination.intpingFromFile(String filename) Ping all destinations listed in a file (one per line).private intpingMultiple(String destination) Multiple ping mode like I2PIng's default behavior.private longpingSingle(String hostname) Single ping attempt usingI2PSocketManager.private static voidPrint help message.private voidprintSummary(String destination, int successCount, int totalCount, List<Long> responseTimes) Print summary in I2PIng format.readDestinationsFromFile(String filename) Read destinations from file.
Field Details
_context
The app context._namingService
Resolver of the local destination names.DEFAULT_COUNT
DEFAULT_TIMEOUT
private static final int DEFAULT_TIMEOUTTime allowed for one reply, in ms.- See Also:
DEFAULT_LEASESET_TYPE
Default lease set encryption types to try.- See Also:
DEST_PATTERN
Matches a full destination in a command line argument.B32_PATTERN
Matches a base32 address in a command line argument.HOSTNAME_PATTERN
Matches a hostname to resolve in a command line argument.EQUALS_SPLIT
Splits a command line argument on the equals sign._count
private int _countNumber of pings to send._timeout
private int _timeoutTime allowed for one reply, in ms._leaseSetType
The lease set encryption types to try._consecutiveMode
private boolean _consecutiveModeTrue to send the pings one after another._debug
private boolean _debugTrue to print the debug detail.
Constructor Details
HostPing
public HostPing()Default constructor, uses global context.
Method Details
pingDestination
Ping a single destination.- Parameters:
destination- the .i2p hostname, b32, or b64 address- Returns:
- 0 if all pings succeeded, 1 otherwise
pingMultiple
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
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
Single ping attempt usingI2PSocketManager.- 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 summarysuccessCount- the number of pings that got a pongtotalCount- the number of pings attemptedresponseTimes- the response times in ms of the successful pings
pingFromFile
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
isValidDestination
Validate destination format (B64, B32, or .i2p).- Parameters:
dest- the destination string to check, null or empty is invalid- Returns:
- whether valid destination
main
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.