Update of /cvsroot/freenet/freenet/src/freenet/node/states/request
In directory sc8-pr-cvs1:/tmp/cvs-serv11480/src/freenet/node/states/request

Modified Files:
      Tag: ngrouting
        AwaitingInsert.java DataPending.java InsertPending.java 
        Pending.java ReceivingInsert.java ReceivingReply.java 
        RequestState.java SendingReply.java TransferInsert.java 
        TransferInsertPending.java TransferReply.java 
Log Message:
Build 7046:
Main objectives of this build are to improve routing success stats, fix deadlocks and 
fix RNFs.
Major ASL bugfix: fix race that could lead to connections getting closed without the 
client being notified.
MAJOR *SL work: Zab fixed some *SL deadlocks.
Change logging of success/failure of Routing, to take into account whether or not the 
failure was apparently caused by routing. Add new diagnostic vars 
requestFailureRoutingOrNotRatio, routingSuccessRatio. Change and consolidate 
terminate() calls all over request/. Minor changes all over states/request: Set 
insertReplyTime *before* sending it on, comment out logFailure*/logSuccess, update 
comments, logging, move *Time assignment after fromLastPeer check in 
receivedQueryRestarted (conceivably exploitable to bias stats), make backtracking 
QueryRejected async in Pending, make sure IOExceptions from the store are treated 
differently to IOExceptions from the network (which are like DNVs) in 
Pending.received(,DataReply), consolidate routes.terminate() calls into a function on 
RequestState, improve some toString()s, change exactly where we terminate the routing 
some places. Reindenting, code restyling


Index: AwaitingInsert.java
===================================================================
RCS file: 
/cvsroot/freenet/freenet/src/freenet/node/states/request/AwaitingInsert.java,v
retrieving revision 1.6
retrieving revision 1.6.6.1
diff -u -r1.6 -r1.6.6.1
--- AwaitingInsert.java 18 Nov 2002 22:07:43 -0000      1.6
+++ AwaitingInsert.java 29 Aug 2003 18:58:06 -0000      1.6.6.1
@@ -34,7 +34,7 @@
         if(ni != null) ni.cancel();
         fail(n, "State lost while waiting for your DataInsert");
     }
-
+    
     public State receivedMessage(Node n, DataInsert dim) throws StateException {
         if (!fromOrigPeer(dim)) {
             throw new BadStateException("DataInsert from the wrong peer!");
@@ -42,25 +42,23 @@
         if(ni != null) ni.cancel();
         try {
             receivingData = dim.cacheData(n, searchKey);
-        }
-        catch (KeyCollisionException e) {
+        } catch (KeyCollisionException e) {
             // we've already sent the Accepted so we should try..
             dim.eatData(n);
             
             scheduleRestart(n, 0);
             // this bloody well ought to work
             return new DataPending(this);
-        }
-        catch (IOException e) {
+        } catch (IOException e) {
             fail(n, "I/O error receiving insert");
             n.logger.log(this, "Failed to cache insert on chain " 
-                               + Long.toHexString(id), e, Logger.ERROR);
+                        + Long.toHexString(id), e, Logger.ERROR);
             return new RequestDone(this);
         }
         receivingData.schedule(n);
         return new ReceivingInsert(this);
     }
-
+    
     public State receivedMessage(Node n, NoInsert ni) throws StateException {
         if (this.ni != ni) {
             throw new BadStateException("Not my NoInsert: "+ni);
@@ -68,10 +66,9 @@
         n.logger.log(this, "Did not receive expected DataInsert on chain " 
                            + Long.toHexString(id), Logger.MINOR);
         fail(n, "DataInsert never received");
-
         return new RequestDone(this);
-    } 
-
+    }
+    
     public State receivedMessage(Node n, QueryAborted q) throws StateException {
        Core.logger.log(this, "Aborted AwaitingInsert", Core.logger.DEBUG);
        if(ni != null) ni.cancel();

Index: DataPending.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/states/request/DataPending.java,v
retrieving revision 1.14.6.3
retrieving revision 1.14.6.4
diff -u -r1.14.6.3 -r1.14.6.4
--- DataPending.java    28 Aug 2003 17:38:05 -0000      1.14.6.3
+++ DataPending.java    29 Aug 2003 18:58:06 -0000      1.14.6.4
@@ -46,19 +46,17 @@
         try {
             checkFailureTable(n);
             super.receivedQueryRejected(n, qr);
-        }
-        catch (EndOfRouteException e) {
+        } catch (EndOfRouteException e) {
             dataNotFound(n);
-           if(routes != null) routes.terminate();
+           terminateRouting(false, true); // because routing produced the QR
             return new RequestDone(this);
-        }
-        catch (RequestAbortException rae) {
+        } catch (RequestAbortException rae) {
            // Might not be a RequestDone - terminate WHEN THROWING
             return rae.state;
         }
         return new DataPending(this);
     }
-
+    
     public State receivedMessage(Node n, RequestInitiator ri) throws StateException {
        if (this.ri == null || ri != this.ri) {
            throw new BadStateException("Not my request initiator: "+ri+" for "+this);
@@ -69,20 +67,18 @@
         try {
             checkFailureTable(n);
             super.receivedRequestInitiator(n, ri);
-        }
-        catch (EndOfRouteException e) {
+        } catch (EndOfRouteException e) {
             dataNotFound(n);
-           if(routes != null) routes.terminate();
+           terminateRouting(false, true);
             return new RequestDone(this);
-        }
-        catch (RequestAbortException rae) {
+        } catch (RequestAbortException rae) {
             return rae.state;
         }
         return new DataPending(this);
     }
     
     // the rest don't...
-
+    
     public State receivedMessage(Node n, DataRequest dr) {
         try {
             checkFailureTable(n);
@@ -92,7 +88,7 @@
             return rae.state;
         }
     }
-
+    
     public State receivedMessage(Node n, QueryRestarted qr) throws StateException {
         try {
             super.receivedQueryRestarted(n, qr);
@@ -102,12 +98,12 @@
         }
         return this;
     }
-
+    
     public State receivedMessage(Node n, Accepted a) throws StateException {
         super.receivedAccepted(n, a);
         return this;
     }
-
+    
     public State receivedMessage(Node n, DataReply dr) throws StateException {
         return super.receivedDataReply(n, dr);
     }
@@ -127,27 +123,27 @@
         long toq = Math.min(dnf.timeOfQuery(),  // not stupid...
                             System.currentTimeMillis());
        
-       routes.dataNotFound(hopsToLive);
+       routes.dataNotFound(hopsToLive); // is terminal
         dataNotFound(n, toq, true);
         // Add this key to the FailureTable
         if (!n.ds.contains(searchKey)) // that sort of sucks...
             n.ft.failedToFind(searchKey, hopsToLive, toq);
         // well, technically they did their job...
         routes.routeSucceeded(dnf.source.isCached());
-       
-       routes.terminate();
         return new RequestDone(this);
     }
     
     private final void checkFailureTable(Node n) throws RequestAbortException {
         long toq = n.ft.shouldFail(searchKey, hopsToLive);
         if ((origPeer != null) && toq > 0) {
-            dataNotFound(n, toq, false);
-           if(routes != null) routes.terminate();
+            dataNotFound(n, toq, true);
+           terminateRouting(false, false);
+           // It certainly wasn't *THIS* Routing's fault
+           
             throw new RequestAbortException(new RequestDone(this));
         }
     }
