Author: toad
Date: 2007-05-30 20:22:33 +0000 (Wed, 30 May 2007)
New Revision: 13397

Modified:
   trunk/freenet/src/freenet/io/comm/DMT.java
   trunk/freenet/src/freenet/io/xfer/BulkReceiver.java
   trunk/freenet/src/freenet/io/xfer/BulkTransmitter.java
   trunk/freenet/src/freenet/io/xfer/PartiallyReceivedBulk.java
Log:
A little more work (yes i know it's broken, 1sec)

Modified: trunk/freenet/src/freenet/io/comm/DMT.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/DMT.java  2007-05-30 19:25:57 UTC (rev 
13396)
+++ trunk/freenet/src/freenet/io/comm/DMT.java  2007-05-30 20:22:33 UTC (rev 
13397)
@@ -229,6 +229,44 @@
                return msg;
        }

+       public static final MessageType FNPBulkPacketSend = new 
MessageType("FNPBulkPacketSend") {{
+               addField(UID, Long.class);
+               addField(PACKET_NO, Integer.class);
+               addField(DATA, ShortBuffer.class);
+       }};
+       
+       public static final Message createFNPBulkPacketSend(long uid, int 
packetNo, ShortBuffer data) {
+               Message msg = new Message(FNPBulkPacketSend);
+               msg.set(UID, uid);
+               msg.set(PACKET_NO, packetNo);
+               msg.set(DATA, data);
+               return msg;
+       }
+       
+       public static final Message createFNPBulkPacketSend(long uid, int 
packetNo, byte[] data) {
+               return createFNPBulkPacketSend(uid, packetNo, new 
ShortBuffer(data));
+       }
+       
+       public static final MessageType FNPBulkSendAborted = new 
MessageType("FNPBulkSendAborted") {{
+               addField(UID, Long.class);
+       }};
+       
+       public static final Message createFNPBulkSendAborted(long uid) {
+               Message msg = new Message(FNPBulkSendAborted);
+               msg.set(UID, uid);
+               return msg;
+       }
+       
+       public static final MessageType FNPBulkReceiveAborted = new 
MessageType("FNPBulkReceiveAborted") {{
+               addField(UID, Long.class);
+       }};
+       
+       public static final Message createFNPBulkReceiveAborted(long uid) {
+               Message msg = new Message(FNPBulkReceiveAborted);
+               msg.set(UID, uid);
+               return msg;
+       }
+       
        public static final MessageType testTransferSend = new 
MessageType("testTransferSend") {{
                addField(UID, Long.class);
        }};

Modified: trunk/freenet/src/freenet/io/xfer/BulkReceiver.java
===================================================================
--- trunk/freenet/src/freenet/io/xfer/BulkReceiver.java 2007-05-30 19:25:57 UTC 
(rev 13396)
+++ trunk/freenet/src/freenet/io/xfer/BulkReceiver.java 2007-05-30 20:22:33 UTC 
(rev 13397)
@@ -25,11 +25,10 @@
                this.uid = uid;
        }

-       /**
-        * Called when the transfer fails because of a Throwable being thrown.
-        * @param t The throwable.
-        */
-       public void fail(Throwable t) {
+       public void onAborted() {
+               peer.
                // TODO Auto-generated method stub
+               
        }
+
 }

Modified: trunk/freenet/src/freenet/io/xfer/BulkTransmitter.java
===================================================================
--- trunk/freenet/src/freenet/io/xfer/BulkTransmitter.java      2007-05-30 
19:25:57 UTC (rev 13396)
+++ trunk/freenet/src/freenet/io/xfer/BulkTransmitter.java      2007-05-30 
20:22:33 UTC (rev 13397)
@@ -49,10 +49,11 @@
        }

        /**
-        * Called if the transfer fails because of a throwable.
-        * @param t The throwable causing the failure.
+        * Called when the PRB is aborted.
         */
-       void fail(Throwable t) {
-               // TODO Auto-generated method stub
+       public void onAborted() {
+               // TODO do something
        }
+
+       
 }

Modified: trunk/freenet/src/freenet/io/xfer/PartiallyReceivedBulk.java
===================================================================
--- trunk/freenet/src/freenet/io/xfer/PartiallyReceivedBulk.java        
2007-05-30 19:25:57 UTC (rev 13396)
+++ trunk/freenet/src/freenet/io/xfer/PartiallyReceivedBulk.java        
2007-05-30 20:22:33 UTC (rev 13397)
@@ -3,6 +3,7 @@
  * http://www.gnu.org/ for further details of the GPL. */
 package freenet.io.xfer;

+import freenet.io.comm.RetrievalException;
 import freenet.support.BitArray;
 import freenet.support.Logger;
 import freenet.support.io.RandomAccessThing;
@@ -27,6 +28,10 @@
        private BulkTransmitter[] transmitters;
        /** The one and only BulkReceiver */
        private BulkReceiver recv;
+       // Abort status
+       boolean _aborted;
+       int _abortReason;
+       String _abortDescription;

        /**
         * Construct a PartiallyReceivedBulk.
@@ -92,7 +97,8 @@
                        int bs = (int) Math.max(blockSize, size - fileOffset);
                        raf.pwrite(fileOffset, data, offset, bs);
                } catch (Throwable t) {
-                       fail(t);
+                       Logger.error(this, "Failed to store received block 
"+blockNum+" on "+this+" : "+t, t);
+                       abort(RetrievalException.IO_ERROR, t.toString());
                }
                if(notifyBTs == null) return;
                for(int i=0;i<notifyBTs.length;i++) {
@@ -101,21 +107,40 @@
                }
        }

-       /**
-        * Fail the transfer because of an unrecoverable exception e.g. an 
error in storing the data.
-        * @param t The throwable causing this failure.
-        */
-       private void fail(Throwable t) {
-               Logger.error(this, "Failing transfer: "+this+" : "+t, t);
+       void abort(int errCode, String why) {
                BulkTransmitter[] notifyBTs;
+               BulkReceiver notifyBR;
                synchronized(this) {
+                       _aborted = true;
+                       _abortReason = errCode;
+                       _abortDescription = why;
                        notifyBTs = transmitters;
+                       notifyBR = recv;
                }
                if(notifyBTs != null) {
-                       for(int i=0;i<notifyBTs.length;i++)
-                               notifyBTs[i].fail(t);
+                       for(int i=0;i<notifyBTs.length;i++) {
+                               notifyBTs[i].onAborted();
+                       }
                }
-               if(recv != null)
-                       recv.fail(t);
+               if(notifyBR != null)
+                       notifyBR.onAborted();
        }
+
+//     /**
+//      * Fail the transfer because of an unrecoverable exception e.g. an 
error in storing the data.
+//      * @param t The throwable causing this failure.
+//      */
+//     private void fail(Throwable t) {
+//             Logger.error(this, "Failing transfer: "+this+" : "+t, t);
+//             BulkTransmitter[] notifyBTs;
+//             synchronized(this) {
+//                     notifyBTs = transmitters;
+//             }
+//             if(notifyBTs != null) {
+//                     for(int i=0;i<notifyBTs.length;i++)
+//                             notifyBTs[i].fail(t);
+//             }
+//             if(recv != null)
+//                     recv.fail(t);
+//     }
 }


Reply via email to