diff --git a/apps/BOB/bob.config b/apps/BOB/bob.config new file mode 100644 index 000000000..f9c28d382 --- /dev/null +++ b/apps/BOB/bob.config @@ -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 diff --git a/apps/BOB/nbproject/project.properties b/apps/BOB/nbproject/project.properties index aa2df5ffd..76e318ff0 100644 --- a/apps/BOB/nbproject/project.properties +++ b/apps/BOB/nbproject/project.properties @@ -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 diff --git a/apps/BOB/src/net/i2p/BOB/BOB.java b/apps/BOB/src/net/i2p/BOB/BOB.java index c4a4f7539..0b7d17318 100644 --- a/apps/BOB/src/net/i2p/BOB/BOB.java +++ b/apps/BOB/src/net/i2p/BOB/BOB.java @@ -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; diff --git a/apps/BOB/src/net/i2p/BOB/DoCMDS.java b/apps/BOB/src/net/i2p/BOB/DoCMDS.java index bb29b1394..27442e35b 100644 --- a/apps/BOB/src/net/i2p/BOB/DoCMDS.java +++ b/apps/BOB/src/net/i2p/BOB/DoCMDS.java @@ -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,32 +114,34 @@ 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."}, {C_verify, C_verify + " BASE64_key * Verifies BASE64 destination."}, {"", "COMMANDS: " + // this is ugly, but... - C_help + " " + - C_clear + " " + - C_getdest + " " + - C_getkeys + " " + - C_getnick + " " + - C_inhost + " " + - C_inport + " " + - C_list + " " + - C_newkeys + " " + - C_option + " " + - C_outhost + " " + - C_outport + " " + - C_quiet + " " + - C_quit + " " + - C_setkeys + " " + - C_setnick + " " + - C_show + " " + - C_start + " " + - C_status + " " + - C_stop + " " + - C_verify + C_help + " " + + C_clear + " " + + C_getdest + " " + + C_getkeys + " " + + C_getnick + " " + + C_inhost + " " + + C_inport + " " + + C_list + " " + + C_newkeys + " " + + C_option + " " + + C_outhost + " " + + C_outport + " " + + C_quiet + " " + + C_quit + " " + + C_setkeys + " " + + C_setnick + " " + + C_show + " " + + C_show_props + " " + + C_start + " " + + C_status + " " + + C_stop + " " + + C_verify }, {" ", " "} // end of list }; @@ -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 { @@ -204,17 +208,17 @@ public class DoCMDS implements Runnable { private void trypnt(PrintStream out, NamedDB info, Object key) throws Exception { try { rlock(info); - } catch(Exception e) { + } catch (Exception e) { throw new Exception(e); } try { out.print(" " + key + ": "); - if(info.exists(key)) { + if (info.exists(key)) { out.print(info.get(key)); } else { out.print("not_set"); } - } catch(Exception e) { + } catch (Exception e) { runlock(info); throw new Exception(e); } @@ -232,13 +236,13 @@ public class DoCMDS implements Runnable { private void tfpnt(PrintStream out, NamedDB info, Object key) throws Exception { try { rlock(info); - } catch(Exception e) { + } catch (Exception e) { throw new Exception(e); } try { out.print(" " + key + ": "); out.print(info.exists(key)); - } catch(Exception e) { + } catch (Exception e) { runlock(info); throw new Exception(e); } @@ -264,7 +268,7 @@ public class DoCMDS implements Runnable { private void nickprint(PrintStream out, NamedDB info) throws Exception { try { rlock(info); - } catch(Exception e) { + } catch (Exception e) { throw new Exception(e); } try { @@ -280,7 +284,32 @@ public class DoCMDS implements Runnable { trypnt(out, info, P_OUTPORT); trypnt(out, info, P_OUTHOST); out.println(); - } catch(Exception e) { + } catch (Exception e) { + runlock(info); + throw new Exception(e); + } + + 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); } @@ -297,16 +326,16 @@ public class DoCMDS implements Runnable { private void ttlpnt(PrintStream out, Object Arg) throws Exception { try { database.getReadLock(); - } catch(Exception e) { + } catch (Exception e) { throw new Exception(e); } try { - if(database.exists(Arg)) { + if (database.exists(Arg)) { out.print("DATA"); - nickprint(out, (NamedDB)database.get(Arg)); + nickprint(out, (NamedDB) database.get(Arg)); } - } catch(Exception e) { + } catch (Exception e) { database.releaseReadLock(); throw new Exception(e); } @@ -325,7 +354,7 @@ public class DoCMDS implements Runnable { boolean retval; try { rlock(Arg); - } catch(Exception e) { + } catch (Exception e) { throw new Exception(e); } @@ -333,7 +362,7 @@ public class DoCMDS implements Runnable { retval = (Arg.get(P_STARTING).equals(Boolean.TRUE) || Arg.get(P_STOPPING).equals(Boolean.TRUE) || Arg.get(P_RUNNING).equals(Boolean.TRUE)); - } catch(Exception e) { + } catch (Exception e) { runlock(); throw new Exception(e); } @@ -352,7 +381,7 @@ public class DoCMDS implements Runnable { try { Destination x = new Destination(data); return true; - } catch(Exception e) { + } catch (Exception e) { return false; } } @@ -369,50 +398,52 @@ 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"); - while((line = in.readLine()) != null) { + while ((line = in.readLine()) != null) { StringTokenizer token = new StringTokenizer(line, " "); // use a space as a delimiter String Command = ""; String Arg = ""; NamedDB info; - if(token.countTokens() != 0) { + if (token.countTokens() != 0) { Command = token.nextToken(); Command = Command.toLowerCase(); - if(token.countTokens() != 0) { + if (token.countTokens() != 0) { Arg = token.nextToken(); } else { Arg = ""; } // The rest of the tokens are considered junk, // and discarded without any warnings. - if(Command.equals(C_help)) { - for(int i = 0; !C_ALL[i][0].equals(" "); i++) { - if(C_ALL[i][0].equalsIgnoreCase(Arg)) { + if (Command.equals(C_help)) { + for (int i = 0; !C_ALL[i][0].equals(" "); i++) { + if (C_ALL[i][0].equalsIgnoreCase(Arg)) { out.println("OK " + C_ALL[i][1]); } } - } else if(Command.equals(C_getdest)) { - if(ns) { - if(dk) { + } else if (Command.equals(C_getdest)) { + if (ns) { + if (dk) { try { rlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } try { out.println("OK " + nickinfo.get(P_DEST)); - } catch(Exception e) { + } catch (Exception e) { try { runlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } break die; @@ -420,7 +451,7 @@ die: { try { runlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } @@ -432,31 +463,31 @@ die: { nns(out); } - } else if(Command.equals(C_list)) { + } else if (Command.equals(C_list)) { // Produce a formatted list of all nicknames database.getReadLock(); - for(int i = 0; i < + for (int i = 0; i < database.getcount(); i++) { try { - info = (NamedDB)database.getnext(i); + info = (NamedDB) database.getnext(i); out.print("DATA"); - } catch(Exception e) { + } catch (Exception e) { database.releaseReadLock(); break die; } try { info.getReadLock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } try { nickprint(out, info); - } catch(Exception e) { + } catch (Exception e) { try { info.releaseReadLock(); database.releaseReadLock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } break die; @@ -464,24 +495,24 @@ die: { try { info.releaseReadLock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } } try { database.releaseReadLock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } out.println("OK Listing done"); - } else if(Command.equals(C_quit)) { + } else if (Command.equals(C_quit)) { // End the command session break quit; - } else if(Command.equals(C_newkeys)) { - if(ns) { + } else if (Command.equals(C_newkeys)) { + if (ns) { try { - if(tunnelactive(nickinfo)) { + if (tunnelactive(nickinfo)) { out.println("ERROR tunnel is active"); } else { try { @@ -490,17 +521,17 @@ die: { d = I2PClientFactory.createClient().createDestination(prikey); try { wlock(); - } catch(Exception e) { + } catch (Exception e) { break die; } try { nickinfo.add(P_KEYS, prikey.toByteArray()); nickinfo.add(P_DEST, d.toBase64()); - } catch(Exception e) { + } catch (Exception e) { try { wunlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } break die; @@ -509,68 +540,68 @@ die: { dk = true; try { wunlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } try { rlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } try { out.println("OK " + nickinfo.get(P_DEST)); - } catch(Exception e) { + } catch (Exception e) { runlock(); break die; } try { runlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } - } catch(I2PException ipe) { + } catch (I2PException ipe) { BOB.error("Error generating keys" + ipe); out.println("ERROR generating keys"); } } - } catch(Exception e) { + } catch (Exception e) { break die; } } else { try { nns(out); - } catch(Exception ex) { + } catch (Exception ex) { break die; } } - } else if(Command.equals(C_getkeys)) { + } else if (Command.equals(C_getkeys)) { // Return public key - if(dk) { + if (dk) { prikey = new ByteArrayOutputStream(); try { rlock(); - } catch(Exception e) { + } catch (Exception e) { break die; } try { - prikey.write(((byte[])nickinfo.get(P_KEYS))); - } catch(Exception ex) { + prikey.write(((byte[]) nickinfo.get(P_KEYS))); + } catch (Exception ex) { try { runlock(); - } catch(Exception ee) { + } catch (Exception ee) { break die; } break die; } try { runlock(); - } catch(Exception e) { + } catch (Exception e) { break die; } @@ -579,23 +610,23 @@ die: { out.println("ERROR no public key has been set"); } - } else if(Command.equals(C_quiet)) { - if(ns) { + } else if (Command.equals(C_quiet)) { + if (ns) { try { - if(tunnelactive(nickinfo)) { + if (tunnelactive(nickinfo)) { out.println("ERROR tunnel is active"); } else { try { wlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } try { nickinfo.add(P_QUIET, new Boolean(Boolean.parseBoolean(Arg) == true)); - } catch(Exception ex) { + } catch (Exception ex) { try { wunlock(); - } catch(Exception ee) { + } catch (Exception ee) { break die; } break die; @@ -603,59 +634,59 @@ die: { try { wunlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } out.println("OK Quiet set"); } - } catch(Exception ex) { + } catch (Exception ex) { break die; } } else { try { nns(out); - } catch(Exception ex) { + } catch (Exception ex) { break die; } } - }else if(Command.equals(C_verify)) { - if(is64ok(Arg)) { + } else if (Command.equals(C_verify)) { + if (is64ok(Arg)) { out.println("OK"); } else { out.println("ERROR not in BASE64 format"); } - } else if(Command.equals(C_setkeys)) { + } else if (Command.equals(C_setkeys)) { // Set the NamedDB to a privatekey in BASE64 format - if(ns) { + if (ns) { try { - if(tunnelactive(nickinfo)) { + if (tunnelactive(nickinfo)) { out.println("ERROR tunnel is active"); } else { try { prikey = new ByteArrayOutputStream(); prikey.write(net.i2p.data.Base64.decode(Arg)); d.fromBase64(Arg); - } catch(Exception ex) { + } catch (Exception ex) { Arg = ""; } - if((Arg.length() == 884) && is64ok(Arg)) { + if ((Arg.length() == 884) && is64ok(Arg)) { try { wlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } try { nickinfo.add(P_KEYS, prikey.toByteArray()); nickinfo.add(P_DEST, d.toBase64()); - } catch(Exception ex) { + } catch (Exception ex) { try { wunlock(); - } catch(Exception ee) { + } catch (Exception ee) { break die; } break die; @@ -663,22 +694,22 @@ die: { dk = true; try { wunlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } try { rlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } try { out.println("OK " + nickinfo.get(P_DEST)); - } catch(Exception e) { + } catch (Exception e) { try { runlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } break die; @@ -686,7 +717,7 @@ die: { try { runlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } } else { @@ -694,34 +725,34 @@ die: { } } - } catch(Exception ex) { + } catch (Exception ex) { break die; } } else { try { nns(out); - } catch(Exception ex) { + } catch (Exception ex) { break die; } } - } else if(Command.equals(C_setnick)) { + } else if (Command.equals(C_setnick)) { ns = dk = ip = op = false; try { database.getReadLock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } try { - nickinfo = (NamedDB)database.get(Arg); - if(!tunnelactive(nickinfo)) { + nickinfo = (NamedDB) database.get(Arg); + if (!tunnelactive(nickinfo)) { nickinfo = null; ns = true; } - } catch(Exception b) { + } catch (Exception b) { nickinfo = null; ns = true; @@ -729,15 +760,15 @@ die: { try { database.releaseReadLock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } // Clears and Sets the initial NamedDB structure to work with - if(ns) { + if (ns) { nickinfo = new NamedDB(); try { wlock(); - } catch(Exception e) { + } catch (Exception e) { break die; } @@ -750,22 +781,23 @@ 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); - } catch(Exception e) { + } catch (Exception e) { try { wunlock(); break die; - } catch(Exception ee) { + } catch (Exception ee) { break die; } } try { wunlock(); - } catch(Exception e) { + } catch (Exception e) { break die; } @@ -774,51 +806,51 @@ die: { out.println("ERROR tunnel is active"); } - } else if(Command.equals(C_option)) { - if(ns) { + } else if (Command.equals(C_option)) { + if (ns) { try { - if(tunnelactive(nickinfo)) { + if (tunnelactive(nickinfo)) { out.println("ERROR tunnel is active"); } else { StringTokenizer otoken = new StringTokenizer(Arg, "="); // use an equal sign as a delimiter - if(otoken.countTokens() != 2) { + if (otoken.countTokens() != 2) { out.println("ERROR to many or no options."); } else { String pname = otoken.nextToken(); String pval = otoken.nextToken(); try { rlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } - Properties Q = (Properties)nickinfo.get(P_PROPERTIES); + Properties Q = (Properties) nickinfo.get(P_PROPERTIES); try { runlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } Q.setProperty(pname, pval); try { wlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } try { nickinfo.add(P_PROPERTIES, Q); - } catch(Exception ex) { + } catch (Exception ex) { try { wunlock(); - } catch(Exception ee) { + } catch (Exception ee) { break die; } break die; } try { wunlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } @@ -826,7 +858,7 @@ die: { } } - } catch(Exception ex) { + } catch (Exception ex) { break die; } @@ -834,23 +866,23 @@ die: { nns(out); } - } else if(Command.equals(C_getnick)) { + } else if (Command.equals(C_getnick)) { // Get the NamedDB to work with... try { database.getReadLock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } try { - nickinfo = (NamedDB)database.get(Arg); + nickinfo = (NamedDB) database.get(Arg); ns = true; - } catch(RuntimeException b) { + } catch (RuntimeException b) { try { nns(out); - } catch(Exception ex) { + } catch (Exception ex) { try { database.releaseReadLock(); - } catch(Exception ee) { + } catch (Exception ee) { break die; } break die; @@ -858,54 +890,54 @@ die: { } database.releaseReadLock(); - if(ns) { + if (ns) { try { rlock(); - } catch(Exception e) { + } catch (Exception e) { break die; } try { dk = nickinfo.exists(P_KEYS); ip = nickinfo.exists(P_INPORT); op = nickinfo.exists(P_OUTPORT); - } catch(Exception ex) { + } catch (Exception ex) { try { runlock(); - } catch(Exception ee) { + } catch (Exception ee) { break die; } break die; } try { runlock(); - } catch(Exception e) { + } catch (Exception e) { break die; } // Finally say OK. out.println("OK Nickname set to " + Arg); } - } else if(Command.equals(C_inport)) { + } else if (Command.equals(C_inport)) { // Set the NamedDB inbound TO the router port // app --> BOB - if(ns) { + if (ns) { try { - if(tunnelactive(nickinfo)) { + if (tunnelactive(nickinfo)) { out.println("ERROR tunnel is active"); } else { int prt; try { wlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } try { nickinfo.kill(P_INPORT); - } catch(Exception ex) { + } catch (Exception ex) { try { wunlock(); - } catch(Exception ee) { + } catch (Exception ee) { break die; } @@ -913,13 +945,13 @@ die: { } try { prt = Integer.parseInt(Arg); - if(prt > 1 && prt < 65536) { + if (prt > 1 && prt < 65536) { try { nickinfo.add(P_INPORT, new Integer(prt)); - } catch(Exception ex) { + } catch (Exception ex) { try { wunlock(); - } catch(Exception ee) { + } catch (Exception ee) { break die; } @@ -927,45 +959,45 @@ die: { } } - } catch(NumberFormatException nfe) { + } catch (NumberFormatException nfe) { out.println("ERROR not a number"); } try { wunlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } try { rlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } try { ip = nickinfo.exists(P_INPORT); - } catch(Exception ex) { + } catch (Exception ex) { try { runlock(); - } catch(Exception ee) { + } catch (Exception ee) { break die; } break die; } try { runlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } - if(ip) { + if (ip) { out.println("OK inbound port set"); } else { out.println("ERROR port out of range"); } } - } catch(Exception ex) { + } catch (Exception ex) { break die; } @@ -973,196 +1005,196 @@ die: { nns(out); } - } else if(Command.equals(C_outport)) { + } else if (Command.equals(C_outport)) { // Set the NamedDB outbound FROM the router port // BOB --> app - if(ns) { + if (ns) { try { - if(tunnelactive(nickinfo)) { + if (tunnelactive(nickinfo)) { out.println("ERROR tunnel is active"); } else { int prt; try { wlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } try { nickinfo.kill(P_OUTPORT); - } catch(Exception ex) { + } catch (Exception ex) { try { wunlock(); - } catch(Exception ee) { + } catch (Exception ee) { break die; } break die; } try { prt = Integer.parseInt(Arg); - if(prt > 1 && prt < 65536) { + if (prt > 1 && prt < 65536) { try { nickinfo.add(P_OUTPORT, new Integer(prt)); - } catch(Exception ex) { + } catch (Exception ex) { try { wunlock(); - } catch(Exception ee) { + } catch (Exception ee) { break die; } break die; } } - } catch(NumberFormatException nfe) { + } catch (NumberFormatException nfe) { out.println("ERROR not a number"); } try { wunlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } try { rlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } try { ip = nickinfo.exists(P_OUTPORT); - } catch(Exception ex) { + } catch (Exception ex) { try { runlock(); - } catch(Exception ee) { + } catch (Exception ee) { break die; } break die; } try { runlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } - if(ip) { + if (ip) { out.println("OK outbound port set"); } else { out.println("ERROR port out of range"); } } - } catch(Exception ex) { + } catch (Exception ex) { break die; } } else { try { nns(out); - } catch(Exception ex) { + } catch (Exception ex) { break die; } } - } else if(Command.equals(C_inhost)) { - if(ns) { + } else if (Command.equals(C_inhost)) { + if (ns) { try { - if(tunnelactive(nickinfo)) { + if (tunnelactive(nickinfo)) { out.println("ERROR tunnel is active"); } else { try { wlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } try { nickinfo.add(P_INHOST, Arg); - } catch(Exception ex) { + } catch (Exception ex) { try { wunlock(); - } catch(Exception ee) { + } catch (Exception ee) { break die; } break die; } try { wunlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } out.println("OK inhost set"); } - } catch(Exception ex) { + } catch (Exception ex) { break die; } } else { try { nns(out); - } catch(Exception ex) { + } catch (Exception ex) { break die; } } - } else if(Command.equals(C_outhost)) { - if(ns) { + } else if (Command.equals(C_outhost)) { + if (ns) { try { - if(tunnelactive(nickinfo)) { + if (tunnelactive(nickinfo)) { out.println("ERROR tunnel is active"); } else { try { wlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } try { nickinfo.add(P_OUTHOST, Arg); - } catch(Exception ex) { + } catch (Exception ex) { try { wunlock(); - } catch(Exception ee) { + } catch (Exception ee) { break die; } break die; } try { wunlock(); - } catch(Exception ex) { + } catch (Exception ex) { break die; } out.println("OK outhost set"); } - } catch(Exception ex) { + } catch (Exception ex) { break die; } } else { try { nns(out); - } catch(Exception ex) { + } catch (Exception ex) { break die; } } - } else if(Command.equals(C_show)) { + } else if (Command.equals(C_show)) { // Get the current NamedDB properties - if(ns) { + if (ns) { out.print("OK"); try { rlock(); - } catch(Exception e) { + } catch (Exception e) { break die; } try { nickprint(out, nickinfo); - } catch(Exception e) { + } catch (Exception e) { try { runlock(); - } catch(Exception ee) { + } catch (Exception ee) { break die; } @@ -1172,23 +1204,60 @@ die: { try { runlock(); - } catch(Exception e) { + } catch (Exception e) { break die; } } else { try { nns(out); - } catch(Exception e) { + } 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)) { + } else if (Command.equals(C_show_props)) { + // Get the current options properties + if (ns) { + out.print("OK"); try { - if(tunnelactive(nickinfo)) { + 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)) { + try { + if (tunnelactive(nickinfo)) { out.println("ERROR tunnel is active"); } else { MUXlisten tunnel; @@ -1197,14 +1266,14 @@ die: { Thread t = new Thread(tunnel); t.start(); out.println("OK tunnel starting"); - } catch(I2PException e) { + } catch (I2PException e) { out.println("ERROR starting tunnel: " + e); - } catch(IOException e) { + } catch (IOException e) { out.println("ERROR starting tunnel: " + e); } } - } catch(Exception ex) { + } catch (Exception ex) { break die; } @@ -1212,26 +1281,26 @@ die: { out.println("ERROR tunnel settings incomplete"); } - } else if(Command.equals(C_stop)) { + } else if (Command.equals(C_stop)) { // Stop the tunnel, if it is running - if(ns) { + if (ns) { try { rlock(); - } catch(Exception e) { + } catch (Exception e) { break die; } try { - if(nickinfo.get(P_RUNNING).equals(Boolean.TRUE) && nickinfo.get(P_STOPPING).equals(Boolean.FALSE) && nickinfo.get(P_STARTING).equals(Boolean.FALSE)) { + if (nickinfo.get(P_RUNNING).equals(Boolean.TRUE) && nickinfo.get(P_STOPPING).equals(Boolean.FALSE) && nickinfo.get(P_STARTING).equals(Boolean.FALSE)) { try { runlock(); - } catch(Exception e) { + } catch (Exception e) { break die; } try { wlock(); - } catch(Exception e) { + } catch (Exception e) { break die; } @@ -1239,7 +1308,7 @@ die: { try { wunlock(); - } catch(Exception e) { + } catch (Exception e) { break die; } @@ -1247,16 +1316,16 @@ die: { } else { try { runlock(); - } catch(Exception e) { + } catch (Exception e) { break die; } out.println("ERROR tunnel is inactive"); } - } catch(Exception e) { + } catch (Exception e) { try { runlock(); - } catch(Exception ee) { + } catch (Exception ee) { break die; } break die; @@ -1265,62 +1334,62 @@ die: { } else { try { nns(out); - } catch(Exception e) { + } catch (Exception e) { break die; } } - } else if(Command.equals(C_clear)) { + } else if (Command.equals(C_clear)) { // Clear use of the NamedDB if stopped - if(ns) { + if (ns) { try { - if(tunnelactive(nickinfo)) { + if (tunnelactive(nickinfo)) { out.println("ERROR tunnel is active"); } else { try { database.getWriteLock(); - } catch(Exception e) { + } catch (Exception e) { break die; } try { database.kill(nickinfo.get(P_NICKNAME)); - } catch(Exception e) { + } catch (Exception e) { try { database.releaseWriteLock(); - } catch(Exception ee) { + } catch (Exception ee) { break die; } break die; } try { database.releaseWriteLock(); - } catch(Exception e) { + } catch (Exception e) { break die; } dk = ns = ip = op = false; out.println("OK cleared"); } - } catch(Exception ex) { + } catch (Exception ex) { break die; } } else { try { nns(out); - } catch(Exception e) { + } catch (Exception e) { break die; } } - } else if(Command.equals(C_status)) { + } else if (Command.equals(C_status)) { try { - if(database.exists(Arg)) { + if (database.exists(Arg)) { // Show status of a NamedDB out.print("OK "); try { ttlpnt(out, Arg); - } catch(Exception e) { + } catch (Exception e) { out.println(); // this will cause an IOE if IOE break die; } @@ -1328,11 +1397,11 @@ die: { } else { try { nns(out); - } catch(Exception e) { + } catch (Exception e) { break die; } } - } catch(Exception e) { + } catch (Exception e) { break die; } @@ -1350,7 +1419,7 @@ die: { out.println("OK Bye!"); server.close(); - } catch(IOException ioe) { + } catch (IOException ioe) { BOB.warn("IOException on socket listen: " + ioe); ioe.printStackTrace(); } diff --git a/apps/BOB/src/net/i2p/BOB/Lifted.java b/apps/BOB/src/net/i2p/BOB/Lifted.java new file mode 100644 index 000000000..fbd23cba5 --- /dev/null +++ b/apps/BOB/src/net/i2p/BOB/Lifted.java @@ -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)); + } + } +} diff --git a/apps/BOB/src/net/i2p/BOB/MUXlisten.java b/apps/BOB/src/net/i2p/BOB/MUXlisten.java index 095481ac2..bd52e27fd 100644 --- a/apps/BOB/src/net/i2p/BOB/MUXlisten.java +++ b/apps/BOB/src/net/i2p/BOB/MUXlisten.java @@ -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();