Author: toad
Date: 2007-03-24 21:16:35 +0000 (Sat, 24 Mar 2007)
New Revision: 12344

Modified:
   trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
   trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java
   trunk/freenet/src/freenet/node/CHKInsertSender.java
   trunk/freenet/src/freenet/node/InsertHandler.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/RequestSender.java
   trunk/freenet/src/freenet/node/SSKInsertHandler.java
   trunk/freenet/src/freenet/node/SSKInsertSender.java
Log:
Track the number of incoming CHK/SSK inserts/requests

Modified: trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java       
2007-03-24 21:08:24 UTC (rev 12343)
+++ trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java       
2007-03-24 21:16:35 UTC (rev 12344)
@@ -195,7 +195,11 @@

                        // Activity box
                        int numInserts = node.getNumInserts();
+                       int numCHKInserts = node.getNumCHKInserts();
+                       int numSSKInserts = node.getNumSSKInserts();
                        int numRequests = node.getNumRequests();
+                       int numCHKRequests = node.getNumCHKRequests();
+                       int numSSKRequests = node.getNumSSKRequests();
                        int numTransferringRequests = 
node.getNumTransferringRequests();
                        int numARKFetchers = node.getNumARKFetchers();

@@ -207,10 +211,10 @@
                        } else {
                                HTMLNode activityList = 
activityInfoboxContent.addChild("ul");
                                if (numInserts > 0) {
-                                       activityList.addChild("li", 
"Inserts:\u00a0" + numInserts);
+                                       activityList.addChild("li", 
"Inserts:\u00a0" + numInserts + "\u00a0(incoming:\u00a0CHK:\u00a0" + 
numCHKInserts+"\u00a0SSK:\u00a0" + numSSKInserts+")");
                                }
                                if (numRequests > 0) {
-                                       activityList.addChild("li", 
"Requests:\u00a0" + numRequests);
+                                       activityList.addChild("li", 
"Requests:\u00a0" + numRequests + "\u00a0(incoming:\u00a0CHK:\u00a0" + 
numCHKRequests+"\u00a0SSK:\u00a0" + numSSKRequests+")");
                                }
                                if (numTransferringRequests > 0) {
                                        activityList.addChild("li", 
"Transferring\u00a0Requests:\u00a0" + numTransferringRequests);

Modified: trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java       
2007-03-24 21:08:24 UTC (rev 12343)
+++ trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java       
2007-03-24 21:16:35 UTC (rev 12344)
@@ -195,7 +195,11 @@

                        // Activity box
                        int numInserts = node.getNumInserts();
+                       int numCHKInserts = node.getNumCHKInserts();
+                       int numSSKInserts = node.getNumSSKInserts();
                        int numRequests = node.getNumRequests();
+                       int numCHKRequests = node.getNumCHKRequests();
+                       int numSSKRequests = node.getNumSSKRequests();
                        int numTransferringRequests = 
node.getNumTransferringRequests();
                        int numARKFetchers = node.getNumARKFetchers();

@@ -207,10 +211,10 @@
                        } else {
                                HTMLNode activityList = 
activityInfoboxContent.addChild("ul");
                                if (numInserts > 0) {
-                                       activityList.addChild("li", 
"Inserts:\u00a0" + numInserts);
+                                       activityList.addChild("li", 
"Inserts:\u00a0" + numInserts + "\u00a0(incoming:\u00a0CHK:\u00a0" + 
numCHKInserts+"\u00a0SSK:\u00a0" + numSSKInserts+")");
                                }
                                if (numRequests > 0) {
-                                       activityList.addChild("li", 
"Requests:\u00a0" + numRequests);
+                                       activityList.addChild("li", 
"Requests:\u00a0" + numRequests + "\u00a0(incoming:\u00a0CHK:\u00a0" + 
numCHKRequests+"\u00a0SSK:\u00a0" + numSSKRequests+")");
                                }
                                if (numTransferringRequests > 0) {
                                        activityList.addChild("li", 
"Transferring\u00a0Requests:\u00a0" + numTransferringRequests);

Modified: trunk/freenet/src/freenet/node/CHKInsertSender.java
===================================================================
--- trunk/freenet/src/freenet/node/CHKInsertSender.java 2007-03-24 21:08:24 UTC 
(rev 12343)
+++ trunk/freenet/src/freenet/node/CHKInsertSender.java 2007-03-24 21:16:35 UTC 
(rev 12344)
@@ -228,7 +228,6 @@
             if(myStatus == NOT_FINISHED)
                finish(INTERNAL_ERROR, null);
         } finally {
-            node.completed(uid);
                node.removeInsertSender(myKey, origHTL, this);
         }
     }

Modified: trunk/freenet/src/freenet/node/InsertHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/InsertHandler.java   2007-03-24 21:08:24 UTC 
(rev 12343)
+++ trunk/freenet/src/freenet/node/InsertHandler.java   2007-03-24 21:16:35 UTC 
(rev 12344)
@@ -77,7 +77,7 @@
             Logger.error(this, "Caught "+t, t);
         } finally {
                if(logMINOR) Logger.minor(this, "Exiting InsertHandler.run() 
for "+uid);
-            node.unlockUID(uid);
+            node.unlockUID(uid, true, true);
         }
     }


Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java    2007-03-24 21:08:24 UTC (rev 
12343)
+++ trunk/freenet/src/freenet/node/Node.java    2007-03-24 21:16:35 UTC (rev 
12344)
@@ -309,6 +309,10 @@

        /** HashSet of currently running request UIDs */
        private final HashSet runningUIDs;
