- All Implemented Interfaces:
Logging, EventDispatcher
Nested Class Summary
Modifier and TypeClassDescriptionprivate static enumHow the tunnel is closed by the console or command line.static interfaceCallback routine to find out.Field Summary
Modifier and TypeFieldDescriptionprivate static final AtomicLongSequence number of the created tunnels.private final PropertiesThe I2CP options of the tunnel.private final I2PAppContextThe app context.private final TunnelControllerThe controller that started the tunnel.private final LogLogger for the tunnel.private final Set<I2PSession> The sessions the tunnel holds open.private final longThis tunnel's position in that sequence.Absolute path to filter definition file.The I2CP host, non-null.private final Set<I2PTunnel.ConnectionEventListener> Listeners of the connection events.The listen-on host.private static final LongOpt[]The command line options of the standalone app.private intId given to the next task.private static final String[]Arguments hidden from the command line help.private static final intPort meaning the standalone app has no console.booleanWhether to use own destination.static final intPacket processing delay in milliseconds.The I2CP port, non-null.longDefault read timeout for tunnel connections (-1 = no timeout).private final List<I2PTunnelTask> The tasks serving the connections.Constructor Summary
ModifierConstructorDescriptionStandard constructor for embedded, uses args "-nocli -die" to return immediately.Seeusage()for options.I2PTunnel(String[] args, I2PTunnel.ConnectionEventListener lsnr) See usage() for options.privateI2PTunnel(String[] args, I2PTunnel.ConnectionEventListener lsnr, TunnelController tc) Creates the tunnel with its listener and controller.New standard constructor in router, with back ref to tc.Method Summary
Modifier and TypeMethodDescriptionvoidRegisters a listener for connection events.(package private) voidaddSession(I2PSession session) Add a session to the tunnel.private voidaddtask(I2PTunnelTask tsk) Adds a task serving the connections.private voidclientRunError(String msg, String taskId, Logging l, IllegalArgumentException iae) Log a failed client tunnel configuration and propagate the error.private booleanclosetask(int num, I2PTunnel.CloseMode mode, Logging l) Helper method to actually close the given task number (optionally forcing closure).private booleanclosetask(I2PTunnelTask t, I2PTunnel.CloseMode mode) Helper method to actually close the given task (optionally forcing closure).private static DestinationResolve a destination from a name or Base64 string.Generic options used for clients and servers.Gets the application context.(package private) TunnelControllerTunnelController that constructed this, or null.private StringReturns the log prefix naming the tunnel.private FilegetPrivKeyFile(String fileArg, Logging l) Resolve a private key file argument relative to the config dir.Snapshot of the primary sessions in use by this tunnel's tasks.getTasks()Snapshot of the running tasks.voidLog the given message using the logging subsystem and standard output.static voidCommand-line entry point.private static voidmakeKey(OutputStream writeTo, OutputStream pubDest, Logging l) Create a new destination, storing the destination and its private keys where instructed.private InetAddressparseServerHost(String hostArg, Logging l) Resolve a server host argument.private intparseServerPort(String portArg, Logging l) Parse a server port argument.private voidHelper task to remove closed / completed tasks.voidUnregisters a connection event listener.(package private) voidremoveSession(I2PSession session) Remove a session from the tunnel.(package private) voidCalled when the router disconnects unexpectedly.private voidSpecify the i2cp username and password.private voidrunBlinding(String[] argv) Send a BlindingInfo message, just for testing.private voidrunCLI()Run an interactive command-line interface on stdin.voidRun the client on the given port number pointing at the specified destination (either the base64 of the destination or file:fileNameContainingDestination).voidrunClientOptions(String[] args, Logging l) Configure the extra I2CP options to use in any subsequent I2CP sessions.voidClose the given task (or all tasks), optionally forcing them to die a hard deathvoidrunCommand(String cmd, Logging l) Parses and executes a tunnel management command.private voidSpecify the i2cp host and port Deprecated - only used by CLIvoidrunConnectClient(String[] args, Logging l) Run a CONNECT client on the given port numberprivate static voidrunGenKeys(String[] args, Logging l) Generate a new keypair.private static voidGenerate a new keypair.private voidrunGUI()Launch the GUI, exiting if it is not available.private static voidDisplay help information through the given logger.voidrunHttpBidirServer(String[] args, Logging l) Run the HTTP server pointing at the host and port specified using the private i2p destination loaded from the specified file, replacing the HTTP headers so that the Host: specified is the one spoofed.voidrunHttpClient(String[] args, Logging l) Run an HTTP client on the given port numbervoidrunHttpServer(String[] args, Logging l) Run the HTTP server pointing at the host and port specified using the private i2p destination loaded from the specified file, replacing the HTTP headers so that the Host: specified is the one spoofed.voidrunIrcClient(String[] args, Logging l) Run an IRC client on the given port numbervoidrunIrcServer(String[] args, Logging l) Same args as runServer (we should stop duplicating all this code...).private voidRetrieve a list of currently running tasks Deprecated - only used by CLIvoidrunListenOn(String[] args, Logging l) Specify the hostname / IP address of the interface that the tunnels should bind toprivate voidPerform a lookup of the name specified Deprecated - only used by CLIprivate voidrunOwnDest(String[] args, Logging l) Specify whether to use its own destination for each outgoing tunnel Deprecated - only used by CLIprivate voidStart up a ping task with the specified args (currently supporting -ns, -h, -l) Deprecated - only used by CLIprivate voidExit the JVM if there are no more tasks left running.voidrunReadTimeout(String[] args, Logging l) Specify the read timeout going to be used for newly-created I2PSocketsprivate voidRun all of the commands in the given file (one command per line) Deprecated - only used by CLIvoidRun the server pointing at the host and port specified using the private i2p destination loaded from the specified file.voidrunSOCKSIRCTunnel(String[] args, Logging l) Run an SOCKS IRC tunnel on the given port numbervoidrunSOCKSTunnel(String[] args, Logging l) Run an SOCKS tunnel on the given port numbervoidrunStreamrClient(String[] args, Logging l) Streamr client.voidrunStreamrServer(String[] args, Logging l) Streamr server.voidrunTextServer(String[] args, Logging l) Run the server pointing at the host and port specified using the private i2p destination loaded from the given base64 stream.voidsetClientOptions(Properties opts) Generic options used for clients and servers.private static voidshowKey(InputStream readFrom, OutputStream pubDest, Logging l) Read in the given destination, display it, and write it to the given location Deprecated - only used by CLI.private static String[]Java 1.3 vs 1.4 :).private static Stringusage()The command-line usage text, one option per line.private static voidwritePubKey(Destination d, OutputStream o, Logging l) Write out the destination to the stream Deprecated - only used by CLI.Methods inherited from class EventDispatcherImpl
attachEventDispatcher, detachEventDispatcher, getEventDispatcher, getEvents, getEventValue, ignoreEvents, notifyEvent, unIgnoreEvents, waitEventValueModifier and TypeMethodDescriptionvoidAttach an EventDispatcher object to the events dispatching chain.voidDetach the specified EventDispatcher object from the events dispatching chain.Object to be used to deliver events (usuallythis, but YMMV).Retrieve the names of all the events that have been received.getEventValue(String name) Retrieve the value currently associated with the specified event value.voidIgnore further event notifications.voidnotifyEvent(String eventName, Object args) Deliver an event.voidAlmost like the method above :-).waitEventValue(String name) Wait until the given event has received a value.
Field Details
_log
Logger for the tunnel._context
The app context.__tunnelId
Sequence number of the created tunnels._tunnelId
private final long _tunnelIdThis tunnel's position in that sequence._clientOptions
The I2CP options of the tunnel._sessions
The sessions the tunnel holds open._controller
The controller that started the tunnel.PACKET_DELAY
public static final int PACKET_DELAYPacket processing delay in milliseconds.- See Also:
ownDest
public volatile boolean ownDestWhether to use own destination.port
The I2CP port, non-null.host
The I2CP host, non-null.listenHost
The listen-on host. Sadly the listen-on port does not have a field.readTimeout
public long readTimeoutDefault read timeout for tunnel connections (-1 = no timeout).filterDefinition
Absolute path to filter definition file.nocli_args
Arguments hidden from the command line help.tasks
The tasks serving the connections.next_task_id
private int next_task_idId given to the next task.listeners
Listeners of the connection events.NOGUI
private static final int NOGUIPort meaning the standalone app has no console.- See Also:
longopts
The command line options of the standalone app.
Constructor Details
I2PTunnel
public I2PTunnel()Standard constructor for embedded, uses args "-nocli -die" to return immediately.I2PTunnel
New standard constructor in router, with back ref to tc.- Parameters:
tc- may be null- Throws:
IllegalArgumentException- if the arguments are unparseable, name more than one command, or the trailing command file does not exist
I2PTunnel
Seeusage()for options.- Parameters:
args- the CLI arguments, parsed per usage()- Throws:
IllegalArgumentException- if the arguments are unparseable, name more than one command, or the trailing command file does not exist
I2PTunnel
See usage() for options.- Parameters:
args- the CLI arguments, parsed per usage()lsnr- may be null- Throws:
IllegalArgumentException- if the arguments are unparseable, name more than one command, or the trailing command file does not exist
I2PTunnel
Creates the tunnel with its listener and controller.- Parameters:
args- the command-line arguments, parsed for the option letters and a trailing command filelsnr- may be nulltc- may be null- Throws:
IllegalArgumentException- if the options are unparseable, or the command file named at the end of the arguments does not exist
Method Details
main
Command-line entry point.- Parameters:
args- the command-line arguments parsed by the I2PTunnel constructor
runGUI
private void runGUI()Launch the GUI, exiting if it is not available.runCLI
private void runCLI()Run an interactive command-line interface on stdin.usage
The command-line usage text, one option per line.- Returns:
- the usage text, with newlines except for last line
getTasks
Snapshot of the running tasks.- Returns:
- an unmodifiable snapshot, non-null; changes to the tunnel's task list are not reflected in an already-returned list
getSessions
Snapshot of the primary sessions in use by this tunnel's tasks. Subsessions are not tracked here; a task's own getSocketManager() remains the way to reach them.- Returns:
- an unmodifiable snapshot, non-null; changes to the tunnel's session set are not reflected in an already-returned list. The iteration order follows the underlying set and is not specified.
addSession
removeSession
getClientOptions
Generic options used for clients and servers. NOT a copy, Do NOT modify for per-connection options, make a copy.- Returns:
- non-null, NOT a copy, do NOT modify for per-connection options
getController
TunnelController getController()TunnelController that constructed this, or null.- Returns:
- controller or null
addtask
Adds a task serving the connections.- Parameters:
tsk- the task to add
split
runCommand
Parses and executes a tunnel management command.This method is the command dispatcher for tunnel management operations. It parses the command string into command name and arguments, then dispatches to the appropriate handler method.
Supported Commands:
- help - Display available commands
- client/server - Create tunnel instances
- list - List active tunnels
- close - Close tunnels
- config - Configure I2CP connection
- genkeys - Generate destination keys
- Parameters:
cmd- the command string to execute, format: "commandName arg1 arg2 ..."l- the Logging instance for command output- See Also:
clientRunError
Log a failed client tunnel configuration and propagate the error.- Parameters:
msg- the error messagetaskId- the event name for the failed tunnel typel- logger to receive events and outputiae- the configuration error
parseServerHost
Resolve a server host argument.- Parameters:
hostArg- the hostname argumentl- logger to receive events and output- Returns:
- the resolved address
- Throws:
IllegalArgumentException- if the host cannot be resolved
parseServerPort
Parse a server port argument.- Parameters:
portArg- the port argumentl- logger to receive events and output- Returns:
- the parsed port
- Throws:
IllegalArgumentException- if the port is not a valid positive integer
getPrivKeyFile
Resolve a private key file argument relative to the config dir.- Parameters:
fileArg- the key file argumentl- logger to receive events and output- Returns:
- the readable key file
- Throws:
IllegalArgumentException- if the file does not exist or is not readable
runHelp
Display help information through the given logger.Does not fire any events to the logger.
- Parameters:
l- logger to receive events and output
runClientOptions
Configure the extra I2CP options to use in any subsequent I2CP sessions. Generic options used for clients and servers Usage: "clientoptions[ key=value]*" .Event "clientoptions_onResult" = "ok" on completion.
Deprecated To be made private, use
setClientOptions(Properties). This does NOT update a running TunnelTask.- Parameters:
args- each args[i] is a key=value pair to add to the optionsl- logger to receive events and output
setClientOptions
Generic options used for clients and servers. This DOES update a running TunnelTask, but NOT the session. A more efficientrunClientOptions(String[], Logging).Defaults in opts properties are not recommended, they may or may not be honored.
- Parameters:
opts- non-null
runServer
Run the server pointing at the host and port specified using the private i2p destination loaded from the specified file.Event "serverTaskId" = Integer(taskId) after the tunnel has been started (or -1 on error) Also sets the event "openServerResult" = "ok" or "error" (displaying "Ready!" on the logger after 'ok'). So, success = serverTaskId != -1 and openServerResult = ok.
- Parameters:
args- {hostname, portNumber, privKeyFilename}l- logger to receive events and output- Throws:
IllegalArgumentException- on config problem
runIrcServer
Same args as runServer (we should stop duplicating all this code...).- Parameters:
args- host, port and privkeyfile, exactly as runServer takes theml- logger to receive events and output- Throws:
IllegalArgumentException- on config problem
runHttpServer
Run the HTTP server pointing at the host and port specified using the private i2p destination loaded from the specified file, replacing the HTTP headers so that the Host: specified is the one spoofed.Event "serverTaskId" = Integer(taskId) after the tunnel has been started (or -1 on error) Also sets the event "openServerResult" = "ok" or "error" (displaying "Ready!" on the logger after 'ok'). So, success = serverTaskId != -1 and openServerResult = ok.
- Parameters:
args- {hostname, portNumber, spoofedHost, privKeyFilename}l- logger to receive events and output- Throws:
IllegalArgumentException- on config problem
runHttpBidirServer
Run the HTTP server pointing at the host and port specified using the private i2p destination loaded from the specified file, replacing the HTTP headers so that the Host: specified is the one spoofed. Also runs an HTTP proxy for bidirectional communications on the same tunnel destination.Event "serverTaskId" = Integer(taskId) after the tunnel has been started (or -1 on error) Also sets the event "openServerResult" = "ok" or "error" (displaying "Ready!" on the logger after 'ok'). So, success = serverTaskId != -1 and openServerResult = ok.
- Parameters:
args- {hostname, portNumber, proxyPortNumber, spoofedHost, privKeyFilename}l- logger to receive events and output- Throws:
IllegalArgumentException- on config problem
runTextServer
Run the server pointing at the host and port specified using the private i2p destination loaded from the given base64 stream.Deprecated? Why run a server with a private destination? Not available from the war GUI
Event "serverTaskId" = Integer(taskId) after the tunnel has been started (or -1 on error) Also sets the event "openServerResult" = "ok" or "error" (displaying "Ready!" on the logger after 'ok'). So, success = serverTaskId != -1 and openServerResult = ok.
- Parameters:
args- {hostname, portNumber, privKeyBase64}l- logger to receive events and output- Throws:
IllegalArgumentException- on config problem
runClient
Run the client on the given port number pointing at the specified destination (either the base64 of the destination or file:fileNameContainingDestination).Event "clientTaskId" = Integer(taskId) after the tunnel has been started (or -1 on error) Also sets the event "openClientResult" = "error" or "ok" (before setting the value to "ok" it also adds "Ready! Port #" to the logger as well). In addition, it will also set "clientLocalPort" = Integer port number if the client is listening sharedClient parameter is a String "true" or "false".
- Parameters:
args- {portNumber, destinationBase64 or "file:filename"[, sharedClient [, privKeyFile]]}l- logger to receive events and output- Throws:
IllegalArgumentException- on config problem
runHttpClient
Run an HTTP client on the given port numberEvent "httpclientTaskId" = Integer(taskId) after the tunnel has been started (or -1 on error). Also sets "httpclientStatus" = "ok" or "error" after the client tunnel has started. parameter sharedClient is a String, either "true" or "false".
- Parameters:
args- {portNumber[, sharedClient][, proxy to be used for the WWW]}l- logger to receive events and output- Throws:
IllegalArgumentException- on config problem
runConnectClient
Run a CONNECT client on the given port numberEvent "connectclientTaskId" = Integer(taskId) after the tunnel has been started (or -1 on error).
- Parameters:
args- {portNumber[, sharedClient][, proxy to be used for the WWW]}l- logger to receive events and output- Throws:
IllegalArgumentException- on config problem
runIrcClient
Run an IRC client on the given port numberEvent "ircclientTaskId" = Integer(taskId) after the tunnel has been started (or -1 on error). Also sets "ircclientStatus" = "ok" or "error" after the client tunnel has started. parameter sharedClient is a String, either "true" or "false".
- Parameters:
args- {portNumber,destinationBase64 or "file:filename" [, sharedClient [, privKeyFile]]}l- logger to receive events and output- Throws:
IllegalArgumentException- on config problem
runSOCKSTunnel
Run an SOCKS tunnel on the given port numberEvent "sockstunnelTaskId" = Integer(taskId) after the tunnel has been started (or -1 on error). Also sets "openSOCKSTunnelResult" = "ok" or "error" after the client tunnel has started.
- Parameters:
args- {portNumber [, sharedClient]} or (portNumber, ignored (false), privKeyFile)l- logger to receive events and output- Throws:
IllegalArgumentException- on config problem
runSOCKSIRCTunnel
Run an SOCKS IRC tunnel on the given port numberEvent "socksirctunnelTaskId" = Integer(taskId) after the tunnel has been started (or -1 on error).
- Parameters:
args- {portNumber [, sharedClient]} or (portNumber, ignored (false), privKeyFile)l- logger to receive events and output- Throws:
IllegalArgumentException- on config problem
runStreamrClient
Streamr client.- Parameters:
args- {targethost, targetport, destinationString}l- logger to receive events and output- Throws:
IllegalArgumentException- on config problem
runStreamrServer
Streamr server.- Parameters:
args- exactly two: the port and the private key file, which is resolved against the config dir when not absolutel- logger to receive events and output- Throws:
IllegalArgumentException- on config problem
runConfig
Specify the i2cp host and port Deprecated - only used by CLIEvent "configResult" = "ok" or "error" after the configuration has been specified.
- Parameters:
args- an optional leading -s for SSL, then the I2CP host and portl- logger to receive events and output
runAuth
runOwnDest
runListenOn
Specify the hostname / IP address of the interface that the tunnels should bind toEvent "listen_onResult" = "ok" or "error" after the interface has been specified.
- Parameters:
args- exactly one: the interface hostname or IP to bind tol- logger to receive events and output
runReadTimeout
Specify the read timeout going to be used for newly-created I2PSocketsEvent "read_timeoutResult" = "ok" or "error" after the interface has been specified.
- Parameters:
args- exactly one: the read timeout in ms; negative waits foreverl- logger to receive events and output
runGenKeys
Generate a new keypair. Does NOT support non-default sig types. Deprecated - only used by CLIEvent "genkeysResult" = "ok" or "error" after the generation is complete.
- Parameters:
args- {privateKeyFilename, publicKeyFilename} or {privateKeyFilename}l- logger to receive events and output
runGenTextKeys
Generate a new keypair. Does NOT support non-default sig types. Deprecated - only used by CLIEvent "privateKey" = base64 of the privateKey stream and sets the event "publicDestination" = base64 of the destination.
- Parameters:
l- logger to receive events and output
runQuit
Exit the JVM if there are no more tasks left running. If there are tunnels running, it returns. Deprecated - only used by CLIEvent "quitResult" = "error" if there are tasks running (but if there aren't, well, there's no point in setting the quitResult to "ok", now is there?).
- Parameters:
l- logger to receive events and output
runList
Retrieve a list of currently running tasks Deprecated - only used by CLIEvent "listDone" = "done" after dumping the tasks to the logger.
- Parameters:
l- logger to receive events and output
runClose
Close the given task (or all tasks), optionally forcing them to die a hard deathEvent "closeResult" = "ok" after the closing is complete.
- Parameters:
args- {jobNumber}, {"forced", jobNumber}, {"forced", "all"}, {"destroy", jobNumber}, {"destroy", "all"}l- logger to receive events and output
runRun
Run all of the commands in the given file (one command per line) Deprecated - only used by CLIEvent "runResult" = "ok" or "error" after the closing is complete.
- Parameters:
args- exactly one: the path to a file of commands, one per linel- logger to receive events and output
runLookup
runPing
Start up a ping task with the specified args (currently supporting -ns, -h, -l) Deprecated - only used by CLIEvent "pingTaskId" = Integer of the taskId, or -1.
- Parameters:
allargs- arguments to pass to the I2Ping taskl- logger to receive events and output
runBlinding
Send a BlindingInfo message, just for testing.- Parameters:
argv- the arguments after the "blinding" command word, parsed for the option letters d, p, k, s and e
closetask
Helper method to actually close the given task number (optionally forcing closure).- Parameters:
num- the task id to look for, the search stops at a higher idmode- how to close it: normal, forced, or destroyl- unused, the class logger is used instead- Returns:
- true if a task with that id was found and closed
closetask
Helper method to actually close the given task (optionally forcing closure).- Parameters:
t- the task to closemode- how to close it: normal, forced, or destroy- Returns:
- true if the task reported it is closed
purgetasks
private void purgetasks()Helper task to remove closed / completed tasks.log
makeKey
Create a new destination, storing the destination and its private keys where instructed. Does NOT support non-default sig types. Deprecated - only used by CLI.- Parameters:
writeTo- location to store the destination and private keyspubDest- location to store the destinationl- logger to send messages to
showKey
Read in the given destination, display it, and write it to the given location Deprecated - only used by CLI.- Parameters:
readFrom- stream to read the destination frompubDest- stream to write the destination tol- logger to send messages to
writePubKey
private static void writePubKey(Destination d, OutputStream o, Logging l) throws I2PException, IOException Write out the destination to the stream Deprecated - only used by CLI.- Parameters:
d- Destination to writeo- stream to write the destination to, or null for noopl- logger to send messages to- Throws:
I2PException- if the destination's key cannot be encoded, a DataFormatExceptionIOException- if the stream write fails
destFromName
private static Destination destFromName(String name, String i2cpHost, String i2cpPort, boolean isSSL, String user, String pw) throws DataFormatException Resolve a destination from a name or Base64 string.- Parameters:
name- the destination as a local name, a base32 or base64 string, or a "file:" pathi2cpHost- may be nulli2cpPort- may be nullisSSL- true to reach the router's I2CP proxy over TLS instead of plain TCPuser- may be nullpw- may be null- Returns:
- the destination, or null if the name is unknown, the file cannot be read, or the lookup fails
- Throws:
DataFormatException- if name is null or blank
addConnectionEventListener
Registers a listener for connection events.The listener will be notified of router disconnection events.
- Parameters:
lsnr- the listener to add; ignored if null
removeConnectionEventListener
Unregisters a connection event listener.- Parameters:
lsnr- the listener to remove; ignored if null
getPrefix
Returns the log prefix naming the tunnel.- Returns:
- the prefix with the tunnel id
getContext
routerDisconnected
void routerDisconnected()Called when the router disconnects unexpectedly.This method notifies all registered ConnectionEventListeners that the router connection has been lost.