Hello,

the attached patch adds an URI field to SimpleProgress messages which reports
the CHK of the just inserted block. Does nothing for fetch requests.

This is potentially useful for filesharing programs, which could communicate
these blocks to downloaders allowing them to prefetch these blocks before the
insertion has completed.

This should encourage filesharing devs to reuse the insertion framework of the
node, instead of developing ad-hoc solutions (like freemulet does).

Here follows a sample client/node messages with the patch applied (against
r19348)

Node -> Client: SimpleProgress
Node -> Client: Required=6
Node -> Client: Failed=0
Node -> Client: FatallyFailed=0
Node -> Client: Identifier=AdaFN-997468889-598983000-onhvvzvhbozlrgczrhsh
Node -> Client: Succeeded=5
Node -> Client: FinalizedTotal=false
Node -> Client:
[EMAIL PROTECTED],dh0stUU9JBAh-qJpy4krFaBlHRuhe8kPr5Q2Mbpc~NM,AAIA--8
Node -> Client: Total=6
Node -> Client: EndMessage

Node -> Client: SimpleProgress
Node -> Client: Required=6
Node -> Client: Failed=0
Node -> Client: FatallyFailed=0
Node -> Client: Identifier=AdaFN-997468889-598983000-onhvvzvhbozlrgczrhsh
Node -> Client: Succeeded=6
Node -> Client: FinalizedTotal=false
Node -> Client:
[EMAIL PROTECTED],YT59aVmwkt26LZ4zNU9YVq5cJwo7l8JwAoa6jC6Oy6A,AAIA--8
Node -> Client: Total=6
Node -> Client: EndMessage

Node -> Client: URIGenerated
Node -> Client: Identifier=AdaFN-997468889-598983000-onhvvzvhbozlrgczrhsh
Node -> Client:
[EMAIL PROTECTED],6wj05kvrZMGtQSsCCtAV3eGB8TGzQ3196la2lSSMvog,AAIC--8
Node -> Client: EndMessage
Index: src/freenet/node/fcp/SimpleProgressMessage.java
===================================================================
--- src/freenet/node/fcp/SimpleProgressMessage.java	(revision 19348)
+++ src/freenet/node/fcp/SimpleProgressMessage.java	(working copy)
@@ -29,6 +29,8 @@
 		fs.put("FinalizedTotal", event.finalizedTotal);
 		fs.putSingle("Identifier", ident);
 		if(global) fs.putSingle("Global", "true");
+		if (event.URI != null)
+			fs.putSingle("URI", event.URI.toString());
 		return fs;
 	}
 
Index: src/freenet/client/events/SplitfileProgressEvent.java
===================================================================
--- src/freenet/client/events/SplitfileProgressEvent.java	(revision 19348)
+++ src/freenet/client/events/SplitfileProgressEvent.java	(working copy)
@@ -3,6 +3,7 @@
  * http://www.gnu.org/ for further details of the GPL. */
 package freenet.client.events;
 
+import freenet.keys.FreenetURI;
 import freenet.support.Logger;
 
 public class SplitfileProgressEvent implements ClientEvent {
@@ -15,15 +16,18 @@
 	public final int fatallyFailedBlocks;
 	public int minSuccessfulBlocks;
 	public final boolean finalizedTotal;
+	public final FreenetURI URI;
 	
 	public SplitfileProgressEvent(int totalBlocks, int fetchedBlocks, int failedBlocks, 
-			int fatallyFailedBlocks, int minSuccessfulBlocks, boolean finalizedTotal) {
+			int fatallyFailedBlocks, int minSuccessfulBlocks, boolean finalizedTotal,
+			FreenetURI URI) {
 		this.totalBlocks = totalBlocks;
 		this.fetchedBlocks = fetchedBlocks;
 		this.failedBlocks = failedBlocks;
 		this.fatallyFailedBlocks = fatallyFailedBlocks;
 		this.minSuccessfulBlocks = minSuccessfulBlocks;
 		this.finalizedTotal = finalizedTotal;
+		this.URI            = URI;
 		if(Logger.shouldLog(Logger.MINOR, this))
 			Logger.minor(this, "Created SplitfileProgressEvent: total="+totalBlocks+" fetched="+fetchedBlocks+" failed="+failedBlocks+" fatally="+fatallyFailedBlocks+" min success="+minSuccessfulBlocks+" finalized="+finalizedTotal);
 	}
Index: src/freenet/client/async/ClientGetter.java
===================================================================
--- src/freenet/client/async/ClientGetter.java	(revision 19348)
+++ src/freenet/client/async/ClientGetter.java	(working copy)
@@ -240,7 +240,7 @@
 	}
 
 	public void notifyClients() {
-		ctx.eventProducer.produceEvent(new SplitfileProgressEvent(this.totalBlocks, this.successfulBlocks, this.failedBlocks, this.fatallyFailedBlocks, this.minSuccessBlocks, this.blockSetFinalized));
+		ctx.eventProducer.produceEvent(new SplitfileProgressEvent(this.totalBlocks, this.successfulBlocks, this.failedBlocks, this.fatallyFailedBlocks, this.minSuccessBlocks, this.blockSetFinalized, null));
 	}
 
 	public void onBlockSetFinished(ClientGetState state) {
Index: src/freenet/client/async/SingleBlockInserter.java
===================================================================
--- src/freenet/client/async/SingleBlockInserter.java	(revision 19348)
+++ src/freenet/client/async/SingleBlockInserter.java	(working copy)
@@ -263,7 +263,7 @@
 		synchronized(this) {
 			finished = true;
 		}
-		parent.completedBlock(false);
+		parent.completedBlock(false, getURI());
 		cb.onSuccess(this);
 	}
 
