net.i2p.i2ptunnel
Class I2PTunnel

java.lang.Object
  extended by net.i2p.i2ptunnel.I2PTunnel
All Implemented Interfaces:
Logging, EventDispatcher

public class I2PTunnel
extends java.lang.Object
implements Logging, EventDispatcher

Todo: Most events are not listened to elsewhere, so error propagation is poor


Nested Class Summary
static interface I2PTunnel.ConnectionEventListener
          Callback routine to find out
 
Field Summary
 java.lang.String host
           
 java.lang.String listenHost
           
 boolean ownDest
           
static int PACKET_DELAY
           
 java.lang.String port
           
 long readTimeout
           
 
Constructor Summary
I2PTunnel()
           
I2PTunnel(java.lang.String[] args)
           
I2PTunnel(java.lang.String[] args, I2PTunnel.ConnectionEventListener lsnr)
           
 
Method Summary
 void addConnectionEventListener(I2PTunnel.ConnectionEventListener lsnr)
           
(package private)  void addSession(I2PSession session)
           
 void attachEventDispatcher(EventDispatcher e)
          Attach an EventDispatcher object to the events dispatching chain.
static Destination destFromName(java.lang.String name)
          Generates a Destination from a name.
 void detachEventDispatcher(EventDispatcher e)
          Detach the specified EventDispatcher object from the events dispatching chain.
 java.util.Properties getClientOptions()
           
 I2PAppContext getContext()
           
 EventDispatcher getEventDispatcher()
          Get an object to be used to deliver events (usually this, but YMMV).
 java.util.Set getEvents()
          Retrieve the names of all the events that have been received
 java.lang.Object getEventValue(java.lang.String n)
          Retrieve the value currently associated with the specified event value
(package private)  java.util.List<I2PSession> getSessions()
           
 void ignoreEvents()
          Ignore further event notifications
 void log(java.lang.String s)
          Log the given message (using both the logging subsystem and standard output...)
static void main(java.lang.String[] args)
           
static void makeKey(java.io.OutputStream writeTo, java.io.OutputStream pubDest, Logging l)
          Create a new destination, storing the destination and its private keys where instructed Deprecated - only used by CLI
 void notifyEvent(java.lang.String e, java.lang.Object a)
          Deliver an event
 void removeConnectionEventListener(I2PTunnel.ConnectionEventListener lsnr)
           
(package private)  void removeSession(I2PSession session)
           
