Author: toad
Date: 2007-10-25 00:28:20 +0000 (Thu, 25 Oct 2007)
New Revision: 15552

Added:
   trunk/freenet/src/freenet/support/io/ByteArrayRandomAccessThing.java
Modified:
   trunk/freenet/src/freenet/io/comm/NotConnectedException.java
   trunk/freenet/src/freenet/node/OpennetManager.java
Log:
Send noderef, padded, in a bulk transfer, using the parent request's UID.
After the next mandatory, we will receive this, for now, we just send it and 
don't wait for an acknowledgement.
Yes this will temporarily result in lost messages. Only way to get back 
compatibility.

Modified: trunk/freenet/src/freenet/io/comm/NotConnectedException.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/NotConnectedException.java        
2007-10-25 00:09:40 UTC (rev 15551)
+++ trunk/freenet/src/freenet/io/comm/NotConnectedException.java        
2007-10-25 00:28:20 UTC (rev 15552)
@@ -19,4 +19,9 @@
         super();
     }

+       public NotConnectedException(DisconnectedException e) {
+               super(e.toString());
+               initCause(e);
+       }
+
 }

Modified: trunk/freenet/src/freenet/node/OpennetManager.java
===================================================================
--- trunk/freenet/src/freenet/node/OpennetManager.java  2007-10-25 00:09:40 UTC 
(rev 15551)
+++ trunk/freenet/src/freenet/node/OpennetManager.java  2007-10-25 00:28:20 UTC 
(rev 15552)
@@ -17,15 +17,19 @@

 import freenet.io.comm.ByteCounter;
 import freenet.io.comm.DMT;
+import freenet.io.comm.DisconnectedException;
 import freenet.io.comm.Message;
 import freenet.io.comm.NotConnectedException;
 import freenet.io.comm.Peer;
 import freenet.io.comm.PeerParseException;
 import freenet.io.comm.ReferenceSignatureVerificationException;
+import freenet.io.xfer.BulkTransmitter;
+import freenet.io.xfer.PartiallyReceivedBulk;
 import freenet.support.LRUQueue;
 import freenet.support.Logger;
 import freenet.support.ShortBuffer;
 import freenet.support.SimpleFieldSet;
+import freenet.support.io.ByteArrayRandomAccessThing;
 import freenet.support.transport.ip.HostnameSyntaxException;

 /**
@@ -77,6 +81,8 @@
        static final int MIN_TIME_BETWEEN_OFFERS = 30*1000;
        private static boolean logMINOR;

+       static final int PADDED_NODEREF_SIZE = 2048;
+       
        public OpennetManager(Node node, NodeCryptoConfig opennetConfig) throws 
NodeInitException {
                logMINOR = Logger.shouldLog(Logger.MINOR, this);
                this.node = node;
@@ -465,7 +471,28 @@
                ShortBuffer buf = new ShortBuffer(noderef);
                Message msg = isReply ? DMT.createFNPOpennetConnectReply(uid, 
buf) : 
                        DMT.createFNPOpennetConnectDestination(uid, buf);
+               byte[] padded = new byte[PADDED_NODEREF_SIZE];
+               if(noderef.length < padded.length) {
+                       Logger.error(this, "Noderef too big: "+noderef.length+" 
bytes");
+                       if(!isReply) {
+                               msg = DMT.createFNPOpennetCompletedAck(uid);
+                               peer.sendAsync(msg, null, 0, ctr);
+                       }
+                       return;
+               }
+               System.arraycopy(noderef, 0, padded, 0, noderef.length);
                peer.sendAsync(msg, null, 0, ctr);
+               ByteArrayRandomAccessThing raf = new 
ByteArrayRandomAccessThing(padded);
+               raf.setReadOnly();
+               PartiallyReceivedBulk prb =
+                       new PartiallyReceivedBulk(node.usm, padded.length, 
Node.PACKET_SIZE, raf, true);
+               try {
+                       BulkTransmitter bt =
+                               new BulkTransmitter(prb, peer, uid, 
node.outputThrottle, true);
+                       bt.send();
+               } catch (DisconnectedException e) {
+                       throw new NotConnectedException(e);
+               }
        }

 }

Added: trunk/freenet/src/freenet/support/io/ByteArrayRandomAccessThing.java
===================================================================
--- trunk/freenet/src/freenet/support/io/ByteArrayRandomAccessThing.java        
                        (rev 0)
+++ trunk/freenet/src/freenet/support/io/ByteArrayRandomAccessThing.java        
2007-10-25 00:28:20 UTC (rev 15552)
@@ -0,0 +1,41 @@
+package freenet.support.io;
+
+import java.io.IOException;
+
+
+public class ByteArrayRandomAccessThing implements RandomAccessThing {
+
+       private final byte[] data;
+       private boolean readOnly;
+       
+       public ByteArrayRandomAccessThing(byte[] padded) {
+               this.data = padded;
+       }
+
+       public void close() {
+               // Do nothing
+       }
+
+       public void pread(long fileOffset, byte[] buf, int bufOffset, int 
length)
+                       throws IOException {
+               if(fileOffset < 0) throw new IOException("Cannot read before 
zero");
+               if(fileOffset + length > data.length) throw new 
IOException("Cannot read after end: trying to read from "+fileOffset+" to 
"+(fileOffset+length)+" on block length "+data.length);
+               System.arraycopy(data, (int)fileOffset, buf, bufOffset, length);
+       }
+
+       public void pwrite(long fileOffset, byte[] buf, int bufOffset, int 
length)
+                       throws IOException {
+               if(fileOffset < 0) throw new IOException("Cannot write before 
zero");
+               if(fileOffset + length > data.length) throw new 
IOException("Cannot write after end: trying to write from "+fileOffset+" to 
"+(fileOffset+length)+" on block length "+data.length);
+               if(readOnly) throw new IOException("Read-only");
+               System.arraycopy(buf, bufOffset, data, (int)fileOffset, length);
+       }
+
+       public long size() throws IOException {
+               return data.length;
+       }
+
+       public void setReadOnly() {
+               readOnly = true;
+       }
+}


Reply via email to