-
+    
     private final void dataNotFound(Node n) {
         dataNotFound(n, System.currentTimeMillis(), false);
     }

Index: InsertPending.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/states/request/InsertPending.java,v
retrieving revision 1.17.2.3
retrieving revision 1.17.2.4
diff -u -r1.17.2.3 -r1.17.2.4
--- InsertPending.java  28 Aug 2003 17:38:05 -0000      1.17.2.3
+++ InsertPending.java  29 Aug 2003 18:58:06 -0000      1.17.2.4
@@ -68,6 +68,8 @@
         try {
             super.receivedQueryRejected(n, qr);
         } catch (EndOfRouteException e) {
+           // endRoute will either terminate or go to AwaitingInsert, either way the 
route is ended, and it's the route's fault
+           terminateRouting(false, true);
             return endRoute(n);
         } catch (RequestAbortException rae) {
             cancelNoInsert();
@@ -88,11 +90,11 @@
         }
         try {
             super.receivedRequestInitiator(n, ri);
-        }
-        catch (EndOfRouteException e) {
+       } catch (EndOfRouteException e) {
+           // see above
+           terminateRouting(false,true);
             return endRoute(n);
-        }
-        catch (RequestAbortException rae) {
+        } catch (RequestAbortException rae) {
             cancelNoInsert();
             // this is going to RequestDone with no route found
            // Should be terminate()d at throw time, not at catch time
@@ -127,7 +129,7 @@
         fail(n, "DataInsert never received");
         queryAborted(n);
        // Not our fault, this is from the requester, so don't tell Routing
-       if(routes != null) routes.terminate();
+       terminateRouting(false, false);
         return new RequestDone(this);
     }
 
@@ -138,8 +140,7 @@
         }
         cancelNoInsert();
         queryAborted(n, qf);
-
-       if(routes != null) routes.terminate();
+       terminateRouting(false, false);
         return new RequestDone(this);
     }
 
@@ -155,27 +156,25 @@
         
         try {
             receivingData = dim.cacheData(n, searchKey);
-        }
-        catch (KeyCollisionException e) {
+        } catch (KeyCollisionException e) {
             // we've already sent the Accepted so we should try..
             dim.eatData(n);
             // propagate QueryAborted upstream in case they
             // are waiting on DataInsert
             queryAborted(n);
-            
+            terminateRouting(false, false);
+           // Won't route again!
             try {
                 searchData(n);
-            }
-            catch (RequestAbortException rae) {
+            } catch (RequestAbortException rae) {
                 return rae.state;
             }
-
+           
             // well damn, it's gone already
             fail(n, "I/O error receiving insert");
             n.logger.log(this, "Failed to find data after key collision for "+this,
                          Logger.NORMAL);
            
-           if(routes != null) routes.terminate();
            return new RequestDone(this);
         } catch (IOException e) {
             dim.drop(n);
@@ -183,8 +182,7 @@
             n.logger.log(this, "Failed to cache insert for " + this,
                         e, Logger.ERROR);
             queryAborted(n);
-           
-           if(routes != null) routes.terminate();
+           terminateRouting(false, false);
             return new RequestDone(this);
         }
         
@@ -198,20 +196,17 @@
                
                 relayInsert(n);
                 return new TransferInsert(this);
-            }
-            else {
+            } else {
                 KeyInputStream doc = receivingData.getKeyInputStream();
                 doc.setParent(id, n.ticker().getMessageHandler(),
                               "Set to TransferInsertPending for "+
                              searchKey);
                 return new TransferInsertPending(this, doc);
             }
-        }
-        catch (RequestAbortException e) {
+        } catch (RequestAbortException e) {
             // immediate restart, or failure
             return e.state;
-        }
-        catch (IOException e) {
+        } catch (IOException e) {
             receivingData.cancel();
             fail(n, "I/O error receiving insert");
             if (e instanceof BufferException)
@@ -221,31 +216,32 @@
                 n.logger.log(this, "Failed to cache insert for "+this,
                             e, Logger.ERROR);
             queryAborted(n);
-           if(routes != null) routes.terminate();
+           terminateRouting(false, false);
             return new RequestDone(this);
-        }
-        finally {
+        } finally {
             receivingData.schedule(n);
         }
     }
-
+    
     public State receivedMessage(Node n, DataReply dr) throws StateException {
         State ret = super.receivedDataReply(n, dr);
+       // super will deal with Routing
         if (this != ret) cancelNoInsert();
         return ret;
     }
-
+    
     public State receivedMessage(Node n, Accepted a) throws StateException {
         if (!accepted)
             checkTime = System.currentTimeMillis();
         super.receivedAccepted(n, a);
         return this;
     }
-
+    
     public State receivedMessage(Node n, InsertReply ir) throws StateException {
         if (!fromLastPeer(ir)) {
             throw new BadStateException("InsertReply from wrong peer!");
         }
+       insertReplyTime = System.currentTimeMillis();
         if (!approved) {
             if (routedTime > 0) 
                 Core.diagnostics.occurrenceContinuous("hopTime",
@@ -258,21 +254,21 @@
             approved = true;
             routes.routeAccepted();
             try {
+               // FIXME: subtract time to send the insertReply from the 
insertReplyTime
+               // Or make insertReply asynchronous (with feedback...)
                 insertReply(n);
-            }
-            catch (RequestAbortException rae) {
+            } catch (RequestAbortException rae) {
                 cancelNoInsert();
-                // send failed to iriginator..
+                // send failed to originator..
                 return rae.state;
             }
         }
-       insertReplyTime = System.currentTimeMillis();
         return this;
     }
-
-
+    
+    
     //=== support methods ======================================================
-
+    
     final void cancelNoInsert() {
         if (ni != null) {
             ni.cancel();
@@ -282,17 +278,19 @@
 
     private final State endRoute(Node n) {
         cancelRestart();
-       logFailure(n);
+//     logFailure(n);
+       terminateRouting(false, false); // just in case
+       // Nobody to route it to, so terminate any routing
+       
         try {
             insertReply(n);
-        }
-        catch (RequestAbortException rae) {
+        } catch (RequestAbortException rae) {
             cancelNoInsert();
             return rae.state;
         }
         return new AwaitingInsert(this);
     }
-
+    
     protected State publicEndRoute(Node n) {
        return endRoute(n);
     } // FIXME!
@@ -312,27 +310,26 @@
             }
         }
     }