(package private)  void routerDisconnected()
          Call this whenever we lose touch with the router involuntarily (aka the router is off / crashed / etc)
 void runClient(java.lang.String[] args, Logging l)
          Run the client on the given port number pointing at the specified destination (either the base64 of the destination or file:fileNameContainingDestination).
 void runClientOptions(java.lang.String[] args, Logging l)
          Configure the extra I2CP options to use in any subsequent I2CP sessions.
 void runClose(java.lang.String[] args, Logging l)
          Close the given task (or all tasks), optionally forcing them to die a hard death Sets the event "closeResult" = "ok" after the closing is complete
 void runCommand(java.lang.String cmd, Logging l)
           
 void runConfig(java.lang.String[] args, Logging l)
          Specify the i2cp host and port Sets the event "configResult" = "ok" or "error" after the configuration has been specified
 void runConnectClient(java.lang.String[] args, Logging l)
          Run a CONNECT client on the given port number
 void runGenKeys(java.lang.String[] args, Logging l)
          Generate a new keypair Sets the event "genkeysResult" = "ok" or "error" after the generation is complete
 void runGenTextKeys(Logging l)
          Generate a new keypair Sets the event "privateKey" = base64 of the privateKey stream and sets the event "publicDestination" = base64 of the destination
 void runHelp(Logging l)
          Display help information through the given logger.
 void runHttpBidirServer(java.lang.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.
 void runHttpClient(java.lang.String[] args, Logging l)
          Run an HTTP client on the given port number Sets the event "httpclientTaskId" = Integer(taskId) after the tunnel has been started (or -1 on error).
 void runHttpServer(java.lang.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.
 void runIrcClient(java.lang.String[] args, Logging l)
          Run an IRC client on the given port number Sets the event "ircclientTaskId" = Integer(taskId) after the tunnel has been started (or -1 on error).
 void runIrcServer(java.lang.String[] args, Logging l)
          Same args as runServer (we should stop duplicating all this code...)
 void runList(Logging l)
          Retrieve a list of currently running tasks Sets the event "listDone" = "done" after dumping the tasks to the logger
 void runListenOn(java.lang.String[] args, Logging l)
          Specify the hostname / IP address of the interface that the tunnels should bind to Sets the event "listen_onResult" = "ok" or "error" after the interface has been specified
 void runLookup(java.lang.String[] args, Logging l)
          Perform a lookup of the name specified Sets the event "lookupResult" = base64 of the destination, or an error message
 void runOwnDest(java.lang.String[] args, Logging l)
          Specify whether to use its own destination for each outgoing tunnel Sets the event "owndestResult" = "ok" or "error" after the configuration has been specified
 void runPing(java.lang.String allargs, Logging l)
          Start up a ping task with the specified args (currently supporting -ns, -h, -l) Sets the event "pingTaskId" = Integer of the taskId, or -1
 void runQuit(Logging l)
          Exit the JVM if there are no more tasks left running.
 void runReadTimeout(java.lang.String[] args, Logging l)
          Specify the read timeout going to be used for newly-created I2PSockets Sets the event "read_timeoutResult" = "ok" or "error" after the interface has been specified
 void runRun(java.lang.String[] args, Logging l)
          Run all of the commands in the given file (one command per line) Sets the event "runResult" = "ok" or "error" after the closing is complete
 void runServer(java.lang.String[] args, Logging l)
          Run the server pointing at the host and port specified using the private i2p destination loaded from the specified file.
 void runSOCKSIRCTunnel(java.lang.String[] args, Logging l)
          Run an SOCKS IRC tunnel on the given port number
 void runSOCKSTunnel(java.lang.String[] args, Logging l)
          Run an SOCKS tunnel on the given port number Sets the event "sockstunnelTaskId" = Integer(taskId) after the tunnel has been started (or -1 on error).
 void runStreamrClient(java.lang.String[] args, Logging l)
          Streamr client
 void runStreamrServer(java.lang.String[] args, Logging l)
          Streamr server
 void runTextServer(java.lang.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.
static void showKey(java.io.InputStream readFrom, java.io.OutputStream pubDest, Logging l)
          Read in the given destination, display it, and write it to the given location Deprecated - only used by CLI
 void unIgnoreEvents()
          Almost like the method above :-)
 java.lang.Object waitEventValue(java.lang.String n)
          Wait until the given event has received a value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PACKET_DELAY

public static final int PACKET_DELAY
See Also:
Constant Field Values

ownDest

public boolean ownDest

port

public java.lang.String port

host

public java.lang.String host

listenHost

public java.lang.String listenHost

readTimeout

public long readTimeout
Constructor Detail

I2PTunnel

public I2PTunnel()

I2PTunnel

public I2PTunnel(java.lang.String[] args)

I2PTunnel

public I2PTunnel(java.lang.String[] args,
                 I2PTunnel.ConnectionEventListener lsnr)
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Throws:
java.io.IOException

getSessions

java.util.List<I2PSession> getSessions()
Returns:
non-null

addSession

void addSession(I2PSession session)

removeSession

void removeSession(I2PSession session)

getClientOptions

public java.util.Properties getClientOptions()

runCommand

public void runCommand(java.lang.String cmd,
                       Logging l)

runHelp

public void runHelp(Logging l)
Display help information through the given logger. Does not fire any events to the logger

Parameters:
l - logger to receive events and output

runClientOptions

public void runClientOptions(java.lang.String[] args,
                             Logging l)
Configure the extra I2CP options to use in any subsequent I2CP sessions. Usage: "clientoptions[ key=value]*" . Sets the event "clientoptions_onResult" = "ok" after completion.

Parameters:
args - each args[i] is a key=value pair to add to the options
l - logger to receive events and output

runServer

public void runServer(java.lang.String[] args,
                      Logging l)
Run the server pointing at the host and port specified using the private i2p destination loaded from the specified file.

Sets the 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:
java.lang.IllegalArgumentException - on config problem

runIrcServer

public void runIrcServer(java.lang.String[] args,
                         Logging l)
Same args as runServer (we should stop duplicating all this code...)

Throws:
java.lang.IllegalArgumentException - on config problem

runHttpServer

public void runHttpServer(java.lang.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.

Sets the 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:
java.lang.IllegalArgumentException - on config problem

runHttpBidirServer

public void runHttpBidirServer(java.lang.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. Also runs an HTTP proxy for bidirectional communications on the same tunnel destination.

Sets the 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:
java.lang.IllegalArgumentException - on config problem

runTextServer

public void runTextServer(java.lang.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.

Deprecated? Why run a server with a private destination? Not available from the war GUI Sets the 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:
java.lang.IllegalArgumentException - on config problem

runClient

public void runClient(java.lang.String[] args,
                      Logging l)
Run the client on the given port number pointing at the specified destination (either the base64 of the destination or file:fileNameContainingDestination). Sets the 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:
java.lang.IllegalArgumentException - on config problem

runHttpClient

public void runHttpClient(java.lang.String[] args,
                          Logging l)
Run an HTTP client on the given port number Sets the event "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:
java.lang.IllegalArgumentException - on config problem

runConnectClient

public void runConnectClient(java.lang.String[] args,
                             Logging l)
Run a CONNECT client on the given port number

Parameters:
args - {portNumber[, sharedClient][, proxy to be used for the WWW]}
l - logger to receive events and output
Throws:
java.lang.IllegalArgumentException - on config problem

runIrcClient

public void runIrcClient(java.lang.String[] args,
                         Logging l)
Run an IRC client on the given port number Sets the event "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:
java.lang.IllegalArgumentException - on config problem

runSOCKSTunnel

public void runSOCKSTunnel(java.lang.String[] args,
                           Logging l)
Run an SOCKS tunnel on the given port number Sets the event "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]}
l - logger to receive events and output
Throws:
java.lang.IllegalArgumentException - on config problem

runSOCKSIRCTunnel

public void runSOCKSIRCTunnel(java.lang.String[] args,
                              Logging l)
Run an SOCKS IRC tunnel on the given port number

Parameters:
args - {portNumber [, sharedClient]} or (portNumber, ignored (false), privKeyFile)
Throws:
java.lang.IllegalArgumentException - on config problem
Since:
0.7.12

runStreamrClient

public void runStreamrClient(java.lang.String[] args,
                             Logging l)
Streamr client

Parameters:
args - {targethost, targetport, destinationString}
l - logger to receive events and output
Throws:
java.lang.IllegalArgumentException - on config problem

runStreamrServer

public void runStreamrServer(java.lang.String[] args,
                             Logging l)
Streamr server

Parameters:
args - {port, privkeyfile}
l - logger to receive events and output
Throws:
java.lang.IllegalArgumentException - on config problem

runConfig

public void runConfig(java.lang.String[] args,
                      Logging l)
Specify the i2cp host and port Sets the event "configResult" = "ok" or "error" after the configuration has been specified

Parameters:
args - {hostname, portNumber}
l - logger to receive events and output

runOwnDest

public void runOwnDest(java.lang.String[] args,
                       Logging l)
Specify whether to use its own destination for each outgoing tunnel Sets the event "owndestResult" = "ok" or "error" after the configuration has been specified

Parameters:
args - {yes or no}
l - logger to receive events and output

runListenOn

public void runListenOn(java.lang.String[] args,
                        Logging l)
Specify the hostname / IP address of the interface that the tunnels should bind to Sets the event "listen_onResult" = "ok" or "error" after the interface has been specified

Parameters:
args - {hostname}
l - logger to receive events and output

runReadTimeout

public void runReadTimeout(java.lang.String[] args,
                           Logging l)
Specify the read timeout going to be used for newly-created I2PSockets Sets the event "read_timeoutResult" = "ok" or "error" after the interface has been specified

Parameters:
args - {hostname}
l - logger to receive events and output

runGenKeys

public void runGenKeys(java.lang.String[] args,
                       Logging l)
Generate a new keypair Sets the event "genkeysResult" = "ok" or "error" after the generation is complete

Parameters:
args - {privateKeyFilename, publicKeyFilename} or {privateKeyFilename}
l - logger to receive events and output

runGenTextKeys

public void runGenTextKeys(Logging l)
Generate a new keypair Sets the event "privateKey" = base64 of the privateKey stream and sets the event "publicDestination" = base64 of the destination

Parameters:
l - logger to receive events and output

runQuit

public void runQuit(Logging l)
Exit the JVM if there are no more tasks left running. If there are tunnels running, it returns. Sets the event "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

public void runList(Logging l)
Retrieve a list of currently running tasks Sets the event "listDone" = "done" after dumping the tasks to the logger

Parameters:
l - logger to receive events and output

runClose

public void runClose(java.lang.String[] args,
                     Logging l)
Close the given task (or all tasks), optionally forcing them to die a hard death Sets the event "closeResult" = "ok" after the closing is complete

Parameters:
args - {jobNumber}, {"forced", jobNumber}, {"forced", "all"}
l - logger to receive events and output

runRun

public void runRun(java.lang.String[] args,
                   Logging l)
Run all of the commands in the given file (one command per line) Sets the event "runResult" = "ok" or "error" after the closing is complete

Parameters:
args - {filename}
l - logger to receive events and output

runLookup

public void runLookup(java.lang.String[] args,
                      Logging l)
Perform a lookup of the name specified Sets the event "lookupResult" = base64 of the destination, or an error message

Parameters:
args - {name}
l - logger to receive events and output

runPing

public void runPing(java.lang.String allargs,
                    Logging l)
Start up a ping task with the specified args (currently supporting -ns, -h, -l) Sets the event "pingTaskId" = Integer of the taskId, or -1

Parameters:
allargs - arguments to pass to the I2Ping task
l - logger to receive events and output

log

public void log(java.lang.String s)
Log the given message (using both the logging subsystem and standard output...)

Specified by:
log in interface Logging

makeKey

public static void makeKey(java.io.OutputStream writeTo,
                           java.io.OutputStream pubDest,
                           Logging l)
Create a new destination, storing the destination and its private keys where instructed Deprecated - only used by CLI

Parameters:
writeTo - location to store the private keys
pubDest - location to store the destination
l - logger to send messages to

showKey

public static void showKey(java.io.InputStream readFrom,
                           java.io.OutputStream pubDest,
                           Logging l)
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 from
pubDest - stream to write the destination to
l - logger to send messages to

destFromName

public static Destination destFromName(java.lang.String name)
                                throws DataFormatException
Generates a Destination from a name. Now only supports base64 names - may support naming servers later. "file:" is also supported, where filename is a file that either contains a binary Destination structure or the Base64 encoding of that structure. Since file: isn't really used, this method is deprecated, just call context.namingService.lookup() directly.

Throws:
DataFormatException

addConnectionEventListener

public void addConnectionEventListener(I2PTunnel.ConnectionEventListener lsnr)

removeConnectionEventListener

public void removeConnectionEventListener(I2PTunnel.ConnectionEventListener lsnr)

getContext

public I2PAppContext getContext()

routerDisconnected

void routerDisconnected()
Call this whenever we lose touch with the router involuntarily (aka the router is off / crashed / etc)


getEventDispatcher

public EventDispatcher getEventDispatcher()
Description copied from interface: EventDispatcher
Get an object to be used to deliver events (usually this, but YMMV).

Specified by:
getEventDispatcher in interface EventDispatcher

attachEventDispatcher

public void attachEventDispatcher(EventDispatcher e)
Description copied from interface: EventDispatcher
Attach an EventDispatcher object to the events dispatching chain. Note that notification is not bidirectional (i.e. events notified to ev won't reach the object calling this method). Good luck, and beware of notification loops! :-)

Specified by:
attachEventDispatcher in interface EventDispatcher
Parameters:
e - Event object to be attached

detachEventDispatcher

public void detachEventDispatcher(EventDispatcher e)
Description copied from interface: EventDispatcher
Detach the specified EventDispatcher object from the events dispatching chain.

Specified by:
detachEventDispatcher in interface EventDispatcher
Parameters:
e - Event object to be detached

notifyEvent

public void notifyEvent(java.lang.String e,
                        java.lang.Object a)
Description copied from interface: EventDispatcher
Deliver an event

Specified by:
notifyEvent in interface EventDispatcher
Parameters:
e - name of the event
a - data being stored for that event

getEventValue

public java.lang.Object getEventValue(java.lang.String n)
Description copied from interface: EventDispatcher
Retrieve the value currently associated with the specified event value

Specified by:
getEventValue in interface EventDispatcher
Parameters:
n - name of the event to query for
Returns:
value (or null if none are available)

getEvents

public java.util.Set getEvents()
Description copied from interface: EventDispatcher
Retrieve the names of all the events that have been received

Specified by:
getEvents in interface EventDispatcher
Returns:
A set of event names

ignoreEvents

public void ignoreEvents()
Description copied from interface: EventDispatcher
Ignore further event notifications

Specified by:
ignoreEvents in interface EventDispatcher

unIgnoreEvents

public void unIgnoreEvents()
Description copied from interface: EventDispatcher
Almost like the method above :-)

Specified by:
unIgnoreEvents in interface EventDispatcher

waitEventValue

public java.lang.Object waitEventValue(java.lang.String n)
Description copied from interface: EventDispatcher
Wait until the given event has received a value

Specified by:
waitEventValue in interface EventDispatcher
Parameters:
n - name of the event to wait for
Returns:
value specified for that event