this si an updated version of the static stream propagation patch. to recap, when it finds a staticly inserted stream rather than a live one (detected by the rpesense of 'EndChunk'), it will randomly grab later parts of the stream early in order to assist in propagation of those poarts of teh stream, based on a user specified probability (default 10% of requests).
i honestly forget what i changed since the last revcision of this patch, but at the very least it compiles against cvs again (thanks for removing the symbol i was using, pascal :-p hehe) -jj -- I probably hate you.
Index: src/freenet/client/http/StreamServlet.java =================================================================== RCS file: /cvsroot/freenet/freenet/src/freenet/client/http/StreamServlet.java,v retrieving revision 1.7 diff -u -3 -p -u -r1.7 StreamServlet.java --- src/freenet/client/http/StreamServlet.java 26 Jun 2003 03:48:28 -0000 1.7 +++ src/freenet/client/http/StreamServlet.java 28 Jun 2003 04:57:16 -0000 @@ -193,6 +193,7 @@ public class StreamServlet extends Fprox pw.println("<tr><td>Source: </td><td><input size=50 name=\"uri\"></td></tr>"); pw.println("<tr><td>Hops To Live: </td><td><input size=50 name=\"htl\" value=10></td></tr>"); pw.println("<tr><td>Buffer Size: </td><td><input size=50 name=\"buffer\" value=5></td></tr>"); + pw.println("<tr><td>Prefetch Probability: </td><td><input size=3 name=\"pprob\" value=10></td></tr>"); pw.println("<tr><td colspan=2><input type=\"submit\"></td></tr>"); pw.println("</table>"); pw.println("</form>"); @@ -293,6 +294,20 @@ public class StreamServlet extends Fprox logger.log(this, "HTL: "+myHtl, logger.DEBUG); + // Precache Probability is the probability that it will fetch a + // random chunk between here and endChunk rather than the next required chunk! + // + // 10% seems like a reasonable value to me, but we need to tune this. + int myPprob=10; + String requestPprob=req.getParameter("pprob"); + if(requestPprob!=null) + { + try { + myPprob=Integer.parseInt(requestPprob); + } + catch (Exception e) {} + } + // Welcome to 'I hate you' theatre, with your // host, dj fish! ///*File*/Bucket metadata = bucketFactory.makeBucket(-1); @@ -346,6 +361,7 @@ public class StreamServlet extends Fprox // don't you love these big try/catch waterfalls, it's so much nicer // than Integer,parseInt behaving sanely, yes. long myStartChunk = sp.startChunk; + long myEndChunk = sp.endChunk; int chunkSeconds = sp.chunkSeconds; if(chunkSeconds > 0) { @@ -384,10 +400,13 @@ public class StreamServlet extends Fprox // fill the head of the queue long currentChunk=myStartChunk; + long blocksBetweenPrefetch=100/myPprob; + long numpi=0; + Random notVeryRandom=new Random(); // get the ASF or other encapsulation format header if it exists (as key 0) if(headerKey) { - requestBuffer.add(new StreamChunkRequestor(myUri, 0, fecType, fecn, feck, fecbitch, htlStep)); + requestBuffer.add(new StreamChunkRequestor(myUri, 0, fecType, fecn, feck, fecbitch, htlStep, false)); if(currentChunk==0) currentChunk++; } @@ -400,12 +419,52 @@ public class StreamServlet extends Fprox // check if we need another block while(requestBuffer.size()<queueLength && !failedBlock) { - requestBuffer.add(new StreamChunkRequestor(myUri, currentChunk, fecType, fecn, feck, fecbitch, htlStep)); - currentChunk++; + long nextChunk= -1; + boolean throwaway=false; + if(myEndChunk>0) { + // are we on the final chunk? + // set a flag to make this all end! + if(currentChunk==myEndChunk) { + failedBlock=true; + nextChunk=currentChunk; + currentChunk++; + } else { + // check if we need to prefetch, and fetch a + // throwaway block if we do + if(numpi>=blocksBetweenPrefetch) { + numpi=0; + throwaway=true; + int s=(int)(myEndChunk-currentChunk); + // nextInt(s) isn't allowed in java 1.1 + // anyhow, this doesn't need to be very random + // just quick and dirty - don't ever do this! + int fromHere=notVeryRandom.nextInt(30); + fromHere%=s; + nextChunk=currentChunk+fromHere; + } else { + // otherwise, just get the next block as normal, + // and increase numpi + nextChunk=currentChunk; + currentChunk++; + numpi++; + } + } + } else { + // always use the retrieve the next chunk if + // the stream is live + nextChunk=currentChunk; + currentChunk++; + } + // sanity check of the above code + if(nextChunk >= 0) + requestBuffer.add(new StreamChunkRequestor(myUri, nextChunk, fecType, fecn, feck, fecbitch, htlStep, throwaway)); + else + logger.log(this, "Big scary monsters when adding to buffer!", Logger.ERROR); } if( !((StreamChunkRequestor)requestBuffer.getFirst()).inProgress && - !((StreamChunkRequestor)requestBuffer.getFirst()).success) + !((StreamChunkRequestor)requestBuffer.getFirst()).success && + !((StreamChunkRequestor)requestBuffer.getFirst()).throwaway) { // All hail the great and powerful Angry Monkey return; @@ -426,10 +485,13 @@ public class StreamServlet extends Fprox { if(j.success) { - outputBuffer.add(j); - l.remove(); - logger.log(this, "Adding chunk #"+myUri+" to outputBuffer", + if(!j.throwaway) + { + outputBuffer.add(j); + logger.log(this, "Adding chunk #"+myUri+" to outputBuffer", logger.DEBUG); + } + l.remove(); } else { logger.log(this, "Chunk #"+myUri+ " failed, not adding to outputBuffer", @@ -626,6 +688,7 @@ public class StreamServlet extends Fprox { public boolean success; public boolean inProgress; + public boolean throwaway; FreenetURI myUri; long myChunk; String fecType; @@ -638,7 +701,7 @@ public class StreamServlet extends Fprox // welcome to iFreenet! StreamChunkRequestor(FreenetURI iUri, long iChunk, String ifecType, int ifecn, - int ifeck, FECCode ifecbitch, int iHtlStep) throws IOException { + int ifeck, FECCode ifecbitch, int iHtlStep, boolean ithrowaway) throws IOException { success=false; inProgress=false; @@ -649,6 +712,7 @@ public class StreamServlet extends Fprox feck=ifeck; fecbitch=ifecbitch; htlStep=iHtlStep; + throwaway=ithrowaway; restart();
pgp00000.pgp
Description: PGP signature