-
+    
     final void insertReply(Node n) throws RequestAbortException {
         try {
             ft.insertReply(n,
                 Core.storeDataTime(hopsToLive,
                                    searchKey.getExpectedTransmissionLength()));
-        }
-        catch (CommunicationException e) {
+        } catch (CommunicationException e) {
             if (receivingData != null) receivingData.cancel();
             queryAborted(n);
             n.logger.log(this,
                         "Failed to send back InsertReply, dropping for "+
                         this, e, Logger.MINOR);
-           if(routes != null) routes.terminate();
+           terminateRouting(false, false);
             throw new RequestAbortException(new RequestDone(this));
         }
     }
     
     /** Schedules the SendData state to relay the data upstream
-      * @throws RequestAbortException  if there is a failure
-      */
+     * @throws RequestAbortException  if there is a failure
+     */
     void relayInsert(Node n) throws RequestAbortException {
         try {
             KeyInputStream doc = receivingData.getKeyInputStream();
@@ -340,29 +337,26 @@
                           "InsertPending.relayInsert");
             try {
                 relayInsert(n, doc);
-            }
-            catch (RequestAbortException e) {
+            } catch (RequestAbortException e) {
                 doc.close();
                 throw e;
             }
-        }
-        catch (IOException e) {
+        } catch (IOException e) {
             receivingData.cancel();
             fail(n, "I/O error receiving insert");
             queryAborted(n);
-            if (e instanceof BufferException) {
-                n.logger.log(this, "Failed to read data from store: "+e+
-                            " for "+this, Logger.MINOR);
-            }
-            else {
+//             if (e instanceof BufferException) {
+//                 n.logger.log(this, "Failed to read data from store: "+e+
+//                          " for "+this, Logger.MINOR);
+//             } else {
                 n.logger.log(this, "Failed to read data from store for "+
                             this, e, Logger.ERROR);
-            }
-           if(routes != null) routes.terminate();
+//             }
+           terminateRouting(false, false);
             throw new RequestAbortException(new RequestDone(this));
         }
     }
