Author: toad
Date: 2006-02-10 21:07:08 +0000 (Fri, 10 Feb 2006)
New Revision: 8011
Added:
trunk/freenet/src/freenet/client/events/FinishedCompressionEvent.java
trunk/freenet/src/freenet/client/events/StartedCompressionEvent.java
trunk/freenet/src/freenet/node/fcp/FinishedCompressionMessage.java
trunk/freenet/src/freenet/node/fcp/StartedCompressionMessage.java
Modified:
trunk/freenet/src/freenet/client/InserterContext.java
trunk/freenet/src/freenet/client/async/SingleFileInserter.java
trunk/freenet/src/freenet/node/Version.java
trunk/freenet/src/freenet/node/fcp/ClientPut.java
trunk/freenet/src/freenet/node/fcp/ClientPutMessage.java
trunk/freenet/src/freenet/node/fcp/NodeHelloMessage.java
Log:
439:
If verbosity & 512 == 512 (or on TMCI), tell user when we start and finish
compression on a ClientPut.
(This doubles as an ack).
Modified: trunk/freenet/src/freenet/client/InserterContext.java
===================================================================
--- trunk/freenet/src/freenet/client/InserterContext.java 2006-02-09
15:21:05 UTC (rev 8010)
+++ trunk/freenet/src/freenet/client/InserterContext.java 2006-02-10
21:07:08 UTC (rev 8011)
@@ -10,7 +10,7 @@
public final BucketFactory bf;
/** If true, don't try to compress the data */
- public final boolean dontCompress;
+ public boolean dontCompress;
public final RandomSource random;
public final short splitfileAlgorithm;
public int maxInsertRetries;
Modified: trunk/freenet/src/freenet/client/async/SingleFileInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleFileInserter.java
2006-02-09 15:21:05 UTC (rev 8010)
+++ trunk/freenet/src/freenet/client/async/SingleFileInserter.java
2006-02-10 21:07:08 UTC (rev 8011)
@@ -6,6 +6,8 @@
import freenet.client.InserterContext;
import freenet.client.InserterException;
import freenet.client.Metadata;
+import freenet.client.events.FinishedCompressionEvent;
+import freenet.client.events.StartedCompressionEvent;
import freenet.keys.CHKBlock;
import freenet.keys.ClientCHKBlock;
import freenet.keys.ClientKey;
@@ -112,6 +114,9 @@
int algos = Compressor.countCompressAlgorithms();
try {
for(int i=0;i<algos;i++) {
+ // Only produce if we are compressing
*the original data*
+ if(parent == cb)
+
ctx.eventProducer.produceEvent(new StartedCompressionEvent(i));
Compressor comp =
Compressor.getCompressionAlgorithmByDifficulty(i);
Bucket result;
result = comp.compress(origData,
ctx.bf, Long.MAX_VALUE);
@@ -142,6 +147,10 @@
}
}
+ if(parent == cb) {
+ ctx.eventProducer.produceEvent(new
FinishedCompressionEvent(bestCodec == null ? -1 :
bestCodec.codecNumberForMetadata(), origSize, data.size()));
+ }
+
// Compressed data
// Insert it...
Added: trunk/freenet/src/freenet/client/events/FinishedCompressionEvent.java
===================================================================
--- trunk/freenet/src/freenet/client/events/FinishedCompressionEvent.java
2006-02-09 15:21:05 UTC (rev 8010)
+++ trunk/freenet/src/freenet/client/events/FinishedCompressionEvent.java
2006-02-10 21:07:08 UTC (rev 8011)
@@ -0,0 +1,28 @@
+package freenet.client.events;
+
+public class FinishedCompressionEvent implements ClientEvent {
+
+ static final int code = 0x09;
+
+ /** Codec, -1 = uncompressed */
+ public final int codec;
+ /** Original size */
+ public final long originalSize;
+ /** Compressed size */
+ public final long compressedSize;
+
+ public FinishedCompressionEvent(int codec, long origSize, long
compressedSize) {
+ this.codec = codec;
+ this.originalSize = origSize;
+ this.compressedSize = compressedSize;
+ }
+
+ public String getDescription() {
+ return "Compressed data: codec="+codec+",
origSize="+originalSize+", compressedSize="+compressedSize;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+}
Added: trunk/freenet/src/freenet/client/events/StartedCompressionEvent.java
===================================================================
--- trunk/freenet/src/freenet/client/events/StartedCompressionEvent.java
2006-02-09 15:21:05 UTC (rev 8010)
+++ trunk/freenet/src/freenet/client/events/StartedCompressionEvent.java
2006-02-10 21:07:08 UTC (rev 8011)
@@ -0,0 +1,24 @@
+package freenet.client.events;
+
+/**
+ * Event indicating that we are attempting to compress the file.
+ */
+public class StartedCompressionEvent implements ClientEvent {
+
+ public final int codec;
+
+ public StartedCompressionEvent(int codec) {
+ this.codec = codec;
+ }
+
+ static final int code = 0x08;
+
+ public String getDescription() {
+ return "Started compression attempt with codec "+codec;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+}
Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-02-09 15:21:05 UTC (rev
8010)
+++ trunk/freenet/src/freenet/node/Version.java 2006-02-10 21:07:08 UTC (rev
8011)
@@ -20,7 +20,7 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- private static final int buildNumber = 438;
+ private static final int buildNumber = 439;
/** Oldest build of Fred we will talk to */
private static final int lastGoodBuild = 403;
Modified: trunk/freenet/src/freenet/node/fcp/ClientPut.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientPut.java 2006-02-09 15:21:05 UTC
(rev 8010)
+++ trunk/freenet/src/freenet/node/fcp/ClientPut.java 2006-02-10 21:07:08 UTC
(rev 8011)
@@ -12,8 +12,10 @@
import freenet.client.async.ClientPutter;
import freenet.client.events.ClientEvent;
import freenet.client.events.ClientEventListener;
+import freenet.client.events.FinishedCompressionEvent;
import freenet.client.events.SimpleEventProducer;
import freenet.client.events.SplitfileProgressEvent;
+import freenet.client.events.StartedCompressionEvent;
import freenet.keys.FreenetURI;
public class ClientPut extends ClientRequest implements ClientCallback,
ClientEventListener {
@@ -31,6 +33,7 @@
// Verbosity bitmasks
private int VERBOSITY_SPLITFILE_PROGRESS = 1;
+ private int VERBOSITY_COMPRESSION_START_END = 512;
public ClientPut(FCPConnectionHandler handler, ClientPutMessage
message) {
this.verbosity = message.verbosity;
@@ -39,6 +42,8 @@
this.getCHKOnly = message.getCHKOnly;
this.priorityClass = message.priorityClass;
ctx = new InserterContext(handler.defaultInsertContext, new
SimpleEventProducer());
+ if(message.dontCompress)
+ ctx.dontCompress = true;
ctx.eventProducer.addEventListener(this);
ctx.maxInsertRetries = message.maxRetries;
// Now go through the fields one at a time
@@ -87,12 +92,25 @@
public void receive(ClientEvent ce) {
if(finished) return;
- if(!(((verbosity & VERBOSITY_SPLITFILE_PROGRESS) ==
VERBOSITY_SPLITFILE_PROGRESS) &&
- (ce instanceof SplitfileProgressEvent)))
- return;
- SimpleProgressMessage progress =
- new SimpleProgressMessage(identifier,
(SplitfileProgressEvent)ce);
- handler.outputHandler.queue(progress);
+ if(ce instanceof SplitfileProgressEvent) {
+ if((verbosity & VERBOSITY_SPLITFILE_PROGRESS) ==
VERBOSITY_SPLITFILE_PROGRESS) {
+ SimpleProgressMessage progress =
+ new SimpleProgressMessage(identifier,
(SplitfileProgressEvent)ce);
+ handler.outputHandler.queue(progress);
+ }
+ } else if(ce instanceof StartedCompressionEvent) {
+ if((verbosity & VERBOSITY_COMPRESSION_START_END) ==
VERBOSITY_COMPRESSION_START_END) {
+ StartedCompressionMessage msg =
+ new
StartedCompressionMessage(identifier, ((StartedCompressionEvent)ce).codec);
+ handler.outputHandler.queue(msg);
+ }
+ } else if(ce instanceof FinishedCompressionEvent) {
+ if((verbosity & VERBOSITY_COMPRESSION_START_END) ==
VERBOSITY_COMPRESSION_START_END) {
+ FinishedCompressionMessage msg =
+ new
FinishedCompressionMessage(identifier, (FinishedCompressionEvent)ce);
+ handler.outputHandler.queue(msg);
+ }
+ }
}
}
Modified: trunk/freenet/src/freenet/node/fcp/ClientPutMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientPutMessage.java 2006-02-09
15:21:05 UTC (rev 8010)
+++ trunk/freenet/src/freenet/node/fcp/ClientPutMessage.java 2006-02-10
21:07:08 UTC (rev 8011)
@@ -41,6 +41,7 @@
final boolean getCHKOnly;
final short priorityClass;
final boolean fromDisk;
+ final boolean dontCompress;
public ClientPutMessage(SimpleFieldSet fs) throws
MessageInvalidException {
identifier = fs.get("Identifier");
@@ -113,6 +114,7 @@
throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing DataLength field: "+e.getMessage(), identifier);
}
}
+ dontCompress = Boolean.getBoolean(fs.get("DontCompress"));
}
public SimpleFieldSet getFieldSet() {
Added: trunk/freenet/src/freenet/node/fcp/FinishedCompressionMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/FinishedCompressionMessage.java
2006-02-09 15:21:05 UTC (rev 8010)
+++ trunk/freenet/src/freenet/node/fcp/FinishedCompressionMessage.java
2006-02-10 21:07:08 UTC (rev 8011)
@@ -0,0 +1,38 @@
+package freenet.node.fcp;
+
+import freenet.client.events.FinishedCompressionEvent;
+import freenet.node.Node;
+import freenet.support.SimpleFieldSet;
+
+public class FinishedCompressionMessage extends FCPMessage {
+
+ final String identifier;
+ final int codec;
+ final long origSize;
+ final long compressedSize;
+
+ public FinishedCompressionMessage(String identifier,
FinishedCompressionEvent event) {
+ this.identifier = identifier;
+ this.codec = event.codec;
+ this.compressedSize = event.compressedSize;
+ this.origSize = event.originalSize;
+ }
+
+ public SimpleFieldSet getFieldSet() {
+ SimpleFieldSet fs = new SimpleFieldSet();
+ fs.put("Identifier", identifier);
+ fs.put("Codec", Integer.toString(codec));
+ fs.put("OriginalSize", Long.toString(origSize));
+ fs.put("CompressedSize", Long.toString(compressedSize));
+ return fs;
+ }
+
+ public String getName() {
+ return "FinishedCompression";
+ }
+
+ public void run(FCPConnectionHandler handler, Node node) throws
MessageInvalidException {
+ throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE,
"FinishedCompression goes from server to client not the other way around",
identifier);
+ }
+
+}
Modified: trunk/freenet/src/freenet/node/fcp/NodeHelloMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/NodeHelloMessage.java 2006-02-09
15:21:05 UTC (rev 8010)
+++ trunk/freenet/src/freenet/node/fcp/NodeHelloMessage.java 2006-02-10
21:07:08 UTC (rev 8011)
@@ -3,6 +3,7 @@
import freenet.node.Node;
import freenet.node.Version;
import freenet.support.SimpleFieldSet;
+import freenet.support.compress.Compressor;
/**
* NodeHello
@@ -28,6 +29,7 @@
sfs.put("Node", "Fred");
sfs.put("Version", Version.getVersionString());
sfs.put("Testnet", Boolean.toString(node.isTestnetEnabled()));
+ sfs.put("CompressionCodecs",
Integer.toString(Compressor.countCompressAlgorithms()));
return sfs;
}
Added: trunk/freenet/src/freenet/node/fcp/StartedCompressionMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/StartedCompressionMessage.java
2006-02-09 15:21:05 UTC (rev 8010)
+++ trunk/freenet/src/freenet/node/fcp/StartedCompressionMessage.java
2006-02-10 21:07:08 UTC (rev 8011)
@@ -0,0 +1,33 @@
+package freenet.node.fcp;
+
+import freenet.node.Node;
+import freenet.support.SimpleFieldSet;
+
+public class StartedCompressionMessage extends FCPMessage {
+
+ final String identifier;
+
+ final int codec;
+
+ public StartedCompressionMessage(String identifier, int codec) {
+ this.identifier = identifier;
+ this.codec = codec;
+ }
+
+ public SimpleFieldSet getFieldSet() {
+ SimpleFieldSet fs = new SimpleFieldSet();
+ fs.put("Identifier", identifier);
+ fs.put("Codec", Integer.toString(codec));
+ return fs;
+ }
+
+ public String getName() {
+ return "StartedCompression";
+ }
+
+ public void run(FCPConnectionHandler handler, Node node)
+ throws MessageInvalidException {
+ throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE,
"StartedCompression goes from server to client not the other way around",
identifier);
+ }
+
+}