Author: j16sdiz
Date: 2008-11-20 15:22:03 +0000 (Thu, 20 Nov 2008)
New Revision: 23756

Modified:
   trunk/freenet/src/freenet/clients/http/ConnectionsToadlet.java
   trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java
   trunk/freenet/src/freenet/node/Node.java
   trunk/freenet/src/freenet/node/NodeStats.java
   trunk/freenet/src/freenet/node/OpennetManager.java
Log:
estimate opennet size (please review if this make sense)

Modified: trunk/freenet/src/freenet/clients/http/ConnectionsToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/ConnectionsToadlet.java      
2008-11-20 13:19:28 UTC (rev 23755)
+++ trunk/freenet/src/freenet/clients/http/ConnectionsToadlet.java      
2008-11-20 15:22:03 UTC (rev 23756)
@@ -245,10 +245,10 @@
                        long nodeUptimeSeconds = (now - node.startupTime) / 
1000;
                        int bwlimitDelayTime = (int) 
stats.getBwlimitDelayTime();
                        int nodeAveragePingTime = (int) 
stats.getNodeAveragePingTime();
-                       int networkSizeEstimateSession = 
stats.getNetworkSizeEstimate(-1);
+                       int networkSizeEstimateSession = 
stats.getDarknetSizeEstimate(-1);
                        int networkSizeEstimateRecent = 0;
                        if(nodeUptimeSeconds > (48*60*60)) {  // 48 hours
-                               networkSizeEstimateRecent = 
stats.getNetworkSizeEstimate(now - (48*60*60*1000));  // 48 hours
+                               networkSizeEstimateRecent = 
stats.getDarknetSizeEstimate(now - (48*60*60*1000));  // 48 hours
                        }
                        DecimalFormat fix4 = new DecimalFormat("0.0000");
                        double routingMissDistance =  
stats.routingMissDistance.currentValue();

Modified: trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java       
2008-11-20 13:19:28 UTC (rev 23755)
+++ trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java       
2008-11-20 15:22:03 UTC (rev 23756)
@@ -950,29 +950,48 @@
                /* node status values */
                int bwlimitDelayTime = (int) stats.getBwlimitDelayTime();
                int nodeAveragePingTime = (int) stats.getNodeAveragePingTime();
-               int networkSizeEstimateSession = 
stats.getNetworkSizeEstimate(-1);
-               int networkSizeEstimate24h = 0;
-               int networkSizeEstimate48h = 0;
                double numberOfRemotePeerLocationsSeenInSwaps = 
node.getNumberOfRemotePeerLocationsSeenInSwaps();
 
+               // Darknet
+               int darknetSizeEstimateSession = 
stats.getDarknetSizeEstimate(-1);
+               int darknetSizeEstimate24h = 0;
+               int darknetSizeEstimate48h = 0;
                if(nodeUptimeSeconds > (24*60*60)) {  // 24 hours
-                       networkSizeEstimate24h = 
stats.getNetworkSizeEstimate(now - (24*60*60*1000));  // 48 hours
+                       darknetSizeEstimate24h = 
stats.getDarknetSizeEstimate(now - (24*60*60*1000));  // 48 hours
                }
                if(nodeUptimeSeconds > (48*60*60)) {  // 48 hours
-                       networkSizeEstimate48h = 
stats.getNetworkSizeEstimate(now - (48*60*60*1000));  // 48 hours
+                       darknetSizeEstimate48h = 
stats.getDarknetSizeEstimate(now - (48*60*60*1000));  // 48 hours
                }
+               // Opennet
+               int opennetSizeEstimateSession = 
stats.getOpennetSizeEstimate(-1);
+               int opennetSizeEstimate24h = 0;
+               int opennetSizeEstimate48h = 0;
+               if (nodeUptimeSeconds > (24 * 60 * 60)) { // 24 hours
+                       opennetSizeEstimate24h = 
stats.getOpennetSizeEstimate(now - (24 * 60 * 60 * 1000)); // 48 hours
+               }
+               if (nodeUptimeSeconds > (48 * 60 * 60)) { // 48 hours
+                       opennetSizeEstimate48h = 
stats.getOpennetSizeEstimate(now - (48 * 60 * 60 * 1000)); // 48 hours
+               }
+               
                double routingMissDistance =  
stats.routingMissDistance.currentValue();
                double backedOffPercent =  
stats.backedOffPercent.currentValue();
                String nodeUptimeString = TimeUtil.formatTime(nodeUptimeSeconds 
* 1000);  // *1000 to convert to milliseconds
                overviewList.addChild("li", "bwlimitDelayTime:\u00a0" + 
bwlimitDelayTime + "ms");
                overviewList.addChild("li", "nodeAveragePingTime:\u00a0" + 
nodeAveragePingTime + "ms");
-               overviewList.addChild("li", "darknetSizeEstimateSession:\u00a0" 
+ networkSizeEstimateSession + "\u00a0nodes");
+               overviewList.addChild("li", "darknetSizeEstimateSession:\u00a0" 
+ darknetSizeEstimateSession + "\u00a0nodes");
                if(nodeUptimeSeconds > (24*60*60)) {  // 24 hours
-                       overviewList.addChild("li", 
"darknetSizeEstimate24h:\u00a0" + networkSizeEstimate24h + "\u00a0nodes");
+                       overviewList.addChild("li", 
"darknetSizeEstimate24h:\u00a0" + darknetSizeEstimate24h + "\u00a0nodes");
                }
                if(nodeUptimeSeconds > (48*60*60)) {  // 48 hours
-                       overviewList.addChild("li", 
"darknetSizeEstimate48h:\u00a0" + networkSizeEstimate48h + "\u00a0nodes");
+                       overviewList.addChild("li", 
"darknetSizeEstimate48h:\u00a0" + darknetSizeEstimate48h + "\u00a0nodes");
                }
+               overviewList.addChild("li", "opennetSizeEstimateSession:\u00a0" 
+ opennetSizeEstimateSession + "\u00a0nodes");
+               if (nodeUptimeSeconds > (24 * 60 * 60)) { // 24 hours
+                       overviewList.addChild("li", 
"opennetSizeEstimate24h:\u00a0" + opennetSizeEstimate24h + "\u00a0nodes");
+               }
+               if (nodeUptimeSeconds > (48 * 60 * 60)) { // 48 hours
+                       overviewList.addChild("li", 
"opennetSizeEstimate48h:\u00a0" + opennetSizeEstimate48h + "\u00a0nodes");
+               }
                if ((numberOfRemotePeerLocationsSeenInSwaps > 0.0) && ((swaps > 
0.0) || (noSwaps > 0.0))) {
                        overviewList.addChild("li", 
"avrConnPeersPerNode:\u00a0" + 
fix6p6.format(numberOfRemotePeerLocationsSeenInSwaps/(swaps+noSwaps)) + 
"\u00a0peers");
                }

Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java    2008-11-20 13:19:28 UTC (rev 
23755)
+++ trunk/freenet/src/freenet/node/Node.java    2008-11-20 15:22:03 UTC (rev 
23756)
@@ -397,7 +397,7 @@
        // Opennet stuff
        
        private final NodeCryptoConfig opennetCryptoConfig;
-       private OpennetManager opennet;
+       OpennetManager opennet;
        private volatile boolean isAllowedToConnectToSeednodes;
        private int maxOpennetPeers;
        private boolean acceptSeedConnections;

Modified: trunk/freenet/src/freenet/node/NodeStats.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeStats.java       2008-11-20 13:19:28 UTC 
(rev 23755)
+++ trunk/freenet/src/freenet/node/NodeStats.java       2008-11-20 15:22:03 UTC 
(rev 23756)
@@ -734,7 +734,12 @@
                return nodePinger.averagePingTime();
        }
 