-
+    
     void relayInsert(Node n, KeyInputStream doc) throws RequestAbortException {
         OutputStream out;
        startedSendTime = System.currentTimeMillis();

Index: Pending.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/states/request/Pending.java,v
retrieving revision 1.47.2.9
retrieving revision 1.47.2.10
diff -u -r1.47.2.9 -r1.47.2.10
--- Pending.java        28 Aug 2003 17:38:05 -0000      1.47.2.9
+++ Pending.java        29 Aug 2003 18:58:06 -0000      1.47.2.10
@@ -90,6 +90,7 @@
       */
     public void lost(Node n) {
         Core.diagnostics.occurrenceCounting("lostRequestState", 1);
+       terminateRouting(false, false);
         fail(n, "Request state lost due to overflow for "+this);
     }
     
@@ -97,10 +98,10 @@
       *          (note that unrecognized fields are lost)
       */
     abstract Request createRequest(FieldSet otherFields, NodeReference ref);
-
+    
     
     //=== message handling =====================================================
-
+    
     void receivedStoreData(Node n, StoreData sd) throws BadStateException {
         if (!fromLastPeer(sd)) {
             throw new BadStateException("StoreData from the wrong peer!");
@@ -112,20 +113,18 @@
     
     void receivedQueryRestarted(Node n, QueryRestarted qr) throws BadStateException,
                                                                   
RequestAbortException {
-       acceptedTime = -1; // this time is no longer meaningful
-       receivedTime = -2;
-
         if (!fromLastPeer(qr)) {
             throw new BadStateException("QueryRestarted from the wrong peer!");
         }
+       acceptedTime = -1; // this time is no longer meaningful
+       receivedTime = -2;
+       
         cancelRestart();
         long timeout = Core.hopTime(hopsToLive);
         relayRestarted(n, timeout);
         scheduleRestart(n, timeout);
-       // If we abort, it is because we can't talk to the orig requester
-       // So NGRouting does not need to know
     }
-
+    
     /**
      * Note the EndOfRouteException and RequestAbortException.
      * Must be called by subclass as part of the implementation
@@ -137,12 +136,12 @@
         if (!fromLastPeer(qr)) {
             throw new BadStateException("QueryRejected from the wrong peer!");
         }
-
+       
        gotTime = System.currentTimeMillis();
        if(receivedTime >= -1) {
            receivedTime = qr.getReceivedTime(); // measure routing time again
-           if(logDEBUG) n.logger.log(this, "Remeasured receivedTime: "+receivedTime,
-                                     Logger.DEBUG);
+           if(logDEBUG) n.logger.log(this, "Remeasured receivedTime: "+receivedTime+
+                                     " for "+this, Logger.DEBUG);
        }
        if (receivedTime < 1000*1000*1000*1000) {
            if(logDEBUG && receivedTime > -1)
@@ -157,10 +156,10 @@
                             new Exception("debug"), Logger.DEBUG);
        }
        
-       logFailure(n, gotTime);
+//     logFailure(n, gotTime);
        
         ++rejected;
-
+       
         // reduce our HTL like the man sez, but by at least 1
         hopsToLive = (int) Math.min(hopsToLive-1, qr.hopsToLive);
         
@@ -199,18 +198,19 @@
      */
     void receivedRequestInitiator(Node n, RequestInitiator ri) throws 
BadStateException,
                                                                       
RequestAbortException,
-                                                                      
EndOfRouteException {        
+                                                                      
EndOfRouteException {
         // it must be my own RequestInitiator
         if (this.ri == null || this.ri != ri) {
             throw new BadStateException("Not my request initiator: "+ri);
         }
-
+       
        gotTime = System.currentTimeMillis();
-       logFailure(n, gotTime);
+//     logFailure(n, gotTime);
        
        if(routedTime > 0) {
            if(routes == null)
-               Core.logger.log(this, "routes NULL in 
"+this+".receivedRequestInitiator", Logger.ERROR);
+               Core.logger.log(this, "routes NULL in 
"+this+".receivedRequestInitiator", 
+                               Logger.ERROR);
            else 
                routes.searchFailed(gotTime - routedTime);
        }
@@ -323,10 +323,11 @@
        if(logDEBUG)
            n.logger.log(this, "Backtracking", Logger.DEBUG);
         try {
-            n.sendMessage(
-                new QueryRejected(id, hopsToLive, "Looped request", r.otherFields),
-                r.getSource(), 0
-            );
+           Message m = new QueryRejected(id, hopsToLive, "Looped request", 
r.otherFields);
+           ConnectionHandler ch = n.makeConnection(r.getSource());
+           RequestSendCallback cb = new RequestSendCallback("QueryRejected (looped 
request)"+
+                                                            " for "+this, n, this);
+            ch.sendMessageAsync(m,cb);
         } catch (CommunicationException e) {
             n.logger.log(this, "Failed to send backtrack reply: "+e+" for "+this,
                         Logger.MINOR);
@@ -371,30 +372,14 @@
             receivingData = dr.cacheData(n, searchKey);
            replyTime = System.currentTimeMillis(); 
            // replyTime must be set AFTER verifying Storables
-           if(routedTime > 0 && logDEBUG) {
-               n.logger.log(this, "NGROUTING: Key "+searchKey+" took "+
-                            (replyTime - routedTime)+" for "+hopsToLive,
-                            Logger.DEBUG);
-               
-           } else {
-               if(logDEBUG)
-                   n.logger.log(this, "NGROUTING: Key "+searchKey+
-                                ": no valid routedTime", Logger.DEBUG);
-           }
             n.ft.remove(searchKey); // remove if in FT.
-        } catch (DataNotValidIOException e) {
-            dr.drop(n);
-           routes.verityFailed();
-           // The transfer has not started yet
-            n.logger.log(this,
-                        "Got DNV: "+Presentation.getCBdescription(e.getCode())+
-                        " for "+this,
-                        Logger.MINOR);
-            scheduleRestart(n, 0); // schedule restart now
-           replyTime = -3;
-            return this;           // back to pending
-        }
-        catch (KeyCollisionException e) {
+       } catch (StoreIOException e) {
+           // Our fault
+           terminateRouting(false, false);
+           dr.drop(n);
+           fail(n, "I/O error storing DataReply");
+           return new RequestDone(this);
+        } catch (KeyCollisionException e) {
             // oh well, try to go to SendingReply
            if(logDEBUG)
                n.logger.log(this, "Got KeyCollisionException on "+
@@ -403,8 +388,7 @@
             dr.drop(n);
             try {
                 searchData(n);
-            }
-            catch (RequestAbortException rae) {
+            } catch (RequestAbortException rae) {
                if(logDEBUG)
                    n.logger.log(this, "RAE in got KCE on "+this, rae,
                                 Logger.DEBUG);
@@ -416,18 +400,23 @@
                         "Failed to find data after key collision on "+
                         this+" while caching DataReply",
                         Logger.NORMAL);
-           if(routes != null) routes.terminate();
+           terminateRouting(false, false); // cache failure? anyway, node not routing
             return new RequestDone(this);
-        }
-        catch (IOException e) {
-           routes.verityFailed();
+        } catch (IOException e) {
+           // Their fault
             dr.drop(n);
-            fail(n, "I/O error replying with data");
-            n.logger.log(this, "I/O error caching DataReply "+this,
-                        e, Logger.ERROR);
-           if(routes != null) routes.terminate();
-            return new RequestDone(this);
-        }
+           routes.verityFailed();
+           // The transfer has not started yet
+           if(e instanceof DataNotValidIOException) {
+               DataNotValidIOException de = (DataNotValidIOException)e;
+               n.logger.log(this, "Got DNV: "+
+                            Presentation.getCBdescription(de.getCode())+
+                            " for "+this, Logger.MINOR);
+           }
+            scheduleRestart(n, 0); // schedule restart now
+           replyTime = -3;
+            return this;           // back to pending
+       }
         
         try {
             KeyInputStream kin = receivingData.getKeyInputStream();
@@ -444,8 +433,7 @@
                 if (!worked)
                     kin.close();
             }
-        }
-        catch (IOException e) {
+        } catch (IOException e) {
             // couldn't get the KeyInputStream
             fail(n, "I/O error replying with data");
             if (e instanceof BufferException) {
@@ -457,33 +445,33 @@
                             this, e, Logger.ERROR);
             }
            // Our fault, or upstream's fault
-           // So don't tell the Routing
+           // Routing is still running and valid
             return new ReceivingReply(this);
-        }
-        catch (CommunicationException e) {
+        } catch (CommunicationException e) {
            // Our fault, or upstream's fault
            // So don't tell the Routing
             n.logger.log(this, "Error replying to peer: "+e+" for "+this,
                         Logger.MINOR);
             return new ReceivingReply(this);
-        }
-        finally {
+        } finally {
             receivingData.schedule(n);
         }
-
+       
         return new TransferReply(this);
     }
-
+    
     
     //=== support methods ======================================================
-
+    
     private void sendOn(Node n, Request r, boolean isFirst)
        throws EndOfRouteException, RequestAbortException {
        
        loggedResult = false;
        
-        if (hopsToLive <= 0)
+        if (hopsToLive <= 0) {
+           terminateRouting(false, true /* probably! */);
             throw new EndOfRouteException("Reached last node in route");
+       }
        
         
         Peer addr = null;
@@ -514,6 +502,7 @@
                if(logDEBUG)
                    n.logger.log(this, "rt exhaused for "+this, 
                                 Logger.DEBUG);
+               terminateRouting(false, true);
                 throw new RequestAbortException(new RequestDone(this));
             } else {
                if(logDEBUG)
@@ -525,7 +514,8 @@
                                      Logger.DEBUG);
            long stillStillInSendOnTime = System.currentTimeMillis();
            if(isFirst && attemptCount == 0) {
-               n.diagnostics.occurrenceContinuous("stillStillInSendOnTime", 
stillStillInSendOnTime - 
+               n.diagnostics.occurrenceContinuous("stillStillInSendOnTime", 
+                                                  stillStillInSendOnTime - 
                                                   stillInSendOnTime);
            }
             if (addr == null) {  // bad node ref
@@ -590,29 +580,27 @@
                    n.logger.log(this, "Routing ("+this+") failure to: "
                                 +e.peerAddress() + " -- " + e, e, 
                                 Logger.DEBUG);
-               //e, Logger.DEBUG);
                 if (e instanceof AuthenticationFailedException) {
                     routes.authFailed();
-                }
-                else {
+                } else {
                     routes.connectFailed();
                 }
             }
         }
-
+       
         // Count outbound Requests.
         n.diagnostics.occurrenceBinomial("outboundAggregateRequests", attemptCount, 
1);
         if (n.outboundRequests != null) {
             n.outboundRequests.incTotal(addr.getAddress().toString());
         }
-
+       
         // Keep track of outbound requests for rate limiting.
         n.outboundRequestLimit.inc();
-
+       
         lastPeer = addr;
         scheduleRestart(n, Core.hopTime(1));  // timeout to get the Accepted
     }
-
+    
     private final void relayRestarted(Node n, long timeout) throws 
RequestAbortException {
         try {
             ft.restarted(n, timeout);
@@ -621,14 +609,14 @@
             n.logger.log(this,
                          "Couldn't restart because relaying QueryRestarted failed: "+
                         e+" for "+this, Logger.MINOR);
-           if(routes != null) routes.terminate();
+           terminateRouting(false, false);
             throw new RequestAbortException(new RequestDone(this));
         }
     }
-
+    
     /** Given an existing KeyInputStream, sets up a SendData state to
-      * transfer the data back to the requester. 
-      */
+     * transfer the data back to the requester. 
+     */
     SendData sendData(Node n, KeyInputStream doc) throws CommunicationException {
        if(logDEBUG) n.logger.log(this, "Sending data (,"+doc+") for "+this,
                                  Logger.DEBUG);
@@ -661,6 +649,7 @@
                    n.logger.log(this, "Trying to fetch "+this
                                 +" at "+startTime, Core.logger.DEBUG);
                doc = n.ds.getData(searchKey);
+               terminateRouting(true, false);
                long gotDataTime = System.currentTimeMillis();
                if(logDEBUG)
                    n.logger.log(this, "getData took "+(gotDataTime-startTime)+
@@ -692,20 +681,19 @@
                n.logger.log(this, "I/O error replying with data on "+this,
                             e, Logger.MINOR);
                thrownTime = System.currentTimeMillis();
-               if(routes != null) routes.terminate();
+               terminateRouting(false, false);
                throw new RequestAbortException(new RequestDone(this));
            } catch (CommunicationException e) {
                n.logger.log(this, "Error replying to peer: "+e+" on "+this, 
                             e, Logger.MINOR);
                thrownTime = System.currentTimeMillis();
-               if(routes != null) routes.terminate();
+               terminateRouting(false, false);
                throw new RequestAbortException(new RequestDone(this));
            } finally {
                if (doc != null) {
                    try {
                        doc.close();
-                   }
-                   catch (IOException e) {
+                   } catch (IOException e) {
                        n.logger.log(this,
                                     "Failed to close KeyInputStream after failing "+
                                     "on "+this, e, Logger.MINOR);
@@ -727,66 +715,66 @@
     long endTransferTime = -1;
     boolean loggedResult = false;
     
-    public void logSuccess(Node n) {
-       if(loggedResult) return;
-       loggedResult = true;
-       endTransferTime = System.currentTimeMillis();
-       
-       double transferRate = (((double)receivingData.length()) /
-                              ((double)(endTransferTime - replyTime))) * 1000;
-       long stdFileSize;
-       if(n.dir.countKeys() > 16)
-           stdFileSize = (n.storeSize - n.dir.available()) / n.dir.countKeys();
-       else stdFileSize = 100000;
-       long expectedTime = (replyTime - routedTime) +
-           (((endTransferTime - replyTime) * stdFileSize) / 
-            receivingData.length());
-       if(logDEBUG)
-           n.logger.log(this, "NGROUTING: Key "+searchKey+": search took "+
-                        (replyTime-routedTime)+" in "+hopsToLive+", transfer took "+
-                        (endTransferTime-replyTime)+" for file length "+
-                        receivingData.length()+": transfer rate "+transferRate+
-                        " bytes per second, expected total time for file of "+
-                        "length "+stdFileSize+": "+expectedTime+"; sent to "+
-                        lastPeer, Logger.DEBUG);
-    }
-    
-    public void logFailure(Node n) {
-       logFailure(n, System.currentTimeMillis());
-    }
-    
-    public void logFailure(Node n, long endTime) {
-       if(routedTime > 0) {
-           if(replyTime > 0) {
-               logFailedTransfer(n, endTime);
-           } else {
-               logFailedSearch(n, endTime);
-           }
-       }
-    }
-    
-    public void logFailedTransfer(Node n) {
-       endTransferTime = System.currentTimeMillis();
-       logFailure(n, endTransferTime);
-    }
-    
-    public void logFailedTransfer(Node n, long endTime) {
-       if(loggedResult) return;
-       loggedResult = true;
-       if(logDEBUG)
-           n.logger.log(this, "NGROUTING: Key "+searchKey+": search took "+
-                           (replyTime-routedTime)+" in "+hopsToLive+
-                           ", failed transfer took "+(endTransferTime - replyTime)+
-                           "; sent to "+lastPeer, Logger.DEBUG);
-       replyTime = -1;
-    }
-    
-    public void logFailedSearch(Node n, long endTime) {
-       if(loggedResult) return;
-       loggedResult = true;
-       if(logDEBUG)
-           n.logger.log(this, "NGROUTING: Key "+searchKey+": search failed in "+
-                        (endTime-routedTime)+" for "+hopsToLive+"; sent to "+
-                        lastPeer, new Exception("debug"), Logger.DEBUG);
-    }
+//     public void logSuccess(Node n) {
+//     if(loggedResult) return;
+//     loggedResult = true;
+//     endTransferTime = System.currentTimeMillis();
+       
+//     double transferRate = (((double)receivingData.length()) /
+//                            ((double)(endTransferTime - replyTime))) * 1000;
+//     long stdFileSize;
+//     if(n.dir.countKeys() > 16)
+//         stdFileSize = (n.storeSize - n.dir.available()) / n.dir.countKeys();
+//     else stdFileSize = 100000;
+//     long expectedTime = (replyTime - routedTime) +
+//         (((endTransferTime - replyTime) * stdFileSize) / 
+//          receivingData.length());
+//     if(logDEBUG)
+//         n.logger.log(this, "NGROUTING: Key "+searchKey+": search took "+
+//                      (replyTime-routedTime)+" in "+hopsToLive+", transfer took "+
+//                      (endTransferTime-replyTime)+" for file length "+
+//                      receivingData.length()+": transfer rate "+transferRate+
+//                      " bytes per second, expected total time for file of "+
+//                      "length "+stdFileSize+": "+expectedTime+"; sent to "+
+//                      lastPeer, Logger.DEBUG);
+//     }
+    
+//     public void logFailure(Node n) {
+//     logFailure(n, System.currentTimeMillis());
+//     }
+    
+//     public void logFailure(Node n, long endTime) {
+//     if(routedTime > 0) {
+//         if(replyTime > 0) {
+//             logFailedTransfer(n, endTime);
+//         } else {
+//             logFailedSearch(n, endTime);
+//         }
+//     }
+//     }
+    
+//     public void logFailedTransfer(Node n) {
+//     endTransferTime = System.currentTimeMillis();
+//     logFailure(n, endTransferTime);
+//     }
+    
+//     public void logFailedTransfer(Node n, long endTime) {
+//     if(loggedResult) return;
+//     loggedResult = true;
+//     if(logDEBUG)
+//         n.logger.log(this, "NGROUTING: Key "+searchKey+": search took "+
+//                         (replyTime-routedTime)+" in "+hopsToLive+
+//                         ", failed transfer took "+(endTransferTime - replyTime)+
+//                         "; sent to "+lastPeer, Logger.DEBUG);
+//     replyTime = -1;
+//     }
+    
+//     public void logFailedSearch(Node n, long endTime) {
+//     if(loggedResult) return;
+//     loggedResult = true;
+//     if(logDEBUG)
+//         n.logger.log(this, "NGROUTING: Key "+searchKey+": search failed in "+
+//                      (endTime-routedTime)+" for "+hopsToLive+"; sent to "+
+//                      lastPeer, new Exception("debug"), Logger.DEBUG);
+//     }
 }

Index: ReceivingInsert.java
===================================================================
RCS file: 
/cvsroot/freenet/freenet/src/freenet/node/states/request/ReceivingInsert.java,v
retrieving revision 1.17.6.3
retrieving revision 1.17.6.4
diff -u -r1.17.6.3 -r1.17.6.4
--- ReceivingInsert.java        28 Aug 2003 17:38:05 -0000      1.17.6.3
+++ ReceivingInsert.java        29 Aug 2003 18:58:06 -0000      1.17.6.4
@@ -60,7 +60,6 @@
                 } catch (IOException e) {
                     fail(n, "Cache failed");
                     n.logger.log(this, "Cache failed on commit", e, Logger.ERROR);
-                   if(routes != null) routes.terminate();
                     return new RequestDone(this);
                 }
                 n.logger.log(this, "Data received successfully!", Logger.MINOR);
@@ -94,7 +93,6 @@
                         "Failed to send back StoreData to peer " + e.peer,
                         e, Logger.MINOR);
                 }
-               if(routes != null) routes.terminate();
                 return new RequestDone(this);
 
             case Presentation.CB_CACHE_FAILED:
@@ -105,7 +103,6 @@
                     "Failed to receive insert with CB 
"+Presentation.getCBdescription(cb)
                     +", on chain "+Long.toHexString(id),
                     (cb == Presentation.CB_CACHE_FAILED ? Logger.ERROR : 
Logger.MINOR));
-               if(routes != null) routes.terminate();
                 return new RequestDone(this);
         }
     }