+       private final HashSet runningCHKGetUIDs;
+       private final HashSet runningSSKGetUIDs;
+       private final HashSet runningCHKPutUIDs;
+       private final HashSet runningSSKPutUIDs;

        byte[] myIdentity; // FIXME: simple identity block; should be unique
        /** Hash of identity. Used as setup key. */
@@ -693,6 +697,10 @@
                transferringRequestSenders = new HashMap();
                insertSenders = new HashMap();
                runningUIDs = new HashSet();
+               runningCHKGetUIDs = new HashSet();
+               runningSSKGetUIDs = new HashSet();
+               runningCHKPutUIDs = new HashSet();
+               runningSSKPutUIDs = new HashSet();
                dnsr = new DNSRequester(this);
                ps = new PacketSender(this);
                bootID = random.nextLong();
@@ -2080,9 +2088,13 @@
                return is;
        }

-       public boolean lockUID(long uid) {
+       public boolean lockUID(long uid, boolean ssk, boolean insert) {
                if(logMINOR) Logger.minor(this, "Locking "+uid);
                Long l = new Long(uid);
+               HashSet set = getUIDTracker(ssk, insert);
+               synchronized(set) {
+                       set.add(l);
+               }
                synchronized(runningUIDs) {
                        if(runningUIDs.contains(l)) return false;
                        runningUIDs.add(l);
@@ -2090,16 +2102,28 @@
                }
        }

-       public void unlockUID(long uid) {
+       public void unlockUID(long uid, boolean ssk, boolean insert) {
                if(logMINOR) Logger.minor(this, "Unlocking "+uid);
                Long l = new Long(uid);
                completed(uid);
+               HashSet set = getUIDTracker(ssk, insert);
+               synchronized(set) {
+                       set.remove(l);
+               }
                synchronized(runningUIDs) {
                        if(!runningUIDs.remove(l))
                                throw new IllegalStateException("Could not 
unlock "+uid+ '!');
                }
        }

+       HashSet getUIDTracker(boolean ssk, boolean insert) {
+               if(ssk) {
+                       return insert ? runningSSKPutUIDs : runningSSKGetUIDs;
+               } else {
+                       return insert ? runningCHKPutUIDs : runningCHKGetUIDs;
+               }
+       }
+       
        /**
         * @return Some status information.
         */
@@ -2158,6 +2182,22 @@
                }
        }

+       public int getNumSSKRequests() {
+               return runningSSKGetUIDs.size();
+       }
+       
+       public int getNumCHKRequests() {
+               return runningCHKGetUIDs.size();
+       }
+       
+       public int getNumSSKInserts() {
+               return runningSSKPutUIDs.size();
+       }
+       
+       public int getNumCHKInserts() {
+               return runningCHKPutUIDs.size();
+       }
+       
        public int getNumTransferringRequests() {
                synchronized(transferringRequestSenders) {
                        return transferringRequestSenders.size();
@@ -2228,7 +2268,7 @@
        /**
         * A request completed (regardless of success).
         */
-       public synchronized void completed(long id) {
+       private synchronized void completed(long id) {
                recentlyCompletedIDs.push(new Long(id));
                while(recentlyCompletedIDs.size() > MAX_RECENTLY_COMPLETED_IDS)
                        recentlyCompletedIDs.pop();

Modified: trunk/freenet/src/freenet/node/NodeClientCore.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeClientCore.java  2007-03-24 21:08:24 UTC 
(rev 12343)
+++ trunk/freenet/src/freenet/node/NodeClientCore.java  2007-03-24 21:16:35 UTC 
(rev 12344)
@@ -410,10 +410,11 @@
                logMINOR = Logger.shouldLog(Logger.MINOR, this);
                long startTime = System.currentTimeMillis();
                long uid = random.nextLong();
-               if(!node.lockUID(uid)) {
+               if(!node.lockUID(uid, false, false)) {
                        Logger.error(this, "Could not lock UID just randomly 
generated: "+uid+" - probably indicates broken PRNG");
                        throw new 
LowLevelGetException(LowLevelGetException.INTERNAL_ERROR);
                }
+               try {
                Object o = node.makeRequestSender(key.getNodeCHK(), 
node.maxHTL(), uid, null, node.getLocation(), false, localOnly, cache, 
ignoreStore);
                if(o instanceof CHKBlock) {
                        try {
@@ -502,16 +503,20 @@
                                }
                        }
                }
+               } finally {
+                       node.unlockUID(uid, false, false);
+               }
        }

        ClientSSKBlock realGetSSK(ClientSSK key, boolean localOnly, boolean 
cache, boolean ignoreStore) throws LowLevelGetException {
                logMINOR = Logger.shouldLog(Logger.MINOR, this);
                long startTime = System.currentTimeMillis();
                long uid = random.nextLong();
-               if(!node.lockUID(uid)) {
+               if(!node.lockUID(uid, true, false)) {
                        Logger.error(this, "Could not lock UID just randomly 
generated: "+uid+" - probably indicates broken PRNG");
                        throw new 
LowLevelGetException(LowLevelGetException.INTERNAL_ERROR);
                }
+               try {
                Object o = node.makeRequestSender(key.getNodeKey(), 
node.maxHTL(), uid, null, node.getLocation(), false, localOnly, cache, 
ignoreStore);
                if(o instanceof SSKBlock) {
                        try {
@@ -600,6 +605,9 @@
                                }
                        }
                }
+               } finally {
+                       node.unlockUID(uid, true, false);
+               }
        }

        public void realPut(KeyBlock block, boolean cache) throws 
LowLevelPutException {
@@ -618,10 +626,11 @@
                PartiallyReceivedBlock prb = new 
PartiallyReceivedBlock(Node.PACKETS_IN_BLOCK, Node.PACKET_SIZE, data);
                CHKInsertSender is;
                long uid = random.nextLong();
-               if(!node.lockUID(uid)) {
+               if(!node.lockUID(uid, false, true)) {
                        Logger.error(this, "Could not lock UID just randomly 
generated: "+uid+" - probably indicates broken PRNG");
                        throw new 
LowLevelPutException(LowLevelPutException.INTERNAL_ERROR);
                }
+               try {
                long startTime = System.currentTimeMillis();
                if(cache) {
                        node.store(block);
@@ -719,16 +728,20 @@
                                throw new 
LowLevelPutException(LowLevelPutException.INTERNAL_ERROR);
                        }
                }
+               } finally {
+                       node.unlockUID(uid, false, true);
+               }
        }

        public void realPutSSK(SSKBlock block, boolean cache) throws 
LowLevelPutException {
                logMINOR = Logger.shouldLog(Logger.MINOR, this);
                SSKInsertSender is;
                long uid = random.nextLong();
-               if(!node.lockUID(uid)) {
+               if(!node.lockUID(uid, true, true)) {
                        Logger.error(this, "Could not lock UID just randomly 
generated: "+uid+" - probably indicates broken PRNG");
                        throw new 
LowLevelPutException(LowLevelPutException.INTERNAL_ERROR);
                }
+               try {
                long startTime = System.currentTimeMillis();
                if(cache) {
                        try {
@@ -836,6 +849,9 @@
                                throw new 
LowLevelPutException(LowLevelPutException.INTERNAL_ERROR);
                        }
                }
+               } finally {
+                       node.unlockUID(uid, true, true);
+               }
        }

        public HighLevelSimpleClient makeClient(short prioClass) {

Modified: trunk/freenet/src/freenet/node/NodeDispatcher.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeDispatcher.java  2007-03-24 21:08:24 UTC 
(rev 12343)
+++ trunk/freenet/src/freenet/node/NodeDispatcher.java  2007-03-24 21:16:35 UTC 
(rev 12344)
@@ -142,7 +142,7 @@
                        }
                        return true;
                }
-               if(!node.lockUID(id)) {
+               if(!node.lockUID(id, isSSK, false)) {
                        if(logMINOR) Logger.minor(this, "Could not lock ID 
"+id+" -> rejecting (already running)");
                        Message rejected = DMT.createFNPRejectedLoop(id);
                        try {
@@ -164,8 +164,7 @@
                        } catch (NotConnectedException e) {
                                Logger.normal(this, "Rejecting (overload) data 
request from "+m.getSource().getPeer()+": "+e);
                        }
-                       node.unlockUID(id);
-                       node.completed(id);
+                       node.unlockUID(id, isSSK, false);
                        return true;
                }
                //if(!node.lockUID(id)) return false;
@@ -187,6 +186,16 @@
                        }
                        return true;
                }
+               if(!node.lockUID(id, isSSK, true)) {
+                       if(logMINOR) Logger.minor(this, "Could not lock ID 
"+id+" -> rejecting (already running)");
+                       Message rejected = DMT.createFNPRejectedLoop(id);
+                       try {
+                               ((PeerNode)(m.getSource())).sendAsync(rejected, 
null, 0, null);
+                       } catch (NotConnectedException e) {
+                               Logger.normal(this, "Rejecting insert request 
from "+m.getSource().getPeer()+": "+e);
+                       }
+                       return true;
+               }
                // SSKs don't fix bwlimitDelayTime so shouldn't be accepted 
when overloaded.
                String rejectReason = nodeStats.shouldRejectRequest(!isSSK, 
true, isSSK);
                if(rejectReason != null) {
@@ -197,19 +206,9 @@
                        } catch (NotConnectedException e) {
                                Logger.normal(this, "Rejecting (overload) 
insert request from "+m.getSource().getPeer()+": "+e);
                        }
-                       node.completed(id);
+                       node.unlockUID(id, isSSK, true);
                        return true;
                }
-               if(!node.lockUID(id)) {
-                       if(logMINOR) Logger.minor(this, "Could not lock ID 
"+id+" -> rejecting (already running)");
-                       Message rejected = DMT.createFNPRejectedLoop(id);
-                       try {
-                               ((PeerNode)(m.getSource())).sendAsync(rejected, 
null, 0, null);
-                       } catch (NotConnectedException e) {
-                               Logger.normal(this, "Rejecting insert request 
from "+m.getSource().getPeer()+": "+e);
-                       }
-                       return true;
-               }
                long now = System.currentTimeMillis();
                if(m.getSpec().equals(DMT.FNPSSKInsertRequest)) {
                        SSKInsertHandler rh = new SSKInsertHandler(m, id, node, 
now);

Modified: trunk/freenet/src/freenet/node/RequestHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/RequestHandler.java  2007-03-24 21:08:24 UTC 
(rev 12343)
+++ trunk/freenet/src/freenet/node/RequestHandler.java  2007-03-24 21:16:35 UTC 
(rev 12344)
@@ -190,7 +190,7 @@
         } catch (Throwable t) {
             Logger.error(this, "Caught "+t, t);
         } finally {
-            node.unlockUID(uid);
+            node.unlockUID(uid, key instanceof NodeSSK, false);
             if((!finalTransferFailed) && rs != null && status != 
RequestSender.TIMED_OUT && status != RequestSender.GENERATED_REJECTED_OVERLOAD 
                        && status != RequestSender.INTERNAL_ERROR) {
                int sent = rs.getTotalSentBytes() + sentBytes;

Modified: trunk/freenet/src/freenet/node/RequestSender.java
===================================================================
--- trunk/freenet/src/freenet/node/RequestSender.java   2007-03-24 21:08:24 UTC 
(rev 12343)
+++ trunk/freenet/src/freenet/node/RequestSender.java   2007-03-24 21:16:35 UTC 
(rev 12344)
@@ -400,7 +400,6 @@
             finish(INTERNAL_ERROR, null);
         } finally {
                if(logMINOR) Logger.minor(this, "Leaving RequestSender.run() 
for "+uid);
-            node.completed(uid);
             node.removeRequestSender(key, origHTL, this);
         }
     }

Modified: trunk/freenet/src/freenet/node/SSKInsertHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/SSKInsertHandler.java        2007-03-24 
21:08:24 UTC (rev 12343)
+++ trunk/freenet/src/freenet/node/SSKInsertHandler.java        2007-03-24 
21:16:35 UTC (rev 12344)
@@ -80,7 +80,7 @@
             Logger.error(this, "Caught "+t, t);
         } finally {
             if(logMINOR) Logger.minor(this, "Exiting InsertHandler.run() for 
"+uid);
-            node.unlockUID(uid);
+            node.unlockUID(uid, true, true);
         }
     }


Modified: trunk/freenet/src/freenet/node/SSKInsertSender.java
===================================================================
--- trunk/freenet/src/freenet/node/SSKInsertSender.java 2007-03-24 21:08:24 UTC 
(rev 12343)
+++ trunk/freenet/src/freenet/node/SSKInsertSender.java 2007-03-24 21:16:35 UTC 
(rev 12344)
@@ -115,7 +115,6 @@
             if(status == NOT_FINISHED)
                finish(INTERNAL_ERROR, null);
         } finally {
-            node.completed(uid);
                node.removeInsertSender(myKey, origHTL, this);
         }
        }


Reply via email to