Author: j16sdiz Date: 2008-10-31 13:11:35 +0000 (Fri, 31 Oct 2008) New Revision: 23242
Removed: trunk/freenet/src/freenet/client/SplitFetchException.java trunk/freenet/src/freenet/client/StartableSplitfileBlock.java trunk/freenet/src/freenet/client/events/BlockInsertErrorEvent.java trunk/freenet/src/freenet/client/events/DecodedBlockEvent.java trunk/freenet/src/freenet/client/events/FetchedMetadataEvent.java trunk/freenet/src/freenet/client/events/GeneratedURIEvent.java trunk/freenet/src/freenet/client/events/GotBlockEvent.java trunk/freenet/src/freenet/client/events/SimpleBlockPutEvent.java trunk/freenet/src/freenet/clients/http/TrivialToadlet.java trunk/freenet/src/freenet/crypt/CipherInputStream.java trunk/freenet/src/freenet/crypt/CipherModes.java trunk/freenet/src/freenet/crypt/CipherOutputStream.java trunk/freenet/src/freenet/crypt/DecipherOutputStream.java trunk/freenet/src/freenet/crypt/DecryptionFailedException.java trunk/freenet/src/freenet/crypt/DigestInputStream.java trunk/freenet/src/freenet/crypt/DigestOutputStream.java trunk/freenet/src/freenet/crypt/EncipherInputStream.java trunk/freenet/src/freenet/crypt/KEProtocol.java trunk/freenet/src/freenet/crypt/UnsupportedDigestException.java trunk/freenet/src/freenet/io/comm/DumpDispatcher.java trunk/freenet/src/freenet/node/CPUAdjustingSwapRequestInterval.java trunk/freenet/src/freenet/node/CPUUsageMonitor.java trunk/freenet/src/freenet/node/DSAPublicKeyDatabase.java trunk/freenet/src/freenet/node/StaticSwapRequestInterval.java trunk/freenet/src/freenet/node/SwapRequestInterval.java trunk/freenet/src/freenet/node/updater/PrivkeyHasBeenBlownException.java trunk/freenet/src/freenet/node/useralerts/OpennetUserAlert.java trunk/freenet/src/freenet/plugin/api/FreenetPlugin.java trunk/freenet/src/freenet/plugin/api/FreenetPluginManager.java trunk/freenet/src/freenet/plugin/api/NeedsConfig.java trunk/freenet/src/freenet/plugin/api/NeedsSimpleKeyFetch.java trunk/freenet/src/freenet/plugin/api/NeedsTempBuckets.java trunk/freenet/src/freenet/plugin/api/NeedsWebInterfaceGeneric.java trunk/freenet/src/freenet/plugin/api/NeedsWebInterfaceHTMLString.java trunk/freenet/src/freenet/plugin/api/PluginFetchException.java trunk/freenet/src/freenet/plugin/api/PluginFetchResult.java trunk/freenet/src/freenet/plugin/api/PluginFreenetURI.java trunk/freenet/src/freenet/plugin/api/ProvidesSimpleKeyFetch.java trunk/freenet/src/freenet/plugin/api/package-info.java trunk/freenet/src/freenet/pluginmanager/FredPluginToadlet.java trunk/freenet/src/freenet/pluginmanager/PluginSecurityException.java trunk/freenet/src/freenet/support/DoubleTokenBucket.java trunk/freenet/src/freenet/support/NumberedItem.java trunk/freenet/src/freenet/support/NumberedItemComparator.java trunk/freenet/src/freenet/support/NumberedRecentItems.java trunk/freenet/src/freenet/support/RandomGrabArrayWithInt.java trunk/freenet/src/freenet/support/api/BaseSubConfig.java trunk/freenet/src/freenet/support/api/HTTPReply.java trunk/freenet/src/freenet/support/compress/DecompressException.java trunk/freenet/src/freenet/support/math/SimpleBinaryRunningAverage.java Modified: trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java trunk/freenet/src/freenet/clients/http/filter/GenericReadFilterCallback.java Log: remove unused class Deleted: trunk/freenet/src/freenet/client/SplitFetchException.java =================================================================== --- trunk/freenet/src/freenet/client/SplitFetchException.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/client/SplitFetchException.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,28 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.client; - -public class SplitFetchException extends FetchException { - - final int failed; - final int fatal; - final int succeeded; - final int enough; - - public SplitFetchException(int failed, int fatal, int succeeded, int enough, FailureCodeTracker errorCodes) { - super(FetchException.SPLITFILE_ERROR, errorCodes); - this.failed = failed; - this.fatal = fatal; - this.succeeded = succeeded; - this.enough = enough; - } - - @Override - public String getMessage() { - return "Splitfile fetch failure: "+failed+" failed, "+fatal+" fatal errors, "+succeeded+" succeeded, "+enough+" enough"; - } - - private static final long serialVersionUID = 1523809424508826893L; - -} Deleted: trunk/freenet/src/freenet/client/StartableSplitfileBlock.java =================================================================== --- trunk/freenet/src/freenet/client/StartableSplitfileBlock.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/client/StartableSplitfileBlock.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,28 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.client; - -import freenet.keys.FreenetURI; - -/** Simple interface for a splitfile block */ -public interface StartableSplitfileBlock extends SplitfileBlock { - - /** Start the fetch (or insert). Implementation is required to call relevant - * methods on RetryTracker when done. */ - abstract void start(); - - /** - * Shut down the fetch as soon as reasonably possible. - */ - abstract public void kill(); - - abstract public int getRetryCount(); - - /** - * Get the URI of the file. For an insert, this is derived during insert. - * For a request, it is fixed in the constructor. - */ - abstract public FreenetURI getURI(); - -} Deleted: trunk/freenet/src/freenet/client/events/BlockInsertErrorEvent.java =================================================================== --- trunk/freenet/src/freenet/client/events/BlockInsertErrorEvent.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/client/events/BlockInsertErrorEvent.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,30 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.client.events; - -import freenet.client.InsertException; -import freenet.keys.FreenetURI; - -public class BlockInsertErrorEvent implements ClientEvent { - - public static final int code = 0x05; - public final InsertException e; - public final FreenetURI key; - public final int retryNumber; - - public BlockInsertErrorEvent(InsertException e, FreenetURI key, int retryNumber) { - this.e = e; - this.key = key; - this.retryNumber = retryNumber; - } - - public String getDescription() { - return e.getMessage()+" for "+key+" ("+retryNumber+ ')'; - } - - public int getCode() { - return code; - } - -} Deleted: trunk/freenet/src/freenet/client/events/DecodedBlockEvent.java =================================================================== --- trunk/freenet/src/freenet/client/events/DecodedBlockEvent.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/client/events/DecodedBlockEvent.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,25 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.client.events; - -import freenet.keys.ClientKey; - -public class DecodedBlockEvent implements ClientEvent { - - public static final int code = 0x03; - public final ClientKey key; - - public DecodedBlockEvent(ClientKey key) { - this.key = key; - } - - public String getDescription() { - return "Decoded a block of data: "+key.getURI(); - } - - public int getCode() { - return code; - } - -} Deleted: trunk/freenet/src/freenet/client/events/FetchedMetadataEvent.java =================================================================== --- trunk/freenet/src/freenet/client/events/FetchedMetadataEvent.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/client/events/FetchedMetadataEvent.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,18 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.client.events; - -public class FetchedMetadataEvent implements ClientEvent { - - public final static int code = 0x01; - - public String getDescription() { - return "Fetched metadata"; - } - - public int getCode() { - return code; - } - -} Deleted: trunk/freenet/src/freenet/client/events/GeneratedURIEvent.java =================================================================== --- trunk/freenet/src/freenet/client/events/GeneratedURIEvent.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/client/events/GeneratedURIEvent.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,24 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.client.events; - -import freenet.keys.FreenetURI; - -public class GeneratedURIEvent implements ClientEvent { - - public static final int code = 0x06; - public final FreenetURI uri; - - public GeneratedURIEvent(FreenetURI uri) { - this.uri = uri; - } - - public String getDescription() { - return "Generated URI on insert: "+uri; - } - - public int getCode() { - return code; - } -} Deleted: trunk/freenet/src/freenet/client/events/GotBlockEvent.java =================================================================== --- trunk/freenet/src/freenet/client/events/GotBlockEvent.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/client/events/GotBlockEvent.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,28 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.client.events; - -import freenet.keys.ClientKey; - -/** - * Fetched a block of data. - */ -public class GotBlockEvent implements ClientEvent { - - public static final int code = 0x02; - public final ClientKey key; - - public GotBlockEvent(ClientKey key) { - this.key = key; - } - - public String getDescription() { - return "Fetched a block of data: "+key.getURI(); - } - - public int getCode() { - return code; - } - -} Deleted: trunk/freenet/src/freenet/client/events/SimpleBlockPutEvent.java =================================================================== --- trunk/freenet/src/freenet/client/events/SimpleBlockPutEvent.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/client/events/SimpleBlockPutEvent.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,26 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.client.events; - -import freenet.keys.ClientKey; - -public class SimpleBlockPutEvent implements ClientEvent { - - public final static int code = 0x04; - - private final ClientKey key; - - public SimpleBlockPutEvent(ClientKey key) { - this.key = key; - } - - public String getDescription() { - return "Inserting simple key: "+key.getURI(); - } - - public int getCode() { - return code; - } - -} Modified: trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -31,20 +31,7 @@ public class StatisticsToadlet extends Toadlet { static final NumberFormat thousendPoint = NumberFormat.getInstance(); - - static class MyComparator implements Comparator<Object[]> { - public int compare(Object[] row0, Object[] row1) { - Integer stat0 = (Integer) row0[2]; // 2 = status - Integer stat1 = (Integer) row1[2]; - int x = stat0.compareTo(stat1); - if(x != 0) return x; - String name0 = (String) row0[9]; // 9 = node name - String name1 = (String) row1[9]; - return name0.toLowerCase().compareTo(name1.toLowerCase()); - } - } - private static class STMessageCount { public String messageName; public int messageCount; Deleted: trunk/freenet/src/freenet/clients/http/TrivialToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/TrivialToadlet.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/clients/http/TrivialToadlet.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,30 +0,0 @@ -package freenet.clients.http; - -import java.io.IOException; -import java.net.URI; - -import freenet.client.HighLevelSimpleClient; -import freenet.support.HTMLEncoder; -import freenet.support.api.HTTPRequest; - -public class TrivialToadlet extends Toadlet { - - TrivialToadlet(HighLevelSimpleClient client) { - super(client); - } - - @Override - public void handleGet(URI uri, HTTPRequest req, ToadletContext ctx) throws ToadletContextClosedException, IOException { - String fetched = uri.toString(); - String encFetched = HTMLEncoder.encode(fetched); - String reply = "<html><head><title>You requested "+encFetched+ - "</title></head><body>You fetched <a href=\""+encFetched+"\">"+ - encFetched+"</a>.</body></html>"; - this.writeHTMLReply(ctx, 200, "OK", reply); - } - - @Override - public String supportedMethods() { - return "GET"; - } -} Modified: trunk/freenet/src/freenet/clients/http/filter/GenericReadFilterCallback.java =================================================================== --- trunk/freenet/src/freenet/clients/http/filter/GenericReadFilterCallback.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/clients/http/filter/GenericReadFilterCallback.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -3,8 +3,8 @@ * http://www.gnu.org/ for further details of the GPL. */ package freenet.clients.http.filter; -import java.net.MalformedURLException; import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URLEncoder; @@ -14,7 +14,6 @@ import freenet.clients.http.StaticToadlet; import freenet.keys.FreenetURI; import freenet.l10n.L10n; -import freenet.node.StaticSwapRequestInterval; import freenet.support.HTMLEncoder; import freenet.support.Logger; import freenet.support.URIPreEncoder; Deleted: trunk/freenet/src/freenet/crypt/CipherInputStream.java =================================================================== --- trunk/freenet/src/freenet/crypt/CipherInputStream.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/crypt/CipherInputStream.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,107 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.crypt; - -import java.io.*; - -/** - * Implements a Java InputStream that is encrypted with any symmetric block - * cipher (implementing the BlockCipher interface). - * - * This stream operates in Periodic Cipher Feedback Mode (PCFB), allowing - * byte at a time encryption with no additional encryption workload. - */ - -public class CipherInputStream extends FilterInputStream { - - private final PCFBMode ctx; - private boolean needIV = false; - - public CipherInputStream(BlockCipher c, InputStream in) { - this(PCFBMode.create(c), in); - } - - public CipherInputStream(BlockCipher c, InputStream in, boolean readIV) - throws IOException { - - this(PCFBMode.create(c), in); - if (readIV) ctx.readIV(this.in); - } - - public boolean needIV() { - return needIV; - } - - /** - * This constructor causes the IV to be read of the connection the - * first time one of the read messages is read (if later is set). - */ - public CipherInputStream(BlockCipher c, InputStream in, boolean readIV, - boolean later) throws IOException { - this(PCFBMode.create(c), in); - if (readIV && later) - needIV = true; - else if (readIV) - ctx.readIV(this.in); - } - - public CipherInputStream(BlockCipher c, InputStream in, byte[] iv) { - this(new PCFBMode(c, iv), in); - } - - public CipherInputStream(PCFBMode ctx, InputStream in) { - super(in); - this.ctx = ctx; - } - - //int read = 0; - @Override - public int read() throws IOException { - if (needIV) { - ctx.readIV(in); - needIV = false; - } - //System.err.println("CIS READING"); - int rv=in.read(); - - //if ((read++ % 5) == 0) - // System.err.println("CIS READ " + read); - return (rv==-1 ? -1 : ctx.decipher(rv)); - } - - @Override - public int read(byte[] b, int off, int len) throws IOException { - if (needIV) { - ctx.readIV(in); - needIV = false; - } - //System.err.println("CIS READING IN: " + in.toString() + " LEN: " + - // len); - int rv=in.read(b, off, len); - //System.err.println("CIS READ " + (read += rv)); - if (rv != -1) { - ctx.blockDecipher(b, off, rv); - return rv; - } else - return -1; - } - - @Override - public int available() throws IOException { - int r = in.available(); - return (needIV ? Math.max(0, r - ctx.lengthIV()) : r); - } - - public PCFBMode getCipher() { - return ctx; - } -} - - - - - - - - Deleted: trunk/freenet/src/freenet/crypt/CipherModes.java =================================================================== --- trunk/freenet/src/freenet/crypt/CipherModes.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/crypt/CipherModes.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,15 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.crypt; - -public interface CipherModes { - - public int - ECB = 0, - CBC = 1, - CFB = 2; -} - - - Deleted: trunk/freenet/src/freenet/crypt/CipherOutputStream.java =================================================================== --- trunk/freenet/src/freenet/crypt/CipherOutputStream.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/crypt/CipherOutputStream.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,63 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.crypt; - -import java.io.*; - -/** - * Implements a Java OutputStream that is encrypted with any symmetric block - * cipher (implementing the BlockCipher interface). - * - * This stream operates in Periodic Cipher Feedback Mode (PCFB), allowing - * byte at a time encryption with no additional encryption workload. - */ -public class CipherOutputStream extends FilterOutputStream { - - private final PCFBMode ctx; - - public PCFBMode getCipher() { - return ctx; - } - - public CipherOutputStream(BlockCipher c, OutputStream out) { - this(PCFBMode.create(c), out); - } - - public CipherOutputStream(BlockCipher c, OutputStream out, byte[] iv) { - this(PCFBMode.create(c, iv), out); - } - - public CipherOutputStream(PCFBMode ctx, OutputStream out) { - super(out); - this.ctx = ctx; - } - - //int wrote = 0; - @Override - public void write(int b) throws IOException { - //System.err.println("WRITING BYTE: " + wrote++); - out.write(ctx.encipher(b)); - } - - @Override - public void write(byte[] buf, int off, int len) throws IOException { - //System.err.println("WRITING BUF LENGTH : " + (wrote += len)); - byte[] tmp = new byte[len]; - System.arraycopy(buf, off, tmp, 0, len); - ctx.blockEncipher(tmp, 0, len); - out.write(tmp); - } - - // FOS will use write(int) to implement this if we don't override it! - @Override - public void write(byte[] buf) throws IOException { - write(buf, 0, buf.length); - } -} - - - - - - Deleted: trunk/freenet/src/freenet/crypt/DecipherOutputStream.java =================================================================== --- trunk/freenet/src/freenet/crypt/DecipherOutputStream.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/crypt/DecipherOutputStream.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,50 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.crypt; - -import java.io.*; - -/** - * Implements a Java OutputStream that decrypts the data before writing - * to the substream. - * This differs from CipherOutputStream, which encrypts the data instead. - * @author tavin - */ -public class DecipherOutputStream extends FilterOutputStream { - - private PCFBMode ctx; - - public DecipherOutputStream(OutputStream out, BlockCipher c) { - this(out, PCFBMode.create(c)); - } - - public DecipherOutputStream(OutputStream out, BlockCipher c, int bufSize) { - this(new BufferedOutputStream(out, bufSize), c); - } - - public DecipherOutputStream(OutputStream out, PCFBMode ctx) { - super(out); - this.ctx = ctx; - } - - public DecipherOutputStream(OutputStream out, PCFBMode ctx, int bufSize) { - this(new BufferedOutputStream(out, bufSize), ctx); - } - - @Override - public void write(int b) throws IOException { - out.write(ctx.decipher(b)); - } - - @Override - public void write(byte[] buf, int off, int len) throws IOException { - byte[] tmp = new byte[len]; - System.arraycopy(buf, off, tmp, 0, len); - ctx.blockDecipher(tmp, 0, len); - out.write(tmp); - } -} - - - Deleted: trunk/freenet/src/freenet/crypt/DecryptionFailedException.java =================================================================== --- trunk/freenet/src/freenet/crypt/DecryptionFailedException.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/crypt/DecryptionFailedException.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,11 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.crypt; - -public class DecryptionFailedException extends Exception { - private static final long serialVersionUID = -1; - public DecryptionFailedException (String m) { - super(m); - } -} Deleted: trunk/freenet/src/freenet/crypt/DigestInputStream.java =================================================================== --- trunk/freenet/src/freenet/crypt/DigestInputStream.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/crypt/DigestInputStream.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,34 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.crypt; - -import java.io.*; - -public class DigestInputStream extends FilterInputStream { - protected Digest ctx; - - public DigestInputStream(Digest d, InputStream in) { - super(in); - this.ctx=d; - } - - @Override - public int read(byte[] b, int offset, int len) throws IOException { - int rl=super.read(b, offset, len); - if (rl>0) ctx.update(b, offset, rl); - return rl; - } - - @Override - public int read() throws IOException { - int rv=super.read(); - if (rv!=-1) ctx.update((byte)rv); - return rv; - } - - public Digest getDigest() { - return ctx; - } -} - Deleted: trunk/freenet/src/freenet/crypt/DigestOutputStream.java =================================================================== --- trunk/freenet/src/freenet/crypt/DigestOutputStream.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/crypt/DigestOutputStream.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,37 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.crypt; - -import java.io.*; - -public class DigestOutputStream extends FilterOutputStream { - protected Digest ctx; - - public DigestOutputStream(Digest d, OutputStream out) { - super(out); - this.ctx=d; - } - - @Override - public void write(byte[] b) throws IOException { - write(b, 0, b.length); - } - - @Override - public void write(byte[] b, int offset, int len) throws IOException { - ctx.update(b, offset, len); - out.write(b, offset, len); - } - - @Override - public void write(int b) throws IOException { - ctx.update((byte)b); - out.write(b); - } - - public Digest getDigest() { - return ctx; - } -} - Deleted: trunk/freenet/src/freenet/crypt/EncipherInputStream.java =================================================================== --- trunk/freenet/src/freenet/crypt/EncipherInputStream.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/crypt/EncipherInputStream.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,47 +0,0 @@ -package freenet.crypt; -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ - -import java.io.*; - -/** - * Implements a Java InputStream that encrypts the substream on the way in. - * This differs from CipherInputStream, which is decrypting an already - * encrypted source - */ -public class EncipherInputStream extends FilterInputStream { - - protected PCFBMode ctx; - - public EncipherInputStream(InputStream in, BlockCipher c) { - this(in, PCFBMode.create(c)); - } - - public EncipherInputStream(InputStream in, BlockCipher c, int bufSize) { - this(bufSize == 0 ? in : new BufferedInputStream(in, bufSize), c); - } - - public EncipherInputStream(InputStream in, PCFBMode ctx) { - super(in); - this.ctx = ctx; - } - - public EncipherInputStream(InputStream in, PCFBMode ctx, int bufSize) { - this(bufSize == 0 ? in : new BufferedInputStream(in, bufSize), ctx); - } - - @Override - public int read() throws IOException { - int rv=in.read(); - return (rv==-1 ? -1 : ctx.encipher(rv)); - } - - @Override - public int read(byte[] b, int off, int len) throws IOException { - int rv=in.read(b, off, len); - if (rv != -1) ctx.blockEncipher(b, off, rv); - return rv; - } -} - Deleted: trunk/freenet/src/freenet/crypt/KEProtocol.java =================================================================== --- trunk/freenet/src/freenet/crypt/KEProtocol.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/crypt/KEProtocol.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,26 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.crypt; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * Defines the interface that must be implemented by key-exchange protocols - * such as RSA and Diffie-Hellman - */ -public abstract class KEProtocol { - protected RandomSource randomSource; - protected EntropySource es; - - public KEProtocol(RandomSource rs) { - randomSource=rs; - es=new EntropySource(); - } - - public abstract void negotiateKey(InputStream in, OutputStream out, - byte[] key, int offset, int len) - throws IOException; -} Deleted: trunk/freenet/src/freenet/crypt/UnsupportedDigestException.java =================================================================== --- trunk/freenet/src/freenet/crypt/UnsupportedDigestException.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/crypt/UnsupportedDigestException.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,9 +0,0 @@ -package freenet.crypt; - -public class UnsupportedDigestException extends Exception { - private static final long serialVersionUID = -1; - public UnsupportedDigestException() {} - public UnsupportedDigestException(String s) { - super(s); - } -} Deleted: trunk/freenet/src/freenet/io/comm/DumpDispatcher.java =================================================================== --- trunk/freenet/src/freenet/io/comm/DumpDispatcher.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/io/comm/DumpDispatcher.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,18 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.io.comm; - -/** - * Dispatcher that just dumps everything received to stderr. - */ -public class DumpDispatcher implements Dispatcher { - - public DumpDispatcher() { - } - - public boolean handleMessage(Message m) { - System.err.println("Received message: "+m); - return true; - } -} Deleted: trunk/freenet/src/freenet/node/CPUAdjustingSwapRequestInterval.java =================================================================== --- trunk/freenet/src/freenet/node/CPUAdjustingSwapRequestInterval.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/node/CPUAdjustingSwapRequestInterval.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,73 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.node; - -import freenet.support.Logger; -import freenet.support.io.NativeThread; - -/** - * @author amphibian - * - * Start at a given default value, adjust up or down according to - * CPU usage for a given target % usage. - */ -public final class CPUAdjustingSwapRequestInterval implements SwapRequestInterval, Runnable { - - double currentValue; - int targetCPUUsage; - CPUUsageMonitor m; - static final double mulPerSecond = 1.05; - static final double max = Double.MAX_VALUE / mulPerSecond; - static final double min = Double.MIN_VALUE; - - CPUAdjustingSwapRequestInterval(double initialValue, int targetCPUUsage) { - currentValue = initialValue; - this.targetCPUUsage = targetCPUUsage; - m = new CPUUsageMonitor(); - } - - public void start() { - NativeThread t = new NativeThread(this, "CPUAdjustingSwapRequestInterval", NativeThread.MAX_PRIORITY, false); - t.setDaemon(true); - t.start(); - } - - public synchronized int getValue() { - return (int)currentValue; - } - - public void run() { - while(true) { - try { - long now = System.currentTimeMillis(); - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - } - int cpuUsage = m.getCPUUsage(); - long endSleepTime = System.currentTimeMillis(); - double mul = Math.pow(mulPerSecond, ((double)(endSleepTime-now))/1000); - if(cpuUsage == -1) { - Logger.error(this, "Cannot auto-adjust based on CPU usage"); - return; - } - synchronized(this) { - if(cpuUsage > targetCPUUsage) { - if(currentValue < max) - currentValue *= mul; // 5% slower per second - } else if(cpuUsage < targetCPUUsage) { - if(currentValue > min) - currentValue /= mul; // 5% faster per second - } - if(currentValue < min) currentValue = min; - if(currentValue > max) currentValue = max; - if(Logger.shouldLog(Logger.MINOR, this)) - Logger.minor(this, "CPU usage: "+cpuUsage+" target "+targetCPUUsage+" current value: "+currentValue); - } - } catch (Throwable t) { - Logger.error(this, "Caught "+t+" in "+this, t); - } - } - } -} Deleted: trunk/freenet/src/freenet/node/CPUUsageMonitor.java =================================================================== --- trunk/freenet/src/freenet/node/CPUUsageMonitor.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/node/CPUUsageMonitor.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,160 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.node; - -import java.io.BufferedReader; -import java.io.EOFException; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStreamReader; - -import freenet.support.Logger; - -/** - * @author amphibian - * - * Class to determine the current CPU usage. - */ -public class CPUUsageMonitor { - - static class TickStat { - - long user; - - long nice; - - long system; - - long spare; - - boolean reportedFailedProcOpen = false; - boolean reportedFailedProcParse = false; - - boolean read(File f) { - String firstline; - FileInputStream fis = null; - try { - fis = new FileInputStream(f); - InputStreamReader ris = new InputStreamReader(fis); - BufferedReader br = new BufferedReader(ris); - firstline = br.readLine(); - if(firstline == null) throw new EOFException(); - ris.close(); - br.close(); - } catch (IOException e) { - if(!reportedFailedProcOpen) - Logger.error(this, "Failed to open /proc/stat: "+e, e); - reportedFailedProcOpen = true; - if(fis != null) try { - fis.close(); - } catch (IOException e1) { - Logger.error(this, "Failed to close /proc/stat: "+e, e); - } - return false; - } - Logger.debug(this, "Read first line: " + firstline); - if (!firstline.startsWith("cpu")) return false; - firstline = firstline.substring("cpu".length()).trim(); - String[] split = firstline.split(" "); - - long[] numbers = new long[split.length]; - for(int i=0;i<split.length;i++) { - try { - numbers[i] = Long.parseLong(split[i]); - } catch (NumberFormatException e) { - if(!reportedFailedProcParse) - Logger.error(this, "Failed to parse /proc: "+e, e); - reportedFailedProcParse = true; - return false; - } - } - - if(split.length == 4) { - // Linux 2.4/2.2 - user = numbers[0]; - nice = numbers[1]; - system = numbers[2]; - spare = numbers[3]; - } else if(split.length == 8) { - // Linux 2.6 - // user, nice, system, idle, iowait, irq, softirq, steal - // No idea what steal is and it's 0 on my box anyway - user = numbers[0]; - system = numbers[2] + numbers[5] + numbers[6]; - nice = numbers[1]; - spare = numbers[3] + numbers[4]; - } else { - if(!reportedFailedProcParse) - Logger.error(this, "Failed to parse /proc: unrecognized number of elements: "+split.length); - reportedFailedProcParse = true; - return false; - } - Logger.debug(this, "Read from file: user " + user + " nice " + nice - + " system " + system + " spare " + spare); - return true; - } - - int calculate(TickStat old) { - long userdiff = user - old.user; - long nicediff = nice - old.nice; - long systemdiff = system - old.system; - long sparediff = spare - old.spare; - - if (userdiff + nicediff + systemdiff + sparediff <= 0) return 0; - Logger.debug(this, "User changed by " + userdiff + ", Nice: " - + nicediff + ", System: " + systemdiff + ", Spare: " - + sparediff); - int usage = (int) ((100 * (userdiff + nicediff + systemdiff)) / (userdiff - + nicediff + systemdiff + sparediff)); - Logger.debug(this, "CPU usage: " + usage); - return usage; - } - - void copyFrom(TickStat old) { - user = old.user; - nice = old.nice; - system = old.system; - spare = old.spare; - } - } - - int lastCPULoadEstimate = 0; - - long lastCPULoadEstimateTime = 0; - - File proc = File.separator.equals("/") ? new File("/proc/stat") : null; - - TickStat tsOld = new TickStat(); - - TickStat tsNew = null; - - public int getCPUUsage() { - if(File.separatorChar != '/') - return -1; - long now = System.currentTimeMillis(); - if (now - lastCPULoadEstimateTime > 1000) { - try { - lastCPULoadEstimateTime = now; - if (tsNew == null) { - tsOld.read(proc); - tsNew = new TickStat(); - } else { - if (!tsNew.read(proc)) { - if(Logger.shouldLog(Logger.MINOR, this)) - Logger.minor(this, "Failed to parse /proc"); - return -1; - } - lastCPULoadEstimate = tsNew.calculate(tsOld); - tsOld.copyFrom(tsNew); - } - } catch (Throwable t) { - lastCPULoadEstimate = -1; - Logger.normal(this, "Failed real-CPU-load estimation: " - + t, t); - } - } - return lastCPULoadEstimate; - } -} \ No newline at end of file Deleted: trunk/freenet/src/freenet/node/DSAPublicKeyDatabase.java =================================================================== --- trunk/freenet/src/freenet/node/DSAPublicKeyDatabase.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/node/DSAPublicKeyDatabase.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,20 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.node; - -import freenet.crypt.DSAPublicKey; - -/** - * Interface for a DSA public key lookup service. - */ -public interface DSAPublicKeyDatabase { - - /** - * Lookup a key by its hash. - * @param hash - * @return The key, or null. - */ - public DSAPublicKey lookupKey(byte[] hash); - -} Deleted: trunk/freenet/src/freenet/node/StaticSwapRequestInterval.java =================================================================== --- trunk/freenet/src/freenet/node/StaticSwapRequestInterval.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/node/StaticSwapRequestInterval.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,21 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.node; - -public class StaticSwapRequestInterval implements SwapRequestInterval { - - int fixedInterval; - - public StaticSwapRequestInterval(int d) { - fixedInterval = d; - } - - public int getValue() { - return fixedInterval; - } - - public void set(int val) { - this.fixedInterval = val; - } -} Deleted: trunk/freenet/src/freenet/node/SwapRequestInterval.java =================================================================== --- trunk/freenet/src/freenet/node/SwapRequestInterval.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/node/SwapRequestInterval.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,11 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.node; - -/** - * Interface to get the current swap request interval - */ -public interface SwapRequestInterval { - int getValue(); -} Deleted: trunk/freenet/src/freenet/node/updater/PrivkeyHasBeenBlownException.java =================================================================== --- trunk/freenet/src/freenet/node/updater/PrivkeyHasBeenBlownException.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/node/updater/PrivkeyHasBeenBlownException.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,16 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.node.updater; - -import freenet.support.HTMLEncoder; - -public class PrivkeyHasBeenBlownException extends Exception{ - private static final long serialVersionUID = -1; - - PrivkeyHasBeenBlownException(String msg) { - super("The project's private key has been blown, meaning that it has been compromized"+ - "and shouldn't be trusted anymore. Please get a new build by hand and verify CAREFULLY"+ - "its signature and CRC. Here is the revocation message: "+HTMLEncoder.encode(msg)); - } -} Deleted: trunk/freenet/src/freenet/node/useralerts/OpennetUserAlert.java =================================================================== --- trunk/freenet/src/freenet/node/useralerts/OpennetUserAlert.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/node/useralerts/OpennetUserAlert.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,21 +0,0 @@ -package freenet.node.useralerts; - -import freenet.l10n.L10n; -import freenet.node.Node; -import freenet.support.HTMLNode; - -public class OpennetUserAlert extends AbstractUserAlert { - - private final Node node; - - public OpennetUserAlert(Node node) { - super(true, L10n.getString("OpennetUserAlert.warningTitle"), L10n.getString("OpennetUserAlert.warning"), L10n.getString("OpennetUserAlert.warningShort"), new HTMLNode("#", L10n.getString("OpennetUserAlert.warning")), UserAlert.WARNING, true, L10n.getString("UserAlert.hide"), false, null); - this.node = node; - } - - @Override - public boolean isValid() { - return node.isOpennetEnabled() && valid; - } - -} Deleted: trunk/freenet/src/freenet/plugin/api/FreenetPlugin.java =================================================================== --- trunk/freenet/src/freenet/plugin/api/FreenetPlugin.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/plugin/api/FreenetPlugin.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,41 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.plugin.api; - -/** - * A Freenet plugin. Base interface, must be implemented by all plugins. - * Other interfaces provide for e.g. HTTP access. FreenetPluginManager provides - * access to variables, factories etc. - */ -public interface FreenetPlugin { - - /** The plugin's short name (shouldn't usually have spaces, punctuation, author etc; one to three words StuckTogetherLikeThis) */ - public String shortName(); - - /** The plugin's description or long name (can have spaces, mention author or purpose, etc) */ - public String description(); - - /** Minimum build number of host node for this plugin to function */ - public long minimumNodeVersion(); - - /** The plugin's version number. MUST BE AT LEAST INCREMENTED ON EVERY RELEASE. */ - public long version(); - - /** The plugin's internal version number e.g. SVN revision number. Plugins hosted - * by FPI will have this as SVN revision number and auto-updated. */ - public long internalVersion(); - - /** - * Start the plugin. This will run on a separate thread unless FreenetPluginThreadless is - * implemented. - * @param manager The parent FreenetPluginManager. Any variables or functions the plugin - * needs to access will be exposed by the FreenetPluginManager. - */ - public void start(FreenetPluginManager manager); - - /** - * Stop the plugin. Perform an orderly shutdown and return in a reasonable period of time. - */ - public void stop(); -} Deleted: trunk/freenet/src/freenet/plugin/api/FreenetPluginManager.java =================================================================== --- trunk/freenet/src/freenet/plugin/api/FreenetPluginManager.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/plugin/api/FreenetPluginManager.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,23 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.plugin.api; - -import java.util.Random; - -/** - * The plugin's interface to the Freenet node. - */ -public interface FreenetPluginManager { - - /** Node version */ - public long version(); - - /** Node SVN version, if known, otherwise -1 */ - public long internalVersion(); - - /** Random number generator */ - public Random random(); - - -} Deleted: trunk/freenet/src/freenet/plugin/api/NeedsConfig.java =================================================================== --- trunk/freenet/src/freenet/plugin/api/NeedsConfig.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/plugin/api/NeedsConfig.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,22 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.plugin.api; - -import freenet.support.api.BaseSubConfig; - -/** - * Indicates that the plugin wants to use (read, write) persistent config settings. These will be saved to the - * freenet.ini file under the plugin's entry. - */ -public interface NeedsConfig { - - /** - * Called by the node when loading the plugin. Allows the plugin to register persistent config settings, and - * read their current values. Note that config settings only persist if the plugin is still loaded; once it is - * unloaded, they are lost. - * @param config A BaseSubConfig object on which the plugin can register config settings. - */ - public void register(BaseSubConfig config); - -} Deleted: trunk/freenet/src/freenet/plugin/api/NeedsSimpleKeyFetch.java =================================================================== --- trunk/freenet/src/freenet/plugin/api/NeedsSimpleKeyFetch.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/plugin/api/NeedsSimpleKeyFetch.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,16 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.plugin.api; - -/** - * Indicates that the plugin requires the ability to fetch keys. - * Simple version of the interface. Once the plugin is loaded, the - * node will call register() and thus provide the means to fetch keys. - * So the plugin author will not forget to implement this interface! :) - */ -public interface NeedsSimpleKeyFetch { - - public void register(ProvidesSimpleKeyFetch fetcher); - -} Deleted: trunk/freenet/src/freenet/plugin/api/NeedsTempBuckets.java =================================================================== --- trunk/freenet/src/freenet/plugin/api/NeedsTempBuckets.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/plugin/api/NeedsTempBuckets.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,18 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.plugin.api; - -import freenet.support.api.BucketFactory; - -/** - * A plugin must implement this interface if it will need to create temporary buckets. - */ -public interface NeedsTempBuckets { - - /** How much space does the plugin require, at most? */ - public long spaceRequired(); - - public void register(BucketFactory provider); - -} Deleted: trunk/freenet/src/freenet/plugin/api/NeedsWebInterfaceGeneric.java =================================================================== --- trunk/freenet/src/freenet/plugin/api/NeedsWebInterfaceGeneric.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/plugin/api/NeedsWebInterfaceGeneric.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,31 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.plugin.api; - -import java.net.URI; - -import freenet.support.api.HTTPReply; -import freenet.support.api.HTTPRequest; - -/** - * Flexible interface for plugins to return data to the browser, of any type and of any amount. - */ -public interface NeedsWebInterfaceGeneric { - - /** - * Called when the plugin is registered. - * @param prefix The absolute path to the plugin's location on the web interface. - */ - public void onRegister(URI prefix); - - /** - * Called to ask the plugin to handle an HTTP GET request. - * @param request The request to be handled. - * @return An HTTPReply containing the data and MIME type to be returned to the browser. - */ - public HTTPReply handleGet(HTTPRequest request); - - public HTTPReply handlePost(HTTPRequest request); - -} Deleted: trunk/freenet/src/freenet/plugin/api/NeedsWebInterfaceHTMLString.java =================================================================== --- trunk/freenet/src/freenet/plugin/api/NeedsWebInterfaceHTMLString.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/plugin/api/NeedsWebInterfaceHTMLString.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,35 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.plugin.api; - -import java.net.URI; - -import freenet.support.api.HTTPRequest; - -/** - * Simple interface for plugins that only need to return a small amount of HTML to the web interface. - */ -public interface NeedsWebInterfaceHTMLString { - - /** - * Called when the plugin is registered. - * @param prefix The absolute path to the plugin's location on the web interface. - */ - public void onRegister(URI prefix); - - /** - * Handle an HTTP GET request. - * @param req The request to be handled. - * @return A String containing HTML to be returned to the browser. - */ - public String handleGet(HTTPRequest req); - - /** - * Handle an HTTP POST request. - * @param req The request to be handled. - * @return A String containing HTML to be returned to the browser. - */ - public String handlePost(HTTPRequest req); - -} Deleted: trunk/freenet/src/freenet/plugin/api/PluginFetchException.java =================================================================== --- trunk/freenet/src/freenet/plugin/api/PluginFetchException.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/plugin/api/PluginFetchException.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,12 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.plugin.api; - -/** - * Base class of exceptions thrown when a plugin fetch fails. - */ - at SuppressWarnings("serial") -public abstract class PluginFetchException extends Exception { - -} Deleted: trunk/freenet/src/freenet/plugin/api/PluginFetchResult.java =================================================================== --- trunk/freenet/src/freenet/plugin/api/PluginFetchResult.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/plugin/api/PluginFetchResult.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,22 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.plugin.api; - -import java.io.InputStream; - -public interface PluginFetchResult { - - /** MIME type of fetched data */ - public String getMIMEType(); - - /** Get an InputStream for the data */ - public InputStream getInputStream(); - - /** Get the size of the data */ - public long size(); - - /** Finished with the data, can free it */ - public void free(); - -} Deleted: trunk/freenet/src/freenet/plugin/api/PluginFreenetURI.java =================================================================== --- trunk/freenet/src/freenet/plugin/api/PluginFreenetURI.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/plugin/api/PluginFreenetURI.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,15 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.plugin.api; - -/** - * Base interface of FreenetURI. - * Provides an interface for plugins. - * Anything inside the node should use FreenetURI directly. - * Any dangerous methods should be left out of this interface. - * BaseFreenetURI's are constructed via FreenetPluginManager. - */ -public interface PluginFreenetURI { - -} Deleted: trunk/freenet/src/freenet/plugin/api/ProvidesSimpleKeyFetch.java =================================================================== --- trunk/freenet/src/freenet/plugin/api/ProvidesSimpleKeyFetch.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/plugin/api/ProvidesSimpleKeyFetch.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,14 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.plugin.api; - -/** - * Provides an interface to the client for it to fetch keys from. - * Simple version of the interface. - */ -public interface ProvidesSimpleKeyFetch { - - public PluginFetchResult fetch(PluginFreenetURI uri) throws PluginFetchException; - -} Deleted: trunk/freenet/src/freenet/plugin/api/package-info.java =================================================================== --- trunk/freenet/src/freenet/plugin/api/package-info.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/plugin/api/package-info.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,11 +0,0 @@ -/** - * Provides the API necessary to write a plugin for Freenet. Freenet plugins run in - * the same JVM as the node, but they can only access it through a limited API. All - * plugins must implement the FreenetPlugin interface, and zero or more of the - * Needs* interfaces depending on what services they require from the node. These - * interfaces indicate to the node what services are required by the plugin; the node - * may ask the user whether (s)he wants to allow the plugin to use these services. - * - * @see freenet.support.api - */ -package freenet.plugin.api; \ No newline at end of file Deleted: trunk/freenet/src/freenet/pluginmanager/FredPluginToadlet.java =================================================================== --- trunk/freenet/src/freenet/pluginmanager/FredPluginToadlet.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/pluginmanager/FredPluginToadlet.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,13 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.pluginmanager; - -/** - * Meta Interface for plugins to be well integrated in to node ui look & feel - * - * @author saces - */ -public interface FredPluginToadlet extends FredPluginHTTP, FredPluginL10n, FredPluginThemed, FredPluginVersioned { - -} Deleted: trunk/freenet/src/freenet/pluginmanager/PluginSecurityException.java =================================================================== --- trunk/freenet/src/freenet/pluginmanager/PluginSecurityException.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/pluginmanager/PluginSecurityException.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,39 +0,0 @@ -package freenet.pluginmanager; - -public class PluginSecurityException extends Exception { - private static final long serialVersionUID = -1; - - /** - * - */ - public PluginSecurityException() { - super(); - // TODO Auto-generated constructor stub - } - - /** - * @param arg0 - * @param arg1 - */ - public PluginSecurityException(String arg0, Throwable arg1) { - super(arg0, arg1); - // TODO Auto-generated constructor stub - } - - /** - * @param arg0 - */ - public PluginSecurityException(String arg0) { - super(arg0); - // TODO Auto-generated constructor stub - } - - /** - * @param arg0 - */ - public PluginSecurityException(Throwable arg0) { - super(arg0); - // TODO Auto-generated constructor stub - } - -} Deleted: trunk/freenet/src/freenet/support/DoubleTokenBucket.java =================================================================== --- trunk/freenet/src/freenet/support/DoubleTokenBucket.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/support/DoubleTokenBucket.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,56 +0,0 @@ -package freenet.support; - -/** - * A TokenBucket where forceGrab() may only use up to some proportion of the total limit. Beyond that, - * we ignore it. So the last X% may be used by blocking grabs, even if the forceGrab() traffic is over - * the limit. This is implemented by using a secondary TokenBucket to track what is allowed. - */ -public class DoubleTokenBucket extends TokenBucket { - - private static boolean logMINOR; - private final TokenBucket grabbedBytesLimiter; - private final double forceGrabLimit; - - public DoubleTokenBucket(long max, long nanosPerTick, long initialValue, double forceGrabLimit) { - super(max, nanosPerTick, initialValue); - if(forceGrabLimit > 1.0) throw new IllegalArgumentException(); - logMINOR = Logger.shouldLog(Logger.MINOR, this); - grabbedBytesLimiter = new TokenBucket((long)(max * forceGrabLimit), (long)(nanosPerTick / forceGrabLimit), (long)(initialValue * forceGrabLimit)); - this.forceGrabLimit = forceGrabLimit; - } - - @Override - public synchronized void forceGrab(long tokens) { - logMINOR = Logger.shouldLog(Logger.MINOR, this); - long maxTokens = grabbedBytesLimiter.partialInstantGrab(tokens); - if(maxTokens < tokens) { - if(logMINOR) Logger.minor(this, "Limiting forceGrab of "+tokens+" to "+maxTokens); - } - if(maxTokens > 0) - super.forceGrab(maxTokens); - } - - /** - * Change the number of nanos per tick. - * @param nanosPerTick The new number of nanos per tick. - */ - @Override - public synchronized void changeNanosPerTick(long nanosPerTick) { - super.changeNanosPerTick(nanosPerTick); - grabbedBytesLimiter.changeNanosPerTick((long)(nanosPerTick * forceGrabLimit)); - } - - @Override - public synchronized void changeBucketSize(long newMax) { - super.changeBucketSize(newMax); - grabbedBytesLimiter.changeBucketSize((long)(newMax * forceGrabLimit)); - } - - @Override - public synchronized void changeNanosAndBucketSize(long nanosPerTick, long newMax) { - super.changeNanosAndBucketSize(nanosPerTick, newMax); - grabbedBytesLimiter.changeNanosAndBucketSize((long)(nanosPerTick * forceGrabLimit), - (long)(newMax * forceGrabLimit)); - } - -} Deleted: trunk/freenet/src/freenet/support/NumberedItem.java =================================================================== --- trunk/freenet/src/freenet/support/NumberedItem.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/support/NumberedItem.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,12 +0,0 @@ -package freenet.support; - -/** - * An object with a number. - * - * @see IntNumberedItem - */ -public interface NumberedItem { - - long getNumber(); - -} Deleted: trunk/freenet/src/freenet/support/NumberedItemComparator.java =================================================================== --- trunk/freenet/src/freenet/support/NumberedItemComparator.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/support/NumberedItemComparator.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,55 +0,0 @@ -package freenet.support; - -import java.util.Comparator; - -public class NumberedItemComparator implements Comparator<Object> { - - public NumberedItemComparator(boolean wrap) { - this.wrapAround = wrap; - } - - final boolean wrapAround; - - public int compare(Object o1, Object o2) { - // Nulls at the end of the list - if((o1 == null) && (o2 == null)) - return 0; // null == null - if((o1 != null) && (o2 == null)) - return 1; // anything > null - if((o2 != null) && (o1 == null)) - return -1; - long i1, i2; - if(o1 instanceof NumberedItem) - i1 = ((NumberedItem)o1).getNumber(); - else if(o1 instanceof Long) - i1 = ((Long)o1).longValue(); - else throw new ClassCastException(o1.toString()); - if(o2 instanceof NumberedItem) - i2 = ((NumberedItem)o2).getNumber(); - else if(o2 instanceof Long) - i2 = ((Long)o2).longValue(); - else throw new ClassCastException(o2.toString()); - if(i1 == i2) return 0; - if(!wrapAround) { - if(i1 > i2) return 1; - else return -1; - } else { - long firstDistance, secondDistance; - if(i1 > i2) { - firstDistance = i1 - i2; // smaller => i1 > i2 - secondDistance = i2 + Long.MAX_VALUE - i1; // smaller => i2 > i1 - } else { - secondDistance = i2 - i1; // smaller => i2 > i1 - firstDistance = i1 + Long.MAX_VALUE - i2; // smaller => i1 > i2 - } - // REDFLAG: base must be odd, so we never get == - assert firstDistance != secondDistance && firstDistance != -secondDistance; - - if(Math.abs(firstDistance) < Math.abs(secondDistance)) { - return 1; // i1>i2 - } else //if(Math.abs(secondDistance) < Math.abs(firstDistance)) { - return -1; // i2>i1 - } - } - -} Deleted: trunk/freenet/src/freenet/support/NumberedRecentItems.java =================================================================== --- trunk/freenet/src/freenet/support/NumberedRecentItems.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/support/NumberedRecentItems.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,114 +0,0 @@ -package freenet.support; - -import java.util.Arrays; -import java.util.Comparator; - -/** - * Keep the last N NumberedItem's by number. Supports fetching - * by number, fetching all items with number greater than a - * certain value, and inserting an item with a given number. - * Any items that don't fit are dropped from the end with the - * lower numerical value. - */ -public class NumberedRecentItems { - - private NumberedItem[] items; - private int count; - private Comparator<Object> myComparator; - /** - * Create a NumberedRecentItems list. - * @param maxSize The maximum number of NumberedItems to keep. - * @param wrap If true, comparisons are modulo 2^63-1. - * We calculate the direct and wrapped distance, and use - * whichever is shorter to determine the direction. - */ - public NumberedRecentItems(int maxSize, boolean wrap) { - items = new NumberedItem[maxSize]; - count = 0; - myComparator = new NumberedItemComparator(wrap); - } - - public synchronized NumberedItem get(int num) { - int x = Arrays.binarySearch(items, num, myComparator); - if(x >= 0) return items[x]; - return null; - } - - /** - * Add an item. - * @return True if we added a new item. Must return false if - * it was already present. Also returns false if the data is - * so old that we don't want it. - */ - public synchronized boolean add(NumberedItem item) { - long num = item.getNumber(); - int x = Arrays.binarySearch(items, num, myComparator); - if(Logger.shouldLog(Logger.MINOR, this)) - Logger.minor(this, "Search pos: "+x); - if(x >= 0) return false; // already present - count++; - if(x == -1) { - // insertion point = 0 - // [0] > item - // do nothing - return false; -// if(count < items.length) { -// -// System.arraycopy(items, 0, items, 1, items.length); -// items[0] = item; -// } else { -// // [0] is greater than item, drop it -// return false; -// } - } - if(x == -(items.length)-1) { - // All items less than this item - // Shift back one, then set last item - System.arraycopy(items, 1, items, 0, items.length-1); - items[items.length-1] = item; - } else if(x == -2) { - // [1] is greater than item, [0] is less - items[0] = item; - } else { - // In the middle somewhere - int firstGreaterItem = (-x)-1; - // [firstGreaterItem]...[size-1] remain constant - // move the rest back one - System.arraycopy(items, 1, items, 0, firstGreaterItem-1); - items[firstGreaterItem-1] = item; - } - // FIXME: remove when confident - checkSorted(); - return true; - } - - private synchronized void checkSorted() { - long prevNum = -1; - for(int i=0;i<Math.min(count, items.length);i++) { - NumberedItem item = items[i]; - long num = item == null ? -1 : item.getNumber(); - if((item != null) && (num < 0)) - throw new IllegalStateException("getNumber() must return positive numbers"); - if((num < prevNum) || ((num != -1) && (num == prevNum))) { - throw new IllegalStateException("Must be higher than prev: "+num+ ' ' +prevNum); - } - prevNum = num; - } - } - - public synchronized NumberedItem[] getAfter(long target) { - int x = Arrays.binarySearch(items, target, myComparator); - if(x == items.length-1) return null; - if(x >= 0) { - NumberedItem[] out = new NumberedItem[items.length-x-1]; - System.arraycopy(items, x+1, out, 0, items.length-x-1); - return out; - } - // Otherwise is not an exact match - if(x == -items.length-1) return null; - int firstGreater = (-x)-1; - NumberedItem[] out = new NumberedItem[items.length-firstGreater]; - System.arraycopy(items, firstGreater, out, 0, items.length-firstGreater); - return out; - } -} Deleted: trunk/freenet/src/freenet/support/RandomGrabArrayWithInt.java =================================================================== --- trunk/freenet/src/freenet/support/RandomGrabArrayWithInt.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/support/RandomGrabArrayWithInt.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,18 +0,0 @@ -package freenet.support; - -import freenet.crypt.RandomSource; - -public class RandomGrabArrayWithInt extends RandomGrabArray implements IntNumberedItem { - - private final int number; - - public RandomGrabArrayWithInt(RandomSource rand, int no) { - super(rand); - number = no; - } - - public int getNumber() { - return number; - } - -} Deleted: trunk/freenet/src/freenet/support/api/BaseSubConfig.java =================================================================== --- trunk/freenet/src/freenet/support/api/BaseSubConfig.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/support/api/BaseSubConfig.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,76 +0,0 @@ -package freenet.support.api; - -import freenet.config.InvalidConfigValueException; - -public interface BaseSubConfig { - - public void register(String optionName, int defaultValue, int sortOrder, - boolean expert, boolean forceWrite, String shortDesc, - String longDesc, IntCallback cb); - - public void register(String optionName, long defaultValue, int sortOrder, - boolean expert, boolean forceWrite, String shortDesc, - String longDesc, LongCallback cb); - - public void register(String optionName, String defaultValueString, - int sortOrder, boolean expert, boolean forceWrite, - String shortDesc, String longDesc, IntCallback cb); - - public void register(String optionName, String defaultValueString, - int sortOrder, boolean expert, boolean forceWrite, - String shortDesc, String longDesc, LongCallback cb); - - public void register(String optionName, boolean defaultValue, - int sortOrder, boolean expert, boolean forceWrite, - String shortDesc, String longDesc, BooleanCallback cb); - - public void register(String optionName, String defaultValue, int sortOrder, - boolean expert, boolean forceWrite, String shortDesc, - String longDesc, StringCallback cb); - - public void register(String optionName, short defaultValue, int sortOrder, - boolean expert, boolean forceWrite, String shortDesc, - String longDesc, ShortCallback cb); - - public void register(String optionName, String[] defaultValue, - int sortOrder, boolean expert, boolean forceWrite, - String shortDesc, String longDesc, StringArrCallback cb); - - public int getInt(String optionName); - - public long getLong(String optionName); - - public boolean getBoolean(String optionName); - - public String getString(String optionName); - - public String[] getStringArr(String optionName); - - public short getShort(String optionName); - - /** - * Has the object we are attached to finished initialization? - */ - public boolean hasFinishedInitialization(); - - /** - * Called when the object we are attached to has finished init. - * After this point, the callbacks are authoritative for values of - * config variables, and will be called when values are changed by - * the user. - */ - public void finishedInitialization(); - - /** - * Force an option to be updated even if it hasn't changed. - * @throws InvalidConfigValueException - */ - public void forceUpdate(String optionName) - throws InvalidConfigValueException; - - public void set(String name, String value) - throws InvalidConfigValueException; - - public void fixOldDefault(String name, String value); - -} \ No newline at end of file Deleted: trunk/freenet/src/freenet/support/api/HTTPReply.java =================================================================== --- trunk/freenet/src/freenet/support/api/HTTPReply.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/support/api/HTTPReply.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,27 +0,0 @@ -/* This code is part of Freenet. It is distributed under the GNU General - * Public License, version 2 (or at your option any later version). See - * http://www.gnu.org/ for further details of the GPL. */ -package freenet.support.api; - -/** - * An HTTP response. - */ -public final class HTTPReply { - - private final String mimeType; - private final Bucket data; - - public HTTPReply(String mimeType, Bucket data) { - this.mimeType = mimeType; - this.data = data; - } - - public final String getMIMEType() { - return mimeType; - } - - public final Bucket getData() { - return data; - } - -} Deleted: trunk/freenet/src/freenet/support/compress/DecompressException.java =================================================================== --- trunk/freenet/src/freenet/support/compress/DecompressException.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/support/compress/DecompressException.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,12 +0,0 @@ -package freenet.support.compress; - -/** - * Exception thrown when there is a permanent failure in decompression due to e.g. a format error. - */ -public class DecompressException extends Exception { - private static final long serialVersionUID = 1L; - public DecompressException(String msg) { - super(msg); - } - -} Deleted: trunk/freenet/src/freenet/support/math/SimpleBinaryRunningAverage.java =================================================================== --- trunk/freenet/src/freenet/support/math/SimpleBinaryRunningAverage.java 2008-10-31 13:10:30 UTC (rev 23241) +++ trunk/freenet/src/freenet/support/math/SimpleBinaryRunningAverage.java 2008-10-31 13:11:35 UTC (rev 23242) @@ -1,237 +0,0 @@ -package freenet.support.math; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.BitSet; - -import freenet.support.HexUtil; -import freenet.support.Logger; - -/** - * Simple running average for binary (0.0/1.0) values. - * Keeps the last 1000 values and generates a probability of - * the next value being 1.0. - * @author amphibian - * Created on May 14, 2004 - */ -public class SimpleBinaryRunningAverage implements RunningAverage { - private static final long serialVersionUID = -1; - - @Override - public Object clone() { - return new SimpleBinaryRunningAverage(this); - } - - static final int MAGIC = 0x4281; - - final int maximumSize; - int totalZeros; - int totalOnes; - int index; - long totalReported; - final double defaultValue; - final BitSet ba; - boolean logDEBUG; - - private synchronized final int baSize() { - return Math.min((int)totalReported, maximumSize); - } - - public SimpleBinaryRunningAverage(int maxSize, double start) { - maximumSize = maxSize; - ba = new BitSet(maxSize); - totalZeros = totalOnes = index = 0; - totalReported = 0; - if((start < 0.0) || (start > 1.0)) { - Logger.error(this, "Illegal default value: "+start+" on "+this, - new Exception("debug")); - start = Math.max(1.0, Math.min(0.0, start)); - } - defaultValue = start; - logDEBUG = Logger.shouldLog(Logger.DEBUG, this); - } - - public synchronized double currentValue() { - if((totalZeros < 0) || (totalOnes < 0)) { - Logger.error(this, "Argh in currentValue(): "+this, - new Exception("debug")); - calculateTotalOnesZeros(); - } - if((totalZeros == 0) && (totalOnes == 0)) - return defaultValue; - return ((double)totalOnes) / (double)(totalZeros + totalOnes); - } - - public void report(double d) { - report(convert(d)); - } - - public void report(long d) { - report((double)d); - } - - public synchronized void report(boolean value) { - if(logDEBUG) - Logger.debug(this, "Reporting: "+value+" on "+this); - totalReported++; - if(totalReported > maximumSize) { - // Remove the value, that is to be overwritten, from the calculations - boolean valueOverwriting = ba.get(index); - if(valueOverwriting) - totalOnes--; - else - totalZeros--; - } - ba.set(index, value); - index++; - if(index >= maximumSize) index = 0; - if(value) - totalOnes++; - else - totalZeros++; - if(logDEBUG) - Logger.debug(this, "Reported: "+value+" on "+this); - if((totalZeros < 0) || (totalOnes < 0)) { - Logger.error(this, "Argh in report("+value+"): "+this, - new Exception("debug")); - calculateTotalOnesZeros(); - } - } - - // Compute what the resulting average -would be- if (value) were - // reported, WITHOUT ACTUALLY UPDATING THE STATE OF THIS OBJECT. - public double valueIfReported(boolean value) { - int to, tz; - synchronized(this) { - to = totalOnes; - tz = totalZeros; - if( (totalReported+1) > maximumSize ) { - // account for the bit that would be dropped - boolean valueOverwriting = ba.get(index); - if(valueOverwriting) - to--; - else - tz--; - } - } - if(value) - to++; - else - tz++; - return ((double)to) / (double)(tz + to); - } - - public synchronized String extraToString() { - return Integer.toString(totalZeros) + " 0s, "+ - totalOnes + " 1s, "+(totalZeros+totalOnes)+ - " total"; - } - - @Override - public synchronized String toString() { - return super.toString() + " ("+extraToString()+ ')' + - ", init="+defaultValue+", index="+index+", totalReported="+ - totalReported; - } - - public synchronized void writeDataTo(DataOutputStream out) throws IOException { - out.writeInt(MAGIC); // magic for this class - out.writeInt(1); - out.writeInt(baSize()); - out.writeInt(index); - out.writeLong(totalReported); - out.write(HexUtil.bitsToBytes(ba, baSize())); - } - - public SimpleBinaryRunningAverage(int maxSize, DataInputStream dis) throws IOException { - logDEBUG = Logger.shouldLog(Logger.DEBUG, this); - int magic = dis.readInt(); - if(magic != MAGIC) throw new IOException("Invalid magic "+magic+" should be "+MAGIC+" - format change?"); - int ver = dis.readInt(); - if(ver != 1) - throw new IOException("Invalid version: "+ver); - int size = dis.readInt(); - if(size < 0) throw new IOException("Invalid size "+size); - if(size > maxSize) throw new IOException("Too big "+size); - index = dis.readInt(); - if(index > size) throw new IOException("Invalid index"); - totalReported = dis.readLong(); - if(totalReported < 0) throw new IOException("Negative totalReported"); - if(totalReported < size) throw new IOException("Invalid totalReported: "+totalReported+", size: "+size); - ba = new BitSet(maxSize); - maximumSize = maxSize; - byte[] b = new byte[HexUtil.countBytesForBits(size)]; - dis.readFully(b); - HexUtil.bytesToBits(b, ba, size); - calculateTotalOnesZeros(); - defaultValue = 0.5; // not used - if(logDEBUG) - Logger.debug(this, "Created: "+this+" from "+dis); - } - - public SimpleBinaryRunningAverage(SimpleBinaryRunningAverage a) { - this.ba = (BitSet) a.ba.clone(); - this.defaultValue = a.defaultValue; - this.index = a.index; - this.maximumSize = a.maximumSize; - this.totalOnes = a.totalOnes; - this.totalReported = a.totalReported; - this.totalZeros = a.totalZeros; - } - - private synchronized void calculateTotalOnesZeros() { - StringBuilder sb = new StringBuilder(); - int tones = 0; - int tzeros = 0; - for(int i=0;i<baSize();i++) { - if(ba.get(i)) { - tones++; - sb.append('1'); - } else { - tzeros++; - sb.append('0'); - } - } - totalOnes = tones; - totalZeros = tzeros; - if(Logger.shouldLog(Logger.DEBUG, this)) - Logger.debug(this, "Returning: "+totalZeros+" zeros, "+totalOnes+ - " ones, binary: "+sb.toString()); - } - - protected String checkOnesZeros() { - StringBuilder sb = new StringBuilder(); - int tones = 0; - int tzeros = 0; - for(int i=0;i<baSize();i++) { - if(ba.get(i)) { - tones++; - sb.append('1'); - } else { - tzeros++; - sb.append('0'); - } - } - return "bits: " + sb.toString() + "counted " + tones + " ones and " + tzeros + " zeros"; - } - - public int getDataLength() { - return 4 + 4 + 4 + 4 + 8 + HexUtil.countBytesForBits(baSize()); - } - - public boolean convert(double d) { - if((d > 1.0) || (d < 0.0)) throw new IllegalArgumentException("invalid : "+d); - if(d > 0.9) return true; - if(d < 0.1) return false; - throw new IllegalArgumentException("not one or other extreme!"); - } - - public double valueIfReported(double d) { - return valueIfReported(convert(d)); - } - - public synchronized long countReports() { - return totalReported; - } -}