Index: ReceivingReply.java
===================================================================
RCS file: 
/cvsroot/freenet/freenet/src/freenet/node/states/request/ReceivingReply.java,v
retrieving revision 1.7.6.3
retrieving revision 1.7.6.4
diff -u -r1.7.6.3 -r1.7.6.4
--- ReceivingReply.java 28 Aug 2003 17:38:05 -0000      1.7.6.3
+++ ReceivingReply.java 29 Aug 2003 18:58:06 -0000      1.7.6.4
@@ -88,18 +88,18 @@
                 } catch (KeyCollisionException e) {
                     n.logger.log(this, "Abandoning after key collision: "+this,
                                 Logger.MINOR);
-                   logSuccess(n);
+//                 logSuccess(n);
                     break;
                 } catch (IOException e) {
                     n.logger.log(this, "Cache failed on commit: "+this, e, 
Logger.ERROR);
-                   logSuccess(n); // it's not the node's fault...
+//                 logSuccess(n); // it's not the node's fault...
                     break;
                 }
                 n.logger.log(this, "Data received successfully!: "+this, 
Logger.MINOR);
                routes.transferSucceeded(replyTime - routedTime, hopsToLive,
                                         receivingData.length(),
                                         endTransferTime - replyTime);
-               logSuccess(n);
+//             logSuccess(n);
                 if (storeData == null) {
                     NoStoreData nosd = new NoStoreData(this);
                     n.schedule(Core.hopTime(2), nosd);
@@ -121,7 +121,7 @@
                routes.transferFailed(replyTime - routedTime, hopsToLive,
                                      receivingData.length(), 
                                      endTransferTime - replyTime);
-               logFailedTransfer(n);
+//             logFailedTransfer(n);
                 // the null check is not really needed but I hate NPEs..
                 if (lastPeer != null)
                     routes.verityFailed();
@@ -146,7 +146,7 @@
                routes.transferFailed(replyTime - routedTime, hopsToLive,
                                      receivingData.length(), 
                                      endTransferTime - replyTime);
-               logFailedTransfer(n); // better safe than sorry...
+//             logFailedTransfer(n); // better safe than sorry...
                 n.logger.log(this,
                             "Failed to receive data with CB "+
                             Presentation.getCBdescription(cb)
@@ -156,7 +156,7 @@
        
        n.logger.log(this, "Transitioning to RequestDone from "+this,
                     Logger.DEBUG);
-       if(routes != null) routes.terminate();
+       terminateRouting(false, true); // routing will ignore if we succeeded already
         return new RequestDone(this);
     }
 }

