Author: cyberdo Date: 2006-02-21 18:34:11 +0000 (Tue, 21 Feb 2006) New Revision: 8090
Added: trunk/freenet/src/freenet/pluginmanager/ trunk/freenet/src/freenet/pluginmanager/FredPlugin.java trunk/freenet/src/freenet/pluginmanager/PluginHandler.java trunk/freenet/src/freenet/pluginmanager/PluginInfoWrapper.java trunk/freenet/src/freenet/pluginmanager/PluginManager.java trunk/freenet/src/freenet/pluginmanager/PluginNotFoundException.java trunk/freenet/src/freenet/pluginmanager/PluginRespirator.java trunk/freenet/src/freenet/pluginmanager/PproxyToadlet.java trunk/freenet/src/freenet/pluginmanager/TestGalleryPlugin.java trunk/freenet/src/freenet/pluginmanager/TestPlugin.java trunk/freenet/src/freenet/snmplib/ trunk/freenet/src/freenet/snmplib/BERDecoder.java trunk/freenet/src/freenet/snmplib/BEREncoder.java trunk/freenet/src/freenet/snmplib/BadFormatException.java trunk/freenet/src/freenet/snmplib/DataConstantInt.java trunk/freenet/src/freenet/snmplib/DataConstantString.java trunk/freenet/src/freenet/snmplib/DataFetcher.java trunk/freenet/src/freenet/snmplib/DataStatisticsInfo.java trunk/freenet/src/freenet/snmplib/InfoSystem.java trunk/freenet/src/freenet/snmplib/MultiplexedDataFetcher.java trunk/freenet/src/freenet/snmplib/SNMPAgent.java trunk/freenet/src/freenet/snmplib/SNMPCounter32.java trunk/freenet/src/freenet/snmplib/SNMPGauge32.java trunk/freenet/src/freenet/snmplib/SNMPInteger32.java trunk/freenet/src/freenet/snmplib/SNMPStarter.java trunk/freenet/src/freenet/snmplib/SNMPTimeTicks.java trunk/freenet/src/freenet/snmplib/SNMPTypeWrapperNum.java Removed: trunk/freenet/src/freenet/pluginmanager/FredPlugin.java trunk/freenet/src/freenet/pluginmanager/PluginHandler.java trunk/freenet/src/freenet/pluginmanager/PluginInfoWrapper.java trunk/freenet/src/freenet/pluginmanager/PluginManager.java trunk/freenet/src/freenet/pluginmanager/PluginNotFoundException.java trunk/freenet/src/freenet/pluginmanager/PluginRespirator.java trunk/freenet/src/freenet/pluginmanager/TestPlugin.java trunk/freenet/src/freenet/snmplib/BERDecoder.java trunk/freenet/src/freenet/snmplib/BEREncoder.java trunk/freenet/src/freenet/snmplib/BadFormatException.java trunk/freenet/src/freenet/snmplib/DataConstantInt.java trunk/freenet/src/freenet/snmplib/DataConstantString.java trunk/freenet/src/freenet/snmplib/DataFetcher.java trunk/freenet/src/freenet/snmplib/DataStatisticsInfo.java trunk/freenet/src/freenet/snmplib/InfoSystem.java trunk/freenet/src/freenet/snmplib/MultiplexedDataFetcher.java trunk/freenet/src/freenet/snmplib/SNMPAgent.java trunk/freenet/src/freenet/snmplib/SNMPCounter32.java trunk/freenet/src/freenet/snmplib/SNMPGauge32.java trunk/freenet/src/freenet/snmplib/SNMPInteger32.java trunk/freenet/src/freenet/snmplib/SNMPStarter.java trunk/freenet/src/freenet/snmplib/SNMPTimeTicks.java trunk/freenet/src/freenet/snmplib/SNMPTypeWrapperNum.java trunk/freenet/src/pluginmanager/ trunk/freenet/src/snmplib/ Modified: trunk/freenet/src/freenet/clients/http/FproxyToadlet.java trunk/freenet/src/freenet/clients/http/Toadlet.java trunk/freenet/src/freenet/clients/http/TrivialToadlet.java trunk/freenet/src/freenet/io/comm/IOStatisticCollector.java trunk/freenet/src/freenet/node/Node.java trunk/freenet/src/freenet/node/TextModeClientInterface.java trunk/freenet/src/freenet/node/Version.java Log: 460: Plugins now have FProxy-support, meaning they can serve over http. for an example plugin, check out: http://wiki.freenetproject.org/TestGalleryPlugin Moved snmplib to freenet.snmplib and pluginmanager to freenet.pluginmanager460: Plugins now have FProxy-support, meaning they can serve over http. for an example plugin, check out: http://wiki.freenetproject.org/TestGalleryPlugin Moved snmplib to freenet.snmplib and pluginmanager to freenet.pluginmanager460: Plugins now have FProxy-support, meaning they can serve over http. for an example plugin, check out: http://wiki.freenetproject.org/TestGalleryPlugin Moved snmplib to freenet.snmplib and pluginmanager to freenet.pluginmanager460: Plugins now have FProxy-support, meaning they can serve over http. for an example plugin, check out: http://wiki.freenetproject.org/TestGalleryPlugin Moved snmplib to freenet.snmplib and pluginmanager to freenet.pluginmanager Modified: trunk/freenet/src/freenet/clients/http/FproxyToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/FproxyToadlet.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/clients/http/FproxyToadlet.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -17,6 +17,7 @@ import freenet.keys.FreenetURI; import freenet.node.Node; import freenet.node.RequestStarter; +import freenet.pluginmanager.PproxyToadlet; import freenet.support.Bucket; import freenet.support.HTMLEncoder; import freenet.support.Logger; @@ -27,7 +28,7 @@ super(client); } - void handleGet(URI uri, ToadletContext ctx) + public void handleGet(URI uri, ToadletContext ctx) throws ToadletContextClosedException, IOException { String ks = uri.toString(); if(ks.startsWith("/")) @@ -62,7 +63,7 @@ } } - void handlePut(URI uri, Bucket data, ToadletContext ctx) + public void handlePut(URI uri, Bucket data, ToadletContext ctx) throws ToadletContextClosedException, IOException { String notSupported = "<html><head><title>Not supported</title></head><body>"+ "Operation not supported</body>"; @@ -134,6 +135,8 @@ FproxyToadlet fproxy = new FproxyToadlet(node.makeClient(RequestStarter.INTERACTIVE_PRIORITY_CLASS)); node.setFproxy(fproxy); server.register(fproxy, "/", false); + PproxyToadlet pproxy = new PproxyToadlet(node.makeClient(RequestStarter.INTERACTIVE_PRIORITY_CLASS), node.pluginManager); + server.register(pproxy, "/plugins/", true); fproxyConfig.finishedInitialization(); System.out.println("Starting fproxy on port "+(port)); } Modified: trunk/freenet/src/freenet/clients/http/Toadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/Toadlet.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/clients/http/Toadlet.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -44,12 +44,12 @@ * @throws IOException * @throws ToadletContextClosedException */ - abstract void handleGet(URI uri, ToadletContext ctx) throws ToadletContextClosedException, IOException; + abstract public void handleGet(URI uri, ToadletContext ctx) throws ToadletContextClosedException, IOException; /** * Likewise for a PUT request. */ - abstract void handlePut(URI uri, Bucket data, ToadletContext ctx) throws ToadletContextClosedException, IOException; + abstract public void handlePut(URI uri, Bucket data, ToadletContext ctx) throws ToadletContextClosedException, IOException; /** * Client calls from the above messages to run a freenet request. @@ -68,7 +68,7 @@ /** * Client calls to write a reply to the HTTP requestor. */ - void writeReply(ToadletContext ctx, int code, String mimeType, String desc, byte[] data, int offset, int length) throws ToadletContextClosedException, IOException { + protected void writeReply(ToadletContext ctx, int code, String mimeType, String desc, byte[] data, int offset, int length) throws ToadletContextClosedException, IOException { ctx.sendReplyHeaders(code, desc, null, mimeType, length); ctx.writeData(data, offset, length); } @@ -76,12 +76,12 @@ /** * Client calls to write a reply to the HTTP requestor. */ - void writeReply(ToadletContext ctx, int code, String mimeType, String desc, Bucket data) throws ToadletContextClosedException, IOException { + protected void writeReply(ToadletContext ctx, int code, String mimeType, String desc, Bucket data) throws ToadletContextClosedException, IOException { ctx.sendReplyHeaders(code, desc, null, mimeType, data.size()); ctx.writeData(data); } - void writeReply(ToadletContext ctx, int code, String mimeType, String desc, String reply) throws ToadletContextClosedException, IOException { + protected void writeReply(ToadletContext ctx, int code, String mimeType, String desc, String reply) throws ToadletContextClosedException, IOException { byte[] buf = reply.getBytes("ISO-8859-1"); ctx.sendReplyHeaders(code, desc, null, mimeType, buf.length); ctx.writeData(buf, 0, buf.length); Modified: trunk/freenet/src/freenet/clients/http/TrivialToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/TrivialToadlet.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/clients/http/TrivialToadlet.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -13,7 +13,7 @@ super(client); } - void handleGet(URI uri, ToadletContext ctx) throws ToadletContextClosedException, IOException { + public void handleGet(URI uri, ToadletContext ctx) throws ToadletContextClosedException, IOException { String fetched = uri.toString(); String encFetched = HTMLEncoder.encode(fetched); String reply = "<html><head><title>You requested "+encFetched+ @@ -22,7 +22,7 @@ this.writeReply(ctx, 200, "text/html", "OK", reply); } - void handlePut(URI uri, Bucket data, ToadletContext ctx) throws ToadletContextClosedException, IOException { + public void handlePut(URI uri, Bucket data, ToadletContext ctx) throws ToadletContextClosedException, IOException { String notSupported = "<html><head><title>Not supported</title></head><body>"+ "Operation not supported</body>"; // This really should be 405, but then we'd have to put an Allow header in. Modified: trunk/freenet/src/freenet/io/comm/IOStatisticCollector.java =================================================================== --- trunk/freenet/src/freenet/io/comm/IOStatisticCollector.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/io/comm/IOStatisticCollector.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -4,8 +4,9 @@ import java.util.HashMap; import java.util.Iterator; -import snmplib.SNMPStarter; +import freenet.snmplib.SNMPStarter; + public class IOStatisticCollector { public static final int STATISTICS_ENTRIES = 10; public static final int STATISTICS_DURATION_S = 30; Modified: trunk/freenet/src/freenet/node/Node.java =================================================================== --- trunk/freenet/src/freenet/node/Node.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/node/Node.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -25,9 +25,6 @@ import java.util.HashSet; import java.util.Iterator; -import pluginmanager.PluginManager; -import pluginmanager.PluginRespirator; -import snmplib.SNMPStarter; import freenet.client.ArchiveManager; import freenet.client.HighLevelSimpleClient; import freenet.client.HighLevelSimpleClientImpl; @@ -71,6 +68,11 @@ import freenet.keys.SSKBlock; import freenet.keys.SSKVerifyException; import freenet.node.fcp.FCPServer; +import freenet.pluginmanager.PluginManager; +import freenet.pluginmanager.PluginRespirator; +import freenet.pluginmanager.PproxyToadlet; +import freenet.snmplib.SNMPAgent; +import freenet.snmplib.SNMPStarter; import freenet.store.BerkeleyDBFreenetStore; import freenet.store.FreenetStore; import freenet.support.BucketFactory; @@ -393,7 +395,22 @@ Thread t = new Thread(new MemoryChecker(), "Memory checker"); t.setPriority(Thread.MAX_PRIORITY); t.start(); + /* + SimpleToadletServer server = new SimpleToadletServer(port+2000); + FproxyToadlet fproxy = new FproxyToadlet(n.makeClient(RequestStarter.INTERACTIVE_PRIORITY_CLASS)); + PproxyToadlet pproxy = new PproxyToadlet(n.makeClient(RequestStarter.INTERACTIVE_PRIORITY_CLASS), n.pluginManager); + server.register(fproxy, "/", false); + server.register(pproxy, "/plugins/", true); + System.out.println("Starting fproxy on port "+(port+2000)); + new FCPServer(port+3000, n); + System.out.println("Starting FCP server on port "+(port+3000)); + SNMPAgent.setSNMPPort(port+4000); + System.out.println("Starting SNMP server on port "+(port+4000)); + SNMPStarter.initialize(); + //server.register(fproxy, "/SSK@", false); + //server.register(fproxy, "/KSK@", false); + */ Node node; try { node = new Node(cfg, random); @@ -815,8 +832,10 @@ // And finally, Initialize the plugin manager PluginManager pm = null; try { - HighLevelSimpleClient hlsc = new HighLevelSimpleClientImpl(this, + HighLevelSimpleClient hlsc = makeClient(RequestStarter.INTERACTIVE_PRIORITY_CLASS); + /*new HighLevelSimpleClientImpl(this, archiveManager, tempBucketFactory, random, false, (short)0); + */ PluginRespirator pluginRespirator = new PluginRespirator(hlsc); pm = new PluginManager(pluginRespirator); } catch (Throwable e) { @@ -857,6 +876,13 @@ e.printStackTrace(); throw new NodeInitException(EXIT_COULD_NOT_START_FPROXY, "Could not start fproxy: "+e); } + /* + SimpleToadletServer server = new SimpleToadletServer(port+2000); + FproxyToadlet fproxy = new FproxyToadlet(n.makeClient(RequestStarter.INTERACTIVE_PRIORITY_CLASS)); + PproxyToadlet pproxy = new PproxyToadlet(n.makeClient(RequestStarter.INTERACTIVE_PRIORITY_CLASS), n.pluginManager); + server.register(fproxy, "/", false); + server.register(pproxy, "/plugins/", true); + * */ // FCP try { Modified: trunk/freenet/src/freenet/node/TextModeClientInterface.java =================================================================== --- trunk/freenet/src/freenet/node/TextModeClientInterface.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/node/TextModeClientInterface.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -512,7 +512,7 @@ } else if(uline.startsWith("PLUGLOAD:")) { n.pluginManager.startPlugin(line.substring("PLUGLOAD:".length()).trim()); } else if(uline.startsWith("PLUGLIST")) { - n.pluginManager.dumpPlugins(); + System.out.println(n.pluginManager.dumpPlugins()); } else if(uline.startsWith("PLUGKILL:")) { n.pluginManager.killPlugin(line.substring("PLUGKILL:".length()).trim()); } else { Modified: trunk/freenet/src/freenet/node/Version.java =================================================================== --- trunk/freenet/src/freenet/node/Version.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/node/Version.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -20,7 +20,7 @@ public static final String protocolVersion = "1.0"; /** The build number of the current revision */ - private static final int buildNumber = 459; + private static final int buildNumber = 460; /** Oldest build of Fred we will talk to */ private static final int lastGoodBuild = 403; Copied: trunk/freenet/src/freenet/pluginmanager (from rev 8059, trunk/freenet/src/pluginmanager) Deleted: trunk/freenet/src/freenet/pluginmanager/FredPlugin.java =================================================================== --- trunk/freenet/src/pluginmanager/FredPlugin.java 2006-02-18 16:46:38 UTC (rev 8059) +++ trunk/freenet/src/freenet/pluginmanager/FredPlugin.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,6 +0,0 @@ -package pluginmanager; - -public interface FredPlugin { - public void terminate(); - public void runPlugin(PluginRespirator pr); -} Copied: trunk/freenet/src/freenet/pluginmanager/FredPlugin.java (from rev 8089, trunk/freenet/src/pluginmanager/FredPlugin.java) =================================================================== --- trunk/freenet/src/pluginmanager/FredPlugin.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/pluginmanager/FredPlugin.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,12 @@ +package freenet.pluginmanager; + +public interface FredPlugin { + public static int handleFproxy = 1; + + + public boolean handles(int thing); + + public void terminate(); + public String handleHTTPGet(String path); + public void runPlugin(PluginRespirator pr); +} Deleted: trunk/freenet/src/freenet/pluginmanager/PluginHandler.java =================================================================== --- trunk/freenet/src/pluginmanager/PluginHandler.java 2006-02-18 16:46:38 UTC (rev 8059) +++ trunk/freenet/src/freenet/pluginmanager/PluginHandler.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,64 +0,0 @@ -package pluginmanager; - -/** - * Methods to handle a specific plugin (= set it up and start it) - * - * @author cyberdo - */ -public class PluginHandler { - - /** - * Will get all needed info from the plugin, put it into the Wrapper. Then - * the Pluginstarter will be greated, and the plugin fedto it, starting the - * plugin. - * - * the pluginInfoWrapper will then be returned - * - * @param plug - */ - public static PluginInfoWrapper startPlugin(PluginManager pm, FredPlugin plug, PluginRespirator pr) { - PluginStarter ps = new PluginStarter(pr); - PluginInfoWrapper pi = new PluginInfoWrapper(); - pi.putPluginThread(plug, ps); - ps.setPlugin(pm, plug); - ps.start(); - return pi; - } - - private static class PluginStarter extends Thread { - private Object plugin = null; - private PluginRespirator pr; - private PluginManager pm = null; - - public PluginStarter(PluginRespirator pr) { - this.pr = pr; - } - - public void setPlugin(PluginManager pm, Object plugin) { - this.plugin = plugin; - this.pm = pm; - } - - public void run() { - int seconds = 120; // give up after 2 min - while (plugin == null) { - // 1s polling - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - } - if (seconds-- <= 0) - return; - } - - if (plugin instanceof FredPlugin) - ((FredPlugin)plugin).runPlugin(pr); - - // If not FredPlugin, then the whole thing is aborted, - // and then this method will return, killing the thread - - pm.removePlugin(this); - } - - } -} Copied: trunk/freenet/src/freenet/pluginmanager/PluginHandler.java (from rev 8089, trunk/freenet/src/pluginmanager/PluginHandler.java) =================================================================== --- trunk/freenet/src/pluginmanager/PluginHandler.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/pluginmanager/PluginHandler.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,68 @@ +package freenet.pluginmanager; + +/** + * Methods to handle a specific plugin (= set it up and start it) + * + * @author cyberdo + */ +public class PluginHandler { + + /** + * Will get all needed info from the plugin, put it into the Wrapper. Then + * the Pluginstarter will be greated, and the plugin fedto it, starting the + * plugin. + * + * the pluginInfoWrapper will then be returned + * + * @param plug + */ + public static PluginInfoWrapper startPlugin(PluginManager pm, FredPlugin plug, PluginRespirator pr) { + PluginStarter ps = new PluginStarter(pr); + PluginInfoWrapper pi = new PluginInfoWrapper(); + pi.putPluginThread(plug, ps); + ps.setPlugin(pm, plug); + ps.start(); + return pi; + } + + private static class PluginStarter extends Thread { + private Object plugin = null; + private PluginRespirator pr; + private PluginManager pm = null; + + public PluginStarter(PluginRespirator pr) { + this.pr = pr; + } + + public void setPlugin(PluginManager pm, Object plugin) { + this.plugin = plugin; + this.pm = pm; + } + + public void run() { + int seconds = 120; // give up after 2 min + while (plugin == null) { + // 1s polling + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + if (seconds-- <= 0) + return; + } + + if (plugin instanceof FredPlugin) { + FredPlugin plug = ((FredPlugin)plugin); + // handles fproxy? If so, register + if (plug.handles(FredPlugin.handleFproxy)) + pm.registerToadlet(plug); + ((FredPlugin)plugin).runPlugin(pr); + } + // If not FredPlugin, then the whole thing is aborted, + // and then this method will return, killing the thread + + pm.removePlugin(this); + } + + } +} Deleted: trunk/freenet/src/freenet/pluginmanager/PluginInfoWrapper.java =================================================================== --- trunk/freenet/src/pluginmanager/PluginInfoWrapper.java 2006-02-18 16:46:38 UTC (rev 8059) +++ trunk/freenet/src/freenet/pluginmanager/PluginInfoWrapper.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,50 +0,0 @@ -package pluginmanager; - -import java.util.Date; - -public class PluginInfoWrapper { - // Parameters to make the object OTP - private boolean fedPluginThread = false; - // Public since only PluginHandler will know about it - private String className; - private Thread thread; - private long start; - private String threadName; - private FredPlugin plug; - //public String - - public void putPluginThread(FredPlugin plug, Thread ps) { - if (fedPluginThread) return; - - className = plug.getClass().toString(); - thread = ps; - this.plug = plug; - threadName = "p" + className.replaceAll("^class ", "") + "_" + ps.hashCode(); - start = System.currentTimeMillis(); - ps.setName(threadName); - - fedPluginThread = true; - } - - public String toString() { - return "ID: \"" +threadName + "\", Name: "+ className +" Started: " + (new Date(start)).toString(); - } - - public String getThreadName() { - return threadName; - } - -/* public FredPlugin getPlugin(){ - return plug; - } - */ - public void stopPlugin() { - plug.terminate(); - //thread.interrupt(); - } - - public boolean sameThread(Thread t){ - return (t == thread); - } - -} Copied: trunk/freenet/src/freenet/pluginmanager/PluginInfoWrapper.java (from rev 8089, trunk/freenet/src/pluginmanager/PluginInfoWrapper.java) =================================================================== --- trunk/freenet/src/pluginmanager/PluginInfoWrapper.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/pluginmanager/PluginInfoWrapper.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,50 @@ +package freenet.pluginmanager; + +import java.util.Date; + +public class PluginInfoWrapper { + // Parameters to make the object OTP + private boolean fedPluginThread = false; + // Public since only PluginHandler will know about it + private String className; + private Thread thread; + private long start; + private String threadName; + private FredPlugin plug; + //public String + + public void putPluginThread(FredPlugin plug, Thread ps) { + if (fedPluginThread) return; + + className = plug.getClass().toString(); + thread = ps; + this.plug = plug; + threadName = "p" + className.replaceAll("^class ", "") + "_" + ps.hashCode(); + start = System.currentTimeMillis(); + ps.setName(threadName); + + fedPluginThread = true; + } + + public String toString() { + return "ID: \"" +threadName + "\", Name: "+ className +", Started: " + (new Date(start)).toString(); + } + + public String getThreadName() { + return threadName; + } + + public String getPluginClassName(){ + return plug.getClass().getName().toString(); + } + + public void stopPlugin() { + plug.terminate(); + thread.interrupt(); + } + + public boolean sameThread(Thread t){ + return (t == thread); + } + +} Deleted: trunk/freenet/src/freenet/pluginmanager/PluginManager.java =================================================================== --- trunk/freenet/src/pluginmanager/PluginManager.java 2006-02-18 16:46:38 UTC (rev 8059) +++ trunk/freenet/src/freenet/pluginmanager/PluginManager.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,143 +0,0 @@ -package pluginmanager; - -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; - -import freenet.client.HighLevelSimpleClient; - -public class PluginManager { - - /* - * - * TODO: Synchronize - * TODO: Synchronize - * TODO: Synchronize - * TODO: Synchronize - * TODO: Synchronize - * - */ - - - private static HashMap pluginInfo; - private static PluginManager pluginManager = null; - private PluginRespirator pluginRespirator = null; - - public PluginManager(PluginRespirator pluginRespirator) { - pluginInfo = new HashMap(); - - this.pluginRespirator = pluginRespirator; - //StartPlugin("misc at file:plugin.jar"); - - // Needed to include plugin in jar-files - if (new Date().equals(null)) - System.err.println(new TestPlugin()); - } - - public void startPlugin(String filename) { - FredPlugin plug; - try { - plug = LoadPlugin(filename); - PluginInfoWrapper pi = PluginHandler.startPlugin(this, plug, pluginRespirator); - pluginInfo.put(pi.getThreadName(), pi); - } catch (PluginNotFoundException e) { - e.printStackTrace(); - } - } - - public void removePlugin(Thread t) { - Object removeKey = null; - { - Iterator it = pluginInfo.keySet().iterator(); - while (it.hasNext()) { - Object key = it.next(); - PluginInfoWrapper pi = (PluginInfoWrapper) pluginInfo.get(key); - if (pi.sameThread(t)) - removeKey = key; - } - } - if (removeKey != null) - pluginInfo.remove(removeKey); - } - - public void dumpPlugins() { - Iterator it = pluginInfo.keySet().iterator(); - while (it.hasNext()) { - PluginInfoWrapper pi = (PluginInfoWrapper) pluginInfo.get(it.next()); - System.out.println(pi); - } - } - - public void killPlugin(String name) { - Iterator it = pluginInfo.keySet().iterator(); - while (it.hasNext()) { - PluginInfoWrapper pi = (PluginInfoWrapper) pluginInfo.get(it.next()); - if (pi.getThreadName().equals(name)) - { - pi.stopPlugin(); - } - } - } - - - /** - * Method to load a plugin from the given path and return is as an object. - * Will accept filename to be of one of the following forms: - * "classname" to load a class from the current classpath - * "classame at file:/path/to/jarfile.jar" to load class from an other jarfile. - * - * @param filename The filename to load from - * @return An instanciated object of the plugin - * @throws PluginNotFoundException If anything goes wrong. - */ - private FredPlugin LoadPlugin(String filename) throws PluginNotFoundException { - Class cls = null; - - if (filename.indexOf("@file:") >= 0) { - // Open from extern file - try { - // Load the jar-file - String[] parts = filename.split("@file:"); - if (parts.length != 2) { - throw new PluginNotFoundException("Could not split at \"@file:\"."); - } - - // Load the class inside file - URL[] serverURLs = new URL[]{new URL("file:" + parts[1])}; - ClassLoader cl = new URLClassLoader(serverURLs); - cls = cl.loadClass(parts[0]); - } catch (Exception e) { - throw new PluginNotFoundException("Initialization error:" - + filename, e); - } - } else { - // Load class - try { - cls = Class.forName(filename); - } catch (ClassNotFoundException e) { - throw new PluginNotFoundException(filename); - } - } - - if(cls == null) - throw new PluginNotFoundException("Unknown error"); - - // Class loaded... Objectize it! - Object o = null; - try { - o = cls.newInstance(); - } catch (Exception e) { - throw new PluginNotFoundException("Could not re-create plugin:" + - filename, e); - } - - // See if we have the right type - if (!(o instanceof FredPlugin)) { - throw new PluginNotFoundException("Not a plugin: " + filename); - } - - return (FredPlugin)o; - } -} Copied: trunk/freenet/src/freenet/pluginmanager/PluginManager.java (from rev 8089, trunk/freenet/src/pluginmanager/PluginManager.java) =================================================================== --- trunk/freenet/src/pluginmanager/PluginManager.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/pluginmanager/PluginManager.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,184 @@ +package freenet.pluginmanager; + +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; + +import freenet.client.HighLevelSimpleClient; + +public class PluginManager { + + /* + * + * TODO: Synchronize + * TODO: Synchronize + * TODO: Synchronize + * TODO: Synchronize + * TODO: Synchronize + * + */ + + private HashMap toadletList; + private HashMap pluginInfo; + private PluginManager pluginManager = null; + private PluginRespirator pluginRespirator = null; + + public PluginManager(PluginRespirator pluginRespirator) { + pluginInfo = new HashMap(); + toadletList = new HashMap(); + + this.pluginRespirator = pluginRespirator; + pluginRespirator.setPluginManager(this); + //StartPlugin("misc at file:plugin.jar"); + + // Needed to include plugin in jar-files + if (new Date().equals(null)){ + System.err.println(new TestPlugin()); + System.err.println(new TestGalleryPlugin()); + } + } + + public void startPlugin(String filename) { + FredPlugin plug; + try { + plug = LoadPlugin(filename); + PluginInfoWrapper pi = PluginHandler.startPlugin(this, plug, pluginRespirator); + synchronized (pluginInfo) { + pluginInfo.put(pi.getThreadName(), pi); + } + } catch (PluginNotFoundException e) { + e.printStackTrace(); + } + } + + public void registerToadlet(FredPlugin pl){ + Exception e = new Exception(); + //toadletList.put(e.getStackTrace()[1].getClass().toString(), pl); + synchronized (toadletList) { + toadletList.put(pl.getClass().getName(), pl); + } + System.err.println("Added HTTP handler for /plugins/"+pl.getClass().getName()+"/"); + } + + public void removePlugin(Thread t) { + Object removeKey = null; + synchronized (pluginInfo) { + Iterator it = pluginInfo.keySet().iterator(); + while (it.hasNext() && removeKey == null) { + Object key = it.next(); + PluginInfoWrapper pi = (PluginInfoWrapper) pluginInfo.get(key); + if (pi.sameThread(t)) { + removeKey = key; + synchronized (toadletList) { + try { + toadletList.remove(pi.getPluginClassName()); + } catch (Throwable ex) { + } + } + } + } + + if (removeKey != null) + pluginInfo.remove(removeKey); + } + } + + public String dumpPlugins() { + StringBuffer out= new StringBuffer(); + synchronized (pluginInfo) { + Iterator it = pluginInfo.keySet().iterator(); + while (it.hasNext()) { + PluginInfoWrapper pi = (PluginInfoWrapper) pluginInfo.get(it.next()); + out.append(pi.toString()); + out.append('\n'); + } + } + return out.toString(); + } + + public String handleHTTPGet(String plugin, String path) { + FredPlugin handler = null; + synchronized (toadletList) { + handler = (FredPlugin)toadletList.get(plugin); + } + if (handler == null) + return null; + + return handler.handleHTTPGet(path); + } + + public void killPlugin(String name) { + synchronized (pluginInfo) { + Iterator it = pluginInfo.keySet().iterator(); + while (it.hasNext()) { + PluginInfoWrapper pi = (PluginInfoWrapper) pluginInfo.get(it.next()); + if (pi.getThreadName().equals(name)) + { + pi.stopPlugin(); + } + } + } + } + + + /** + * Method to load a plugin from the given path and return is as an object. + * Will accept filename to be of one of the following forms: + * "classname" to load a class from the current classpath + * "classame at file:/path/to/jarfile.jar" to load class from an other jarfile. + * + * @param filename The filename to load from + * @return An instanciated object of the plugin + * @throws PluginNotFoundException If anything goes wrong. + */ + private FredPlugin LoadPlugin(String filename) throws PluginNotFoundException { + Class cls = null; + + if (filename.indexOf("@file:") >= 0) { + // Open from extern file + try { + // Load the jar-file + String[] parts = filename.split("@file:"); + if (parts.length != 2) { + throw new PluginNotFoundException("Could not split at \"@file:\"."); + } + + // Load the class inside file + URL[] serverURLs = new URL[]{new URL("file:" + parts[1])}; + ClassLoader cl = new URLClassLoader(serverURLs); + cls = cl.loadClass(parts[0]); + } catch (Exception e) { + throw new PluginNotFoundException("Initialization error:" + + filename, e); + } + } else { + // Load class + try { + cls = Class.forName(filename); + } catch (ClassNotFoundException e) { + throw new PluginNotFoundException(filename); + } + } + + if(cls == null) + throw new PluginNotFoundException("Unknown error"); + + // Class loaded... Objectize it! + Object o = null; + try { + o = cls.newInstance(); + } catch (Exception e) { + throw new PluginNotFoundException("Could not re-create plugin:" + + filename, e); + } + + // See if we have the right type + if (!(o instanceof FredPlugin)) { + throw new PluginNotFoundException("Not a plugin: " + filename); + } + + return (FredPlugin)o; + } +} Deleted: trunk/freenet/src/freenet/pluginmanager/PluginNotFoundException.java =================================================================== --- trunk/freenet/src/pluginmanager/PluginNotFoundException.java 2006-02-18 16:46:38 UTC (rev 8059) +++ trunk/freenet/src/freenet/pluginmanager/PluginNotFoundException.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,25 +0,0 @@ -package pluginmanager; - -public class PluginNotFoundException extends Exception { - - public PluginNotFoundException() { - super(); - // TODO Auto-generated constructor stub - } - - public PluginNotFoundException(String arg0) { - super(arg0); - // TODO Auto-generated constructor stub - } - - public PluginNotFoundException(String arg0, Throwable arg1) { - super(arg0, arg1); - // TODO Auto-generated constructor stub - } - - public PluginNotFoundException(Throwable arg0) { - super(arg0); - // TODO Auto-generated constructor stub - } - -} Copied: trunk/freenet/src/freenet/pluginmanager/PluginNotFoundException.java (from rev 8089, trunk/freenet/src/pluginmanager/PluginNotFoundException.java) =================================================================== --- trunk/freenet/src/pluginmanager/PluginNotFoundException.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/pluginmanager/PluginNotFoundException.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,25 @@ +package freenet.pluginmanager; + +public class PluginNotFoundException extends Exception { + + public PluginNotFoundException() { + super(); + // TODO Auto-generated constructor stub + } + + public PluginNotFoundException(String arg0) { + super(arg0); + // TODO Auto-generated constructor stub + } + + public PluginNotFoundException(String arg0, Throwable arg1) { + super(arg0, arg1); + // TODO Auto-generated constructor stub + } + + public PluginNotFoundException(Throwable arg0) { + super(arg0); + // TODO Auto-generated constructor stub + } + +} Deleted: trunk/freenet/src/freenet/pluginmanager/PluginRespirator.java =================================================================== --- trunk/freenet/src/pluginmanager/PluginRespirator.java 2006-02-18 16:46:38 UTC (rev 8059) +++ trunk/freenet/src/freenet/pluginmanager/PluginRespirator.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,17 +0,0 @@ -package pluginmanager; - -import freenet.client.HighLevelSimpleClient; -import freenet.client.HighLevelSimpleClientImpl; -import freenet.node.Node; - -public class PluginRespirator { - private HighLevelSimpleClient hlsc = null; - - public PluginRespirator(HighLevelSimpleClient hlsc) { - this.hlsc = hlsc; - } - - public HighLevelSimpleClient getHLSimpleClient() { - return hlsc; - } -} Copied: trunk/freenet/src/freenet/pluginmanager/PluginRespirator.java (from rev 8089, trunk/freenet/src/pluginmanager/PluginRespirator.java) =================================================================== --- trunk/freenet/src/pluginmanager/PluginRespirator.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/pluginmanager/PluginRespirator.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,32 @@ +package freenet.pluginmanager; + +import java.util.HashMap; + +import freenet.client.HighLevelSimpleClient; +import freenet.client.HighLevelSimpleClientImpl; +import freenet.node.Node; + +public class PluginRespirator { + private HighLevelSimpleClient hlsc = null; + private PluginManager pm = null; + private HashMap toadletList; + + public PluginRespirator(HighLevelSimpleClient hlsc) { + this.hlsc = hlsc; + toadletList = new HashMap(); + } + + public void setPluginManager(PluginManager pm) { + if (this.pm == null) + this.pm = pm; + } + + /*// TODO:.. really best solution? + public void registerToadlet(FredPlugin pl){ + pm.registerToadlet(pl); + }*/ + + public HighLevelSimpleClient getHLSimpleClient() { + return hlsc; + } +} Added: trunk/freenet/src/freenet/pluginmanager/PproxyToadlet.java =================================================================== --- trunk/freenet/src/pluginmanager/PproxyToadlet.java 2006-02-18 16:46:38 UTC (rev 8059) +++ trunk/freenet/src/freenet/pluginmanager/PproxyToadlet.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,94 @@ +package freenet.pluginmanager; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.net.MalformedURLException; +import java.net.URI; + + + +import freenet.client.FetchException; +import freenet.client.FetchResult; +import freenet.client.HighLevelSimpleClient; +import freenet.clients.http.Toadlet; +import freenet.clients.http.ToadletContext; +import freenet.clients.http.ToadletContextClosedException; +import freenet.keys.FreenetURI; +import freenet.support.Bucket; +import freenet.support.Logger; + +public class PproxyToadlet extends Toadlet { + private PluginManager pm = null; + + public PproxyToadlet(HighLevelSimpleClient client, PluginManager pm) { + super(client); + this.pm = pm; + } + + /** + * TODO: Remove me eventually!!!! + * + * @param title + * @param content + * @return + */ + private String mkPage(String title, String content) { + if (content == null) content = "null"; + return "<html><head><title>" + title + "</title></head><body><h1>"+ + title +"</h1>" + content.replaceAll("\n", "<br/>\n") + "</body>"; + } + + public void handleGet(URI uri, ToadletContext ctx) + throws ToadletContextClosedException, IOException { + String ks = uri.toString(); + if(ks.startsWith("/")) + ks = ks.substring(1); + ks = ks.substring("plugins/".length()); + Logger.minor(this, "Pproxy fetching "+ks); + try { + if (ks.equals("")) { + String ret = pm.dumpPlugins().replaceAll(",", "\n "); + writeReply(ctx, 200, "text/html", "OK", mkPage("Plugin list", ret)); + } else { + int to = ks.indexOf("/"); + String plugin, data; + if (to == -1) { + plugin = ks; + data = ""; + } else { + plugin = ks.substring(0, to); + data = ks.substring(to + 1); + } + + //pm.handleHTTPGet(plugin, data); + + //writeReply(ctx, 200, "text/html", "OK", mkPage("plugin", pm.handleHTTPGet(plugin, data))); + writeReply(ctx, 200, "text/html", "OK", pm.handleHTTPGet(plugin, data)); + + } + + //FetchResult result = fetch(key); + //writeReply(ctx, 200, result.getMimeType(), "OK", result.asBucket()); + + } catch (Throwable t) { + Logger.error(this, "Caught "+t, t); + String msg = "<html><head><title>Internal Error</title></head><body><h1>Internal Error: please report</h1><pre>"; + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + t.printStackTrace(pw); + pw.flush(); + msg = msg + sw.toString() + "</pre></body></html>"; + this.writeReply(ctx, 500, "text/html", "Internal Error", msg); + } + } + + public void handlePut(URI uri, Bucket data, ToadletContext ctx) + throws ToadletContextClosedException, IOException { + String notSupported = "<html><head><title>Not supported</title></head><body>"+ + "Operation not supported</body>"; + // FIXME should be 405? Need to let toadlets indicate what is allowed maybe in a callback? + super.writeReply(ctx, 200, "text/html", "OK", notSupported); + } + +} Added: trunk/freenet/src/freenet/pluginmanager/TestGalleryPlugin.java =================================================================== --- trunk/freenet/src/pluginmanager/TestGalleryPlugin.java 2006-02-18 16:46:38 UTC (rev 8059) +++ trunk/freenet/src/freenet/pluginmanager/TestGalleryPlugin.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,148 @@ +package freenet.pluginmanager; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.Date; +import java.util.Random; + +import freenet.client.FetchException; +import freenet.client.FetchResult; +import freenet.client.HighLevelSimpleClient; +import freenet.keys.FreenetURI; + +public class TestGalleryPlugin implements FredPlugin { + boolean goon = true; + Random rnd = new Random(); + PluginRespirator pr; + public void terminate() { + goon = false; + } + + private String getArrayElement(String[] array, int element) { + try { + return array[element]; + } catch (Exception e) { + //e.printStackTrace(); + return ""; + } + } + + public String handleHTTPGet(String path) { + StringBuffer out = new StringBuffer(); + String[] pathelements = path.split("\\?"); + String uri = pathelements[0]; + String[] getelements = getArrayElement(pathelements, 1).split("\\?"); + int page = 1; + for (int i = 0; i < getelements.length ; i++) { + if (getelements[i].startsWith("page=")) + page = Integer.parseInt(getelements[i].substring("page=".length())); + } + + + try { + /* Cache later! */ + HighLevelSimpleClient hlsc = pr.getHLSimpleClient(); + String imglist = new String(hlsc.fetch(new FreenetURI(uri)).asByteArray()).trim(); + imglist = imglist.replaceAll("\r","\n"); + imglist = imglist.replaceAll("\n\n", "\n"); + imglist = imglist.replaceAll("\n\n", "\n"); + imglist = imglist.replaceAll("\n\n", "\n"); + imglist = imglist.replaceAll("\n\n", "\n"); + imglist = imglist.replaceAll("\n\n", "\n"); + /* /Cache! */ + + String[] imgarr = imglist.split("\n"); + //imgarr[0] == title; + out.append("<HTML><HEAD><TITLE>" + imgarr[0] + "</TITLE></HEAD><BODY>\n"); + out.append("<CENTER><H1>" + imgarr[0] + "</H1><BR/>Page " + page + "<BR/><BR/>\n"); + out.append("<table><tr>\n"); + int images = 0; + int flush = (page - 1)*6*4; + for(int i = 1 ; (i < imgarr.length && images < 6*4); i++) { + // url | name | size + if (imgarr[i].trim().length() < 5) + continue; + if (flush > 0) { + flush--; + continue; + } + images++; + + String imginfo[] = imgarr[i].split("\\|"); + String iname = getArrayElement(imginfo, 1).trim(); + String isname = iname; + if (iname.length() > 15) + isname = iname.substring(0,11) + "..." + iname.substring(iname.lastIndexOf(".")); + + // f2="`echo "$f" | rev | cut -d . -f2- | rev | cut -c-13`...`echo "$f" | rev | cut -d . -f1 | rev`" + //String isize = getArrayElement(imginfo, 2).trim(); + String iurl = getArrayElement(imginfo, 0).trim(); + iurl = iurl.replaceAll("^URI: ", ""); + iurl = iurl.replaceAll("^freenet:", ""); + iurl = "/" + iurl; + + + + out.append("<td align=\"center\" valign=\"top\" width=\"102px\">\n"); + out.append(" <a title=\""+iname+"\" href=\"" + iurl + "\"><img src=\"" + iurl + "\" border=\"0\" width=\"100\"><br/>\n"); + out.append(" <font size=\"-2\">\"" + isname + "\"</font>\n"); + out.append(" </a>\n"); + for (int j = 2 ; j < imginfo.length ; j++) + out.append(" <br><font size=\"-2\">" + imginfo[j].trim() + "</font>\n"); + out.append("</td>\n"); + + // new row? + if (i%6 == 0) { + out.append("</tr><tr>\n"); + } + } + out.append("</tr><table>\n"); + for (int pg = 1 ; pg <= (int)Math.ceil((imgarr.length-1)/(6*4)) ; pg++) { + out.append(" "); + if (pg != page) + out.append("<a href=\""+uri+"?page="+pg+"\">["+pg+"]</a>"); + else + out.append("["+pg+"]"); + out.append(" \n"); + } + + + out.append("</CENTER></BODY></HTML>"); + return out.toString(); + } catch (Exception e) { + // TODO Auto-generated catch block + return e.toString();// e.printStackTrace(); + } + } + + public void runPlugin(PluginRespirator pr) { + this.pr = pr; + + //int i = (int)System.currentTimeMillis()%1000; + while(goon) { + System.err.println("Heartbeat from gallery-plugin: " + (new Date())); + /* + FetchResult fr; + try { + fr = pr.getHLSimpleClient().fetch(new FreenetURI("freenet:CHK at j-v1zc0cuN3wlaCpxlKd6vT6c1jAnT9KiscVjfzLu54,q9FIlJSh8M1I1ymRBz~A0fsIcGkvUYZahZb5j7uepLA,AAEA--8")); + System.err.println(" Got data from key, length = " + fr.size() + " Message: " + + new String(fr.asByteArray()).trim()); + } catch (Exception e) { + } + */ + try { + Thread.sleep(300000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + } + } + } + + public boolean handles(int thing) { + return ((thing == FredPlugin.handleFproxy) || + (thing == FredPlugin.handleFproxy) || + (thing == FredPlugin.handleFproxy)); + } + +} Deleted: trunk/freenet/src/freenet/pluginmanager/TestPlugin.java =================================================================== --- trunk/freenet/src/pluginmanager/TestPlugin.java 2006-02-18 16:46:38 UTC (rev 8059) +++ trunk/freenet/src/freenet/pluginmanager/TestPlugin.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,38 +0,0 @@ -package pluginmanager; - -import java.net.MalformedURLException; -import java.util.Date; - -import freenet.client.FetchException; -import freenet.client.FetchResult; -import freenet.keys.FreenetURI; - -public class TestPlugin implements FredPlugin { - boolean goon = true; - public void terminate() { - goon = false; - } - - public void runPlugin(PluginRespirator pr) { - int i = (int)System.currentTimeMillis()%1000; - while(goon) { - System.err.println("This is a threaded test-plugin (" + - i + "). " + - "Time is now: " + (new Date())); - FetchResult fr; - try { - fr = pr.getHLSimpleClient().fetch(new FreenetURI("freenet:CHK at j-v1zc0cuN3wlaCpxlKd6vT6c1jAnT9KiscVjfzLu54,q9FIlJSh8M1I1ymRBz~A0fsIcGkvUYZahZb5j7uepLA,AAEA--8")); - System.err.println(" Got data from key, length = " + fr.size() + " Message: " - + new String(fr.asByteArray()).trim()); - } catch (Exception e) { - } - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - -} Copied: trunk/freenet/src/freenet/pluginmanager/TestPlugin.java (from rev 8089, trunk/freenet/src/pluginmanager/TestPlugin.java) =================================================================== --- trunk/freenet/src/pluginmanager/TestPlugin.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/pluginmanager/TestPlugin.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,168 @@ +package freenet.pluginmanager; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.Date; +import java.util.Random; + +import freenet.client.FetchException; +import freenet.client.FetchResult; +import freenet.keys.FreenetURI; + +public class TestPlugin implements FredPlugin { + boolean goon = true; + Random rnd = new Random(); + PluginRespirator pr; + + public boolean handles(int thing) { + return ((thing == FredPlugin.handleFproxy) || + (thing == FredPlugin.handleFproxy) || + (thing == FredPlugin.handleFproxy)); + } + + public void terminate() { + goon = false; + } + + public String handleHTTPGet(String path) { + try { + String key = getRandomKey();//"freenet:CHK at j-v1zc0cuN3wlaCpxlKd6vT6c1jAnT9KiscVjfzLu54,q9FIlJSh8M1I1ymRBz~A0fsIcGkvUYZahZb5j7uepLA,AAEA--8"; + FetchResult fr = pr.getHLSimpleClient().fetch(new FreenetURI(key)); + + return "This is the echo of the past.... ["+ path + "]\n" + + "This is from within the plugin. I've fetched some data for you.\n"+ + "The key is: " + key + ", and the data inside:\n"+ + "-----------------------------------------------------------\n"+ + new String(fr.asByteArray()).trim() + "\n" + + "-----------------------------------------------------------\n"+ + "Length: " + fr.size() + ", Mime-Type: " + fr.getMimeType(); + } catch (Exception e) { + // TODO Auto-generated catch block + return e.toString();// e.printStackTrace(); + } + } + + public void runPlugin(PluginRespirator pr) { + this.pr = pr; + //pr.registerToadlet(this); + //int i = (int)System.currentTimeMillis()%1000; + while(goon) { + /*System.err.println("This is a threaded test-plugin (" + + i + "). " + + "Time is now: " + (new Date()));*/ + try { + Thread.sleep(60000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + } + } + } + + private String getRandomKey() { + String[] strs = {"freenet:CHK at 22Lk6FBe3OxPBVMlrjFkH-4cgySwcghOz7hDQPzXKp4,wxOg3Ob8mjI5eg4WNvmDA~1CsW9MWAqwOhXXzLdrN-A,AAEA--8", + "freenet:CHK at ZFpjcNHONAxLPDadG~v6QcSwM775-5Iw2k~QBhb63Ts,QPrrwXciPnyAEbsK5EBW-aYOGhlTaa~3YBhR-nIcx8A,AAEA--8", + "freenet:CHK at OPpTiKOEwZbl73o7Tb~QQJaP4JEgLT8o3mP5jyJujvk,9~8TDGJAW8LfIDhC7xWrey3tEjFpdOpBa6OituIVJpA,AAEA--8", + "freenet:CHK at sCb-Z1ATTkXvoZLBI9k3ciLz~6rqb9Io3AQL2~MliAM,a60Eoe90z5fcViuIXLecUBHFUeFf6Ge69sSdlzIHrEg,AAEA--8", + "freenet:CHK at dcpPsRY0BG4OViN8wsXvWZTnP2ZBemz2BwENPBZC9TU,goiIQkp8OWaTc3wqr-A0Rf-aCwsEeOQPaVdjCxVpaRI,AAEA--8", + "freenet:CHK at 6OAQs98FSUo6rFcJtRMF92SFfqBXK4Yt01Yshcwp3c8,wnLfm5swG7xDbKAuSrnL8GEFz5~-4~7a2P5K8nnBV9Q,AAEA--8", + "freenet:CHK at ePPkqAWESJVQzGO3wr6nPee8SzOuexpXYtHIWv4onTg,JlwdILVoS6OtXZqlRShtnuogFgTRO0bnXDVxUj3BusA,AAEA--8", + "freenet:CHK at MWC8oxXg1BYZ0AJFXKOkuYrYiK7qn1PtBlBjc14Jw7o,fKxCbs0u8fjT1X-8oE3dKnQaVpZ07CpiX-gBxkwO7xc,AAEA--8", + "freenet:CHK@~E5LGhRcvCep6pYb-odjnyS3nA0vS7Xe5GIQmmQAzMA,U3o9V86hkUMqbtgXSR9PJAQpsOodM25qDHg2KHMEJZI,AAEA--8", + "freenet:CHK at qHaTIegEd3bWsHBB~SqvO-y3wFBU5EPEjEJBj4MJfzg,J8LcoIXB7fwXHrhPmxT6Ec-rfbw0SKTBaI84BH-pv80,AAEA--8", + "freenet:CHK at SBBZXAsF1uSQc~cp-MC35IZTpd78hDhOQq7YTbwHgAE,c8jjxzd6f8aPDHbTy2JQRWwhEiDUNCwxO8mtZwAmq-s,AAEA--8", + "freenet:CHK at BB~ePfxucL0NzayJ2jvtivpRXcNooyepNdhE~dvN6ec,nMNZuv0CwiObgvSyWPmTv29GPj~JuiRTl~dMuuOTOik,AAEA--8", + "freenet:CHK at hDKNl~vitO25RmgQgbGx-Iytu4W14mHSeEIn9YyD2pg,-EJc8KXGzNtdrvKF0h90geENZgBDux~h9Gkc1fyFMUg,AAEA--8", + "freenet:CHK at p3Xa12sfgQg3LS~VU9SsVgj4kBh58GpIqrkgRpacnFM,lyCvmN88mtvX~L9BqTQV51Ontj39X8ms5soRA~K3LU8,AAEA--8", + "freenet:CHK at d9TEpYgV77l2zmro8igbU44F~5kUYmo-9Xoa~UFHrgw,yu-zz2qp5W2BWptDmv5Dw9~dMP3wH3n-U4qrKdMnlAQ,AAEA--8", + "freenet:CHK at T7ytkBob45SqxK7xWZxmwAUJCdwvA1K7EPcZUAcRirc,acnBQ4qO4T2T~lA5h6QytR3UaOuzWz03tYK0~epHzHI,AAEA--8", + "freenet:CHK at XAvuSwiW4IdyQ-4~CWOVCXGUQPsdMjP9ofLeRpWeIBE,YefUEommdgaTrVo9dxQpc-UiraiYDCnpKH65Smk6jas,AAEA--8", + "freenet:CHK at 3wdFmakCldQH0TQYQH-D4gQH8iiNT7XZM~2MVVosass,N-BZoCgtLWSZYDJ-ib44-dl2ye3m1zltK1c4yITz8bo,AAEA--8", + "freenet:CHK at VueT2wZS~72S~QxBAXNPJCVy8GkqxMUGe78aAmeOeC4,3MZ7jVw~wNUaS~pv9w1vVYN79UkK9SUEUCaffSua07s,AAEA--8", + "freenet:CHK at IMTdF9b9CDXy7ZvWMGxTp02llxati8iRGjtletbyqLU,2Ca6lUsRsQa~lhMesSYVPcD5SrS06anutMcqLZvcjLI,AAEA--8", + "freenet:CHK at 5tig2I52NoMH6IPAuDcE7lowJ1vqBBTowtPzxaPImp0,oXWcEqx0enGaSTniRA6ZWIEtqmm2wJb8O87VZ7kNV7w,AAEA--8", + "freenet:CHK at 1oxIcrwDCqI7hGFCd3DX4dWVsK7xVPZcyIBEHZybsXc,GeL01biXlxUnkacw4cXRsajbNrUc43h2rm390q8mMt0,AAEA--8", + "freenet:CHK at bwieoklnnSaWHTUl3wZu9w2FCJy5uH7Dmi~XRKivGXA,ILg2cordIWtMncA2glyj9iVf6YZDYscRkO3P8sRBXDk,AAEA--8", + "freenet:CHK at xXKRVMJpcYEa0Md2W7Rz~hsUpL80-bSx9Kc04fLeIKc,A3rmIcwQ8n33nd5xJTTrrKIOMQ3g8C2C8vjJtneYMAk,AAEA--8", + "freenet:CHK at s8aihl-4JN9a6GF9DYUmCTN2~3PpSj0-ktQA49jYC1U,iPgZU7lVKT-gbs5ioNX9swRjveGjo0ShyOoBn8wUQ2U,AAEA--8", + "freenet:CHK at 7gZlzbJyFtHndt213T33aYySsuSyP0rxHEmI~q8yjVM,37QtrM6FXFkMVEMM4JF6xXV4lDbba~cigWJZi5-aDVk,AAEA--8", + "freenet:CHK at MclS9N1182pJszp4LfmrLl--HX9vxTgbz9ZY44ju1FY,rUh2VghoLFpRl2fdv8hQB5uk6mEb3phg2IufhmknD~w,AAEA--8", + "freenet:CHK at FFIUGUHHX9otAyAWjTWDbhl7IUKLuYxVPJKUARmLhjQ,hAnfNPCnDClMjbwgUKgOSNQl8o6vO7TJ5xUpsHKWMj0,AAEA--8", + "freenet:CHK at dTqjUyWM2KY0qVcF8d6oVNqA9DfEEheg9XPTA-DlL4k,7zfbWAcvvNqwNwPyj32mraJEmJsvL6h0jPT2Ly5knO0,AAEA--8", + "freenet:CHK at VrHAQguyuR6MyJoZ7vxb-FIuxlab3T7EuBE3OoMIVkc,S2VpJiI2wybbNXGHfhOaGz8sK75EfABlLh54RS22HI8,AAEA--8", + "freenet:CHK at HKjIaWYvjDnWLWcf31qkwTU7g5I5M7XxxZED9XTpLB8,TnCRaYlmIhRdkIQEFTQFmpqmCci8igZ7QxrUVtbH~rU,AAEA--8", + "freenet:CHK at -4OVhcd0Z8fpv0a~xDFL2RSO3pcyHFp1xdDiiL-0gAk,gDfK9Rq6TVEdB0C2nOF~gI7-Ha-ihMnEytSfdc3yONQ,AAEA--8", + "freenet:CHK at MH4kDRNM91llmNWvet9rhQvTvNGyNItV0GpCLrH8nB0,Ujtgu4e3KRAtgrLTOTU8qGNvBOJQKOy8i5N835rsYdk,AAEA--8", + "freenet:CHK at aDDabThMhxD51CJfH1zVJYGBxagnfOWbazGGCo-QiLI,BBEHrcSWL3voIJ~Y7MJQ1d7AAo4F-kp0CwUWkN3vFyE,AAEA--8", + "freenet:CHK at YK48GQ4USNAn2XkICsEf2UiL7h3SA3PLbPCJeZEYdyg,34IBcb0gtftGYEx2rxMpqXE6PnMTTfZhWW9CEy3IwSU,AAEA--8", + "freenet:CHK at nvxUqTKVU30vw-J3MVGHKmuJygKH~MlCEmfA~gFzuDM,TYAhcs2zH3iz6MKFO7rEevdieAqAi3GQmz5SBKdRYls,AAEA--8", + "freenet:CHK at zFidd1PPfnInB2g6vFVXOYYLn5Z2Cb~V7eBbJDkQDc8,qa5vmLnzP~wXYHnLYVrbIqpXtM2SxJe4PyroUCFCKHo,AAEA--8", + "freenet:CHK at wXSOHVNFfTkBeunCKH8zt8iJ6Ew0AzFbjKN6YYWPOfw,~AWwaK7-Nc0qwSmu~9GNMljr6LO8ZcuhLS5lJz7bw~U,AAEA--8", + "freenet:CHK at gAS-BcHvDin-RTXP8CGIhMjl~bd3oWYsE0rXTmH6cmM,8UVfpn5nWN6knaxnbArtbBC8dZZjpJydglyu0mH2MQM,AAEA--8", + "freenet:CHK at qm6NeyMAAyrK-rjludc~PU57wf8WwccW6UxdoBjW2aw,hZuS-nu6KTZcDmVUrhRjIC-D3kIpBn5za8e08p3eBOU,AAEA--8", + "freenet:CHK at BADSo4J4DExwbFDtRqula8pg6BcBvoYO-ofG0HXxK7s,PodpsdvupZXIKBNqQvEMyR4kBENZYoX60SEOb~gwmHo,AAEA--8", + "freenet:CHK at CMhnDAP155BeHBnvcdy0e~Zw30TSA7QFF17k0BNcghQ,qRFzWscI4FyEItjLZCAR6YeOsUAxb-zwHzO~D~7A2y8,AAEA--8", + "freenet:CHK at 85rCG8gpBLyCs9rANwe~C25qE7DuHIrw6m6k0mFawxM,bJk4gnPRVbXFhWuKUFQbNBKBYhQ-fjr97quD0--1Cu0,AAEA--8", + "freenet:CHK at 0WM8xGmUt7EN9nvf70YfiuqyQNiUW205shC4qrn~Ns0,X1Ik3nQFAGgjdmDZ1nOUU1GXiegf~G3Tz87P6R1qYg0,AAEA--8", + "freenet:CHK at faUvYOLxYaALzqNWgCL2QLRhjqtTd-uv4uXH788DwMQ,qa-hBaE7KW3fpsQ5WjVYY~yXr0hawdbiVnrAbwbIkLA,AAEA--8", + "freenet:CHK at oBPbYfSrA3Rx7gHQgKwPdqdszaj4ONCTzIDBXH3svgA,88C~2Qh3KsaMKP2Mpk4-O9YMzcJzecw0q5pggfE2M08,AAEA--8", + "freenet:CHK@~Zt~6FIo-A5rzzS0tj9dzphfkvMpmd3Bk0f~kgguso8,EzIecOo7y6ylQjpB362EPthTiU2BZmrBcIsEy5B-1rU,AAEA--8", + "freenet:CHK at 5dnfR7qQRvdwy~jYSntIUYrULz2dvTIViChTa-Ga1bA,dGkeHwJwKMk~raaTPihVuXnHz6oxSdZOvlMnK35p4YI,AAEA--8", + "freenet:CHK at luPA1WEgPIsvIN~x5mQvLGz5VJSB4RxZ~9NirffJRsE,onY58d-Mutx7486NLFVsnCqkM9vi1qdUDJSBa5R8FDU,AAEA--8", + "freenet:CHK at TBe4MGTY9Lu6wTNdSPNx5OMAFbfxXfIkOg2pR-Vfe30,dJ9gGlMpv0bws7Ke1k-i2NM4b0S4fwD~ITturyNk744,AAEA--8", + "freenet:CHK at F1helg8ZSNn4CdukZbtfMVefuv52USzvF3hM8mws3Ac,EimUXQHhPkv2fQkxKMuPX9QmTmJS9nrd8ArOZjxVB5E,AAEA--8", + "freenet:CHK at LmaWgF2qdQpLsYbNGa16TWdZLexawx1b9ShmXCZIj8Y,ixYZWPQt3yyeJJRkWxVZi43y4hQ5HWvfqAEmOLkCaXQ,AAEA--8", + "freenet:CHK at bIr5JYe5r8zkN~uDKYGHevnTy9zA4xFbGnoGk-GhKRA,iEphrMMrQg6g5WErFh~6pl0eaFadjiUnuCQgz3~NmM4,AAEA--8", + "freenet:CHK at bGkt2Ts2GZvHhaJK-ZNLgREXTyYiJsXmxEp69gl-6Pw,xdJlV03sukfH-k2sJXvHJBe5OZk3kV5otziFck6taFE,AAEA--8", + "freenet:CHK at Zi6UP52jpjc8VY~GvKIGTXQ~gHtLVckbgwv2s9sOZAE,fEihjP3NhwTcI0oxvMP0ltjUiGo-ajramwZkp2sMTjQ,AAEA--8", + "freenet:CHK at aaY0424jBE--ihUHUIjnwIYcc8XsHCjYo8lZxlsYLw0,Zrbo~u7CdkQwwtuDl5WYn~RTM1x98w2MYUR45tBCe0g,AAEA--8", + "freenet:CHK at Xnhr7YNdBoULZcx5txklkgzI1zreUGInML1VyaNuVwo,tXwbaRw-GBpR~0qfKXLxVRVccZmPQhiq1iu32uIjkJU,AAEA--8", + "freenet:CHK at hIhlz3TKPePv3gWJ~rZZ6OB8vvgMVVfT6aPgSR1FnMA,4cotECTTOWwTeCzwYBykCm9LPV1c67l39YyrWe20FoA,AAEA--8", + "freenet:CHK at 3v00FlnsU~zGLwkk5h15EUjA4eDyedGQZc9SaK4b4r8,24jIhn37UrvUBimYfXoDEkaL4zIMTDQISN8TM3HJihk,AAEA--8", + "freenet:CHK at iZejNyB6rzx6pBMyEgmb~bVY-rKLFRmcqbyU5nnJsOU,4SzvJPq80vGKCxoGs~YjfufJVEWOtSnK2~6oDX1~JYc,AAEA--8", + "freenet:CHK at 722nP2beISRaezmlf77tF2lPlTDFWt~f6LhWmeV3Qhg,tCXclyWJxo1Zbk5S7KaxBMpbQO4eKB~sq4cgLXY-eT4,AAEA--8", + "freenet:CHK at 3eQXbBxgp9XMFJl6RLcrnHJVpBtA93pyYfyz0~RmNTs,JTvyP5PbXhJA99HEGE0I1pjKoGue6vqUtToNWbab~6g,AAEA--8", + "freenet:CHK at UnOcTSATPLJpMDI-GItNf~xW9AdEtnLYrV1Pv-TH0E0,IkS~sHRntHdFSNjsZCeJVnK-NonDl~MRsKUCQEOtu24,AAEA--8", + "freenet:CHK at SZ37shG9ItJvOZQUvo9j~mvxv40mtsLrMc8MdM2JdnE,52ZfbfXwiGyvcO6sY~qhPWYq882SzGuOd7OgNSt7oLo,AAEA--8", + "freenet:CHK at 4mjEB-dHqxQg893scFwrU0~HefqUVznlMwKyRpdzzQo,FrgZGdkPy8zjQvJ8Hl2nG0JilRXGAucTBVKzZargw4Y,AAEA--8", + "freenet:CHK at 2tKNQArJRTMrQsRXZiEAYcMn2Rxe22IIWE8diNnHmoM,VsJNZXGVVX-WkgljzJSo8GYWji-z-1BZfr5cV2pygE0,AAEA--8", + "freenet:CHK at is0FXAzhvLdv4g0~HLEXsJFSIp1v319hnMnxnhKxqLc,xiBGU9O-aoJaK7G-wcGxNMbT~c3f1RhczvmmZ8w0DSg,AAEA--8", + "freenet:CHK at spwqSrO76h37NRtxZWQChyQHMdxexaHfyW4Ek0armbM,9oYMnoCYI-dDW3jxM4O2QJZXgiNIlMTRecJAjyQCpoA,AAEA--8", + "freenet:CHK at Drv5UiWTFZRsMmW1XsmORmIYmFua7kQ3HC8Gpf~Z7lw,qPvQljP70NMKSoUErx-WZGFhS1-NphOMDX2PbJx-0Z4,AAEA--8", + "freenet:CHK at ny~Z9cswPh-QAyXbBD~kVePYwFsAXxXHMojtSynm-uY,u-CTGxEFSKiI0KLc2tCYqrOzKZn-mTAjUyOND6nK~1g,AAEA--8", + "freenet:CHK at JayfOnhoh7Ca7V5aEXBow8pjOtbl1Jrww-ZaQTv2OFM,fO3nsGwjG6TyhtodUcMSrFLod8QkNxonrcaE1qnDGCg,AAEA--8", + "freenet:CHK at Zd7v8UX-Epu63EajrXYq-LbnQq9hpOC5s9QTTn3SD5Y,aTa~zsekEdsQzg3hkEtqFV~7r-0bVSM-pCnKmzu8-rA,AAEA--8", + "freenet:CHK at n7sanppniixJU~Z-0dydiI~Yv7AhSUHzQma-cdiXYHQ,~g7p9ab8RoYqQQ9L-GwMx9p1q7uVMkl2T1Q7D-LND3o,AAEA--8", + "freenet:CHK at PKMXz2s-UJNNbptKG0DxEJ9gif7A8d9WbBDwakIW61w,lXGbvq4vIegspY9LNmxdUKm~WybKSZxvxr8BaH3YG08,AAEA--8", + "freenet:CHK at 0Ic8A20PWBpXguk91k9Nd~3LrgW9t7QeMli3xNXiUdI,UEUe32p7zhNzMIn4JwxAjytf-~rUKgcfnQdXREkuTY4,AAEA--8", + "freenet:CHK at JMvVsAIUMInRyBhO5Ed9dK9EwhdKazWRZHUU6ArhYmg,sssqrFIIt92q2uV1Zjvy4Z2vR0DM9q1KS7VL8JpvdSs,AAEA--8", + "freenet:CHK at IkENo0XDD-Q-hviv6sZxPKwzbqf60uumVTiZJyv78PE,3GhtiGj85scotmUI4cubABS5ej~g1crGIRF7-vgWJks,AAEA--8", + "freenet:CHK at 2QGeu-1d-PXK0PSIiv~jUY3q2DNn55yJz7tMHRFTxN0,oGQEpZHQBZrp6m77JgXhD-lMd6Bi~fDK3vdfTrUlQGY,AAEA--8", + "freenet:CHK at NbfYmO12vIzV2Ds7CPzJY7laoweeelyrdoZj2LtYCzo,eXU6jnMIz2bvRVgdlWFpiT80i04eWKTSxPJfzLAKQRY,AAEA--8", + "freenet:CHK at t7rdcOQimxvX~usT64rIoXnu4gZKZ182DHIWlRV5n3w,~ouf6zKvL9-w7o10y8ulS40vD7CXsqsyTZQpuDGCTwY,AAEA--8", + "freenet:CHK at 9SEZVTS1gJ3~H6mAtpVbe-F2RaihUgZZSMj1jNLHK5k,IZGKoASFC7aw2pUTMqzhCuFE4Pj8bOJqlG3APCXPiBo,AAEA--8", + "freenet:CHK at mqdcHwIG6FYjWgOlAkPnOn7k7wZPO0BwVVbtyyEjB74,wUp3cXP0kcwYa0jh9lzF6KYA5BWVPgCD2QO4ovetTcY,AAEA--8", + "freenet:CHK at zu9IP0PY3yWFhhtbqk5MMUzrfvis3mZ2lYEyiB9bZBc,isN286~-3GMCOT7u3ydfENHpxJwpueabYVLvhewLqnQ,AAEA--8", + "freenet:CHK at 4Pd~R2UZjVY3SA~B0FbCHPz4apKxsCAHVPuEyl5YGvM,dYefpkUbgpZg1jCXddmFvE3BVk2en17zYjF735KiGJs,AAEA--8", + "freenet:CHK at 0EkRUDOKense1U7tesZJUtmh5sn5DLx6wDXhWNdWyuk,h8o-3GaSKFjkgBVgBFRTJIQQoFYkmfXBduXASFoXWW0,AAEA--8", + "freenet:CHK at IUahAbz57yJo0qoboW6aOpRVG9ZOJOB~1UqOKc5LcT8,P9Ox2SadqD68AcmcplD4sczVZGAXlm2OmaMGw4LshD0,AAEA--8", + "freenet:CHK at ofwNaV6jyV55tzx~ITsNtZ~WrVRaFG3obDx8TYDhISQ,uODtN3okiXN~r2xo-FGw78JM8E1ZAoz9VgpLRFQrqVM,AAEA--8", + "freenet:CHK at EpE~qowzjOGj7PUbBDXiwjzoYsvwRScEGSKHcayWu-U,clthFYamf1PNrVODld~ncGsGO2INasyRPgZRnbkB~xs,AAEA--8", + "freenet:CHK at AxwocOdzkWNPlje7ZCOmgjxXVesqAY-cy5c~mmfrEcY,pCEBBdxrxVuKh3~ZfNOnwqvDcVmRH2Amg-uVK~eE13E,AAEA--8", + "freenet:CHK at cSeB79VYXKUcZqvUOrbvnal-3xQCmWzXGbfTo5vT8Y0,WCCKYWPoVL1OU2XIVwxmkX1Xl5co8XF~z9Z2CvL6Vww,AAEA--8", + "freenet:CHK at Xb5adJ2HdJ1naklGdGm7qv~kfxtdqW7PRm6Gy9LofN8,Fy6VobihpZa4OtympTDln81VdZmnzKRPjwtj9ODgXls,AAEA--8", + "freenet:CHK at 3w6hYXe9v7LtwsjDnnwpeGx~MYSPmJ6xAcUdx8EgaeI,vYPwsvgfGSYFKBobdpokN8tgGSCbhF-lzSvKZtiRqT4,AAEA--8", + "freenet:CHK at nA7Xr5OrNPg7onRMUsdB2iBeaZ3v0Bg8~F6VbqmCGvU,isZBjeqn~w2-K8ii1W2~KTO6kmfYD8vKj1n4SIbj1KM,AAEA--8", + "freenet:CHK at MGHfXlEsz22DNn4u4RV4a2MQSeMB4SwicZzeqkIt38k,6wr2mczL3iKJbirah7M1rbh~9K~kUWb7H1KaqW2rP2Q,AAEA--8", + "freenet:CHK at tjiCMAn2k1b1sh3BGrMrHaIpZGmgp5Z5B404eO8mhXY,UQ1ATP-ad4yDY~crT2CQxE9WPMtVFv~zrrGH7~8Q3JY,AAEA--8", + "freenet:CHK at o4uf-acnRkOjQzOEvn0JOWmyxIx~LjfKkoj6Sxa3xSI,xE5o9DA-VcnKXJqN-q-szVxcQ0sOiPzmBaEIK72~Ulk,AAEA--8", + "freenet:CHK at MIt51tETNvPoebvqnz9RrHxeIJvow-zpZ0gOTXEyb7M,1Hxx2xbrhrOZc5cwhvCkO6v5ze3MwwA2uUnicEGv8n4,AAEA--8", + "freenet:CHK at NDD26EHpZJoEWrUX1irVVEDDHV4RG8vWby4HRIDorEQ,EwHTK7Q8EPmrzSjvaaGQaCuGvQfsvXy7EzJzB6xYq80,AAEA--8", + "freenet:CHK at K5ZhE4VY5qIjBG9L3WciC~cFbf976rfZGxNxKBEG2mM,rly3fkg5LEby2T2albPgAVm8z8Cb2-pPJ0HdRH3YHx0,AAEA--8", + "freenet:CHK at aH73gnCP5BHrBllzjkMidAL9omoZhArbLx~E8ohfhXY,tFiT49y7VJycJggw9oITCP5LxPza~WnrmM3KY02V~3g,AAEA--8", + "freenet:CHK at EWWH3-KJevOv5bFRZunpJWZmKCY5UmtStpsRL~68U1A,opipVzjgGF4jKm~f9hTRY1fjrGhDfl2vQYs5IdabixE,AAEA--8"}; + + return strs[Math.abs(rnd.nextInt())%strs.length]; + } + +} Copied: trunk/freenet/src/freenet/snmplib (from rev 8057, trunk/freenet/src/snmplib) Deleted: trunk/freenet/src/freenet/snmplib/BERDecoder.java =================================================================== --- trunk/freenet/src/snmplib/BERDecoder.java 2006-02-17 23:08:53 UTC (rev 8057) +++ trunk/freenet/src/freenet/snmplib/BERDecoder.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,133 +0,0 @@ -package snmplib; - -import java.util.Stack; - -public class BERDecoder { - private byte[] buf; - private int ptr = 0; - private Stack seqStack; - - public BERDecoder(byte[] buf) { - this.buf = buf; - seqStack = new Stack(); - } - - public void startSequence() throws BadFormatException { - startSequence((byte)0x30); - } - - public void startSequence(byte id) throws BadFormatException { - if (buf[ptr] != id) - throw new BadFormatException("Unknown Sequence (expected: 0x" + - Integer.toHexString(id) + ", got: 0x" + - Integer.toHexString(buf[ptr]) + ")"); - ptr++; - int len = readBERInt(); - seqStack.push(new Integer(ptr + len)); - seqStack.push(new Integer(len)); - } - - public void endSequence() throws BadFormatException { - int length = ((Integer)seqStack.pop()).intValue(); - int pos = ((Integer)seqStack.pop()).intValue(); - if (pos != ptr) - throw new BadFormatException("Wrong length of field " + - length + ":" + pos + ":" + ptr); - } - - public boolean sequenceHasMore() { - //int length = ((Integer)seqStack.peek()).intValue(); - int pos = ((Integer)seqStack.get(seqStack.size()-2)).intValue(); - return (pos != ptr); - } - - public byte peekRaw() { - return buf[ptr]; - } - - public long[] fetchOID() throws BadFormatException { - startSequence((byte)0x06); - long[] ret = readOID(); - endSequence(); - return ret; - } - - private long[] readOID() throws BadFormatException { - if (buf[ptr] != 0x2b) - throw new BadFormatException("Bad start of OID"); - int inptr = ptr; - ptr++; - int length = ((Integer)seqStack.peek()).intValue(); - if (length < 2) - return new long[0]; - long ret[] = new long[length]; // it won't getlonger then this - int i; - for(i = 0; i < length ; i++) { - ret[i] = readBERInt(); - if ((ptr - inptr) >= length) - break; - } - - if (i < length) { // Bring out the scissors - long ret2[] = (long[])ret.clone(); - ret = new long[i + 1]; - for ( ; i >= 0 ; i--) - ret[i] = ret2[i]; - } - return ret; - } - - - public byte[] fetchOctetString() throws BadFormatException { - startSequence((byte)0x04); - byte[] ret = readOctetString(); - endSequence(); - return ret; - } - - private byte[] readOctetString() { - int length = ((Integer)seqStack.peek()).intValue(); - byte ret[] = new byte[length]; - for(int i = 0; i < length ; i++) { - ret[i] = buf[ptr++]; - } - return ret; - } - - - public void fetchNull() throws BadFormatException { - startSequence((byte)0x05); - endSequence(); - } - - public int fetchInt() throws BadFormatException { - startSequence((byte)0x02); - int ret = readInt(); - endSequence(); - return ret; - } - - private int readInt() { - int length = ((Integer)seqStack.peek()).intValue(); - int ret = 0; - for ( ; length > 0 ; length--) { - ret = ret * 256; - ret = ret + ((((int)buf[ptr])+256)%256); - ptr++; - } - return ret; - } - - - - private int readBERInt() { - int ret = 0; - do { - ret = ret * 128; - ret = ret + ((((int)buf[ptr])+128)%128); - ptr++; - } while (buf[ptr-1] < 0); - return ret; - } - -} Copied: trunk/freenet/src/freenet/snmplib/BERDecoder.java (from rev 8089, trunk/freenet/src/snmplib/BERDecoder.java) =================================================================== --- trunk/freenet/src/snmplib/BERDecoder.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/snmplib/BERDecoder.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,133 @@ +package freenet.snmplib; + +import java.util.Stack; + +public class BERDecoder { + private byte[] buf; + private int ptr = 0; + private Stack seqStack; + + public BERDecoder(byte[] buf) { + this.buf = buf; + seqStack = new Stack(); + } + + public void startSequence() throws BadFormatException { + startSequence((byte)0x30); + } + + public void startSequence(byte id) throws BadFormatException { + if (buf[ptr] != id) + throw new BadFormatException("Unknown Sequence (expected: 0x" + + Integer.toHexString(id) + ", got: 0x" + + Integer.toHexString(buf[ptr]) + ")"); + ptr++; + int len = readBERInt(); + seqStack.push(new Integer(ptr + len)); + seqStack.push(new Integer(len)); + } + + public void endSequence() throws BadFormatException { + int length = ((Integer)seqStack.pop()).intValue(); + int pos = ((Integer)seqStack.pop()).intValue(); + if (pos != ptr) + throw new BadFormatException("Wrong length of field " + + length + ":" + pos + ":" + ptr); + } + + public boolean sequenceHasMore() { + //int length = ((Integer)seqStack.peek()).intValue(); + int pos = ((Integer)seqStack.get(seqStack.size()-2)).intValue(); + return (pos != ptr); + } + + public byte peekRaw() { + return buf[ptr]; + } + + public long[] fetchOID() throws BadFormatException { + startSequence((byte)0x06); + long[] ret = readOID(); + endSequence(); + return ret; + } + + private long[] readOID() throws BadFormatException { + if (buf[ptr] != 0x2b) + throw new BadFormatException("Bad start of OID"); + int inptr = ptr; + ptr++; + int length = ((Integer)seqStack.peek()).intValue(); + if (length < 2) + return new long[0]; + long ret[] = new long[length]; // it won't getlonger then this + int i; + for(i = 0; i < length ; i++) { + ret[i] = readBERInt(); + if ((ptr - inptr) >= length) + break; + } + + if (i < length) { // Bring out the scissors + long ret2[] = (long[])ret.clone(); + ret = new long[i + 1]; + for ( ; i >= 0 ; i--) + ret[i] = ret2[i]; + } + return ret; + } + + + public byte[] fetchOctetString() throws BadFormatException { + startSequence((byte)0x04); + byte[] ret = readOctetString(); + endSequence(); + return ret; + } + + private byte[] readOctetString() { + int length = ((Integer)seqStack.peek()).intValue(); + byte ret[] = new byte[length]; + for(int i = 0; i < length ; i++) { + ret[i] = buf[ptr++]; + } + return ret; + } + + + public void fetchNull() throws BadFormatException { + startSequence((byte)0x05); + endSequence(); + } + + public int fetchInt() throws BadFormatException { + startSequence((byte)0x02); + int ret = readInt(); + endSequence(); + return ret; + } + + private int readInt() { + int length = ((Integer)seqStack.peek()).intValue(); + int ret = 0; + for ( ; length > 0 ; length--) { + ret = ret * 256; + ret = ret + ((((int)buf[ptr])+256)%256); + ptr++; + } + return ret; + } + + + + private int readBERInt() { + int ret = 0; + do { + ret = ret * 128; + ret = ret + ((((int)buf[ptr])+128)%128); + ptr++; + } while (buf[ptr-1] < 0); + return ret; + } + +} Deleted: trunk/freenet/src/freenet/snmplib/BEREncoder.java =================================================================== --- trunk/freenet/src/snmplib/BEREncoder.java 2006-02-17 23:08:53 UTC (rev 8057) +++ trunk/freenet/src/freenet/snmplib/BEREncoder.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,229 +0,0 @@ -package snmplib; - -import java.lang.reflect.InvocationTargetException; -import java.util.Stack; -import java.util.Vector; - -public class BEREncoder { - private IDVector fields; - private Stack fstack; - - public BEREncoder() { - this((byte)0x30); - } - - public BEREncoder(byte id) { - fields = new IDVector(id); - fstack = new Stack(); - fstack.add(fields); - } - - - public int toBytes(byte[] buf) { - while (fields.size() > 1) - endSequence(); - - int len = vecToBytes(fields, buf, 0); - byte tmpbt; - // Remember.. this function writes backwards first! - for (int i = 0 ; i < len/2 ; i++) { - tmpbt = buf[i]; - buf[i] = buf[len - 1 - i]; - buf[len - 1 - i] = tmpbt; - } - - return len; - } - - private int vecToBytes(IDVector v, byte[] buf, int offset) { - int inoffset = offset; - for (int i = v.size() - 1 ; i >= 0 ; i--) { - Object o = v.get(i); -// if (o instanceof Integer) { -// int dlen = intToBytes(((Integer)o).intValue(), buf, offset); - if (o == null) { - buf[offset++] = 0x00; - buf[offset++] = 0x05; - } else if (o instanceof Long) { - int dlen = intToBytes(((Long)o).longValue(), buf, offset); - offset += dlen; - offset += intToBERBytes(dlen, buf, offset); - buf[offset++] = 0x02; - } else if (o instanceof SNMPTypeWrapperNum) { - int dlen = intToBytes(((SNMPTypeWrapperNum)o).getValue(), buf, offset); - offset += dlen; - offset += intToBERBytes(dlen, buf, offset); - buf[offset++] = ((SNMPTypeWrapperNum)o).getTypeID(); - } else if (o instanceof IDVector) { - int dlen = vecToBytes((IDVector)o, buf, offset); - offset += dlen; - offset += intToBERBytes(dlen, buf, offset); - buf[offset++] = ((IDVector)o).getVid(); - } else if (o instanceof ByteArrWrapper) { - byte[] barr = ((ByteArrWrapper)o).arr; - for (int j = 0 ; j < barr.length ; j++) - buf[offset + j] = barr[barr.length - 1 - j]; - offset += barr.length; - offset += intToBERBytes(barr.length, buf, offset); - buf[offset++] = ((ByteArrWrapper)o).id; - } -// myoffset += intToBytes(v.get(i), buf, myoffset); - - } - - return (offset - inoffset); - } - - - private int intToBytes(long i, byte[] buf, int offset) { - // TODO: handle negative numbers also!!!! - int inoffset = offset; - if (i == 0) { - buf[offset++] = 0; - } else { - for (; i > 0 ; i = i / 256) { - buf[offset] = (byte)(i % 256); - offset++; - } - } - // make the number unsigned - if (buf[offset-1]<0) - buf[offset++] = 0; - return (offset - inoffset); - } - - private int intToBERBytes(long i, byte[] buf, int offset) { - //String bs = Long.toBinaryString(i); - //int len = (bs.length()%7); - //bs = ("0000000" + bs).substring(len); - //char bits[] = bs.toCharArray(); - //int eatenbits = 0; - buf[offset] = 0; - int inoffset = offset; - //for (int j = bits.length - 1 ; j >= 0 ; j--) { - long j = i; - //System.out.print("intToBERBytes: " + i + ": "); - if (i == 0) { - offset++; - } else { - for ( ; j > 0 ; j = j/128) { - buf[offset++] += (byte)(j%128); - buf[offset] = (byte)((j > 127)?128:0); - //System.out.print("[" + (j%128) + " + " + ((j > 127)?128:0) + " = " + ((j%128) + ((j > 127)?128:0) ) + "] "); - } - - // now; turn it around! - if ((offset - inoffset) > 1) { - // System.err.println("Started at: " + inoffset + ", ended at: " + offset); - for (int p = 0 ; p < (offset - inoffset)/2 ;p++) { - // System.err.println("stap: " + (offset-p-1) + " <-> " + (inoffset+p)); - byte tmp = buf[offset-p-1]; - buf[offset-p-1] = buf[inoffset+p]; - buf[inoffset+p] = tmp; - } - } - //System.err.println(); - /* - for (int j = 0 ; j < bits.length ; j++) { - if (eatenbits == 7) { - buf[offset] += 128; - offset++; - eatenbits = 0; - buf[offset] = 0; - } - - buf[offset] |= (bits[j]=='1'?1:0) << (6 - eatenbits); - eatenbits++; - } - offset++; - */ - } - return (offset - inoffset); - } - - - public void putSNMPTypeWrapperNum(SNMPTypeWrapperNum o) { - addToTop(o.clone()); - } - - /*public void putInteger(int i) { - addToTop(new Integer(i)); - }*/ - public void putTimeticks(long i) { - addToTop(new SNMPTimeTicks(i)); - } - - public void putInteger(long i) { - addToTop(new Long(i)); - } - - public void putCounter32(long i) { - addToTop(new SNMPCounter32(i)); - } - - public void putNull() { - addToTop(null); - } - - public void putOctetString(byte buf[]) { - addToTop(new ByteArrWrapper((byte[])buf.clone(), (byte)0x04)); - } - - public void putOID(long buf[]) { - byte bufa[] = new byte[10*buf.length]; - int offset = 1; - bufa[0] = 0x2b; - for (int i = 2 ; i < buf.length ; i++) { - offset += intToBERBytes(buf[i], bufa, offset); - } - byte bufb[] = new byte[offset]; - for (int i = 0 ; i < bufb.length ; i++) - bufb[i] = bufa[i]; - - addToTop(new ByteArrWrapper(bufb, (byte)0x06)); - } - - public void startSequence() { - startSequence((byte)0x30); - } - - public void startSequence(byte id) { - IDVector v = new IDVector(id); - addToTop(v); - fstack.add(v); - } - - public void endSequence() { - fstack.pop(); - } - - private void addToTop(Object o) { - ((IDVector)fstack.peek()).addElement(o); - } - - private class ByteArrWrapper { - public byte arr[]; - public byte id; - - public ByteArrWrapper(byte arr[], byte id) { - this.arr = arr; - this.id = id; - } - } - - // unpublic - private class IDVector extends Vector { - private static final long serialVersionUID = 2689317091785298027L; - byte vid = (byte)0x30; - - public IDVector(byte id) { - super(); - vid = id; - } - - public byte getVid() { - return vid; - } - - } -} Copied: trunk/freenet/src/freenet/snmplib/BEREncoder.java (from rev 8089, trunk/freenet/src/snmplib/BEREncoder.java) =================================================================== --- trunk/freenet/src/snmplib/BEREncoder.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/snmplib/BEREncoder.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,232 @@ +package freenet.snmplib; + +import java.lang.reflect.InvocationTargetException; +import java.util.Stack; +import java.util.Vector; + +public class BEREncoder { + private IDVector fields; + private Stack fstack; + + public BEREncoder() { + this((byte)0x30); + } + + public BEREncoder(byte id) { + fields = new IDVector(id); + fstack = new Stack(); + fstack.add(fields); + } + + + public int toBytes(byte[] buf) { + while (fields.size() > 1) + endSequence(); + + int len = vecToBytes(fields, buf, 0); + byte tmpbt; + // Remember.. this function writes backwards first! + for (int i = 0 ; i < len/2 ; i++) { + tmpbt = buf[i]; + buf[i] = buf[len - 1 - i]; + buf[len - 1 - i] = tmpbt; + } + + return len; + } + + private int vecToBytes(IDVector v, byte[] buf, int offset) { + int inoffset = offset; + for (int i = v.size() - 1 ; i >= 0 ; i--) { + Object o = v.get(i); +// if (o instanceof Integer) { +// int dlen = intToBytes(((Integer)o).intValue(), buf, offset); + if (o == null) { + buf[offset++] = 0x00; + buf[offset++] = 0x05; + } else if (o instanceof Long) { + int dlen = intToBytes(((Long)o).longValue(), buf, offset); + offset += dlen; + offset += intToBERBytes(dlen, buf, offset); + buf[offset++] = 0x02; + } else if (o instanceof SNMPTypeWrapperNum) { + int dlen = intToBytes(((SNMPTypeWrapperNum)o).getValue(), buf, offset); + offset += dlen; + offset += intToBERBytes(dlen, buf, offset); + buf[offset++] = ((SNMPTypeWrapperNum)o).getTypeID(); + } else if (o instanceof IDVector) { + int dlen = vecToBytes((IDVector)o, buf, offset); + offset += dlen; + offset += intToBERBytes(dlen, buf, offset); + buf[offset++] = ((IDVector)o).getVid(); + } else if (o instanceof ByteArrWrapper) { + byte[] barr = ((ByteArrWrapper)o).arr; + for (int j = 0 ; j < barr.length ; j++) + buf[offset + j] = barr[barr.length - 1 - j]; + offset += barr.length; + offset += intToBERBytes(barr.length, buf, offset); + buf[offset++] = ((ByteArrWrapper)o).id; + } +// myoffset += intToBytes(v.get(i), buf, myoffset); + + } + + return (offset - inoffset); + } + + + private int intToBytes(long i, byte[] buf, int offset) { + // TODO: handle negative numbers also!!!! + int inoffset = offset; + if (i == 0) { + buf[offset++] = 0; + } else { + for (; i > 0 ; i = i / 256) { + buf[offset] = (byte)(i % 256); + offset++; + } + } + // make the number unsigned + /* + * No, we should allow signed numbers + * if (buf[offset-1]<0) + buf[offset++] = 0; + */ + return (offset - inoffset); + } + + private int intToBERBytes(long i, byte[] buf, int offset) { + //String bs = Long.toBinaryString(i); + //int len = (bs.length()%7); + //bs = ("0000000" + bs).substring(len); + //char bits[] = bs.toCharArray(); + //int eatenbits = 0; + buf[offset] = 0; + int inoffset = offset; + //for (int j = bits.length - 1 ; j >= 0 ; j--) { + long j = i; + //System.out.print("intToBERBytes: " + i + ": "); + if (i == 0) { + offset++; + } else { + for ( ; j > 0 ; j = j/128) { + buf[offset++] += (byte)(j%128); + buf[offset] = (byte)((j > 127)?128:0); + //System.out.print("[" + (j%128) + " + " + ((j > 127)?128:0) + " = " + ((j%128) + ((j > 127)?128:0) ) + "] "); + } + + // now; turn it around! + if ((offset - inoffset) > 1) { + // System.err.println("Started at: " + inoffset + ", ended at: " + offset); + for (int p = 0 ; p < (offset - inoffset)/2 ;p++) { + // System.err.println("stap: " + (offset-p-1) + " <-> " + (inoffset+p)); + byte tmp = buf[offset-p-1]; + buf[offset-p-1] = buf[inoffset+p]; + buf[inoffset+p] = tmp; + } + } + //System.err.println(); + /* + for (int j = 0 ; j < bits.length ; j++) { + if (eatenbits == 7) { + buf[offset] += 128; + offset++; + eatenbits = 0; + buf[offset] = 0; + } + + buf[offset] |= (bits[j]=='1'?1:0) << (6 - eatenbits); + eatenbits++; + } + offset++; + */ + } + return (offset - inoffset); + } + + + public void putSNMPTypeWrapperNum(SNMPTypeWrapperNum o) { + addToTop(o.clone()); + } + + /*public void putInteger(int i) { + addToTop(new Integer(i)); + }*/ + public void putTimeticks(long i) { + addToTop(new SNMPTimeTicks(i)); + } + + public void putInteger(long i) { + addToTop(new Long(i)); + } + + public void putCounter32(long i) { + addToTop(new SNMPCounter32(i)); + } + + public void putNull() { + addToTop(null); + } + + public void putOctetString(byte buf[]) { + addToTop(new ByteArrWrapper((byte[])buf.clone(), (byte)0x04)); + } + + public void putOID(long buf[]) { + byte bufa[] = new byte[10*buf.length]; + int offset = 1; + bufa[0] = 0x2b; + for (int i = 2 ; i < buf.length ; i++) { + offset += intToBERBytes(buf[i], bufa, offset); + } + byte bufb[] = new byte[offset]; + for (int i = 0 ; i < bufb.length ; i++) + bufb[i] = bufa[i]; + + addToTop(new ByteArrWrapper(bufb, (byte)0x06)); + } + + public void startSequence() { + startSequence((byte)0x30); + } + + public void startSequence(byte id) { + IDVector v = new IDVector(id); + addToTop(v); + fstack.add(v); + } + + public void endSequence() { + fstack.pop(); + } + + private void addToTop(Object o) { + ((IDVector)fstack.peek()).addElement(o); + } + + private class ByteArrWrapper { + public byte arr[]; + public byte id; + + public ByteArrWrapper(byte arr[], byte id) { + this.arr = arr; + this.id = id; + } + } + + // unpublic + private class IDVector extends Vector { + private static final long serialVersionUID = 2689317091785298027L; + byte vid = (byte)0x30; + + public IDVector(byte id) { + super(); + vid = id; + } + + public byte getVid() { + return vid; + } + + } +} Deleted: trunk/freenet/src/freenet/snmplib/BadFormatException.java =================================================================== --- trunk/freenet/src/snmplib/BadFormatException.java 2006-02-17 23:08:53 UTC (rev 8057) +++ trunk/freenet/src/freenet/snmplib/BadFormatException.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,7 +0,0 @@ -package snmplib; - -public class BadFormatException extends Exception { - public BadFormatException(String s) { - super(s); - } -} Copied: trunk/freenet/src/freenet/snmplib/BadFormatException.java (from rev 8089, trunk/freenet/src/snmplib/BadFormatException.java) =================================================================== --- trunk/freenet/src/snmplib/BadFormatException.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/snmplib/BadFormatException.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,7 @@ +package freenet.snmplib; + +public class BadFormatException extends Exception { + public BadFormatException(String s) { + super(s); + } +} Deleted: trunk/freenet/src/freenet/snmplib/DataConstantInt.java =================================================================== --- trunk/freenet/src/snmplib/DataConstantInt.java 2006-02-17 23:08:53 UTC (rev 8057) +++ trunk/freenet/src/freenet/snmplib/DataConstantInt.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,20 +0,0 @@ -package snmplib; - - -public class DataConstantInt implements DataFetcher { - private String OID; - private int value; - - public DataConstantInt(String oID, int value) { - this.OID = oID; - this.value = value; - } - - public String getSNMPOID() { - return OID; - } - - public Object getSNMPData() { - return new Integer(value); - } -} Copied: trunk/freenet/src/freenet/snmplib/DataConstantInt.java (from rev 8089, trunk/freenet/src/snmplib/DataConstantInt.java) =================================================================== --- trunk/freenet/src/snmplib/DataConstantInt.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/snmplib/DataConstantInt.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,20 @@ +package freenet.snmplib; + + +public class DataConstantInt implements DataFetcher { + private String OID; + private int value; + + public DataConstantInt(String oID, int value) { + this.OID = oID; + this.value = value; + } + + public String getSNMPOID() { + return OID; + } + + public Object getSNMPData() { + return new Integer(value); + } +} Deleted: trunk/freenet/src/freenet/snmplib/DataConstantString.java =================================================================== --- trunk/freenet/src/snmplib/DataConstantString.java 2006-02-17 23:08:53 UTC (rev 8057) +++ trunk/freenet/src/freenet/snmplib/DataConstantString.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,19 +0,0 @@ -package snmplib; - -public class DataConstantString implements DataFetcher { - private String OID; - private String value; - - public DataConstantString(String oID, String value) { - this.OID = oID; - this.value = value; - } - - public String getSNMPOID() { - return OID; - } - - public Object getSNMPData() { - return value; - } -} Copied: trunk/freenet/src/freenet/snmplib/DataConstantString.java (from rev 8089, trunk/freenet/src/snmplib/DataConstantString.java) =================================================================== --- trunk/freenet/src/snmplib/DataConstantString.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/snmplib/DataConstantString.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,19 @@ +package freenet.snmplib; + +public class DataConstantString implements DataFetcher { + private String OID; + private String value; + + public DataConstantString(String oID, String value) { + this.OID = oID; + this.value = value; + } + + public String getSNMPOID() { + return OID; + } + + public Object getSNMPData() { + return value; + } +} Deleted: trunk/freenet/src/freenet/snmplib/DataFetcher.java =================================================================== --- trunk/freenet/src/snmplib/DataFetcher.java 2006-02-17 23:08:53 UTC (rev 8057) +++ trunk/freenet/src/freenet/snmplib/DataFetcher.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,10 +0,0 @@ -package snmplib; - -public interface DataFetcher { - - public String getSNMPOID(); - - /* Must return an Integer or a String */ - public Object getSNMPData(); - -} Copied: trunk/freenet/src/freenet/snmplib/DataFetcher.java (from rev 8089, trunk/freenet/src/snmplib/DataFetcher.java) =================================================================== --- trunk/freenet/src/snmplib/DataFetcher.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/snmplib/DataFetcher.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,10 @@ +package freenet.snmplib; + +public interface DataFetcher { + + public String getSNMPOID(); + + /* Must return an Integer or a String */ + public Object getSNMPData(); + +} Deleted: trunk/freenet/src/freenet/snmplib/DataStatisticsInfo.java =================================================================== --- trunk/freenet/src/snmplib/DataStatisticsInfo.java 2006-02-17 23:08:53 UTC (rev 8057) +++ trunk/freenet/src/freenet/snmplib/DataStatisticsInfo.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,35 +0,0 @@ -package snmplib; - -import freenet.io.comm.IOStatisticCollector; - -public class DataStatisticsInfo implements DataFetcher { - private String OID; - int blocks; - boolean in; - - public DataStatisticsInfo(int blocks, boolean in) { - this.OID = "1.1." + blocks + "." + (in?"1":"0"); - //System.err.println("adding: " + this.OID); - this.in = in; - this.blocks = blocks; - } - - public String getSNMPOID() { - //System.err.println(" " + this.OID); - return OID; - } - - public Object getSNMPData() { - if (blocks == 0) { - long io[] = IOStatisticCollector.getTotalIO(); - return new SNMPCounter32(io[in?1:0]); - } - // else sum all fields up to <blocks> - int res = 0; - int stats[][] = IOStatisticCollector.getTotalStatistics(); - for (int i = 0 ; i < blocks ; i++) - res += stats[i][in?1:0]; - - return new Long(res); - } -} Copied: trunk/freenet/src/freenet/snmplib/DataStatisticsInfo.java (from rev 8089, trunk/freenet/src/snmplib/DataStatisticsInfo.java) =================================================================== --- trunk/freenet/src/snmplib/DataStatisticsInfo.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/snmplib/DataStatisticsInfo.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,35 @@ +package freenet.snmplib; + +import freenet.io.comm.IOStatisticCollector; + +public class DataStatisticsInfo implements DataFetcher { + private String OID; + int blocks; + boolean in; + + public DataStatisticsInfo(int blocks, boolean in) { + this.OID = "1.1." + blocks + "." + (in?"1":"0"); + //System.err.println("adding: " + this.OID); + this.in = in; + this.blocks = blocks; + } + + public String getSNMPOID() { + //System.err.println(" " + this.OID); + return OID; + } + + public Object getSNMPData() { + if (blocks == 0) { + long io[] = IOStatisticCollector.getTotalIO(); + return new SNMPCounter32(io[in?1:0]); + } + // else sum all fields up to <blocks> + int res = 0; + int stats[][] = IOStatisticCollector.getTotalStatistics(); + for (int i = 0 ; i < blocks ; i++) + res += stats[i][in?1:0]; + + return new Long(res); + } +} Deleted: trunk/freenet/src/freenet/snmplib/InfoSystem.java =================================================================== --- trunk/freenet/src/snmplib/InfoSystem.java 2006-02-17 23:08:53 UTC (rev 8057) +++ trunk/freenet/src/freenet/snmplib/InfoSystem.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,59 +0,0 @@ -package snmplib; - -import freenet.node.Version; - -public class InfoSystem implements MultiplexedDataFetcher { - long created; - - public InfoSystem() { - created = System.currentTimeMillis()/10; - } - - public String getSNMPOID(int index) { - switch (index) { - - case 0: //UCD-SNMP-MIB::memTotalReal.0 - return ".1.3.6.1.4.1.2021.4.5.0"; - case 1: //UCD-SNMP-MIB::memAvailReal.0 - return ".1.3.6.1.4.1.2021.4.6.0"; - case 2: //SNMPv2-MIB::sysName.0 - return ".1.3.6.1.2.1.1.5.0"; - case 3: //SNMPv2-MIB::sysUpTime.0 - return ".1.3.6.1.2.1.1.3.0"; - - case 4: //UCD-SNMP-MIB::memTotalReal.0 - return ".1.3.6.1.4.1.2021.4.5"; - case 5: //UCD-SNMP-MIB::memAvailReal.0 - return ".1.3.6.1.4.1.2021.4.6"; - - - } - // default - return null; - } - - public Object getSNMPData(String oid) { - Runtime r = Runtime.getRuntime(); - //System.err.println("requesting: " + oid); - if (oid.equals(".1.3.6.1.2.1.1.3.0")) //SNMPv2-MIB::sysUpTime.0 - return new SNMPTimeTicks(System.currentTimeMillis()/10 - created); - if (oid.equals(".1.3.6.1.4.1.2021.4.5.0")) //UCD-SNMP-MIB::memTotalReal.0 - return new SNMPInteger32(r.totalMemory()); - if (oid.equals(".1.3.6.1.4.1.2021.4.6.0")) //UCD-SNMP-MIB::memAvailReal.0 - return new SNMPInteger32(r.freeMemory()); - - - if (oid.equals(".1.3.6.1.2.1.1.5.0")) //SNMPv2-MIB::sysName.0 - return (Version.nodeName + " " + Version.nodeVersion + " (" + Version.buildNumber() + ")"); - - - if (oid.equals(".1.3.6.1.4.1.2021.4.5")) //UCD-SNMP-MIB::memTotalReal.0 - return new SNMPInteger32(r.totalMemory()); - if (oid.equals(".1.3.6.1.4.1.2021.4.6")) //UCD-SNMP-MIB::memAvailReal.0 - return new SNMPInteger32(r.freeMemory()); - - return null; - } - - -} Copied: trunk/freenet/src/freenet/snmplib/InfoSystem.java (from rev 8089, trunk/freenet/src/snmplib/InfoSystem.java) =================================================================== --- trunk/freenet/src/snmplib/InfoSystem.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/snmplib/InfoSystem.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,59 @@ +package freenet.snmplib; + +import freenet.node.Version; + +public class InfoSystem implements MultiplexedDataFetcher { + long created; + + public InfoSystem() { + created = System.currentTimeMillis()/10; + } + + public String getSNMPOID(int index) { + switch (index) { + + case 0: //UCD-SNMP-MIB::memTotalReal.0 + return ".1.3.6.1.4.1.2021.4.5.0"; + case 1: //UCD-SNMP-MIB::memAvailReal.0 + return ".1.3.6.1.4.1.2021.4.6.0"; + case 2: //SNMPv2-MIB::sysName.0 + return ".1.3.6.1.2.1.1.5.0"; + case 3: //SNMPv2-MIB::sysUpTime.0 + return ".1.3.6.1.2.1.1.3.0"; + + case 4: //UCD-SNMP-MIB::memTotalReal.0 + return ".1.3.6.1.4.1.2021.4.5"; + case 5: //UCD-SNMP-MIB::memAvailReal.0 + return ".1.3.6.1.4.1.2021.4.6"; + + + } + // default + return null; + } + + public Object getSNMPData(String oid) { + Runtime r = Runtime.getRuntime(); + //System.err.println("requesting: " + oid); + if (oid.equals(".1.3.6.1.2.1.1.3.0")) //SNMPv2-MIB::sysUpTime.0 + return new SNMPTimeTicks(System.currentTimeMillis()/10 - created); + if (oid.equals(".1.3.6.1.4.1.2021.4.5.0")) //UCD-SNMP-MIB::memTotalReal.0 + return new SNMPInteger32(r.totalMemory()); + if (oid.equals(".1.3.6.1.4.1.2021.4.6.0")) //UCD-SNMP-MIB::memAvailReal.0 + return new SNMPInteger32(r.freeMemory()); + + + if (oid.equals(".1.3.6.1.2.1.1.5.0")) //SNMPv2-MIB::sysName.0 + return (Version.nodeName + " " + Version.nodeVersion + " (" + Version.buildNumber() + ")"); + + + if (oid.equals(".1.3.6.1.4.1.2021.4.5")) //UCD-SNMP-MIB::memTotalReal.0 + return new SNMPInteger32(r.totalMemory()); + if (oid.equals(".1.3.6.1.4.1.2021.4.6")) //UCD-SNMP-MIB::memAvailReal.0 + return new SNMPInteger32(r.freeMemory()); + + return null; + } + + +} Deleted: trunk/freenet/src/freenet/snmplib/MultiplexedDataFetcher.java =================================================================== --- trunk/freenet/src/snmplib/MultiplexedDataFetcher.java 2006-02-17 23:08:53 UTC (rev 8057) +++ trunk/freenet/src/freenet/snmplib/MultiplexedDataFetcher.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,11 +0,0 @@ -package snmplib; - -public interface MultiplexedDataFetcher { - - /* Return null when the last OID is reached */ - public String getSNMPOID(int index); - - /* Must return an Integer or a String */ - public Object getSNMPData(String oid); - -} Copied: trunk/freenet/src/freenet/snmplib/MultiplexedDataFetcher.java (from rev 8089, trunk/freenet/src/snmplib/MultiplexedDataFetcher.java) =================================================================== --- trunk/freenet/src/snmplib/MultiplexedDataFetcher.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/snmplib/MultiplexedDataFetcher.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,11 @@ +package freenet.snmplib; + +public interface MultiplexedDataFetcher { + + /* Return null when the last OID is reached */ + public String getSNMPOID(int index); + + /* Must return an Integer or a String */ + public Object getSNMPData(String oid); + +} Deleted: trunk/freenet/src/freenet/snmplib/SNMPAgent.java =================================================================== --- trunk/freenet/src/snmplib/SNMPAgent.java 2006-02-17 23:08:53 UTC (rev 8057) +++ trunk/freenet/src/freenet/snmplib/SNMPAgent.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,433 +0,0 @@ -package snmplib; - -import java.io.BufferedReader; -import java.io.IOException; -import java.net.DatagramPacket; -import java.net.DatagramSocket; -import java.net.InetAddress; -import java.util.Date; -import java.util.Iterator; -import java.util.TreeMap; - -public class SNMPAgent implements Runnable { - private int port = 4445; - - /** - * @param args - */ - public static void main(String[] args) throws IOException { - SNMPAgent.getSNMPAgent().addFetcher(new DataConstantInt("1.1.1", 10)); - SNMPAgent.getSNMPAgent().addFetcher(new DataConstantInt("1.1.2", 20)); - SNMPAgent.getSNMPAgent().addFetcher(new DataConstantInt("1.1.3", 30)); - SNMPAgent.getSNMPAgent().addFetcher(new DataConstantInt("1.1.4", 40)); - SNMPAgent.getSNMPAgent().addFetcher(new DataConstantInt("1.1.5", 50)); - SNMPAgent.getSNMPAgent().addFetcher(new DataConstantString("1.1.0", "Step by 10")); - SNMPAgent.getSNMPAgent().addFetcher(new DataConstantString("1.2", "Nothing here")); - } - - protected DatagramSocket socket = null; - protected BufferedReader in = null; - protected boolean moreQuotes = true; - private TreeMap alldata; - private static SNMPAgent _SNMPAgent = null; - - public static void setSNMPPort(int port) { - ensureCreated(); - _SNMPAgent.port = port; - restartSNMPAgent(); - } - - public static void restartSNMPAgent() { - ensureCreated(); - _SNMPAgent.stopRunning(); - new Thread(_SNMPAgent, "SNMP-Agent").start(); - } - - public static SNMPAgent getSNMPAgent() { - ensureCreated(); - return _SNMPAgent; - } - - private static void ensureCreated() { - if (_SNMPAgent == null) - _SNMPAgent = new SNMPAgent(); - } - - private SNMPAgent() { - alldata = new TreeMap(); - //alldata.put("99.99", null); - } - - public void addFetcher(DataFetcher df) { - //DataHandler dh = new DataHandler(df); - //alldata.put(dh.getStringOID(), dh); - alldata.put(df.getSNMPOID().replaceAll("^\\.1\\.3\\.",""), df); - //System.err.println("sAdded: " + df.getSNMPOID() + "as" + df.getSNMPOID().replaceAll("^\\.1\\.3\\.","")); - } - - public void addFetcher(MultiplexedDataFetcher df) { - String oid; - for (int i = 0 ; (oid = df.getSNMPOID(i)) != null ; i++) { - alldata.put(oid.replaceAll("^\\.1\\.3\\.",""), df); - // System.err.println("mAdded: " + oid + " as: " + oid.replaceAll("^\\.1\\.3\\.","")); - } - } - - public void removeFetcher(String OID) { - alldata.remove(((OID.startsWith("\\."))?"":".") + OID); - } - - public void stopRunning() { - try { - socket.close(); - } catch (Throwable e) { - // prpbably since not running... - } - } - - public void run() { - try { - socket = new DatagramSocket(port, InetAddress.getByName("localhost")); - } catch (IOException e) { - e.printStackTrace(); - return ; - } - // make smaller.... 0484 enough? - - while (socket.isBound()) { - byte[] buf = new byte[65536]; - DatagramPacket packet = new DatagramPacket(buf, buf.length); - - try { - socket.receive(packet); - - RequestContainer rc = new RequestContainer(); - int replylength = 0; - //DataHandler dh = null; - - //if (rc != null) - // throw new BadFormatException("asdfa"); - - BERDecoder question = parseRequestStart(buf, rc); - - - BEREncoder reply = replyStart(rc); - - int errIndex = 0; - int errStatus = 0; - - try { - while (question.sequenceHasMore()) { - errIndex++; - question.startSequence(); - rc.lOID = question.fetchOID(); - rc.OID = (rc.lOID.length == 0)?"":""; - for (int i = 0; i < rc.lOID.length ; i++) - rc.OID += (i==0?"":".") + rc.lOID[i]; - //System.err.println("Doing: " + rc.OID); - question.fetchNull(); - question.endSequence(); - replyAddOID(reply, rc); - } - } catch (NoSuchFieldException e) { - errStatus = 0x02; // NO SUCH NAME - } - - if (errStatus != 0) { - // Need to restart the question - question = parseRequestStart(buf, rc); - - // TODO! This does not follow the standard, but works with SNMPWALK - // Or does it? ;o) - reply = replyStart(rc, errStatus, errIndex); - while (question.sequenceHasMore()) { - question.startSequence(); - - - reply.startSequence(); // value - reply.putOID(question.fetchOID()); // oid - reply.putNull(); - reply.endSequence(); - - question.fetchNull(); - question.endSequence(); - } - } - - replylength = replyEnd(reply, buf); - //rc.pdutype == RequestContainer.PDU_GET_NEXT - - // send the response to the client at "address" and "port" - InetAddress address = packet.getAddress(); - int port = packet.getPort(); - packet = new DatagramPacket(buf, replylength, address, port); - socket.send(packet); - - } catch (IOException e) { - e.printStackTrace(); - break; - } catch (BadFormatException e) { - System.err.println("Datapacket length: " + packet.getLength()); - for (int i = 0 ; i < packet.getLength() ; i++) { - String num = "000" + Integer.toHexString(buf[i]); - num = num.substring(num.length()-2); - System.err.print("0x" + num + " "); - if ((i+1)%8 == 0) - System.err.print(" "); - if ((i+1)%16 == 0) - System.err.println(); - } - System.err.println(); - e.printStackTrace(); - //System.err.println(e.toString()); - } catch (ArrayIndexOutOfBoundsException e) { - e.printStackTrace(); - // not much to do.. ignore the request and it'll time out - } - } - socket.close(); - } - - private String getAccualOID(String oid, boolean thisval) throws NoSuchFieldException { - boolean keyfound = false; - Iterator it = alldata.keySet().iterator(); - String key = ""; - while (it.hasNext() && !keyfound) { - key = (String)it.next(); - if (key.startsWith(oid)) - keyfound = true; - } - - - if (it.hasNext() && !thisval) { - key = key.equals(oid)?(String)it.next():key; - } else if (!keyfound ) { - throw new NoSuchFieldException("OID not found"); - } - - return key; - } - - private Object getResultFromOID(String oid, boolean thisval) { - /*boolean keyfound = false; - Iterator it = alldata.keySet().iterator(); - String key = ""; - while (it.hasNext() && !keyfound) { - key = (String)it.next(); - if (key.startsWith(oid)) - keyfound = true; - } - */ - // keyfound /\ ( (equal -> hasnext) V (rc.pdutype == rc.PDU_GET_THIS)) - //System.err.println("("+keyfound+" && (!"+key.equals(rc.OID)+" || "+it.hasNext()+"))"); - /*if (keyfound && ( - (!key.equals(rc.OID) || it.hasNext())) || - (rc.pdutype == RequestContainer.PDU_GET_THIS) ) { - */ - Object data = null; - /*if (keyfound && ( - (!key.equals(oid) || it.hasNext())) ) { - if (it.hasNext() && !thisval) - key = key.equals(oid)?(String)it.next():key; - */ - Object df = alldata.get(oid); - - if (df instanceof DataFetcher) { - data = ((DataFetcher)df).getSNMPData(); - } else if (df instanceof MultiplexedDataFetcher) { - data = ((MultiplexedDataFetcher)df).getSNMPData(oid); - if (data == null) - if (!oid.startsWith(".1.3.")) - data = ((MultiplexedDataFetcher)df).getSNMPData(".1.3."+oid); - else - data = ((MultiplexedDataFetcher)df).getSNMPData(oid.substring(5)); - - } else - data = null; //new Integer(0); - - //rc.lOID = splitToLong(key); - //replylength = makeIntReply(buf, rc, data); - //} else { - /* - if (rc.lOID.length > 0) - rc.lOID[0] = 100; - else { - rc.lOID = new long[1]; - rc.lOID[0] = 0; - } - data = new Integer(1); - */ - // data = null; - //replylength = makeIntReply(buf, rc, new Integer(1)); - //} - if (data == null) - debug("DNF@"+oid); - return data; - } - - private void debug(String s) { - System.err.println("SNMP-Agent " + (new Date()) + ": " + s); - } - - private BEREncoder replyStart(RequestContainer rc) { - return replyStart(rc, 0, 0); - } - private BEREncoder replyStart(RequestContainer rc, int errStatus, int errIndex) /* throws SnmpTooBigException */ { - int replyLength = 0; - BEREncoder be = new BEREncoder(); - be.startSequence(); // whole pkg - be.putInteger(0); // version - be.putOctetString(rc.community); // community - be.startSequence((byte)0xa2); // Response - be.putInteger(rc.requestID); // RID - be.putInteger(errStatus); // err - be.putInteger(errIndex); // err - be.startSequence(); // OID:s and their values - - return be; - } - - private void replyAddOID(BEREncoder be, RequestContainer rc) throws NoSuchFieldException { - String aOID = getAccualOID(rc.OID, rc.pdutype == RequestContainer.PDU_GET_THIS); - Object data = getResultFromOID(aOID, rc.pdutype == RequestContainer.PDU_GET_THIS); - be.startSequence(); // value - be.putOID(splitToLong(aOID)); // oid - //System.err.println("Will reply with OID: " + rc.OID + " -> " + aOID); - if (data instanceof Number) - be.putInteger(((Number)data).longValue()); - else if (data instanceof SNMPTypeWrapperNum) - be.putSNMPTypeWrapperNum((SNMPTypeWrapperNum)data); -// else if (data instanceof SNMPCounter32) -// be.putCunter32(((SNMPCounter32)data).getValue()); - else if (data instanceof String) { - char[] charr = ((String)data).toCharArray(); - byte[] byarr = new byte[charr.length]; - for (int i = 0 ; i < charr.length ; i++) - byarr[i] = (byte)charr[i]; - be.putOctetString(byarr); - } - be.endSequence(); - } - - private int replyEnd(BEREncoder be, byte[] buf) /* throws SnmpTooBigException */ { - return be.toBytes(buf); - } - - - // http://www.rane.com/note161.html - private BERDecoder parseRequestStart(byte buf[], RequestContainer rc) throws BadFormatException { - int tmpint; - - BERDecoder bd = new BERDecoder(buf); - bd.startSequence(); - if ((tmpint = bd.fetchInt()) != 0) - throw new BadFormatException("Wrong version, expected 0, got " - + tmpint); - - rc.community = bd.fetchOctetString(); - if (! rc.setPDU(bd.peekRaw())) - throw new BadFormatException("Unknown PDU"); - bd.startSequence(bd.peekRaw()); - rc.requestID = bd.fetchInt(); - - // TODO: care about errors eventually? - bd.fetchInt(); - bd.fetchInt(); - - bd.startSequence(); - /* - - bd.startSequence(); - rc.lOID = bd.fetchOID(); - rc.OID = (rc.lOID.length == 0)?".":""; - for (int i = 0; i < rc.lOID.length ; i++) - rc.OID += (i==0?"":".") + rc.lOID[i]; - */ - return bd; - } - - private long[] splitToLong(String list) { - if (!list.startsWith(".1.3.")) - list = ".1.3." + list; - list = list.substring(1); - String nums[] = list.split("\\."); - long ret[] = new long[nums.length]; - for(int i = 0; i < ret.length ; i++) { - ret[i] = Long.parseLong(nums[i]); - //System.err.print("," + Long.parseLong(nums[i])); - } - // System.err.println(); - return ret; - } - /* - private class DataHandler { - //public Integer data; - public long lOID[] = null; - DataFetcher df; - - public DataHandler(DataFetcher df) { - lOID = splitToLong(df.getSNMPOID()); - this.df = df; - } - - private long[] splitToLong(String list) { - String nums[] = list.split("\\."); - long ret[] = new long[nums.length]; - for(int i = 0; i < ret.length ; i++) - ret[i] = Long.parseLong(nums[i]); - return ret; - } - - public Object getData() { - return df.getSNMPData(); - } - - public String getStringOID() { - String ret = ""; - for (int i = 0; i < lOID.length ; i++) - ret += "." + lOID[i]; - return ret; - } - } - */ - - - - - private class RequestContainer { - public long lOID[] = null; - public byte community[] = null; - public int pdutype = 0; - public static final int PDU_GET_NEXT = 2; - public static final int PDU_GET_THIS = 1; - public int requestID = 0; - public String OID = null; - - public boolean setPDU(byte id) { - switch(id) { - case (byte)0xA0: - pdutype = PDU_GET_THIS; - break; - - case (byte)0xA1: - pdutype = PDU_GET_NEXT; - break; - - default: - System.err.println("Unknown PDU: 0x" + Integer.toHexString((id + 256)%256)); - return false; - } - return true; - } - - public String toString() { - return ("Community: " + new String(community) + - ", PDU: " + pdutype + ", OID: " + OID); - } - - public boolean pduIsGet() { - return ((pdutype == RequestContainer.PDU_GET_THIS) || - (pdutype == RequestContainer.PDU_GET_NEXT)); - } - } -} Copied: trunk/freenet/src/freenet/snmplib/SNMPAgent.java (from rev 8089, trunk/freenet/src/snmplib/SNMPAgent.java) =================================================================== --- trunk/freenet/src/snmplib/SNMPAgent.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/snmplib/SNMPAgent.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,433 @@ +package freenet.snmplib; + +import java.io.BufferedReader; +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.util.Date; +import java.util.Iterator; +import java.util.TreeMap; + +public class SNMPAgent implements Runnable { + private int port = 4445; + + /** + * @param args + */ + public static void main(String[] args) throws IOException { + SNMPAgent.getSNMPAgent().addFetcher(new DataConstantInt("1.1.1", 10)); + SNMPAgent.getSNMPAgent().addFetcher(new DataConstantInt("1.1.2", 20)); + SNMPAgent.getSNMPAgent().addFetcher(new DataConstantInt("1.1.3", 30)); + SNMPAgent.getSNMPAgent().addFetcher(new DataConstantInt("1.1.4", 40)); + SNMPAgent.getSNMPAgent().addFetcher(new DataConstantInt("1.1.5", 50)); + SNMPAgent.getSNMPAgent().addFetcher(new DataConstantString("1.1.0", "Step by 10")); + SNMPAgent.getSNMPAgent().addFetcher(new DataConstantString("1.2", "Nothing here")); + } + + protected DatagramSocket socket = null; + protected BufferedReader in = null; + protected boolean moreQuotes = true; + private TreeMap alldata; + private static SNMPAgent _SNMPAgent = null; + + public static void setSNMPPort(int port) { + ensureCreated(); + _SNMPAgent.port = port; + restartSNMPAgent(); + } + + public static void restartSNMPAgent() { + ensureCreated(); + _SNMPAgent.stopRunning(); + new Thread(_SNMPAgent, "SNMP-Agent").start(); + } + + public static SNMPAgent getSNMPAgent() { + ensureCreated(); + return _SNMPAgent; + } + + private static void ensureCreated() { + if (_SNMPAgent == null) + _SNMPAgent = new SNMPAgent(); + } + + private SNMPAgent() { + alldata = new TreeMap(); + //alldata.put("99.99", null); + } + + public void addFetcher(DataFetcher df) { + //DataHandler dh = new DataHandler(df); + //alldata.put(dh.getStringOID(), dh); + alldata.put(df.getSNMPOID().replaceAll("^\\.1\\.3\\.",""), df); + //System.err.println("sAdded: " + df.getSNMPOID() + "as" + df.getSNMPOID().replaceAll("^\\.1\\.3\\.","")); + } + + public void addFetcher(MultiplexedDataFetcher df) { + String oid; + for (int i = 0 ; (oid = df.getSNMPOID(i)) != null ; i++) { + alldata.put(oid.replaceAll("^\\.1\\.3\\.",""), df); + // System.err.println("mAdded: " + oid + " as: " + oid.replaceAll("^\\.1\\.3\\.","")); + } + } + + public void removeFetcher(String OID) { + alldata.remove(((OID.startsWith("\\."))?"":".") + OID); + } + + public void stopRunning() { + try { + socket.close(); + } catch (Throwable e) { + // prpbably since not running... + } + } + + public void run() { + try { + socket = new DatagramSocket(port, InetAddress.getByName("localhost")); + } catch (IOException e) { + e.printStackTrace(); + return ; + } + // make smaller.... 0484 enough? + + while (socket.isBound()) { + byte[] buf = new byte[65536]; + DatagramPacket packet = new DatagramPacket(buf, buf.length); + + try { + socket.receive(packet); + + RequestContainer rc = new RequestContainer(); + int replylength = 0; + //DataHandler dh = null; + + //if (rc != null) + // throw new BadFormatException("asdfa"); + + BERDecoder question = parseRequestStart(buf, rc); + + + BEREncoder reply = replyStart(rc); + + int errIndex = 0; + int errStatus = 0; + + try { + while (question.sequenceHasMore()) { + errIndex++; + question.startSequence(); + rc.lOID = question.fetchOID(); + rc.OID = (rc.lOID.length == 0)?"":""; + for (int i = 0; i < rc.lOID.length ; i++) + rc.OID += (i==0?"":".") + rc.lOID[i]; + //System.err.println("Doing: " + rc.OID); + question.fetchNull(); + question.endSequence(); + replyAddOID(reply, rc); + } + } catch (NoSuchFieldException e) { + errStatus = 0x02; // NO SUCH NAME + } + + if (errStatus != 0) { + // Need to restart the question + question = parseRequestStart(buf, rc); + + // TODO! This does not follow the standard, but works with SNMPWALK + // Or does it? ;o) + reply = replyStart(rc, errStatus, errIndex); + while (question.sequenceHasMore()) { + question.startSequence(); + + + reply.startSequence(); // value + reply.putOID(question.fetchOID()); // oid + reply.putNull(); + reply.endSequence(); + + question.fetchNull(); + question.endSequence(); + } + } + + replylength = replyEnd(reply, buf); + //rc.pdutype == RequestContainer.PDU_GET_NEXT + + // send the response to the client at "address" and "port" + InetAddress address = packet.getAddress(); + int port = packet.getPort(); + packet = new DatagramPacket(buf, replylength, address, port); + socket.send(packet); + + } catch (IOException e) { + e.printStackTrace(); + break; + } catch (BadFormatException e) { + System.err.println("Datapacket length: " + packet.getLength()); + for (int i = 0 ; i < packet.getLength() ; i++) { + String num = "000" + Integer.toHexString(buf[i]); + num = num.substring(num.length()-2); + System.err.print("0x" + num + " "); + if ((i+1)%8 == 0) + System.err.print(" "); + if ((i+1)%16 == 0) + System.err.println(); + } + System.err.println(); + e.printStackTrace(); + //System.err.println(e.toString()); + } catch (ArrayIndexOutOfBoundsException e) { + e.printStackTrace(); + // not much to do.. ignore the request and it'll time out + } + } + socket.close(); + } + + private String getAccualOID(String oid, boolean thisval) throws NoSuchFieldException { + boolean keyfound = false; + Iterator it = alldata.keySet().iterator(); + String key = ""; + while (it.hasNext() && !keyfound) { + key = (String)it.next(); + if (key.startsWith(oid)) + keyfound = true; + } + + + if (it.hasNext() && !thisval) { + key = key.equals(oid)?(String)it.next():key; + } else if (!keyfound ) { + throw new NoSuchFieldException("OID not found"); + } + + return key; + } + + private Object getResultFromOID(String oid, boolean thisval) { + /*boolean keyfound = false; + Iterator it = alldata.keySet().iterator(); + String key = ""; + while (it.hasNext() && !keyfound) { + key = (String)it.next(); + if (key.startsWith(oid)) + keyfound = true; + } + */ + // keyfound /\ ( (equal -> hasnext) V (rc.pdutype == rc.PDU_GET_THIS)) + //System.err.println("("+keyfound+" && (!"+key.equals(rc.OID)+" || "+it.hasNext()+"))"); + /*if (keyfound && ( + (!key.equals(rc.OID) || it.hasNext())) || + (rc.pdutype == RequestContainer.PDU_GET_THIS) ) { + */ + Object data = null; + /*if (keyfound && ( + (!key.equals(oid) || it.hasNext())) ) { + if (it.hasNext() && !thisval) + key = key.equals(oid)?(String)it.next():key; + */ + Object df = alldata.get(oid); + + if (df instanceof DataFetcher) { + data = ((DataFetcher)df).getSNMPData(); + } else if (df instanceof MultiplexedDataFetcher) { + data = ((MultiplexedDataFetcher)df).getSNMPData(oid); + if (data == null) + if (!oid.startsWith(".1.3.")) + data = ((MultiplexedDataFetcher)df).getSNMPData(".1.3."+oid); + else + data = ((MultiplexedDataFetcher)df).getSNMPData(oid.substring(5)); + + } else + data = null; //new Integer(0); + + //rc.lOID = splitToLong(key); + //replylength = makeIntReply(buf, rc, data); + //} else { + /* + if (rc.lOID.length > 0) + rc.lOID[0] = 100; + else { + rc.lOID = new long[1]; + rc.lOID[0] = 0; + } + data = new Integer(1); + */ + // data = null; + //replylength = makeIntReply(buf, rc, new Integer(1)); + //} + if (data == null) + debug("DNF@"+oid); + return data; + } + + private void debug(String s) { + System.err.println("SNMP-Agent " + (new Date()) + ": " + s); + } + + private BEREncoder replyStart(RequestContainer rc) { + return replyStart(rc, 0, 0); + } + private BEREncoder replyStart(RequestContainer rc, int errStatus, int errIndex) /* throws SnmpTooBigException */ { + int replyLength = 0; + BEREncoder be = new BEREncoder(); + be.startSequence(); // whole pkg + be.putInteger(0); // version + be.putOctetString(rc.community); // community + be.startSequence((byte)0xa2); // Response + be.putInteger(rc.requestID); // RID + be.putInteger(errStatus); // err + be.putInteger(errIndex); // err + be.startSequence(); // OID:s and their values + + return be; + } + + private void replyAddOID(BEREncoder be, RequestContainer rc) throws NoSuchFieldException { + String aOID = getAccualOID(rc.OID, rc.pdutype == RequestContainer.PDU_GET_THIS); + Object data = getResultFromOID(aOID, rc.pdutype == RequestContainer.PDU_GET_THIS); + be.startSequence(); // value + be.putOID(splitToLong(aOID)); // oid + //System.err.println("Will reply with OID: " + rc.OID + " -> " + aOID); + if (data instanceof Number) + be.putInteger(((Number)data).longValue()); + else if (data instanceof SNMPTypeWrapperNum) + be.putSNMPTypeWrapperNum((SNMPTypeWrapperNum)data); +// else if (data instanceof SNMPCounter32) +// be.putCunter32(((SNMPCounter32)data).getValue()); + else if (data instanceof String) { + char[] charr = ((String)data).toCharArray(); + byte[] byarr = new byte[charr.length]; + for (int i = 0 ; i < charr.length ; i++) + byarr[i] = (byte)charr[i]; + be.putOctetString(byarr); + } + be.endSequence(); + } + + private int replyEnd(BEREncoder be, byte[] buf) /* throws SnmpTooBigException */ { + return be.toBytes(buf); + } + + + // http://www.rane.com/note161.html + private BERDecoder parseRequestStart(byte buf[], RequestContainer rc) throws BadFormatException { + int tmpint; + + BERDecoder bd = new BERDecoder(buf); + bd.startSequence(); + if ((tmpint = bd.fetchInt()) != 0) + throw new BadFormatException("Wrong version, expected 0, got " + + tmpint); + + rc.community = bd.fetchOctetString(); + if (! rc.setPDU(bd.peekRaw())) + throw new BadFormatException("Unknown PDU"); + bd.startSequence(bd.peekRaw()); + rc.requestID = bd.fetchInt(); + + // TODO: care about errors eventually? + bd.fetchInt(); + bd.fetchInt(); + + bd.startSequence(); + /* + + bd.startSequence(); + rc.lOID = bd.fetchOID(); + rc.OID = (rc.lOID.length == 0)?".":""; + for (int i = 0; i < rc.lOID.length ; i++) + rc.OID += (i==0?"":".") + rc.lOID[i]; + */ + return bd; + } + + private long[] splitToLong(String list) { + if (!list.startsWith(".1.3.")) + list = ".1.3." + list; + list = list.substring(1); + String nums[] = list.split("\\."); + long ret[] = new long[nums.length]; + for(int i = 0; i < ret.length ; i++) { + ret[i] = Long.parseLong(nums[i]); + //System.err.print("," + Long.parseLong(nums[i])); + } + // System.err.println(); + return ret; + } + /* + private class DataHandler { + //public Integer data; + public long lOID[] = null; + DataFetcher df; + + public DataHandler(DataFetcher df) { + lOID = splitToLong(df.getSNMPOID()); + this.df = df; + } + + private long[] splitToLong(String list) { + String nums[] = list.split("\\."); + long ret[] = new long[nums.length]; + for(int i = 0; i < ret.length ; i++) + ret[i] = Long.parseLong(nums[i]); + return ret; + } + + public Object getData() { + return df.getSNMPData(); + } + + public String getStringOID() { + String ret = ""; + for (int i = 0; i < lOID.length ; i++) + ret += "." + lOID[i]; + return ret; + } + } + */ + + + + + private class RequestContainer { + public long lOID[] = null; + public byte community[] = null; + public int pdutype = 0; + public static final int PDU_GET_NEXT = 2; + public static final int PDU_GET_THIS = 1; + public int requestID = 0; + public String OID = null; + + public boolean setPDU(byte id) { + switch(id) { + case (byte)0xA0: + pdutype = PDU_GET_THIS; + break; + + case (byte)0xA1: + pdutype = PDU_GET_NEXT; + break; + + default: + System.err.println("Unknown PDU: 0x" + Integer.toHexString((id + 256)%256)); + return false; + } + return true; + } + + public String toString() { + return ("Community: " + new String(community) + + ", PDU: " + pdutype + ", OID: " + OID); + } + + public boolean pduIsGet() { + return ((pdutype == RequestContainer.PDU_GET_THIS) || + (pdutype == RequestContainer.PDU_GET_NEXT)); + } + } +} Deleted: trunk/freenet/src/freenet/snmplib/SNMPCounter32.java =================================================================== --- trunk/freenet/src/snmplib/SNMPCounter32.java 2006-02-17 23:08:53 UTC (rev 8057) +++ trunk/freenet/src/freenet/snmplib/SNMPCounter32.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,16 +0,0 @@ -package snmplib; - -public class SNMPCounter32 extends SNMPTypeWrapperNum { - public SNMPCounter32() { super(); } - public SNMPCounter32(long value) { super(value); } - - public void setValue(long value) { - // TODO: make it prettier! - this.value = new Long(value).intValue(); - //System.err.println("Value cut from: " + value + " to " + this.value); - } - - protected void init() { - this.typeID = 0x41; - } -} Copied: trunk/freenet/src/freenet/snmplib/SNMPCounter32.java (from rev 8089, trunk/freenet/src/snmplib/SNMPCounter32.java) =================================================================== --- trunk/freenet/src/snmplib/SNMPCounter32.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/snmplib/SNMPCounter32.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,16 @@ +package freenet.snmplib; + +public class SNMPCounter32 extends SNMPTypeWrapperNum { + public SNMPCounter32() { super(); } + public SNMPCounter32(long value) { super(value); } + + public void setValue(long value) { + // TODO: make it prettier! + this.value = new Long(value).intValue(); + //System.err.println("Value cut from: " + value + " to " + this.value); + } + + protected void init() { + this.typeID = 0x41; + } +} Deleted: trunk/freenet/src/freenet/snmplib/SNMPGauge32.java =================================================================== --- trunk/freenet/src/snmplib/SNMPGauge32.java 2006-02-17 23:08:53 UTC (rev 8057) +++ trunk/freenet/src/freenet/snmplib/SNMPGauge32.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,16 +0,0 @@ -package snmplib; - -public class SNMPGauge32 extends SNMPTypeWrapperNum { - public SNMPGauge32() { super(); } - public SNMPGauge32(long value) { super(value); } - - public void setValue(long value) { - // TODO: make it prettier! - this.value = new Long(value).intValue(); - //System.err.println("Value cut from: " + value + " to " + this.value); - } - - protected void init() { - this.typeID = 0x42; - } -} Copied: trunk/freenet/src/freenet/snmplib/SNMPGauge32.java (from rev 8089, trunk/freenet/src/snmplib/SNMPGauge32.java) =================================================================== --- trunk/freenet/src/snmplib/SNMPGauge32.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/snmplib/SNMPGauge32.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,16 @@ +package freenet.snmplib; + +public class SNMPGauge32 extends SNMPTypeWrapperNum { + public SNMPGauge32() { super(); } + public SNMPGauge32(long value) { super(value); } + + public void setValue(long value) { + // TODO: make it prettier! + this.value = new Long(value).intValue(); + //System.err.println("Value cut from: " + value + " to " + this.value); + } + + protected void init() { + this.typeID = 0x42; + } +} Deleted: trunk/freenet/src/freenet/snmplib/SNMPInteger32.java =================================================================== --- trunk/freenet/src/snmplib/SNMPInteger32.java 2006-02-17 23:08:53 UTC (rev 8057) +++ trunk/freenet/src/freenet/snmplib/SNMPInteger32.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,16 +0,0 @@ -package snmplib; - -public class SNMPInteger32 extends SNMPTypeWrapperNum { - public SNMPInteger32() { super(); } - public SNMPInteger32(long value) { super(value); } - - public void setValue(long value) { - // TODO: make it prettier! - this.value = new Long(value).intValue(); - //System.err.println("Value cut from: " + value + " to " + this.value); - } - - protected void init() { - this.typeID = 0x02; - } -} Copied: trunk/freenet/src/freenet/snmplib/SNMPInteger32.java (from rev 8089, trunk/freenet/src/snmplib/SNMPInteger32.java) =================================================================== --- trunk/freenet/src/snmplib/SNMPInteger32.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/snmplib/SNMPInteger32.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,16 @@ +package freenet.snmplib; + +public class SNMPInteger32 extends SNMPTypeWrapperNum { + public SNMPInteger32() { super(); } + public SNMPInteger32(long value) { super(value); } + + public void setValue(long value) { + // TODO: make it prettier! + this.value = new Long(value).intValue(); + //System.err.println("Value cut from: " + value + " to " + this.value); + } + + protected void init() { + this.typeID = 0x02; + } +} Deleted: trunk/freenet/src/freenet/snmplib/SNMPStarter.java =================================================================== --- trunk/freenet/src/snmplib/SNMPStarter.java 2006-02-17 23:08:53 UTC (rev 8057) +++ trunk/freenet/src/freenet/snmplib/SNMPStarter.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,26 +0,0 @@ -package snmplib; - -import freenet.io.comm.IOStatisticCollector; - -/** - * @author cyberdo - * - * Creates the SNMP-agent - */ -public class SNMPStarter { - - private static boolean has_been_runned = false; - - public static void initialize() { - //SNMPAgent.setSNMPPort(port); - if (has_been_runned) return; - // 0 is toatl I/O - for (int i = 0 ; i < IOStatisticCollector.STATISTICS_ENTRIES ; i++) { - SNMPAgent.getSNMPAgent().addFetcher(new DataStatisticsInfo(i, true)); - SNMPAgent.getSNMPAgent().addFetcher(new DataStatisticsInfo(i, false)); - } - SNMPAgent.getSNMPAgent().addFetcher(new InfoSystem()); - - has_been_runned = true; - } -} Copied: trunk/freenet/src/freenet/snmplib/SNMPStarter.java (from rev 8089, trunk/freenet/src/snmplib/SNMPStarter.java) =================================================================== --- trunk/freenet/src/snmplib/SNMPStarter.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/snmplib/SNMPStarter.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,32 @@ +package freenet.snmplib; + +import freenet.config.Config; +import freenet.io.comm.IOStatisticCollector; +import freenet.node.Node; + +/** + * @author cyberdo + * + * Creates the SNMP-agent + */ +public class SNMPStarter { + + private static boolean has_been_runned = false; + + public static void initialize() { + //SNMPAgent.setSNMPPort(port); + if (has_been_runned) return; + // 0 is toatl I/O + for (int i = 0 ; i < IOStatisticCollector.STATISTICS_ENTRIES ; i++) { + SNMPAgent.getSNMPAgent().addFetcher(new DataStatisticsInfo(i, true)); + SNMPAgent.getSNMPAgent().addFetcher(new DataStatisticsInfo(i, false)); + } + SNMPAgent.getSNMPAgent().addFetcher(new InfoSystem()); + + has_been_runned = true; + } + + public static void maybeCreate(Node node, Config config) { + // FIXME any config needed for SNMPStarter? + } +} Deleted: trunk/freenet/src/freenet/snmplib/SNMPTimeTicks.java =================================================================== --- trunk/freenet/src/snmplib/SNMPTimeTicks.java 2006-02-17 23:08:53 UTC (rev 8057) +++ trunk/freenet/src/freenet/snmplib/SNMPTimeTicks.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,24 +0,0 @@ -package snmplib; - -public class SNMPTimeTicks extends SNMPTypeWrapperNum { - public SNMPTimeTicks() { super(); } - public SNMPTimeTicks(long value) { super(value); } - - protected void init() { - this.typeID = 0x43; - } - - public String toString() { - long rest = value; - long dec = rest%100; - rest = rest/100; - long sec = rest%60; - rest = rest/60; - long min = rest%60; - rest = rest/60; - long hour = rest%24; - rest = rest/24; - long day = rest; - return day + ":" + hour + ":" + min + ":" + sec + "." + dec; - } -} Copied: trunk/freenet/src/freenet/snmplib/SNMPTimeTicks.java (from rev 8089, trunk/freenet/src/snmplib/SNMPTimeTicks.java) =================================================================== --- trunk/freenet/src/snmplib/SNMPTimeTicks.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/snmplib/SNMPTimeTicks.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,24 @@ +package freenet.snmplib; + +public class SNMPTimeTicks extends SNMPTypeWrapperNum { + public SNMPTimeTicks() { super(); } + public SNMPTimeTicks(long value) { super(value); } + + protected void init() { + this.typeID = 0x43; + } + + public String toString() { + long rest = value; + long dec = rest%100; + rest = rest/100; + long sec = rest%60; + rest = rest/60; + long min = rest%60; + rest = rest/60; + long hour = rest%24; + rest = rest/24; + long day = rest; + return day + ":" + hour + ":" + min + ":" + sec + "." + dec; + } +} Deleted: trunk/freenet/src/freenet/snmplib/SNMPTypeWrapperNum.java =================================================================== --- trunk/freenet/src/snmplib/SNMPTypeWrapperNum.java 2006-02-17 23:08:53 UTC (rev 8057) +++ trunk/freenet/src/freenet/snmplib/SNMPTypeWrapperNum.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -1,58 +0,0 @@ -package snmplib; - -public abstract class SNMPTypeWrapperNum { - protected long value; - protected byte typeID; - - /** - * This methd is used to initialize for instance typeID; - */ - protected abstract void init(); - - public SNMPTypeWrapperNum() { - this(0); - } - - public SNMPTypeWrapperNum(long value) { - this.setValue(value); - init(); - } - - //public final byte typeID; - //= 0x02; - public byte getTypeID() { - //System.err.println("Returning " + Integer.toHexString(typeID) + " for a " + this.getClass().toString()); - return typeID; - } - - public long getValue() { - return value; - } - - public void setValue(long value) { - this.value = value; - } - - public Object clone() { - Object ret = null; - try { - ret = this.getClass().newInstance(); - ((SNMPTypeWrapperNum)ret).setValue(getValue()); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return ret; - } - - public String toString() { - return Long.toString(value); - } - -} Copied: trunk/freenet/src/freenet/snmplib/SNMPTypeWrapperNum.java (from rev 8089, trunk/freenet/src/snmplib/SNMPTypeWrapperNum.java) =================================================================== --- trunk/freenet/src/snmplib/SNMPTypeWrapperNum.java 2006-02-21 17:52:44 UTC (rev 8089) +++ trunk/freenet/src/freenet/snmplib/SNMPTypeWrapperNum.java 2006-02-21 18:34:11 UTC (rev 8090) @@ -0,0 +1,58 @@ +package freenet.snmplib; + +public abstract class SNMPTypeWrapperNum { + protected long value; + protected byte typeID; + + /** + * This methd is used to initialize for instance typeID; + */ + protected abstract void init(); + + public SNMPTypeWrapperNum() { + this(0); + } + + public SNMPTypeWrapperNum(long value) { + this.setValue(value); + init(); + } + + //public final byte typeID; + //= 0x02; + public byte getTypeID() { + //System.err.println("Returning " + Integer.toHexString(typeID) + " for a " + this.getClass().toString()); + return typeID; + } + + public long getValue() { + return value; + } + + public void setValue(long value) { + this.value = value; + } + + public Object clone() { + Object ret = null; + try { + ret = this.getClass().newInstance(); + ((SNMPTypeWrapperNum)ret).setValue(getValue()); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return ret; + } + + public String toString() { + return Long.toString(value); + } + +}
