Author: toad
Date: 2008-03-20 17:20:03 +0000 (Thu, 20 Mar 2008)
New Revision: 18652

Modified:
   trunk/freenet/src/freenet/node/RequestHandler.java
   trunk/freenet/src/freenet/node/SSKInsertHandler.java
Log:
Send both formats of SSK on an insert collision as well.

Modified: trunk/freenet/src/freenet/node/RequestHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/RequestHandler.java  2008-03-20 17:17:09 UTC 
(rev 18651)
+++ trunk/freenet/src/freenet/node/RequestHandler.java  2008-03-20 17:20:03 UTC 
(rev 18652)
@@ -377,6 +377,26 @@
                }
        }

+    static void sendSSK(byte[] headers, byte[] data, boolean needsPubKey, 
DSAPublicKey pubKey, final PeerNode source, long uid, ByteCounter ctr) throws 
NotConnectedException, WaitedTooLongException {
+               // SUCCESS requires that BOTH the pubkey AND the data/headers 
have been received.
+               // The pubKey will have been set on the SSK key, and the 
SSKBlock will have been constructed.
+               Message headersMsg = DMT.createFNPSSKDataFoundHeaders(uid, 
headers);
+               source.sendAsync(headersMsg, null, 0, ctr);
+               final Message dataMsg = DMT.createFNPSSKDataFoundData(uid, 
data);
+               source.sendThrottledMessage(dataMsg, 1024, ctr, 60*1000);
+               
+               if(SEND_OLD_FORMAT_SSK) {
+                       Message df = DMT.createFNPSSKDataFound(uid, headers, 
data);
+                       source.sendAsync(df, null, 0, ctr);
+                       // Not throttled, so report payload here.
+                       ctr.sentPayload(data.length);
+               }
+               if(needsPubKey) {
+                       Message pk = DMT.createFNPSSKPubKey(uid, pubKey);
+                       source.sendAsync(pk, null, 0, ctr);
+               }
+    }
+    
        /**
      * Return data from the datastore.
      * @param block The block we found in the datastore.

Modified: trunk/freenet/src/freenet/node/SSKInsertHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/SSKInsertHandler.java        2008-03-20 
17:17:09 UTC (rev 18651)
+++ trunk/freenet/src/freenet/node/SSKInsertHandler.java        2008-03-20 
17:20:03 UTC (rev 18652)
@@ -11,6 +11,7 @@
 import freenet.io.comm.Message;
 import freenet.io.comm.MessageFilter;
 import freenet.io.comm.NotConnectedException;
+import freenet.io.xfer.WaitedTooLongException;
 import freenet.keys.NodeSSK;
 import freenet.keys.SSKBlock;
 import freenet.keys.SSKVerifyException;
@@ -177,13 +178,14 @@
                SSKBlock storedBlock = node.fetch(key, false);

                if((storedBlock != null) && !storedBlock.equals(block)) {
-                       Message msg = DMT.createFNPSSKDataFound(uid, 
storedBlock.getRawHeaders(), storedBlock.getRawData());
                        try {
-                               source.sendSync(msg, this);
-                               
node.sentPayload(storedBlock.getRawData().length);
-                       } catch (NotConnectedException e) {
+                               
RequestHandler.sendSSK(storedBlock.getRawHeaders(), storedBlock.getRawData(), 
false, pubKey, source, uid, this);
+                       } catch (NotConnectedException e1) {
                                if(logMINOR) Logger.minor(this, "Lost 
connection to source on "+uid);
                                return;
+                       } catch (WaitedTooLongException e1) {
+                               Logger.error(this, "Took too long to send ssk 
datareply to "+uid);
+                               return;
                        }
                        block = storedBlock;
                }
@@ -239,14 +241,15 @@
                                        // Is verified elsewhere...
                                        throw new Error("Impossible: "+e1);
                                }
-               Message msg = DMT.createFNPSSKDataFound(uid, headers, data);
-               try {
-                       source.sendSync(msg, this);
-                               node.sentPayload(data.length);
-               } catch (NotConnectedException e) {
-                       if(logMINOR) Logger.minor(this, "Lost connection to 
source");
-                       return;
-               }
+                               try {
+                                       RequestHandler.sendSSK(headers, data, 
false, pubKey, source, uid, this);
+                               } catch (NotConnectedException e1) {
+                                       if(logMINOR) Logger.minor(this, "Lost 
connection to source on "+uid);
+                                       return;
+                               } catch (WaitedTooLongException e1) {
+                                       Logger.error(this, "Took too long to 
send ssk datareply to "+uid);
+                                       return;
+                               }
             }

             int status = sender.getStatus();


Reply via email to