Index: RequestState.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/states/request/RequestState.java,v
retrieving revision 1.11
retrieving revision 1.11.2.1
diff -u -r1.11 -r1.11.2.1
--- RequestState.java   19 Jun 2003 13:31:20 -0000      1.11
+++ RequestState.java   29 Aug 2003 18:58:06 -0000      1.11.2.1
@@ -147,8 +147,15 @@
     
     public String toString() {
        return getClass().getName()+": key="+searchKey+", hopsToLive="+
-           hopsToLive+", id="+Fields.longToHex(id)+",ft="+ft+"@"+
-           System.currentTimeMillis();
+           hopsToLive+", id="+Fields.longToHex(id)+", routes="+routes+
+           ",ft="+ft+"@"+System.currentTimeMillis();
+    }
+    
+    public void terminateRouting(boolean success, boolean routingRelated) {
+       if(routes != null) {
+           routes.terminate(success, routingRelated);
+           routes = null;
+       }
     }
 }
 

Index: SendingReply.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/states/request/SendingReply.java,v
retrieving revision 1.18.6.3
retrieving revision 1.18.6.4
diff -u -r1.18.6.3 -r1.18.6.4
--- SendingReply.java   28 Aug 2003 17:38:05 -0000      1.18.6.3
+++ SendingReply.java   29 Aug 2003 18:58:06 -0000      1.18.6.4
@@ -77,7 +77,6 @@
                }
                n.logger.log(this, "Finalizing sendingData: "+this, Logger.DEBUG);
                sendingData.finalize();
-               if(routes != null) routes.terminate();
                return new RequestDone(this);
                
             case Presentation.CB_CACHE_FAILED:
@@ -91,7 +90,6 @@
                             (cb == Presentation.CB_CACHE_FAILED ? 
                              Logger.ERROR : Logger.MINOR));
                 sendingData.finalize();
-               routes.terminate();
                 return new RequestDone(this);
                 
             // the StoreInputStream we were reading from got restarted

