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

Modified Files:
      Tag: stable
        AnnouncementDone.java AnnouncementState.java 
        CompletePending.java ExecutePending.java LastNode.java 
        NewAnnouncement.java ReplyPending.java 
Log Message:
5029: Merge from unstable after months of work. MASSIVE changes.
Highlights:
* Next Generation Routing, massive related changes
* Major changes to handling of messages and connections (PeerHandler and related 
changes)
* Even more non-blocking I/O
* Documentation improvements
* Lots of new diagnostics and config options
* Lots of bug fixes and performance tweaking
* Probably lots of new bugs too!


Index: AnnouncementDone.java
===================================================================
RCS file: 
/cvsroot/freenet/freenet/src/freenet/node/states/announcement/AnnouncementDone.java,v
retrieving revision 1.1.1.1.4.1
retrieving revision 1.1.1.1.4.1.2.1
diff -u -w -r1.1.1.1.4.1 -r1.1.1.1.4.1.2.1
--- AnnouncementDone.java       4 Nov 2002 18:46:33 -0000       1.1.1.1.4.1
+++ AnnouncementDone.java       28 Oct 2003 20:20:42 -0000      1.1.1.1.4.1.2.1
@@ -12,6 +12,7 @@
 
     public AnnouncementDone(AnnouncementState st) {
         super(st);
+       terminateRouting(false, false);
     }
 
     public String getName() {

Index: AnnouncementState.java
===================================================================
RCS file: 
/cvsroot/freenet/freenet/src/freenet/node/states/announcement/AnnouncementState.java,v
retrieving revision 1.1.1.1.4.1.2.2
retrieving revision 1.1.1.1.4.1.2.3
diff -u -w -r1.1.1.1.4.1.2.2 -r1.1.1.1.4.1.2.3
--- AnnouncementState.java      23 May 2003 13:06:19 -0000      1.1.1.1.4.1.2.2
+++ AnnouncementState.java      28 Oct 2003 20:20:42 -0000      1.1.1.1.4.1.2.3
@@ -28,6 +28,7 @@
     NodeReference announcee;
     int depth;
     int hopsToLive;
+    final int origHopsToLive;
     byte[] commitVal;
 
     byte[] myVal;
@@ -56,6 +57,7 @@
         this.commitVal = commitVal;
         this.routed = 0;
         this.totalRestarts = 0;
+       this.origHopsToLive = hopsToLive;
     }
 
     /**
@@ -73,7 +75,7 @@
         this.origRec = as.origRec;
         this.lastAddr = as.lastAddr;
         this.routes = as.routes;
-
+       this.origHopsToLive = as.origHopsToLive;
         this.routed = as.routed;
         this.totalRestarts = as.totalRestarts;
     }
@@ -105,7 +107,10 @@
         }
     }
 
-
+    // FIXME: Does announcement really need a different interval to
+    // everything else?
+    // @see Core.hopTime (97.5% interval)
+    // I'm not sure that announcing/ uses this...
     /**
      * @return The upper bound of a one sided 99% confidence interval
      *         for the time it should take to get a reply based on the
@@ -118,20 +123,29 @@
                        + 2.33 * Math.sqrt(htl) * Core.hopTimeDeviation);
     }
 
-    void sendMessage(Node n, Peer p, Message m, KeyList kl) 
+    void sendMessage(Node n, Peer p, Message m, KeyList kl,
+                    long timeout) 
                                         throws CommunicationException {
 
-        OutputStream out = n.sendMessage(m, p);
+        TrailerWriter out = n.sendMessage(m, p, timeout);
         try {
-            if (out != null) kl.writeTo(out);
+            if (out != null) {
+               OutputStream os = new TrailerWriterOutputStream(out);
+               kl.writeTo(os);
+           }
         } catch (IOException e) {
             //e.printStackTrace();
             throw new SendFailedException(p.getAddress(), 
                                           "Writing keys failed: "+e);
         } finally {
-            try {
                if(out != null) out.close();
-            } catch (IOException e) {}
+        }
+    }
+    
+    public void terminateRouting(boolean success, boolean routingRelated) {
+       if(routes != null) {
+           routes.terminate(success, routingRelated);
+           routes = null;
         }
     }
 }

Index: CompletePending.java
===================================================================
RCS file: 
/cvsroot/freenet/freenet/src/freenet/node/states/announcement/CompletePending.java,v
retrieving revision 1.3.4.1.2.1
retrieving revision 1.3.4.1.2.2
diff -u -w -r1.3.4.1.2.1 -r1.3.4.1.2.2
--- CompletePending.java        29 Jul 2003 21:08:08 -0000      1.3.4.1.2.1
+++ CompletePending.java        28 Oct 2003 20:20:42 -0000      1.3.4.1.2.2
@@ -41,6 +41,7 @@
         // insert into Routing table
         n.reference(k, announcee);
         
+        terminateRouting(false, false);
         // since we have added the reference
         return new AnnouncementDone(this);
     }
@@ -119,12 +120,12 @@
         n.reference(k, announcee);
         
         try {
-            sendMessage(n, origRec, ac, newKeys);
+            sendMessage(n, origRec, ac, newKeys, getTime(hopsToLive)*3);
         } catch (CommunicationException e) {
             n.logger.log(this, "Failed to send AnnouncementComplete",
                          e, n.logger.MINOR);
         }
-
+       terminateRouting(false, false);
         // since we've added the ref
         return new AnnouncementDone(this);
     }

Index: ExecutePending.java
===================================================================
RCS file: 
/cvsroot/freenet/freenet/src/freenet/node/states/announcement/ExecutePending.java,v
retrieving revision 1.1.1.1.4.1.2.1
retrieving revision 1.1.1.1.4.1.2.2
diff -u -w -r1.1.1.1.4.1.2.1 -r1.1.1.1.4.1.2.2
--- ExecutePending.java 1 Jul 2003 02:27:16 -0000       1.1.1.1.4.1.2.1
+++ ExecutePending.java 28 Oct 2003 20:20:42 -0000      1.1.1.1.4.1.2.2
@@ -43,7 +43,8 @@
        n.logger.log(this, "ExecutePending got NoExecute "+ne,
                     Logger.NORMAL);
         try {
-            n.sendMessage(new QueryAborted(id), lastAddr);
+            n.sendMessage(new QueryAborted(id), lastAddr, 
+                         getTime((int)depth)); 
         } catch (CommunicationException e) {
             n.logger.log(this, "Failed to send QueryAborted after no Execute",
                          e, Logger.DEBUG);
@@ -52,7 +53,7 @@
         try {
             n.sendMessage(
                 new AnnouncementFailed(id, AnnouncementFailed.NO_EXECUTE),
-                origRec);
+                origRec, getTime(origHopsToLive));
            
         } catch (CommunicationException e) {
             n.logger.log(this, 
@@ -60,6 +61,7 @@
                          e, Logger.DEBUG);
         }
 
+       terminateRouting(false, false);
         return new AnnouncementDone(this);
     }
 
@@ -70,12 +72,13 @@
 
         ne.cancel();
         try {
-            n.sendMessage(qr, lastAddr);
+            n.sendMessage(qr, lastAddr, getTime((int)depth));
         } catch (CommunicationException e) {
             n.logger.log(this, "Failed to send QueryAborted after no Execute",
                          e, Logger.DEBUG);
         }
 
+       terminateRouting(false, false);
         return new AnnouncementDone(this);
     }
 
@@ -90,8 +93,10 @@
             CompletePending cp = new CompletePending(this, k, nc);
 
             try {
-                sendMessage(n, lastAddr, ae, ae.getValueList());
-                n.schedule(getTime(hopsToLive), nc);
+                sendMessage(n, lastAddr, ae, ae.getValueList(),
+                           getTime((int)depth));
+                n.schedule(getTime(hopsToLive)*3, nc);
+               // LONG timeout, announcements should be quite tolerant
                 return cp;
             } catch (CommunicationException e) {
                 n.logger.log(this, "Failed to send AnnouncementComplete - "
@@ -101,18 +106,19 @@
                 return cp.received(n, nc);
             }
         } else {
+           terminateRouting(false, false);
             QueryAborted qa = new QueryAborted(id);
             AnnouncementFailed af = 
                 new AnnouncementFailed(id,
                                        AnnouncementFailed.CORRUPT_EXECUTE);
             try {
-                n.sendMessage(qa, lastAddr);
+                n.sendMessage(qa, lastAddr, getTime((int)depth));
             } catch (CommunicationException e) {
                 n.logger.log(this, "Failed to send QueryAborted after bad AE.",
                              n.logger.MINOR);
             }
             try {
-                n.sendMessage(af, origRec);
+                n.sendMessage(af, origRec, getTime(origHopsToLive));
             } catch (CommunicationException e) {
                 n.logger.log(this, "Failed to send AnnouncementFailed after " 
                              + "bad AE.", n.logger.MINOR);

Index: LastNode.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/states/announcement/LastNode.java,v
retrieving revision 1.3.4.1.2.2
retrieving revision 1.3.4.1.2.3
diff -u -w -r1.3.4.1.2.2 -r1.3.4.1.2.3
--- LastNode.java       29 Jul 2003 21:08:08 -0000      1.3.4.1.2.2
+++ LastNode.java       28 Oct 2003 20:20:42 -0000      1.3.4.1.2.3
@@ -15,6 +15,7 @@
 
     public LastNode(AnnouncementState as, NoExecute ne) {
         super(as, ne, bCopy(as.myVal));
+       terminateRouting(false, false);
     }
 
     private static byte[] bCopy(byte[] b) {
@@ -48,7 +49,7 @@
                 new AnnouncementFailed(id,
                                        AnnouncementFailed.CORRUPT_EXECUTE);
             try {
-                n.sendMessage(af, origRec);
+                n.sendMessage(af, origRec, getTime(origHopsToLive));
             } catch (CommunicationException sfe) {
                 n.logger.log(this, "Failed to send AnnouncementFailed",
                              sfe, n.logger.MINOR);
@@ -76,7 +77,7 @@
                 
         AnnouncementComplete ac = new AnnouncementComplete(id, keys);
         try {
-            sendMessage(n, origRec, ac, keys); 
+            sendMessage(n, origRec, ac, keys, getTime(origHopsToLive));
         } catch (CommunicationException e) {
             n.logger.log(this, "Failed to send AnnouncementComplete",
                          e, n.logger.MINOR);

Index: NewAnnouncement.java
===================================================================
RCS file: 
/cvsroot/freenet/freenet/src/freenet/node/states/announcement/NewAnnouncement.java,v
retrieving revision 1.1.1.1.4.4.2.1
retrieving revision 1.1.1.1.4.4.2.2
diff -u -w -r1.1.1.1.4.4.2.1 -r1.1.1.1.4.4.2.2
--- NewAnnouncement.java        29 Jul 2003 21:08:08 -0000      1.1.1.1.4.4.2.1
+++ NewAnnouncement.java        28 Oct 2003 20:20:42 -0000      1.1.1.1.4.4.2.2
@@ -46,7 +46,8 @@
 
                 n.sendMessage(new QueryRejected(id, na.hopsToLive(), 
                                                 "Node overloaded", null),
-                              origRec);
+                              origRec, getTime(2)); 
+               // see announcing.SendAnnouncement
 
                 n.loadStats.receivedQuery(false);
                 return null;
@@ -62,7 +63,8 @@
                     +": "+reason,
                     Logger.MINOR);
                 n.sendMessage(new QueryRejected(id, na.hopsToLive(),
-                                                reason, null), origRec);
+                                                reason, null), origRec,
+                             getTime(2));
 
                 return null;
             }
@@ -75,24 +77,25 @@
                                  + announcee.toString(), n.logger.MINOR);
                 n.sendMessage(new QueryRejected(id, na.hopsToLive(),
                                                 "Broken addresses.", 
-                                                null), origRec);
+                                                null), origRec,
+                             getTime(2));
                                                 
             }
             if (n.rt.references(announcee.getIdentity())) {
-               if(n.logger.shouldLog(Logger.DEBUG))
+               if(n.logger.shouldLog(Logger.DEBUG,this))
                    n.logger.log(this, "Previously knew Announcee, rejecting.",
                                 Logger.DEBUG);
                 n.sendMessage(new AnnouncementFailed(id, 
AnnouncementFailed.KNOWN_ANNOUNCEE),
-                             origRec);
+                             origRec, getTime(2));
                
                 return null;
             } else if ((depth + hopsToLive) > Node.maxHopsToLive) {
-               if(n.logger.shouldLog(Logger.DEBUG))
+               if(n.logger.shouldLog(Logger.DEBUG,this))
                    n.logger.log(this, "Too high HTL on Announcement, rejecting.",
                                 Logger.DEBUG);
                 n.sendMessage(
                     new AnnouncementFailed(id, AnnouncementFailed.UNACCEPTABLE_HTL),
-                    origRec);
+                    origRec, getTime(2));
 
                 return null;
             }
@@ -104,7 +107,7 @@
             na.decHopsToLive();
             
             // Return Accepted
-            n.sendMessage(new Accepted(id), origRec);
+            n.sendMessage(new Accepted(id), origRec, getTime(2));
 
             
         } catch (CommunicationException e) {
@@ -114,7 +117,7 @@
         }
         // Our random commit value
         myVal = new byte[20];
-        n.randSource.nextBytes(myVal);
+        n.getRandSource().nextBytes(myVal);
         
         // update commitVal
         synchronized (ctx) {
@@ -132,7 +135,7 @@
                 AnnouncementReply ar = new AnnouncementReply(id, myVal);
                 NoExecute ne = new NoExecute(id);
                 n.schedule(getTime((int)depth), ne);
-                n.sendMessage(ar, origRec);
+                n.sendMessage(ar, origRec, getTime((int)depth));
                 //System.err.println("MYVAL: " + Fields.bytesToHex(myVal));
                 return new LastNode(this, ne);
             } catch (CommunicationException e) {
@@ -154,19 +157,19 @@
         if (routes == null) {  // first time
             // Route. No sense in taking too much entropy. (And this way
             // I can test Tavin's routing table :-) ).
-            long l = n.randSource.nextLong();
+            long l = n.getRandSource().nextLong();
             Key k = new Key(new byte[] {
                 (byte) l, (byte) (l >> 8), (byte) (l >> 16), 
                 (byte) (l >> 24), (byte) (l >> 32), (byte) (l >> 40), 
                 (byte) (l >> 48), (byte) (l >> 56)
             });
-            routes = n.rt.route(k, false);
+            routes = n.rt.route(k, hopsToLive, 0, false, false);
         }
 
         routed++;
 
         while (routed < MAX_ROUTING_TIMES) { // routed does not change in loop
-           if(n.logger.shouldLog(Logger.DEBUG))
+           if(n.logger.shouldLog(Logger.DEBUG,this))
                n.logger.log(this, "Trying to route "+Fields.longToHex(id)+
                             " - iteration "+routed+" of "+MAX_ROUTING_TIMES,
                             Logger.DEBUG);
@@ -179,18 +182,16 @@
                 // don't loop back to the sender
                 continue;
             
-           if(n.logger.shouldLog(Logger.DEBUG))
+           if(n.logger.shouldLog(Logger.DEBUG,this))
                n.logger.log(this, "Forwarding query ("+Fields.longToHex(id)+
                             ") to: "+nr, Logger.DEBUG);
             try {
                 n.sendMessage(na, nr, n.routeConnectTimeout);
-                routes.routeConnected();
                 
                 lastAddr = n.getPeer(nr);
                 NoReply nrm = new NoReply(id);
                 n.schedule(getTime(1), nrm);
                 return new ReplyPending(this, nrm);
-                
             } catch (AuthenticationFailedException e) {
                 //routes.routeConnected();
                 routes.authFailed();
@@ -201,7 +202,8 @@
         try {
             n.sendMessage(new QueryRejected(id, hopsToLive, 
                                             "All routes failed.",
-                                            na.otherFields), origRec);
+                                            na.otherFields), origRec,
+                         getTime(2));
         } catch (CommunicationException e) {
             n.logger.log(this, "Failed to send back QueryRejected.",
                          e, n.logger.MINOR);

Index: ReplyPending.java
===================================================================
RCS file: 
/cvsroot/freenet/freenet/src/freenet/node/states/announcement/ReplyPending.java,v
retrieving revision 1.1.1.1.4.2.2.1
retrieving revision 1.1.1.1.4.2.2.2
diff -u -w -r1.1.1.1.4.2.2.1 -r1.1.1.1.4.2.2.2
--- ReplyPending.java   22 Apr 2003 20:07:53 -0000      1.1.1.1.4.2.2.1
+++ ReplyPending.java   28 Oct 2003 20:20:42 -0000      1.1.1.1.4.2.2.2
@@ -54,6 +54,7 @@
                          Logger.MINOR);
         }
 
+       terminateRouting(false, false);
         return new AnnouncementDone(this);
     }
 
@@ -86,10 +87,12 @@
 
             routes.timedOut();
             if (!sendQueryRestarted(n, new QueryRestarted(id))) {
+               terminateRouting(false, false);
                 return new AnnouncementDone(this);
             }
             try {
-                n.sendMessage(new QueryAborted(id), lastAddr);
+                n.sendMessage(new QueryAborted(id), lastAddr,
+                             getTime(origHopsToLive));
             } catch (CommunicationException e) {
                 // so that is why he didn't reply....
             }
@@ -107,13 +110,14 @@
         throws BadStateException {
         checkReply(qr);
 
-       if(n.logger.shouldLog(Logger.DEBUG))
+       if(n.logger.shouldLog(Logger.DEBUG,this))
            n.logger.log(this, "Received QueryRejected on "+Fields.longToHex(id)+
                         " ("+qr.hopsToLive+","+qr.reason+")", n.logger.DEBUG);
         
         nr.cancel();
 
         if (!sendQueryRestarted(n, new QueryRestarted(id))) {
+           terminateRouting(false, false);
             return new AnnouncementDone(this);
         }
             
@@ -132,11 +136,11 @@
         nr = new NoReply(id);
         n.schedule(getTime(hopsToLive), nr);
 
-        if (!sendQueryRestarted(n, qr))
+        if (!sendQueryRestarted(n, qr)) {
+           terminateRouting(false, false);
             return new AnnouncementDone(this);
-        else
+       } else
             return this;
-        
     }
 
     public State receivedMessage(Node n, AnnouncementFailed af) 
@@ -147,11 +151,12 @@
         n.logger.log(this, "Announcement failed for reason " + af.reason()
                      + "at later node", n.logger.DEBUG);
         try {
-            n.sendMessage(af, origRec);
+            n.sendMessage(af, origRec, getTime(origHopsToLive));
         } catch (CommunicationException e) {
             n.logger.log(this, "Failed to send AnnouncementFailed",
                          e, n.logger.MINOR);
         }
+       terminateRouting(false, false);
         return new AnnouncementDone(this);
     }
 
@@ -169,7 +174,7 @@
         // note side effect on message
 
         try {
-            n.sendMessage(ar, origRec);
+            n.sendMessage(ar, origRec, getTime(origHopsToLive));
         } catch (CommunicationException e) {
             n.logger.log(this, "Failed to send AnnouncementReply", e,
                          n.logger.MINOR);
@@ -190,14 +195,15 @@
                 try {
                     n.sendMessage(new AnnouncementFailed(id,
                                        AnnouncementFailed.TOO_MANY_RESTARTS),
-                                  origRec);
+                                  origRec, getTime(origHopsToLive));
                 } finally {
-                    n.sendMessage(new QueryAborted(id), lastAddr);
+                    n.sendMessage(new QueryAborted(id), lastAddr,
+                                 getTime(origHopsToLive));
                 }
                 return false;
             }
             
-            n.sendMessage(qr, origRec);
+            n.sendMessage(qr, origRec, getTime(origHopsToLive));
 
             return true;
         } catch (CommunicationException e) {

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

Reply via email to