Index: src/freenet/client/async/ClientRequester.java
===================================================================
--- src/freenet/client/async/ClientRequester.java	(revision 19348)
+++ src/freenet/client/async/ClientRequester.java	(working copy)
@@ -89,13 +89,17 @@
 	}
 
 	public void completedBlock(boolean dontNotify) {
+		completedBlock(dontNotify, null);
+	}
+	
+	public void completedBlock(boolean dontNotify, FreenetURI URI) {
 		if(Logger.shouldLog(Logger.MINOR, this))
 			Logger.minor(this, "Completed block ("+dontNotify+ "): total="+totalBlocks+" success="+successfulBlocks+" failed="+failedBlocks+" fatally="+fatallyFailedBlocks+" finalised="+blockSetFinalized+" required="+minSuccessBlocks+" on "+this);
 		synchronized(this) {
 			successfulBlocks++;
 			if(dontNotify) return;
 		}
-		notifyClients();
+		notifyClients(URI);
 	}
 
 	public void failedBlock() {
@@ -118,6 +122,10 @@
 	}
 
 	public abstract void notifyClients();
+	
+	public void notifyClients(FreenetURI URI) {
+		notifyClients();
+	}
 
 	/** Get client context object */
 	public Object getClient() {
Index: src/freenet/client/async/ClientPutter.java
===================================================================
--- src/freenet/client/async/ClientPutter.java	(revision 19348)
+++ src/freenet/client/async/ClientPutter.java	(working copy)
@@ -240,9 +240,13 @@
 	}
 	
 	public void notifyClients() {
-		ctx.eventProducer.produceEvent(new SplitfileProgressEvent(this.totalBlocks, this.successfulBlocks, this.failedBlocks, this.fatallyFailedBlocks, this.minSuccessBlocks, this.blockSetFinalized));
+		ctx.eventProducer.produceEvent(new SplitfileProgressEvent(this.totalBlocks, this.successfulBlocks, this.failedBlocks, this.fatallyFailedBlocks, this.minSuccessBlocks, this.blockSetFinalized, null));
 	}
 	
+	public void notifyClients(FreenetURI URI) {
+		ctx.eventProducer.produceEvent(new SplitfileProgressEvent(this.totalBlocks, this.successfulBlocks, this.failedBlocks, this.fatallyFailedBlocks, this.minSuccessBlocks, this.blockSetFinalized, URI));
+	}
+	
 	public void onBlockSetFinished(ClientPutState state) {
 		if(Logger.shouldLog(Logger.MINOR, this))
 			Logger.minor(this, "Set finished", new Exception("debug"));
Index: src/freenet/client/async/SimpleManifestPutter.java
===================================================================
--- src/freenet/client/async/SimpleManifestPutter.java	(revision 19348)
+++ src/freenet/client/async/SimpleManifestPutter.java	(working copy)
@@ -608,7 +608,7 @@
 	}
 
 	public void notifyClients() {
-		ctx.eventProducer.produceEvent(new SplitfileProgressEvent(this.totalBlocks, this.successfulBlocks, this.failedBlocks, this.fatallyFailedBlocks, this.minSuccessBlocks, this.blockSetFinalized));
+		ctx.eventProducer.produceEvent(new SplitfileProgressEvent(this.totalBlocks, this.successfulBlocks, this.failedBlocks, this.fatallyFailedBlocks, this.minSuccessBlocks, this.blockSetFinalized, getURI()));
 	}
 
 	public void onBlockSetFinished(ClientPutState state) {

_______________________________________________
Devl mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/devl

Reply via email to