Index: TransferInsert.java
===================================================================
RCS file: 
/cvsroot/freenet/freenet/src/freenet/node/states/request/TransferInsert.java,v
retrieving revision 1.9.2.4
retrieving revision 1.9.2.5
diff -u -r1.9.2.4 -r1.9.2.5
--- TransferInsert.java 28 Aug 2003 17:38:05 -0000      1.9.2.4
+++ TransferInsert.java 29 Aug 2003 18:58:06 -0000      1.9.2.5
@@ -63,8 +63,7 @@
     public State receivedMessage(Node n, QueryRestarted qr) throws StateException {
         try {
             super.receivedQueryRestarted(n, qr);
-        }
-        catch (RequestAbortException rae) {
+        } catch (RequestAbortException rae) {
             // going to RequestDone with SendFailedException
             receivingData.cancel();
             sendingData.abort(Presentation.CB_ABORTED);
@@ -83,11 +82,9 @@
         try {
            // Will cause a searchFailed() and a restart
             super.receivedRequestInitiator(n, ri);
-        }
-        catch (EndOfRouteException e) {
+        } catch (EndOfRouteException e) {
             return super.publicEndRoute(n);
-        }
-        catch (RequestAbortException rae) {
+        } catch (RequestAbortException rae) {
             cancelNoInsert();
             // this is going to RequestDone with no route found
             return rae.state;
@@ -135,8 +132,7 @@
        if(logDEBUG) n.logger.log(this, "Cancelled restart for "+this, Logger.DEBUG);
         try {
             insertReply(n);
-        }
-        catch (RequestAbortException rae) {
+        } catch (RequestAbortException rae) {
             // send failed..
             sendingData.abort(Presentation.CB_ABORTED);  // QueryAborted already sent
             transition(rae.state, false);
@@ -155,7 +151,7 @@
         super.receivedStoreData(n, sd);
         return this;
     }
-
+    
     public State receivedMessage(Node n, InsertRequest ir) {
         super.receivedRequest(n, ir);
         return this;
@@ -169,7 +165,8 @@
            if(logDEBUG) n.logger.log(this, "CB_OK: committing "+
                                      this, Logger.DEBUG);
            tryCommit(n);
-           logSuccess(n);
+           // We have already logged transferSucceeded
+//         logSuccess(n);
            if(logDEBUG) n.logger.log(this, "Going to AWSD for "+this, 
                                      new Exception("debug"), Logger.DEBUG);
            State awsd;
@@ -187,8 +184,8 @@
                n.logger.log(this, "dataReceived control bytes not CB_OK, "+
                             "going to RequestDone for "+this, Logger.DEBUG);
            receivingData.cancel();
-           logFailedTransfer(n);
-           if(routes != null) routes.terminate();
+//         logFailedTransfer(n);
+           // Routing dealt with in received(DataReceived)
            return transition(new RequestDone(this), false);
        }
     }
@@ -203,13 +200,12 @@
             n.logger.log(this, "Going to DataPending after key collision for "+this,
                          Logger.MINOR);
             scheduleRestart(n, 0);
-           logSuccess(n);
+//         logSuccess(n);
             transition(new DataPending(this), false);
         } catch (IOException e) {
             fail(n, "Cache failed");
             n.logger.log(this, "Cache failed on commit for "+this, e, Logger.ERROR);
-           logSuccess(n); // not node's fault
-           if(routes != null) routes.terminate();
+           terminateRouting(false, false); // our fault
             transition(new RequestDone(this), false);
         }
     }
@@ -226,6 +222,7 @@
        case Presentation.CB_OK:
            n.logger.log(this, "Data received successfully! for "+this,
                         n.logger.MINOR);
+           
            break;
            
        case Presentation.CB_CACHE_FAILED:
@@ -244,9 +241,8 @@
        default:
            fail(n, "You sent "+Presentation.getCBdescription(cb));
            n.logger.log(this,
-                        "Failed to receive insert data with CB 
"+Presentation.getCBdescription(cb)
-                        +", for "+this,
-                        Logger.MINOR);
+                        "Failed to receive insert data with CB "+Presentation.
+                        getCBdescription(cb)+", for "+this, Logger.MINOR);
         }
        
         return checkTransition(n);
@@ -286,6 +282,7 @@
        case Presentation.CB_CACHE_FAILED:
            n.logger.log(this, "Transfer of insert failed, cache broken! for "+this, 
                         Logger.ERROR);
+           terminateRouting(false, false);
            queryAborted(n);
            break;
            
@@ -306,9 +303,9 @@
            n.logger.log(this, "Send aborted: "+
                         Presentation.getCBdescription(cb)+", for "+this,
                         Logger.MINOR);
+           terminateRouting(false, false);
            queryAborted(n);
-           // Not upstream's fault
-           // Ignore for Routing purposes
+           // Not routed-to node's fault
            break;
            
        default:

Index: TransferInsertPending.java
===================================================================
RCS file: 
/cvsroot/freenet/freenet/src/freenet/node/states/request/TransferInsertPending.java,v
retrieving revision 1.14.2.3
retrieving revision 1.14.2.4
diff -u -r1.14.2.3 -r1.14.2.4
--- TransferInsertPending.java  28 Aug 2003 17:38:05 -0000      1.14.2.3
+++ TransferInsertPending.java  29 Aug 2003 18:58:06 -0000      1.14.2.4
@@ -58,40 +58,36 @@
        }
         try {
             super.receivedQueryRejected(n, qr);
-        }
-        catch (EndOfRouteException e) {
+        } catch (EndOfRouteException e) {
            if(Core.logger.shouldLog(Logger.DEBUG))
               Core.logger.log(this, "end of route exception "+searchKey,
                               Logger.DEBUG);
             return endRoute(n);
-        }
-        catch (RequestAbortException rae) {
+        } catch (RequestAbortException rae) {
             // we are either going to SendingReply or RequestDone with no route found
            // So don't terminate()!
            if(Core.logger.shouldLog(Logger.DEBUG))
-              Core.logger.log(this, "request abort exception "+searchKey, 
-                              rae, Logger.DEBUG);
+               Core.logger.log(this, "request abort exception "+searchKey, 
+                               rae, Logger.DEBUG);
             if (receivingData.result() == -1)
                 receivingData.cancel();
             return rae.state;
         } finally {
             cleanDoc(); // if nobody is reading, nobody will
         }
-
+       
         return new TransferInsertPending(this);
     }
