Author: ljn1981
Date: 2006-09-09 21:15:19 +0000 (Sat, 09 Sep 2006)
New Revision: 10444
Modified:
trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
trunk/freenet/src/freenet/node/LocationManager.java
trunk/freenet/src/freenet/node/Node.java
Log:
Completing the code I stared writing a long time ago for network size
estimation.
It's way slow if the new functionality is used though, could someone with a bit
more clue about java optimize it for me?
The idea with having this new functionality is to put it on the darknet page
too and have it only count locations in the past say 24 hours so long running
nodes won't get too wrong estimates.
Modified: trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
2006-09-09 18:37:01 UTC (rev 10443)
+++ trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
2006-09-09 21:15:19 UTC (rev 10444)
@@ -141,7 +141,7 @@
/* node status values */
int bwlimitDelayTime = (int) node.getBwlimitDelayTime();
int nodeAveragePingTime = (int)
node.getNodeAveragePingTime();
- int networkSizeEstimate =
node.getNetworkSizeEstimate(0);
+ int networkSizeEstimateSession =
node.getNetworkSizeEstimate(-1);
DecimalFormat fix4 = new DecimalFormat("0.0000");
double missRoutingDistance =
node.missRoutingDistance.currentValue();
DecimalFormat fix1 = new DecimalFormat("##0.0%");
@@ -162,7 +162,7 @@
HTMLNode overviewList =
overviewInfoboxContent.addChild("ul");
overviewList.addChild("li",
"bwlimitDelayTime:\u00a0" + bwlimitDelayTime + "ms");
overviewList.addChild("li",
"nodeAveragePingTime:\u00a0" + nodeAveragePingTime + "ms");
- overviewList.addChild("li",
"networkSizeEstimate:\u00a0" + networkSizeEstimate + "\u00a0nodes");
+ overviewList.addChild("li",
"networkSizeEstimateSession:\u00a0" + networkSizeEstimateSession +
"\u00a0nodes");
overviewList.addChild("li", "nodeUptime:\u00a0"
+ nodeUptimeString);
overviewList.addChild("li",
"missRoutingDistance:\u00a0" + fix4.format(missRoutingDistance));
overviewList.addChild("li",
"backedoffPercent:\u00a0" + fix1.format(backedoffPercent));
Modified: trunk/freenet/src/freenet/node/LocationManager.java
===================================================================
--- trunk/freenet/src/freenet/node/LocationManager.java 2006-09-09 18:37:01 UTC
(rev 10443)
+++ trunk/freenet/src/freenet/node/LocationManager.java 2006-09-09 21:15:19 UTC
(rev 10444)
@@ -974,13 +974,23 @@
}
}
- //Return the estimated network size for numberOfMinutes back or for the
whole session if 0
- public int getNetworkSizeEstimate(int numberOfMinutes) {
- //if (numberOfMinutes == 0) {
- return knownLocs.size();
- //}
- //else {
- //TODO: Add possibility to get an estimate based on the past
numberOfMinutes minutes.
- //}
+ //Return the estimated network size based on locations seen after
timestamp or for the whole session if -1
+ public int getNetworkSizeEstimate(long timestamp) {
+ int size = 0;
+ if (timestamp == -1) {
+ size = knownLocs.size();
+ }
+ else if (timestamp > -1) {
+ Date tresshold = new Date(timestamp);
+ int numberOfLocationsInPeriod = 0;
+ //TODO Optimize so it doesn't take forever..
+ while (knownLocs.values().iterator().hasNext()) {
+ if
(tresshold.after((Date)knownLocs.values().iterator().next())) {
+ numberOfLocationsInPeriod++;
+ }
+ }
+ size = numberOfLocationsInPeriod;
+ }
+ return size;
}
}
Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java 2006-09-09 18:37:01 UTC (rev
10443)
+++ trunk/freenet/src/freenet/node/Node.java 2006-09-09 21:15:19 UTC (rev
10444)
@@ -2654,8 +2654,8 @@
return usm;
}
- public int getNetworkSizeEstimate(int numberOfMinutes) {
- return lm.getNetworkSizeEstimate( numberOfMinutes );
+ public int getNetworkSizeEstimate(long timestamp) {
+ return lm.getNetworkSizeEstimate( timestamp );
}
/**