-       public int getNetworkSizeEstimate(long timestamp) {
+       public int getOpennetSizeEstimate(long timestamp) {
+               if (node.opennet == null)
+                       return 0;
+               return node.opennet.getNetworkSizeEstimate(timestamp);
+       }
+       public int getDarknetSizeEstimate(long timestamp) {
                return node.lm.getNetworkSizeEstimate( timestamp );
        }
 
@@ -900,10 +905,10 @@
                }
                fs.put("averagePingTime", getNodeAveragePingTime());
                fs.put("bwlimitDelayTime", getBwlimitDelayTime());
-               fs.put("networkSizeEstimateSession", 
getNetworkSizeEstimate(-1));
-               int networkSizeEstimate24hourRecent = 
getNetworkSizeEstimate(now - (24*60*60*1000));  // 24 hours
+               fs.put("networkSizeEstimateSession", 
getDarknetSizeEstimate(-1));
+               int networkSizeEstimate24hourRecent = 
getDarknetSizeEstimate(now - (24*60*60*1000));  // 24 hours
                fs.put("networkSizeEstimate24hourRecent", 
networkSizeEstimate24hourRecent);
-               int networkSizeEstimate48hourRecent = 
getNetworkSizeEstimate(now - (48*60*60*1000));  // 48 hours
+               int networkSizeEstimate48hourRecent = 
getDarknetSizeEstimate(now - (48*60*60*1000));  // 48 hours
                fs.put("networkSizeEstimate48hourRecent", 
networkSizeEstimate48hourRecent);
                fs.put("routingMissDistance", 
routingMissDistance.currentValue());
                fs.put("backedOffPercent", backedOffPercent.currentValue());

Modified: trunk/freenet/src/freenet/node/OpennetManager.java
===================================================================
--- trunk/freenet/src/freenet/node/OpennetManager.java  2008-11-20 13:19:28 UTC 
(rev 23755)
+++ trunk/freenet/src/freenet/node/OpennetManager.java  2008-11-20 15:22:03 UTC 
(rev 23756)
@@ -32,6 +32,7 @@
 import freenet.support.Logger;
 import freenet.support.SimpleFieldSet;
 import freenet.support.SizeUtil;
+import freenet.support.TimeSortedHashtable;
 import freenet.support.io.ByteArrayRandomAccessThing;
 import freenet.support.io.Closer;
 import freenet.support.io.FileUtil;
@@ -101,9 +102,8 @@
        /** Maximum number of peers */
        public static final int MAX_PEERS_FOR_SCALING = 20;
        
-       
        private final long creationTime;
-       
+    
        public OpennetManager(Node node, NodeCryptoConfig opennetConfig, long 
startupTime, boolean enableAnnouncement) throws NodeInitException {
                logMINOR = Logger.shouldLog(Logger.MINOR, this);
                this.creationTime = System.currentTimeMillis();
@@ -682,6 +682,7 @@
                        return null;
                }
        
+               registerKnownIdentity(ref.get("identity"));
                return ref;
        }
 
@@ -698,4 +699,27 @@
                return creationTime;
        }
 
+
+       private static final long MAX_AGE = 7 * 24 * 60 * 60 * 1000;
+       private final TimeSortedHashtable<String> knownIds = new 
TimeSortedHashtable<String>();
+
+       private void registerKnownIdentity(String d) {
+               if (logMINOR)
+                       Logger.minor(this, "Known Id: " + d);
+               long now = System.currentTimeMillis();
+
+               synchronized (knownIds) {
+                       Logger.minor(this, "Adding Id " + d + " knownIds size " 
+ knownIds.size());
+                       knownIds.push(d, now);
+                       Logger.minor(this, "Added Id " + d + " knownIds size " 
+ knownIds.size());
+                       knownIds.removeBefore(now - MAX_AGE);
+                       Logger.minor(this, "Added and pruned location " + d + " 
knownIds size " + knownIds.size());
+               }
+               if (logMINOR)
+                       Logger.minor(this, "Estimated opennet size(session): " 
+ knownIds.size());
+       }
+    //Return the estimated network size based on locations seen after 
timestamp or for the whole session if -1
+       public int getNetworkSizeEstimate(long timestamp) {
+               return knownIds.countValuesAfter(timestamp);
+       }
 }

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to