-
+    
     public State receivedMessage(Node n, RequestInitiator ri) throws StateException {
        if (this.ri == null || this.ri != ri) {
            throw new BadStateException("Not my request initiator: "+ri);
        }
         try {
             super.receivedRequestInitiator(n, ri);
-        }
-        catch (EndOfRouteException e) {
+        } catch (EndOfRouteException e) {
             return endRoute(n);
-        }
-        catch (RequestAbortException rae) {
+        } catch (RequestAbortException rae) {
             // this is going to RequestDone with no route found
             receivingData.cancel();
             return rae.state;
@@ -112,8 +108,7 @@
     public State receivedMessage(Node n, QueryRestarted qr) throws StateException {
         try {
             super.receivedQueryRestarted(n, qr);
-        }
-        catch (RequestAbortException rae) {
+        } catch (RequestAbortException rae) {
             // going to RequestDone with SendFailedException
             receivingData.cancel();
             return rae.state;
@@ -153,7 +148,7 @@
                 } finally {
                     cleanDoc(); // if nobody is reading, nobody will
                 }
-               if(routes != null) routes.terminate();
+               terminateRouting(false, false);
                 return new RequestDone(this);
         }
         return this;  // still waiting for Accepted
@@ -164,12 +159,12 @@
         if (!fromOrigPeer(qf)) {
             throw new BadStateException("QueryAborted from the wrong peer!");
         }
-       logFailure(n);
+//     logFailure(n);
         queryAborted(n, qf);
         receivingData.cancel();
        
         cleanDoc(); // if nobody is reading, nobody will
-       if(routes != null) routes.terminate();
+       terminateRouting(false, false);
         return new RequestDone(this);
     }
     
@@ -185,27 +180,26 @@
         }
         return ret;
     }
-
+    
     public State receivedMessage(Node n, Accepted a) throws StateException {
         super.receivedAccepted(n, a);
         try {
-            n.logger.log(this,
-                "Got Accepted " + ((System.currentTimeMillis() - dimRecvTime) / 1000)
-                +"s after DataInsert", Logger.DEBUG);
+            n.logger.log(this, "Got Accepted " + 
+                        ((System.currentTimeMillis() - dimRecvTime) / 1000)
+                        +"s after DataInsert", Logger.DEBUG);
             if (doc == null)
                 relayInsert(n);
             else {
                 relayInsert(n, doc);
                doc = null; // Don't close it, don't hold on to it
            }
-        }
-        catch (RequestAbortException rae) {
+        } catch (RequestAbortException rae) {
             // immediate restart, or failure
             return rae.state;
         }
         return new TransferInsert(this);
     }
-
+    
     public State receivedMessage(Node n, InsertReply ir) throws StateException {
         if (!fromLastPeer(ir)) {
             throw new BadStateException("InsertReply from wrong peer!");
@@ -216,9 +210,9 @@
             accepted = true;
             approved = true;
             try {
-                n.logger.log(this,
-                    "Got InsertReply " + ((System.currentTimeMillis() - dimRecvTime) 
/ 1000)
-                    +"s after DataInsert", Logger.DEBUG);
+                n.logger.log(this, "Got InsertReply " + 
+                            ((System.currentTimeMillis() - dimRecvTime) / 1000)
+                            +"s after DataInsert", Logger.DEBUG);
                 insertReply(n);
                 if (doc == null)
                     relayInsert(n);
@@ -226,20 +220,18 @@
                     relayInsert(n, doc);
                    doc = null; // Don't close it, don't hold on to it
                }
-            }
-            catch (RequestAbortException rae) {
+            } catch (RequestAbortException rae) {
                 return rae.state;
             }
         }
         return new TransferInsert(this);
     }
-
+    
     private final State endRoute(Node n) throws StateTransition {
-       logFailure(n);
+//     logFailure(n);
         try {
             insertReply(n);
-        }
-        catch (RequestAbortException rae) {
+        } catch (RequestAbortException rae) {
             return rae.state;
         }
         State s = new ReceivingInsert(this);
@@ -248,7 +240,7 @@
         else
             return s;
     }
-
+    
     // close the doc if necessary before leaving state.
     private final void cleanDoc() {
        if(logDEBUG) {

Index: TransferReply.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/states/request/TransferReply.java,v
retrieving revision 1.11.2.6
retrieving revision 1.11.2.7
diff -u -r1.11.2.6 -r1.11.2.7
--- TransferReply.java  28 Aug 2003 17:38:05 -0000      1.11.2.6
+++ TransferReply.java  29 Aug 2003 18:58:06 -0000      1.11.2.7
@@ -112,26 +112,27 @@
                                      this, Logger.DEBUG);
             try {
                 receivingData.commit();  // make the key available
-            }
-            catch (KeyCollisionException e) {
+            } catch (KeyCollisionException e) {
                 // this is a little bit of a hack.  we jump into a
                 // DataPending state and then handle a restart which
                 // makes us check for the data in the store again
                 n.logger.log(this, "Going to DataPending after key collision for 
"+this,
                              Logger.MINOR);
-               logSuccess(n);
+//             logSuccess(n);
+//             terminateRouting(true, false);
+               // Will be terminated or restarted in the DataPending
                 scheduleRestart(n, 0);
                 transition(new DataPending(this), false);
             } catch (IOException e) {
                 fail(n, "Cache failed");
                 n.logger.log(this, "Cache failed on commit for "+this, e, 
                             Logger.ERROR);
-               logSuccess(n);
-               if(routes != null) routes.terminate();
+//             logSuccess(n);
+               // Routing already terminated
                 transition(new RequestDone(this), false);
             }
             
-           logSuccess(n);
+//         logSuccess(n);
            if(logDEBUG) n.logger.log(this, "Going to AWSD for "+this, 
                                      new Exception("debug"), Logger.DEBUG);
             State awsd;
@@ -149,8 +150,8 @@
                n.logger.log(this, "dataReceived control bytes not CB_OK, "+
                             "going to RequestDone for "+this, Logger.DEBUG);
            receivingData.cancel();
-           logFailedTransfer(n);
-           if(routes != null) routes.terminate();
+           terminateRouting(false, false);
+//         logFailedTransfer(n);
            return transition(new RequestDone(this), false);
        }
     }
@@ -178,12 +179,13 @@
             case Presentation.CB_CACHE_FAILED:
                 n.logger.log(this, "Cache failed while receiving data! for "+this,
                             Logger.ERROR);
+               terminateRouting(false, false);
                 // the repercussions will strike in the DataSent..
                // Ignore for NGRouting, our fault
                 break;
                
-            case Presentation.CB_BAD_DATA:
-                n.logger.log(this, "Upstream node sent bad data! for "+this,
+           case Presentation.CB_BAD_DATA:
+               n.logger.log(this, "Upstream node sent bad data! for "+this,
                             Logger.NORMAL);
                 // the null check is not really needed but I hate NPEs..
                 if (lastPeer != null)
@@ -191,14 +193,14 @@
                 // do the restart with the DataSent
                sendingData.abort(Presentation.CB_RESTARTED);
                 break;
-           
+               
            case Presentation.CB_RECV_CONN_DIED:
                n.logger.log(this, "Upstream node connection died for "+
                             this, Logger.NORMAL);
                routes.transferFailed(replyTime - routedTime, hopsToLive,
                                      receivingData.length(), 
                                      endTransferTime - replyTime);
-               sendingData.abort(Presentation.CB_RESTARTED);
+               sendingData.abort(Presentation.CB_RESTARTED); // restart
                break;
                
             case Presentation.CB_RESTARTED:

_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to