Author: toad
Date: 2007-05-29 22:24:23 +0000 (Tue, 29 May 2007)
New Revision: 13394

Added:
   trunk/freenet/src/freenet/io/xfer/BulkReceiver.java
   trunk/freenet/src/freenet/io/xfer/BulkTransmitter.java
   trunk/freenet/src/freenet/io/xfer/PartiallyReceivedBulk.java
   trunk/freenet/src/freenet/support/io/RandomAccessThing.java
Modified:
   trunk/freenet/src/freenet/support/BitArray.java
Log:
Beginnings of new bulk data transfer mechanism (used for large files sent 
directly peer to peer, not individual key blocks).

Added: trunk/freenet/src/freenet/io/xfer/BulkReceiver.java
===================================================================
--- trunk/freenet/src/freenet/io/xfer/BulkReceiver.java                         
(rev 0)
+++ trunk/freenet/src/freenet/io/xfer/BulkReceiver.java 2007-05-29 22:24:23 UTC 
(rev 13394)
@@ -0,0 +1,27 @@
+/* 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.xfer;
+
+import freenet.io.comm.PeerContext;
+
+/**
+ * Bulk (not block) data transfer - receiver class. Bulk transfer is designed 
for largish files, much
+ * larger than blocks, where we have the whole file at the outset.
+ * @author toad
+ */
+public class BulkReceiver {
+       
+       /** Tracks the data we have received */
+       final PartiallyReceivedBulk prb;
+       /** Peer we are receiving from */
+       final PeerContext peer;
+       /** Transfer UID for messages */
+       final long uid;
+
+       public BulkReceiver(PartiallyReceivedBulk prb, PeerContext peer, long 
uid) {
+               this.prb = prb;
+               this.peer = peer;
+               this.uid = uid;
+       }
+}

Added: trunk/freenet/src/freenet/io/xfer/BulkTransmitter.java
===================================================================
--- trunk/freenet/src/freenet/io/xfer/BulkTransmitter.java                      
        (rev 0)
+++ trunk/freenet/src/freenet/io/xfer/BulkTransmitter.java      2007-05-29 
22:24:23 UTC (rev 13394)
@@ -0,0 +1,29 @@
+/* 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.xfer;
+
+import freenet.io.comm.PeerContext;
+
+/**
+ * Bulk data transfer (not block). Bulk transfer is designed for files which 
may be much bigger than a 
+ * key block, and where we have the whole file at the outset. 
+ * 
+ * Used by update over mandatory, sending a file to our peers attached to an 
N2NTM etc.
+ * @author toad
+ */
+public class BulkTransmitter {
+
+       /** Available blocks */
+       final PartiallyReceivedBulk prb;
+       /** Peer who we are sending the data to */
+       final PeerContext peer;
+       /** Transfer UID for messages */
+       final long uid;
+
+       public BulkTransmitter(PartiallyReceivedBulk prb, PeerContext peer, 
long uid) {
+               this.prb = prb;
+               this.peer = peer;
+               this.uid = uid;
+       }
+}

Added: trunk/freenet/src/freenet/io/xfer/PartiallyReceivedBulk.java
===================================================================
--- trunk/freenet/src/freenet/io/xfer/PartiallyReceivedBulk.java                
                (rev 0)
+++ trunk/freenet/src/freenet/io/xfer/PartiallyReceivedBulk.java        
2007-05-29 22:24:23 UTC (rev 13394)
@@ -0,0 +1,47 @@
+/* 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.xfer;
+
+import freenet.support.BitArray;
+import freenet.support.io.RandomAccessThing;
+
+/**
+ * Equivalent of PartiallyReceivedBlock, for large(ish) file transfers.
+ * As presently implemented, we keep a bitmap in RAM of blocks received, so it 
should be adequate
+ * for fairly large files (128kB for a 1GB file e.g.). We can compress this 
structure later on if
+ * need be.
+ * @author toad
+ */
+public class PartiallyReceivedBulk {
+       
+       /** The size of the data being received. Does *not* have to be a 
multiple of blockSize. */
+       final long size;
+       /** The size of the blocks sent as packets. */
+       final int blockSize;
+       final RandomAccessThing raf;
+       /** Which blocks have been received and written? */
+       final BitArray blocksReceived;
+       final int blocks;
+       
+       /**
+        * Construct a PartiallyReceivedBulk.
+        * @param size Size of the file, does not have to be a multiple of 
blockSize.
+        * @param blockSize Block size.
+        * @param raf Where to store the data.
+        * @param initialState If true, assume all blocks have been received. 
If false, assume no blocks have
+        * been received.
+        */
+       public PartiallyReceivedBulk(long size, int blockSize, 
RandomAccessThing raf, boolean initialState) {
+               this.size = size;
+               this.blockSize = blockSize;
+               this.raf = raf;
+               long blocks = size / blockSize + (size % blockSize > 0 ? 1 : 0);
+               if(blocks > Integer.MAX_VALUE)
+                       throw new IllegalArgumentException("Too big");
+               this.blocks = (int)blocks;
+               blocksReceived = new BitArray(this.blocks);
+               if(initialState)
+                       blocksReceived.setAllOnes();
+       }
+}

Modified: trunk/freenet/src/freenet/support/BitArray.java
===================================================================
--- trunk/freenet/src/freenet/support/BitArray.java     2007-05-29 19:36:38 UTC 
(rev 13393)
+++ trunk/freenet/src/freenet/support/BitArray.java     2007-05-29 22:24:23 UTC 
(rev 13394)
@@ -105,4 +105,9 @@
        public int hashCode() {
            return Fields.hashCode(_bits);
        }
+
+       public void setAllOnes() {
+               for(int i=0;i<_bits.length;i++)
+                       _bits[i] = (byte)0xFF;
+       }
 }
\ No newline at end of file

Added: trunk/freenet/src/freenet/support/io/RandomAccessThing.java
===================================================================
--- trunk/freenet/src/freenet/support/io/RandomAccessThing.java                 
        (rev 0)
+++ trunk/freenet/src/freenet/support/io/RandomAccessThing.java 2007-05-29 
22:24:23 UTC (rev 13394)
@@ -0,0 +1,20 @@
+/* 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.io;
+
+import java.io.IOException;
+
+/**
+ * Trivial random access file base interface.
+ * @author toad
+ */
+public interface RandomAccessThing {
+
+       public long size();
+       
+       public void pread(long fileOffset, byte[] buf, int bufOffset, int 
length) throws IOException;
+       
+       public void pwrite(long fileOffset, byte[] buf, int bufOffset, int 
length) throws IOException;
+       
+}


Reply via email to