Update of /cvsroot/freenet/freenet/src/freenet/node/rt
In directory sc8-pr-cvs1:/tmp/cvs-serv29371/src/freenet/node/rt
Modified Files:
NGRoutingTable.java
Log Message:
Prevent possible NPE by calling updateNewNodeStats(); in NGRoutingTable constuctor.
Old code assumed that everyone would have added at least one node to the rt or routed
once before 'newNodeStats' was used.
Supply location of routing files in NGRoutingTable constructor instead of having
NGRoutingTable use the static variable 'Node.routingDir'
Make the NGRoutingTable able to guess a mean network file size even when it doesn't
have a ds to ask. In that case a default size of 128k will currently be used.
Index: NGRoutingTable.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/NGRoutingTable.java,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -w -r1.50 -r1.51
--- NGRoutingTable.java 25 Nov 2003 02:21:12 -0000 1.50
+++ NGRoutingTable.java 26 Nov 2003 13:09:43 -0000 1.51
@@ -41,6 +41,7 @@
* @author amphibian, but edt did lots of prior work, and sanity's concept
*/
public class NGRoutingTable extends StoredRoutingTable implements Checkpointed {
+ private static final int DEFAULT_FILE_SIZE = 131072;
final Hashtable estimators;
final NodeEstimatorFactory factory;
final TimeEstimatorFactory timeFactory;
@@ -71,14 +72,13 @@
*/
long lowestEstimatedDNFTime = 0;
final long defaultLowestEstimatedDNFTime = 1000; // 1 second - FIXME should be
configurable
- File[] globalFiles =
- { new File(Node.routingDir, "ngrt_global_a"),
- new File(Node.routingDir, "ngrt_global_b") };
+ File[] globalFiles;
+ String[] globalFileNames = {"ngrt_global_a","ngrt_global_b"};
int nextGlobalEstimatorFile = 0; //Which file should we use next. Index into the
array above.
public NGRoutingTable(RoutingStore routingStore, int maxNodes,
NodeEstimatorFactory factory,
TimeEstimatorFactory tf,
- double defaultFastestTransferSeen)
+ double defaultFastestTransferSeen,File routingDir)
throws IOException {
super(routingStore, maxNodes);
estimators = new Hashtable();
@@ -89,7 +89,11 @@
newNodeStatsLegit = factory.createStats();
newNodeStatsSemiLegit = factory.createStats();
defaultNodeStats = factory.defaultStats();
+ globalFiles = new File[globalFileNames.length];
+ for(int i =0;i<globalFileNames.length;i++)
+ globalFiles[i] = new File(routingDir, globalFileNames[i]);
loadEstimators();
+ updateNewNodeStats();
}
public void reportRate(double rate) {
@@ -398,6 +402,18 @@
return global;
}
+ //Takes a shot on calculating a mean network file size
+ //falls back to 128k if insufficent data is available or this NGRT is
+ //unable to ask the store (== if this NGRT doesn't know what node it is used
in)
+ private long calculateStandardFileSize(){
+ if(node == null)
+ return DEFAULT_FILE_SIZE;
+ else if(node.dir.countKeys() > 16)
+ return node.dir.used() / node.dir.countKeys();
+ else
+ return DEFAULT_FILE_SIZE;
+ }
+
public synchronized RTDiagSnapshot getSnapshot() {
HashSet nodeRefs = new HashSet();
HashSet refInfos = new HashSet();
@@ -408,10 +424,7 @@
long totalConnectAttempts = 0;
long totalConnectSuccesses = 0;
int backedOffNodes = 0;
- long stdFileSize;
- if(node.dir.countKeys() > 16)
- stdFileSize = node.dir.used() / node.dir.countKeys();
- else stdFileSize = 131072;
+ long stdFileSize= calculateStandardFileSize();
Key k = new Key(Key.halfkeyspace);
double global = guessGlobal(k,stdFileSize);
updateNewNodeStats();
_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs