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

Modified Files:
        Node.java FailureTable.java 
Log Message:
6319:
Probabilistic rejection, based on work by Benny Amorsen.
Make a distinction in stats between rejecting nearly all requests, and rejecting most 
requests.
Make NewAnnouncement use the Node.acceptRequest() method rather than rejectingRequests 
so it works with prejecting.
Don't accept requests just because they are in the failtable, they have to be likely 
to be DNFed by it.

Index: Node.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/Node.java,v
retrieving revision 1.241
retrieving revision 1.242
diff -u -w -r1.241 -r1.242
--- Node.java   7 Nov 2003 21:16:41 -0000       1.241
+++ Node.java   7 Nov 2003 21:47:46 -0000       1.242
@@ -2572,13 +2572,14 @@
     long nextLoggedRejectingConns = 0;
     
     /**
+     * @param all if true, only return true if the node is rejecting nearly all 
incoming reqs
      * @return true if the Node is QueryRejecting inbound requests, false otherwise.
      **/
-    public boolean rejectingRequests() {
-        return rejectingRequests(null);
+    public boolean rejectingRequests(boolean all) {
+        return rejectingRequests(null, all);
     }
 
-    public boolean rejectingRequests(StringBuffer why) {
+    public boolean rejectingRequests(StringBuffer why, boolean all) {
         if (outboundRequestLimit != null && outboundRequestLimit.exceeded()) {
             if (why != null) {
                 why.append("outboundRequestLimit exceeded.");
@@ -2586,12 +2587,12 @@
             return true;
         }
         float estimatedLoad = estimatedLoad();
-        if (estimatedLoad > overloadLow) {
+        if (estimatedLoad > (all ? overloadHigh : overloadLow)) {
             if (why != null) {
                 why.append("Estimated load (");
                 why.append(nfp.format(estimatedLoad));
-                why.append(") > overloadLow (");
-                why.append(nfp.format(overloadLow));
+                why.append(") > overload"+(all ? "High" : "Low") + " (");
+                why.append(nfp.format(all ? overloadHigh : overloadLow));
                 why.append(")");
             }
             return true;
@@ -2817,7 +2818,8 @@
     /**
      * Hook for rate limiting.
      */
-    public boolean acceptRequest(Key searchKey, Address source) {
+    public boolean acceptRequest(Key searchKey, 
+                                                                       int 
hopsToLive, Address source) {
 
         String diagAddr = null;
 
@@ -2841,7 +2843,7 @@
         // Node is loaded
         if (load < overloadHigh) {
                if (searchKey != null && 
-                                               (ft.contains(searchKey) || 
ds.contains(searchKey))) {
+                                               (ft.contains(searchKey, hopsToLive) || 
ds.contains(searchKey))) {
                        if (inboundRequests != null && diagAddr != null) {
                                inboundRequests.incSuccesses(diagAddr);
                        }
@@ -2861,7 +2863,7 @@
        // Node is seriously loaded
         if (load < 1) {
            if (searchKey != null &&
-                       (ft.contains(searchKey) || ds.contains(searchKey))) {
+                       (ft.contains(searchKey, hopsToLive) || 
ds.contains(searchKey))) {
                if (Math.random() * (1 - overloadHigh) + overloadHigh < load) {
                    if (inboundRequests != null && diagAddr != null) {
                        inboundRequests.incSuccesses(diagAddr);

Index: FailureTable.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/FailureTable.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -w -r1.34 -r1.35
--- FailureTable.java   4 Nov 2003 09:18:17 -0000       1.34
+++ FailureTable.java   7 Nov 2003 21:47:49 -0000       1.35
@@ -127,18 +127,21 @@
         fe.failed(hopsToLive, time);
     }
 
+    public synchronized long shouldFail(Key k, int hopsToLive) {
+       return shouldFail(k, hopsToLive, false);
+    }
     /**
      * Checks whether a query should fail.
      * @return  The time at which the query that failed to find the key
      *          occured, or < 0 if no such query is known.
      */
-    public synchronized long shouldFail(Key k, int hopsToLive) {
+    public synchronized long shouldFail(Key k, int hopsToLive, boolean noStats) {
         FailureEntry fe = (FailureEntry) failedKeys.get(k);
         long time = System.currentTimeMillis();
         
         if (fe == null) return -1;
         
-        return fe.shouldFail(hopsToLive, time);
+        return fe.shouldFail(hopsToLive, time, noStats);
     }
     
     public synchronized void ignoredDNF(Key k) {
@@ -156,8 +159,8 @@
     /**
      * @return true, if the Key is contained in the failuretable
      */
-    public synchronized boolean contains(Key k) {
-        return failedKeys.containsKey(k);
+    public synchronized boolean contains(Key k, int hopsToLive) {
+       return shouldFail(k, hopsToLive, true) > 0;
     }
 
     /**
@@ -357,7 +360,7 @@
                 * @return  The time at which the query that failed to find the key
                 *          occured, or < 0 if no such query is known.
                 */
-               public long shouldFail(int hopsToLive, long time) {
+               public long shouldFail(int hopsToLive, long time, boolean noStats) {
                        long failedTime=-1;
                        for(Iterator i = myItems.iterator();i.hasNext();) {
                                FailItem fi = (FailItem)i.next();
@@ -367,11 +370,13 @@
                                        continue;
                                }
                                if( (failedTime=fi.shouldFail(hopsToLive,time)) >= 0 ) 
{
+                                       if(!noStats) {
                                        blocks++;
                                        totalBlocks++;
                                        
Core.diagnostics.occurrenceContinuous("timeBetweenFailedRequests",
                                                                                       
                                                          (double)(time - lastHit));
                                        lastHit = time;
+                                       }
                                        break;
                                }
                        }

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

Reply via email to