net.i2p.i2ptunnel
Class TunnelManager

java.lang.Object
  extended bynet.i2p.i2ptunnel.TunnelManager
All Implemented Interfaces:
java.lang.Runnable

public class TunnelManager
extends java.lang.Object
implements java.lang.Runnable

Quick and dirty socket listener to control an I2PTunnel. Basically run this class as TunnelManager [listenHost] [listenPort] and then send it commands on that port. Commands are one shot deals - Send a command + newline, get a response plus newline, then get disconnected.

Implemented commands:

 -------------------------------------------------
 lookup <name>\n
 --
 <base64 of the destination>\n
  or
 <error message, usually 'Unknown host'>\n
 
  Lookup the public key of a named destination (i.e. listed in hosts.txt)
 -------------------------------------------------
 genkey\n
 --
 <base64 of the destination>\t<base64 of private data>\n
 
  Generates a new public and private key pair
 -------------------------------------------------
 convertprivate <base64 of privkey>
 --
 <base64 of destination>\n
  or
 <error message>\n

  Returns the destination (pubkey) of a given private key. 
 -------------------------------------------------
 listen_on <ip>\n
 --
 ok\n
  or
 error\n
 
  Sets the ip address clients will listen on. By default this is the
  localhost (127.0.0.1)
 -------------------------------------------------
 openclient <listenPort> <peer>\n
 --
 ok [<jobId>]\n
  or
 ok <listenPort> [<jobId>]\n
  or
 error\n
 
  Open a tunnel on the given <listenport> to the destination specified
  by <peer>. If <listenPort> is 0 a free port is picked and returned in
  the reply message. Otherwise the short reply message is used.
  Peer can be the base64 of the destination, a file with the public key
  specified as 'file:<filename>' or the name of a destination listed in
  hosts.txt. The <jobId> returned together with "ok" and <listenport> can
  later be used as argument for the "close" command.
 -------------------------------------------------
 openhttpclient <listenPort> [<proxy>]\n
 --
 ok [<jobId>]\n
  or
 ok <listenPort> [<jobId>]\n
  or
 error\n
 
  Open an HTTP proxy through the I2P on the given
  <listenport>. <proxy> (optional) specifies a
  destination to be used as an outbound proxy, to access normal WWW
  sites out of the .i2p domain. If <listenPort> is 0 a free
  port is picked and returned in the reply message. Otherwise the
  short reply message is used.  <proxy> can be the base64 of the
  destination, a file with the public key specified as
  'file:<filename>' or the name of a destination listed in
  hosts.txt. The <jobId> returned together with "ok" and
  <listenport> can later be used as argument for the "close"
  command.
 -------------------------------------------------
 opensockstunnel <listenPort>\n
 --
 ok [<jobId>]\n
  or
 ok <listenPort> [<jobId>]\n
  or
 error\n
 
  Open an SOCKS tunnel through the I2P on the given
  <listenport>. If <listenPort> is 0 a free port is
  picked and returned in the reply message. Otherwise the short
  reply message is used.  The <jobId> returned together with
  "ok" and <listenport> can later be used as argument for the
  "close" command.
 -------------------------------------------------
 openserver <serverHost> <serverPort> <serverKeys>\n
 --
 ok [<jobId>]\n
  or
 error\n
 
  Starts receiving traffic for the destination specified by <serverKeys>
  and forwards it to the <serverPort> of <serverHost>.
  <serverKeys> is the base 64 encoded private key set of the local
  destination. The <joId> returned together with "ok" can later be used
  as argument for the "close" command.
 -------------------------------------------------
 close [forced] <jobId>\n
  or
 close [forced] all\n
 --
 ok\n
  or
 error\n
 
  Closes the job specified by <jobId> or all jobs. Use the list command
  for a list of running jobs.
  Normally a connection job is not closed when it still has an active
  connection. Use the optional 'forced' keyword to close connections
  regardless of their use.
 -------------------------------------------------
 list\n
 --
  Example output:
 
 [0] i2p.dnsalias.net/69.55.226.145:5555 <- C:\i2pKeys\squidPriv
 [1] 8767 -> HTTPClient
 [2] 7575 -> file:C:\i2pKeys\squidPub
 [3] 5252 -> sCcSANIO~f4AQtCNI1BvDp3ZBS~9Ag5O0k0Msm7XBWWz5eOnZWL3MQ-2rxlesucb9XnpASGhWzyYNBpWAfaIB3pux1J1xujQLOwscMIhm7T8BP76Ly5jx6BLZCYrrPj0BI0uV90XJyT~4UyQgUlC1jzFQdZ9HDgBPJDf1UI4-YjIwEHuJgdZynYlQ1oUFhgno~HhcDByXO~PDaO~1JDMDbBEfIh~v6MgmHp-Xchod1OfKFrxFrzHgcJbn7E8edTFjZA6JCi~DtFxFelQz1lSBd-QB1qJnA0g-pVL5qngNUojXJCXs4qWcQ7ICLpvIc-Fpfj-0F1gkVlGDSGkb1yLH3~8p4czYgR3W5D7OpwXzezz6clpV8kmbd~x2SotdWsXBPRhqpewO38coU4dJG3OEUbuYmdN~nJMfWbmlcM1lXzz2vBsys4sZzW6dV3hZnbvbfxNTqbdqOh-KXi1iAzXv7CVTun0ubw~CfeGpcAqutC5loRUq7Mq62ngOukyv8Z9AAAA

  Lists descriptions of all running jobs. The exact format of the
  description depends on the type of job.
 -------------------------------------------------
 


Constructor Summary
TunnelManager(int listenPort)
           
TunnelManager(java.lang.String listenHost, int listenPort)
           
 
Method Summary
 void error(java.lang.String msg, java.io.OutputStream out)
           
static void main(java.lang.String[] args)
           
 void processClose(java.lang.String which, boolean forced, java.io.OutputStream out)
           
 void processConvertPrivate(java.lang.String priv, java.io.OutputStream out)
           
 void processGenKey(java.io.OutputStream out)
          "genkey" returns with the base64 of the destination, followed by a tab, then the base64 of that destination's private keys, then a newline.
 void processList(java.io.OutputStream out)
           
 void processListenOn(java.lang.String ip, java.io.OutputStream out)
           
 void processLookup(java.lang.String name, java.io.OutputStream out)
          "lookup " returns with the result in base64, else "Unknown host" [or something like that], then a newline.
 void processOpenClient(int listenPort, java.lang.String peer, java.io.OutputStream out)
           
 void processOpenHTTPClient(int listenPort, java.lang.String proxy, java.io.OutputStream out)
           
 void processOpenServer(java.lang.String serverHost, int serverPort, java.lang.String privateKeys, java.io.OutputStream out)
           
 void processOpenSOCKSTunnel(int listenPort, java.io.OutputStream out)
           
 void processQuit(java.io.OutputStream out)
           
 void processTestDestination(java.lang.String destKey, java.io.OutputStream out)
           
 void run()
           
 void unknownCommand(java.lang.String command, java.io.OutputStream out)
          Frisbee.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TunnelManager

public TunnelManager(int listenPort)

TunnelManager

public TunnelManager(java.lang.String listenHost,
                     int listenPort)
Method Detail

main

public static void main(java.lang.String[] args)

run

public void run()
Specified by:
run in interface java.lang.Runnable

error

public void error(java.lang.String msg,
                  java.io.OutputStream out)
           throws java.io.IOException
Throws:
java.io.IOException

processQuit

public void processQuit(java.io.OutputStream out)
                 throws java.io.IOException
Throws:
java.io.IOException

processList

public void processList(java.io.OutputStream out)
                 throws java.io.IOException
Throws:
java.io.IOException

processListenOn

public void processListenOn(java.lang.String ip,
                            java.io.OutputStream out)
                     throws java.io.IOException
Throws:
java.io.IOException

processLookup

public void processLookup(java.lang.String name,
                          java.io.OutputStream out)
                   throws java.io.IOException
"lookup " returns with the result in base64, else "Unknown host" [or something like that], then a newline.

Throws:
java.io.IOException

processTestDestination

public void processTestDestination(java.lang.String destKey,
                                   java.io.OutputStream out)
                            throws java.io.IOException
Throws:
java.io.IOException

processConvertPrivate

public void processConvertPrivate(java.lang.String priv,
                                  java.io.OutputStream out)
                           throws java.io.IOException
Throws:
java.io.IOException

processClose

public void processClose(java.lang.String which,
                         boolean forced,
                         java.io.OutputStream out)
                  throws java.io.IOException
Throws:
java.io.IOException

processGenKey

public void processGenKey(java.io.OutputStream out)
                   throws java.io.IOException
"genkey" returns with the base64 of the destination, followed by a tab, then the base64 of that destination's private keys, then a newline.

Throws:
java.io.IOException

processOpenClient

public void processOpenClient(int listenPort,
                              java.lang.String peer,
                              java.io.OutputStream out)
                       throws java.io.IOException
Throws:
java.io.IOException

processOpenHTTPClient

public void processOpenHTTPClient(int listenPort,
                                  java.lang.String proxy,
                                  java.io.OutputStream out)
                           throws java.io.IOException
Throws:
java.io.IOException

processOpenSOCKSTunnel

public void processOpenSOCKSTunnel(int listenPort,
                                   java.io.OutputStream out)
                            throws java.io.IOException
Throws:
java.io.IOException

processOpenServer

public void processOpenServer(java.lang.String serverHost,
                              int serverPort,
                              java.lang.String privateKeys,
                              java.io.OutputStream out)
                       throws java.io.IOException
Throws:
java.io.IOException

unknownCommand

public void unknownCommand(java.lang.String command,
                           java.io.OutputStream out)
                    throws java.io.IOException
Frisbee.

Throws:
java.io.IOException