Bugfix for getting Properties to actually work.

This commit is contained in:
sponge
2008-12-30 07:52:04 +00:00
parent ba8de6c565
commit 841feaedff
6 changed files with 393 additions and 237 deletions

14
apps/BOB/bob.config Normal file
View File

@ -0,0 +1,14 @@
#bob.config
#Tue Dec 30 00:00:00 UTC 2008
# Please leave this file here for testing.
# Thank you,
# Sponge
i2cp.tcp.port=7654
BOB.host=localhost
inbound.lengthVariance=0
i2cp.messageReliability=BestEffort
BOB.port=45067
outbound.length=1
inbound.length=1
outbound.lengthVariance=0
i2cp.tcp.host=localhost

View File

@ -1,5 +1,11 @@
application.title=BOB
application.vendor=root
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs=false
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width=8
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab=8
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.tab-size=8
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width=80
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.usedProfile=project
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
@ -76,6 +82,12 @@ javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
jnlp.codebase.type=local
jnlp.codebase.url=file:/root/NetBeansProjects/i2p.i2p/apps/BOB/dist/
jnlp.descriptor=application
jnlp.enabled=false
jnlp.offline-allowed=false
jnlp.signed=false
main.class=net.i2p.BOB.Main
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF

View File

@ -114,6 +114,8 @@ public class BOB {
public final static String PROP_BOB_HOST = "BOB.host";
private static int maxConnections = 0;
private static NamedDB database;
private static Properties props = new Properties();
/**
* Log a warning
@ -157,7 +159,6 @@ public class BOB {
// Set up all defaults to be passed forward to other threads.
// Re-reading the config file in each thread is pretty damn stupid.
// I2PClient client = I2PClientFactory.createClient();
Properties props = new Properties();
String configLocation = System.getProperty(PROP_CONFIG_LOCATION, "bob.config");
// This is here just to ensure there is no interference with our threadgroups.
@ -217,6 +218,7 @@ public class BOB {
}
try {
info(props.toString());
info("BOB is now running.");
ServerSocket listener = new ServerSocket(Integer.parseInt(props.getProperty(PROP_BOB_PORT)), 10, InetAddress.getByName(props.getProperty(PROP_BOB_HOST)));
Socket server;

View File

@ -89,6 +89,7 @@ public class DoCMDS implements Runnable {
private static final String C_setkeys = "setkeys";
private static final String C_setnick = "setnick";
private static final String C_show = "show";
private static final String C_show_props = "showprops";
private static final String C_start = "start";
private static final String C_status = "status";
private static final String C_stop = "stop";
@ -113,6 +114,7 @@ public class DoCMDS implements Runnable {
{C_setkeys, C_setkeys + " BASE64_keypair * Sets the keypair for the current nickname."},
{C_setnick, C_setnick + " nickname * Create a new nickname."},
{C_show, C_show + " * Display the status of the current nickname."},
{C_show_props, C_show_props + " * Display the properties of the current nickname."},
{C_start, C_start + " * Start the current nickname tunnel."},
{C_status, C_status + " nickname * Display status of a nicknamed tunnel."},
{C_stop, C_stop + " * Stops the current nicknamed tunnel."},
@ -135,6 +137,7 @@ public class DoCMDS implements Runnable {
C_setkeys + " " +
C_setnick + " " +
C_show + " " +
C_show_props + " " +
C_start + " " +
C_status + " " +
C_stop + " " +
@ -152,9 +155,10 @@ public class DoCMDS implements Runnable {
*/
DoCMDS(Socket server, Properties props, NamedDB database, Log _log) {
this.server = server;
this.props = new Properties(props);
this.props = new Properties();
this.database = database;
this._log = _log;
Lifted.copyProperties(props, this.props);
}
private void rlock() throws Exception {
@ -288,6 +292,31 @@ public class DoCMDS implements Runnable {
runlock(info);
}
/**
* Dump properties information from the database
*
* @param out
* @param info
* @throws Exception
*/
private void propprint(PrintStream out, NamedDB info) throws Exception {
try {
rlock(info);
} catch (Exception e) {
throw new Exception(e);
}
try {
trypnt(out, info, P_PROPERTIES);
out.println();
} catch (Exception e) {
runlock(info);
throw new Exception(e);
}
runlock(info);
}
/**
* Print information on a specific record, indicated by NamedDB
* @param out
@ -369,8 +398,10 @@ public class DoCMDS implements Runnable {
// Get input from the client
BufferedReader in = new BufferedReader(new InputStreamReader(server.getInputStream()));
PrintStream out = new PrintStream(server.getOutputStream());
quit: {
die: {
quit:
{
die:
{
prikey = new ByteArrayOutputStream();
out.println("BOB " + BOBversion);
out.println("OK");
@ -750,7 +781,8 @@ die: {
nickinfo.add(P_QUIET, Boolean.FALSE);
nickinfo.add(P_INHOST, "localhost");
nickinfo.add(P_OUTHOST, "localhost");
Properties Q = new Properties(props);
Properties Q = new Properties();
Lifted.copyProperties(this.props, Q);
Q.setProperty("inbound.nickname", Arg);
Q.setProperty("outbound.nickname", Arg);
nickinfo.add(P_PROPERTIES, Q);
@ -1184,6 +1216,43 @@ die: {
}
}
} else if (Command.equals(C_show_props)) {
// Get the current options properties
if (ns) {
out.print("OK");
try {
rlock();
} catch (Exception e) {
break die;
}
try {
propprint(out, nickinfo);
} catch (Exception e) {
try {
runlock();
} catch (Exception ee) {
break die;
}
out.println(); // this will cause an IOE if IOE
break die;
}
try {
runlock();
} catch (Exception e) {
break die;
}
} else {
try {
nns(out);
} catch (Exception e) {
break die;
}
}
} else if (Command.equals(C_start)) {
// Start the tunnel, if we have all the information
if (ns && dk && (ip || op)) {

View File

@ -0,0 +1,56 @@
/**
* 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;
import java.util.Enumeration;
import java.util.Properties;
/**
* Sets of "friendly" utilities to make life easier.
* Any "Lifted" code will apear here, and credits given.
* It's better to "Lift" a small chunk of "free" code than add in piles of
* code we don't need, and don't want.
*
* @author sponge
*/
public class Lifted {
/**
* Copy a set of properties from one Property to another.
* Lifted from Apache Derby code svn repository.
* Liscenced as follows:
* http://svn.apache.org/repos/asf/db/derby/code/trunk/LICENSE
*
* @param src_prop Source set of properties to copy from.
* @param dest_prop Dest Properties to copy into.
*
**/
public static void copyProperties(Properties src_prop, Properties dest_prop) {
for (Enumeration propertyNames = src_prop.propertyNames();
propertyNames.hasMoreElements();) {
Object key = propertyNames.nextElement();
dest_prop.put(key, src_prop.get(key));
}
}
}

View File

@ -74,7 +74,10 @@ public class MUXlisten implements Runnable {
this.info.getReadLock();
N = this.info.get("NICKNAME").toString();
prikey = new ByteArrayInputStream((byte[])info.get("KEYS"));
Properties Q = (Properties)info.get("PROPERTIES");
// Make a new copy so that anything else won't muck with our database.
Properties R = (Properties)info.get("PROPERTIES");
Properties Q = new Properties();
Lifted.copyProperties(R, Q);
this.database.releaseReadLock();
this.info.releaseReadLock();