diff --git a/apps/BOB/Demos/echo/echoclient/client.sh b/apps/BOB/Demos/echo/echoclient/client.sh new file mode 100755 index 000000000..a08bc2ff4 --- /dev/null +++ b/apps/BOB/Demos/echo/echoclient/client.sh @@ -0,0 +1,5 @@ +#!/bin/bash +( +cd dist +java -jar echoclient.jar main 37338 testclient $1 +) diff --git a/apps/BOB/Demos/echo/echoclient/nbproject/private/private.xml b/apps/BOB/Demos/echo/echoclient/nbproject/private/private.xml new file mode 100644 index 000000000..7cb76d1fd --- /dev/null +++ b/apps/BOB/Demos/echo/echoclient/nbproject/private/private.xml @@ -0,0 +1,7 @@ + + + + + file:/root/NetBeansProjects/BOB/Demos/echo/echoclient/src/net/i2p/BOB/Demos/echo/echoclient/Main.java + + diff --git a/apps/BOB/Demos/echo/echoclient/src/net/i2p/BOB/Demos/echo/echoclient/Main.java b/apps/BOB/Demos/echo/echoclient/src/net/i2p/BOB/Demos/echo/echoclient/Main.java new file mode 100644 index 000000000..d3398caaa --- /dev/null +++ b/apps/BOB/Demos/echo/echoclient/src/net/i2p/BOB/Demos/echo/echoclient/Main.java @@ -0,0 +1,201 @@ +/** + * DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + * Version 2, December 2004 + * + * Copyright (C) sponge + * Planet Earth + * Everyone is permitted to copy and distribute verbatim or modified + * copies of this license document, and changing it is allowed as long + * as the name is changed. + * + * DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + * TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + * + * 0. You just DO WHAT THE FUCK YOU WANT TO. + * + * See... + * + * http://sam.zoy.org/wtfpl/ + * and + * http://en.wikipedia.org/wiki/WTFPL + * + * ...for any additional details and liscense questions. + */ +package net.i2p.BOB.Demos.echo.echoclient; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.Socket; +import java.net.UnknownHostException; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author sponge + */ +public class Main { + + public static String Lread(InputStream in) throws IOException { + String S; + int b; + char c; + + S = new String(); + + while(true) { + b = in.read(); + if(b == 13) { + //skip CR + continue; + } + if(b < 20 || b > 126) { + // exit on anything not legal + break; + } + c = (char)(b & 0x7f); // We only really give a fuck about ASCII + S = new String(S + c); + } + return S; + } + + /** + * Check for "ERROR" and if so, throw RuntimeException + * @param line + * @throws java.lang.RuntimeException + */ + static void checkline(String line) throws RuntimeException { + System.out.println(line); // print status + if(line.startsWith("ERROR")) { + throw new RuntimeException(line); + } + } + + static void wrtxt(OutputStream CMDout, String s) throws IOException { + CMDout.write(s.getBytes()); + CMDout.write('\n'); + CMDout.flush(); + } + + static void setupconn(String[] args) throws UnknownHostException, IOException, RuntimeException { + String line; + Socket CMDsock = new Socket("localhost", 0xB0B); + InputStream CMDin = CMDsock.getInputStream(); + OutputStream CMDout = CMDsock.getOutputStream(); + // setup the tunnel. + line = Lread(CMDin); + System.out.println(line); // print the banner + line = Lread(CMDin); + System.out.println(line); // print initial status, should always be "OK" + try { + wrtxt(CMDout, "status " + args[2]); + line = Lread(CMDin); // get the status of this nickname, if it's an error, create it + checkline(line); + } catch(RuntimeException rte) { + wrtxt(CMDout, "setnick " + args[2]); + line = Lread(CMDin); // create a new nickname + checkline(line); + wrtxt(CMDout, "newkeys"); + line = Lread(CMDin); // set up new keys + checkline(line); + wrtxt(CMDout, "inport " + args[1]); + line = Lread(CMDin); // set the port we connect in on + checkline(line); + } + wrtxt(CMDout, "getnick " + args[2]); + line = Lread(CMDin); // Set to our nick + try { + checkline(line); + } catch(RuntimeException rte) { + System.out.println("Continuing on existing tunnel.."); + return; + } + wrtxt(CMDout, "start"); + line = Lread(CMDin); // an error here is OK + System.out.println(line); // print status + CMDsock.close(); // we no longer need this particular socket + + } + + static void deleteconn(String[] args) throws UnknownHostException, IOException, RuntimeException { + String line; + // Wait for things to flush + try { + Thread.sleep(10000); + } catch(InterruptedException ex) { + // nop + } + Socket CMDsock = new Socket("localhost", 0xB0B); + InputStream CMDin = CMDsock.getInputStream(); + OutputStream CMDout = CMDsock.getOutputStream(); + // delete the tunnel. + line = Lread(CMDin); + System.out.println(line); // print the banner + line = Lread(CMDin); + System.out.println(line); // print initial status, should always be "OK" + wrtxt(CMDout, "getnick " + args[2]); // Set to our nick + line = Lread(CMDin); + checkline(line); + wrtxt(CMDout, "stop"); + line = Lread(CMDin); + checkline(line); + try { + Thread.sleep(2000); //sleep for 2000 ms (Two seconds) + } catch(Exception e) { + // nop + } + + wrtxt(CMDout, "clear"); + line = Lread(CMDin); + while(line.startsWith("ERROR")) { + wrtxt(CMDout, "clear"); + line = Lread(CMDin); + } + System.out.println(line); // print status + CMDsock.close(); // we no longer need this particular socket + + } + + static void chatter(String[] args) throws UnknownHostException, IOException, RuntimeException { + String line; + Socket sock = new Socket("localhost", Integer.parseInt(args[1])); + InputStream in = sock.getInputStream(); + OutputStreamWriter out = new OutputStreamWriter(sock.getOutputStream()); + out.write(args[3] + "\n"); // send out the i2p address to connect to + out.flush(); + System.out.println("Connecting to " + args[3]); + line = Lread(in); // get server greeting + System.out.println("Got " + line); // show user + out.write("Test complete.\n"); // send something back + out.flush(); // make sure it's sent. + sock.close(); // done. + } + + /** + * + * @param args tunnelport tunnelnickname I2Pdestkey + */ + public static void main(String[] args) { + // I'm lazy, and want to exit on any failures. + try { + setupconn(args); // talk to BOB, set up an outbound port + chatter(args); // talk over the connection + + } catch(UnknownHostException ex) { + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); + } catch(IOException ex) { + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); + } + try { + deleteconn(args); + } catch(UnknownHostException ex) { + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); + } catch(IOException ex) { + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); + } catch(RuntimeException ex) { + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); + } + } +} diff --git a/apps/BOB/Demos/echo/echoserver/build.xml b/apps/BOB/Demos/echo/echoserver/build.xml new file mode 100644 index 000000000..24fb9b004 --- /dev/null +++ b/apps/BOB/Demos/echo/echoserver/build.xml @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project echoserver. + + + diff --git a/apps/BOB/Demos/echo/echoserver/manifest.mf b/apps/BOB/Demos/echo/echoserver/manifest.mf new file mode 100644 index 000000000..328e8e5bc --- /dev/null +++ b/apps/BOB/Demos/echo/echoserver/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/apps/BOB/Demos/echo/echoserver/nbproject/build-impl.xml b/apps/BOB/Demos/echo/echoserver/nbproject/build-impl.xml new file mode 100644 index 000000000..19cf614fa --- /dev/null +++ b/apps/BOB/Demos/echo/echoserver/nbproject/build-impl.xml @@ -0,0 +1,629 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + diff --git a/apps/BOB/Demos/echo/echoserver/nbproject/genfiles.properties b/apps/BOB/Demos/echo/echoserver/nbproject/genfiles.properties new file mode 100644 index 000000000..30e60e8c2 --- /dev/null +++ b/apps/BOB/Demos/echo/echoserver/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=4ce39738 +build.xml.script.CRC32=c1deb82c +build.xml.stylesheet.CRC32=be360661 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=4ce39738 +nbproject/build-impl.xml.script.CRC32=555cdd2d +nbproject/build-impl.xml.stylesheet.CRC32=487672f9 diff --git a/apps/BOB/Demos/echo/echoserver/nbproject/private/private.properties b/apps/BOB/Demos/echo/echoserver/nbproject/private/private.properties new file mode 100644 index 000000000..d814cb447 --- /dev/null +++ b/apps/BOB/Demos/echo/echoserver/nbproject/private/private.properties @@ -0,0 +1,2 @@ +jaxws.endorsed.dir=/usr/local/netbeans-6.1/java2/modules/ext/jaxws21/api +user.properties.file=/root/.netbeans/6.1/build.properties diff --git a/apps/BOB/Demos/echo/echoserver/nbproject/private/private.xml b/apps/BOB/Demos/echo/echoserver/nbproject/private/private.xml new file mode 100644 index 000000000..f046e8bf3 --- /dev/null +++ b/apps/BOB/Demos/echo/echoserver/nbproject/private/private.xml @@ -0,0 +1,6 @@ + + + + file:/root/NetBeansProjects/BOB/Demos/echo/echoserver/src/net/i2p/BOB/Demos/echo/echoserver/Main.java + + diff --git a/apps/BOB/Demos/echo/echoserver/nbproject/project.properties b/apps/BOB/Demos/echo/echoserver/nbproject/project.properties new file mode 100644 index 000000000..163ed780c --- /dev/null +++ b/apps/BOB/Demos/echo/echoserver/nbproject/project.properties @@ -0,0 +1,60 @@ +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/echoserver.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +file.reference.BOB.jar=../../../dist/BOB.jar +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=net.i2p.BOB.Demos.echo.echoserver.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/apps/BOB/Demos/echo/echoserver/nbproject/project.xml b/apps/BOB/Demos/echo/echoserver/nbproject/project.xml new file mode 100644 index 000000000..a7139f0c0 --- /dev/null +++ b/apps/BOB/Demos/echo/echoserver/nbproject/project.xml @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + echoserver + 1.6.5 + + + + + + + + + diff --git a/apps/BOB/Demos/echo/echoserver/server.sh b/apps/BOB/Demos/echo/echoserver/server.sh new file mode 100755 index 000000000..0fafae117 --- /dev/null +++ b/apps/BOB/Demos/echo/echoserver/server.sh @@ -0,0 +1,4 @@ +( +cd dist +java -jar echoserver.jar main 37337 testserver +) diff --git a/apps/BOB/Demos/echo/echoserver/src/net/i2p/BOB/Demos/echo/echoserver/Main.java b/apps/BOB/Demos/echo/echoserver/src/net/i2p/BOB/Demos/echo/echoserver/Main.java new file mode 100644 index 000000000..86344b1a8 --- /dev/null +++ b/apps/BOB/Demos/echo/echoserver/src/net/i2p/BOB/Demos/echo/echoserver/Main.java @@ -0,0 +1,197 @@ +/** + * DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + * Version 2, December 2004 + * + * Copyright (C) sponge + * Planet Earth + * Everyone is permitted to copy and distribute verbatim or modified + * copies of this license document, and changing it is allowed as long + * as the name is changed. + * + * DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + * TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + * + * 0. You just DO WHAT THE FUCK YOU WANT TO. + * + * See... + * + * http://sam.zoy.org/wtfpl/ + * and + * http://en.wikipedia.org/wiki/WTFPL + * + * ...for any additional details and liscense questions. + */ +package net.i2p.BOB.Demos.echo.echoserver; + +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.UnknownHostException; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author sponge + */ +public class Main { + public static String Lread(InputStream in) throws IOException { + String S; + int b; + char c; + + S = new String(); + + while(true) { + b = in.read(); + if(b < 20) { + break; + } + c = (char)(b & 0x7f); // We only really give a fuck about ASCII + S = new String(S + c); + } + return S; + } + + /** + * Check for "ERROR" and if so, throw RuntimeException + * @param line + * @throws java.lang.RuntimeException + */ + static void checkline(String line) throws RuntimeException { + System.out.println(line); // print status + if(line.startsWith("ERROR")) { + throw new RuntimeException(line); + } + } + + static void wrtxt(OutputStream CMDout, String s) throws IOException { + CMDout.write(s.getBytes()); + CMDout.write('\n'); + CMDout.flush(); + } + + static void setupconn(String[] args) throws UnknownHostException, IOException, RuntimeException { + String line; + Socket CMDsock = new Socket("localhost", 0xB0B); + InputStream CMDin = CMDsock.getInputStream(); + OutputStream CMDout = CMDsock.getOutputStream(); + // setup the tunnel. + line = Lread(CMDin); + System.out.println(line); // print the banner + line = Lread(CMDin); + System.out.println(line); // print initial status, should always be "OK" + try { + wrtxt(CMDout, "status " + args[2]); + line =Lread(CMDin); // get the status of this nickname, if it's an error, create it + checkline(line); + } catch(RuntimeException rte) { + wrtxt(CMDout, "setnick " + args[2]); + line =Lread(CMDin); // create a new nickname + checkline(line); + wrtxt(CMDout, "newkeys "); + line =Lread(CMDin); // set up new keys + checkline(line); + wrtxt(CMDout, "outport " + args[1]); + line = Lread(CMDin); // set the port we connect out on + checkline(line); + } + wrtxt(CMDout, "getnick " + args[2]); + line = Lread(CMDin); // Set to our nick + checkline(line); + wrtxt(CMDout, "start "); + line = Lread(CMDin); // an error here is OK + System.out.println(line); // print status + CMDsock.close(); // we no longer need this particular socket + + } + + static void deleteconn(String[] args) throws UnknownHostException, IOException, RuntimeException { + String line; + Socket CMDsock = new Socket("localhost", 0xB0B); + InputStream CMDin = CMDsock.getInputStream(); + OutputStream CMDout = CMDsock.getOutputStream(); + // delete the tunnel. + line = Lread(CMDin); + System.out.println(line); // print the banner + line = Lread(CMDin); + System.out.println(line); // print initial status, should always be "OK" + wrtxt(CMDout, "getnick " + args[2]); // Set to our nick + line = Lread(CMDin); + checkline(line); + wrtxt(CMDout, "stop"); + line = Lread(CMDin); + checkline(line); + try { + Thread.sleep(2000); //sleep for 2000 ms (Two seconds) + } catch(Exception e) { + // nop + } + + wrtxt(CMDout, "clear"); + line = Lread(CMDin); + while(line.startsWith("ERROR")) { + wrtxt(CMDout, "clear"); + line = Lread(CMDin); + } + System.out.println(line); // print status + CMDsock.close(); // we no longer need this particular socket + + } + + static void chatter(Socket sock) throws UnknownHostException, IOException, RuntimeException { + String line; + InputStream in = sock.getInputStream(); + OutputStreamWriter out = new OutputStreamWriter(new BufferedOutputStream(sock.getOutputStream())); + + line = Lread(in); // get remote I2P address + System.out.println("Connect from: " + line); // show user + + out.write("Hello, You are connecting from " + line + "\n"); // send greeting + out.flush(); // make sure it's sent. + line = Lread(in); // get test text from client + System.out.println("Got "+line); // show user + sock.close(); // done. + } + + private static void serverlistener(String[] args) throws UnknownHostException, IOException, RuntimeException { + ServerSocket listener = new ServerSocket(Integer.parseInt(args[1]), 10, InetAddress.getByName("localhost")); + Socket server; + + while(true) { + server = listener.accept(); + chatter(server); + } + } + + /** + * + * @param args tunnelport tunnelnickname + */ + public static void main(String[] args) { + // I'm lazy, and want to exit on any failures. + try { + setupconn(args); // talk to BOB, set up an inbound port + serverlistener(args); // talk over the connection + + } catch(UnknownHostException ex) { + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); + } catch(IOException ex) { + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); + } + try { + deleteconn(args); + } catch(UnknownHostException ex) { + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); + } catch(IOException ex) { + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); + } catch(RuntimeException ex) { + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); + } + } +}