I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 872d2c48 authored by sponge's avatar sponge
Browse files

Added demos for BOB

parent a3b9345f
No related branches found
No related tags found
No related merge requests found
Showing
with 1207 additions and 0 deletions
#!/bin/bash
(
cd dist
java -jar echoclient.jar main 37338 testclient $1
)
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/1">
<file>file:/root/NetBeansProjects/BOB/Demos/echo/echoclient/src/net/i2p/BOB/Demos/echo/echoclient/Main.java</file>
</open-files>
</project-private>
/**
* 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);
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<project name="echoserver" default="default" basedir=".">
<description>Builds, tests, and runs the project echoserver.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar-with-manifest: JAR building (if you are using a manifest)
-do-jar-without-manifest: JAR building (if you are not using a manifest)
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="echoserver-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
This diff is collapsed.
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
jaxws.endorsed.dir=/usr/local/netbeans-6.1/java2/modules/ext/jaxws21/api
user.properties.file=/root/.netbeans/6.1/build.properties
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/1">
<file>file:/root/NetBeansProjects/BOB/Demos/echo/echoserver/src/net/i2p/BOB/Demos/echo/echoserver/Main.java</file>
</open-files>
</project-private>
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
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>echoserver</name>
<minimum-ant-version>1.6.5</minimum-ant-version>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>
(
cd dist
java -jar echoserver.jar main 37337 testserver
)
/**
* 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);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment