Author: toad
Date: 2008-04-22 13:43:37 +0000 (Tue, 22 Apr 2008)
New Revision: 19494

Modified:
   trunk/freenet/src/freenet/node/CHKInsertHandler.java
   trunk/freenet/src/freenet/node/FailureTable.java
   trunk/freenet/src/freenet/node/Node.java
   trunk/freenet/src/freenet/node/NodeClientCore.java
   trunk/freenet/src/freenet/node/NodeDispatcher.java
   trunk/freenet/src/freenet/node/RequestHandler.java
   trunk/freenet/src/freenet/node/SSKInsertHandler.java
Log:
Track running local UIDs vs remote UIDs.

Modified: trunk/freenet/src/freenet/node/CHKInsertHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/CHKInsertHandler.java        2008-04-22 
12:44:37 UTC (rev 19493)
+++ trunk/freenet/src/freenet/node/CHKInsertHandler.java        2008-04-22 
13:43:37 UTC (rev 19494)
@@ -74,7 +74,7 @@
             Logger.error(this, "Caught in run() "+t, t);
         } finally {
                if(logMINOR) Logger.minor(this, "Exiting CHKInsertHandler.run() 
for "+uid);
-            node.unlockUID(uid, false, true, false, false);
+            node.unlockUID(uid, false, true, false, false, false);
         }
     }


Modified: trunk/freenet/src/freenet/node/FailureTable.java
===================================================================
--- trunk/freenet/src/freenet/node/FailureTable.java    2008-04-22 12:44:37 UTC 
(rev 19493)
+++ trunk/freenet/src/freenet/node/FailureTable.java    2008-04-22 13:43:37 UTC 
(rev 19494)
@@ -377,7 +377,7 @@
                                                // :<
                                                Logger.error(this, "Waited too 
long sending SSK data");
                                        } finally {
-                                               node.unlockUID(uid, isSSK, 
false, false, true);
+                                               node.unlockUID(uid, isSSK, 
false, false, true, false);
                                        }
                                }

@@ -416,7 +416,7 @@
                                        } catch (Throwable t) {
                                                Logger.error(this, "Sending 
offered key failed: "+t, t);
                                        } finally {
-                                               node.unlockUID(uid, isSSK, 
false, false, true);
+                                               node.unlockUID(uid, isSSK, 
false, false, true, false);
                                        }
                                }


Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java    2008-04-22 12:44:37 UTC (rev 
19493)
+++ trunk/freenet/src/freenet/node/Node.java    2008-04-22 13:43:37 UTC (rev 
19494)
@@ -350,9 +350,13 @@
        /** HashSet of currently running request UIDs */
        private final HashSet runningUIDs;
        private final HashSet runningCHKGetUIDs;
+       private final HashSet runningLocalCHKGetUIDs;
        private final HashSet runningSSKGetUIDs;
+       private final HashSet runningLocalSSKGetUIDs;
        private final HashSet runningCHKPutUIDs;
+       private final HashSet runningLocalCHKPutUIDs;
        private final HashSet runningSSKPutUIDs;
+       private final HashSet runningLocalSSKPutUIDs;
        private final HashSet runningCHKOfferReplyUIDs;
        private final HashSet runningSSKOfferReplyUIDs;

@@ -664,9 +668,13 @@
                insertSenders = new HashMap();
                runningUIDs = new HashSet();
                runningCHKGetUIDs = new HashSet();
+               runningLocalCHKGetUIDs = new HashSet();
                runningSSKGetUIDs = new HashSet();
+               runningLocalSSKGetUIDs = new HashSet();
                runningCHKPutUIDs = new HashSet();
+               runningLocalCHKPutUIDs = new HashSet();
                runningSSKPutUIDs = new HashSet();
+               runningLocalSSKPutUIDs = new HashSet();
                runningCHKOfferReplyUIDs = new HashSet();
                runningSSKOfferReplyUIDs = new HashSet();

@@ -2360,10 +2368,10 @@
                return is;
        }

-       public boolean lockUID(long uid, boolean ssk, boolean insert, boolean 
offerReply) {
+       public boolean lockUID(long uid, boolean ssk, boolean insert, boolean 
offerReply, boolean local) {
                if(logMINOR) Logger.minor(this, "Locking "+uid+" ssk="+ssk+" 
insert="+insert+" offerReply="+offerReply);
                Long l = new Long(uid);
-               HashSet set = getUIDTracker(ssk, insert, offerReply);
+               HashSet set = getUIDTracker(ssk, insert, offerReply, local);
                synchronized(set) {
                        set.add(l);
                }
@@ -2374,11 +2382,11 @@
                }
        }

-       public void unlockUID(long uid, boolean ssk, boolean insert, boolean 
canFail, boolean offerReply) {
+       public void unlockUID(long uid, boolean ssk, boolean insert, boolean 
canFail, boolean offerReply, boolean local) {
                if(logMINOR) Logger.minor(this, "Unlocking "+uid+" ssk="+ssk+" 
insert="+insert+" offerReply="+offerReply);
                Long l = new Long(uid);
                completed(uid);
-               HashSet set = getUIDTracker(ssk, insert, offerReply);
+               HashSet set = getUIDTracker(ssk, insert, offerReply, local);
                synchronized(set) {
                        set.remove(l);
                }
@@ -2388,15 +2396,21 @@
                }
        }

-       HashSet getUIDTracker(boolean ssk, boolean insert, boolean offerReply) {
+       HashSet getUIDTracker(boolean ssk, boolean insert, boolean offerReply, 
boolean local) {
                if(ssk) {
                        if(offerReply)
                                return runningSSKOfferReplyUIDs;
-                       return insert ? runningSSKPutUIDs : runningSSKGetUIDs;
+                       if(!local)
+                               return insert ? runningSSKPutUIDs : 
runningSSKGetUIDs;
+                       else
+                               return insert ? runningLocalSSKPutUIDs : 
runningLocalSSKGetUIDs;
                } else {
                        if(offerReply)
                                return runningCHKOfferReplyUIDs;
-                       return insert ? runningCHKPutUIDs : runningCHKGetUIDs;
+                       if(!local)
+                               return insert ? runningCHKPutUIDs : 
runningCHKGetUIDs;
+                       else
+                               return insert ? runningLocalCHKPutUIDs : 
runningLocalCHKGetUIDs;
                }
        }

@@ -2461,19 +2475,19 @@
        }

        public int getNumSSKRequests() {
-               return runningSSKGetUIDs.size();
+               return runningSSKGetUIDs.size() + runningLocalSSKGetUIDs.size();
        }

        public int getNumCHKRequests() {
-               return runningCHKGetUIDs.size();
+               return runningCHKGetUIDs.size() + runningLocalCHKGetUIDs.size();
        }

        public int getNumSSKInserts() {
-               return runningSSKPutUIDs.size();
+               return runningSSKPutUIDs.size() + runningLocalSSKPutUIDs.size();
        }

        public int getNumCHKInserts() {
-               return runningCHKPutUIDs.size();
+               return runningCHKPutUIDs.size() + runningLocalCHKPutUIDs.size();
        }

        public int getNumSSKOfferReplies() {

Modified: trunk/freenet/src/freenet/node/NodeClientCore.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeClientCore.java  2008-04-22 12:44:37 UTC 
(rev 19493)
+++ trunk/freenet/src/freenet/node/NodeClientCore.java  2008-04-22 13:43:37 UTC 
(rev 19494)
@@ -431,7 +431,7 @@
        public void asyncGet(Key key, boolean cache, boolean offersOnly, final 
SimpleRequestSenderCompletionListener listener) {
                final long uid = random.nextLong();
                final boolean isSSK = key instanceof NodeSSK;
-               if(!node.lockUID(uid, isSSK, false, false)) {
+               if(!node.lockUID(uid, isSSK, false, false, true)) {
                        Logger.error(this, "Could not lock UID just randomly 
generated: "+uid+" - probably indicates broken PRNG");
                        return;
                }
@@ -447,7 +447,7 @@

                        public void onRequestSenderFinished(int status) {
                                // If transfer coalescing has happened, we may 
have already unlocked.
-                               node.unlockUID(uid, isSSK, false, true, false);
+                               node.unlockUID(uid, isSSK, false, true, false, 
true);
                                if(listener != null)
                                        listener.completed(status == 
RequestSender.SUCCESS);
                        }
@@ -465,22 +465,22 @@
                try {
                        Object o = node.makeRequestSender(key, node.maxHTL(), 
uid, null, false, cache, false, offersOnly);
                        if(o instanceof KeyBlock) {
-                               node.unlockUID(uid, false, false, true, false);
+                               node.unlockUID(uid, false, false, true, false, 
true);
                                return; // Already have it.
                        }
                        RequestSender rs = (RequestSender) o;
                        rs.addListener(listener);
                        if(rs.uid != uid)
-                               node.unlockUID(uid, false, false, false, false);
+                               node.unlockUID(uid, false, false, false, false, 
true);
                        // Else it has started a request.
                        if(logMINOR)
                                Logger.minor(this, "Started "+o+" for "+uid+" 
for "+key);
                } catch (RuntimeException e) {
                        Logger.error(this, "Caught error trying to start 
request: "+e, e);
-                       node.unlockUID(uid, false, false, true, false);
+                       node.unlockUID(uid, false, false, true, false, true);
                } catch (Error e) {
                        Logger.error(this, "Caught error trying to start 
request: "+e, e);
-                       node.unlockUID(uid, false, false, true, false);
+                       node.unlockUID(uid, false, false, true, false, true);
                }
        }

@@ -497,7 +497,7 @@
                logMINOR = Logger.shouldLog(Logger.MINOR, this);
                long startTime = System.currentTimeMillis();
                long uid = random.nextLong();
-               if(!node.lockUID(uid, false, false, false)) {
+               if(!node.lockUID(uid, false, false, false, true)) {
                        Logger.error(this, "Could not lock UID just randomly 
generated: "+uid+" - probably indicates broken PRNG");
                        throw new 
LowLevelGetException(LowLevelGetException.INTERNAL_ERROR);
                }
@@ -604,7 +604,7 @@
                        }
                }
                } finally {
-                       node.unlockUID(uid, false, false, true, false);
+                       node.unlockUID(uid, false, false, true, false, true);
                }
        }

@@ -612,7 +612,7 @@
                logMINOR = Logger.shouldLog(Logger.MINOR, this);
                long startTime = System.currentTimeMillis();
                long uid = random.nextLong();
-               if(!node.lockUID(uid, true, false, false)) {
+               if(!node.lockUID(uid, true, false, false, true)) {
                        Logger.error(this, "Could not lock UID just randomly 
generated: "+uid+" - probably indicates broken PRNG");
                        throw new 
LowLevelGetException(LowLevelGetException.INTERNAL_ERROR);
                }
@@ -719,7 +719,7 @@
                        }
                }
                } finally {
-                       node.unlockUID(uid, true, false, true, false);
+                       node.unlockUID(uid, true, false, true, false, true);
                }
        }

@@ -739,7 +739,7 @@
                PartiallyReceivedBlock prb = new 
PartiallyReceivedBlock(Node.PACKETS_IN_BLOCK, Node.PACKET_SIZE, data);
                CHKInsertSender is;
                long uid = random.nextLong();
-               if(!node.lockUID(uid, false, true, false)) {
+               if(!node.lockUID(uid, false, true, false, true)) {
                        Logger.error(this, "Could not lock UID just randomly 
generated: "+uid+" - probably indicates broken PRNG");
                        throw new 
LowLevelPutException(LowLevelPutException.INTERNAL_ERROR);
                }
@@ -848,7 +848,7 @@
                        }
                }
                } finally {
-                       node.unlockUID(uid, false, true, true, false);
+                       node.unlockUID(uid, false, true, true, false, true);
                }
        }

@@ -856,7 +856,7 @@
                logMINOR = Logger.shouldLog(Logger.MINOR, this);
                SSKInsertSender is;
                long uid = random.nextLong();
-               if(!node.lockUID(uid, true, true, false)) {
+               if(!node.lockUID(uid, true, true, false, true)) {
                        Logger.error(this, "Could not lock UID just randomly 
generated: "+uid+" - probably indicates broken PRNG");
                        throw new 
LowLevelPutException(LowLevelPutException.INTERNAL_ERROR);
                }
@@ -977,7 +977,7 @@
                        }
                }
                } finally {
-                       node.unlockUID(uid, true, true, true, false);
+                       node.unlockUID(uid, true, true, true, false, true);
                }
        }


Modified: trunk/freenet/src/freenet/node/NodeDispatcher.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeDispatcher.java  2008-04-22 12:44:37 UTC 
(rev 19493)
+++ trunk/freenet/src/freenet/node/NodeDispatcher.java  2008-04-22 13:43:37 UTC 
(rev 19494)
@@ -242,7 +242,7 @@

                // Do we want it? We can RejectOverload if we don't have the 
bandwidth...
                boolean isSSK = key instanceof NodeSSK;
-               node.lockUID(uid, isSSK, false, true);
+               node.lockUID(uid, isSSK, false, true, false);
                boolean needPubKey;
                try {
                needPubKey = m.getBoolean(DMT.NEED_PUB_KEY);
@@ -256,15 +256,15 @@
                        } catch (NotConnectedException e) {
                                Logger.normal(this, "Rejecting (overload) data 
request from "+source.getPeer()+": "+e);
                        }
-                       node.unlockUID(uid, isSSK, false, false, true);
+                       node.unlockUID(uid, isSSK, false, false, true, false);
                        return true;
                }

                } catch (Error e) {
-                       node.unlockUID(uid, isSSK, false, false, true);
+                       node.unlockUID(uid, isSSK, false, false, true, false);
                        throw e;
                } catch (RuntimeException e) {
-                       node.unlockUID(uid, isSSK, false, false, true);
+                       node.unlockUID(uid, isSSK, false, false, true, false);
                        throw e;
                } // Otherwise, sendOfferedKey is responsible for unlocking. 

@@ -339,7 +339,7 @@
                }
         short htl = m.getShort(DMT.HTL);
         Key key = (Key) m.getObject(DMT.FREENET_ROUTING_KEY);
-               if(!node.lockUID(id, isSSK, false, false)) {
+               if(!node.lockUID(id, isSSK, false, false, false)) {
                        if(logMINOR) Logger.minor(this, "Could not lock ID 
"+id+" -> rejecting (already running)");
                        Message rejected = DMT.createFNPRejectedLoop(id);
                        try {
@@ -362,7 +362,7 @@
                        } catch (NotConnectedException e) {
                                Logger.normal(this, "Rejecting (overload) data 
request from "+source.getPeer()+": "+e);
                        }
-                       node.unlockUID(id, isSSK, false, false, false);
+                       node.unlockUID(id, isSSK, false, false, false, false);
                        // Do not tell failure table.
                        // Otherwise an attacker can flood us with requests 
very cheaply and purge our
                        // failure table even though we didn't accept any of 
them.
@@ -386,7 +386,7 @@
                        }
                        return true;
                }
-               if(!node.lockUID(id, isSSK, true, false)) {
+               if(!node.lockUID(id, isSSK, true, false, false)) {
                        if(logMINOR) Logger.minor(this, "Could not lock ID 
"+id+" -> rejecting (already running)");
                        Message rejected = DMT.createFNPRejectedLoop(id);
                        try {
@@ -406,7 +406,7 @@
                        } catch (NotConnectedException e) {
                                Logger.normal(this, "Rejecting (overload) 
insert request from "+source.getPeer()+": "+e);
                        }
-                       node.unlockUID(id, isSSK, true, false, false);
+                       node.unlockUID(id, isSSK, true, false, false, false);
                        return true;
                }
                long now = System.currentTimeMillis();

Modified: trunk/freenet/src/freenet/node/RequestHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/RequestHandler.java  2008-04-22 12:44:37 UTC 
(rev 19493)
+++ trunk/freenet/src/freenet/node/RequestHandler.java  2008-04-22 13:43:37 UTC 
(rev 19494)
@@ -76,11 +76,11 @@
         } catch (NotConnectedException e) {
                Logger.normal(this, "requestor gone, could not start request 
handler wait");
                        node.removeTransferringRequestHandler(uid);
-            node.unlockUID(uid, key instanceof NodeSSK, false, false, false);
+            node.unlockUID(uid, key instanceof NodeSSK, false, false, false, 
false);
         } catch (Throwable t) {
             Logger.error(this, "Caught "+t, t);
                        node.removeTransferringRequestHandler(uid);
-            node.unlockUID(uid, key instanceof NodeSSK, false, false, false);
+            node.unlockUID(uid, key instanceof NodeSSK, false, false, false, 
false);
         }
     }

@@ -430,7 +430,7 @@

        private void unregisterRequestHandlerWithNode() {
                node.removeTransferringRequestHandler(uid);
-               node.unlockUID(uid, key instanceof NodeSSK, false, false, 
false);
+               node.unlockUID(uid, key instanceof NodeSSK, false, false, 
false, false);
        }

        /**

Modified: trunk/freenet/src/freenet/node/SSKInsertHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/SSKInsertHandler.java        2008-04-22 
12:44:37 UTC (rev 19493)
+++ trunk/freenet/src/freenet/node/SSKInsertHandler.java        2008-04-22 
13:43:37 UTC (rev 19494)
@@ -76,7 +76,7 @@
             Logger.error(this, "Caught "+t, t);
         } finally {
             if(logMINOR) Logger.minor(this, "Exiting InsertHandler.run() for 
"+uid);
-            node.unlockUID(uid, true, true, false, false);
+            node.unlockUID(uid, true, true, false, false, false);
         }
     }



Reply via email to