Update of /cvsroot/freenet/freenet/src/freenet/node/rt
In directory sc8-pr-cvs1:/tmp/cvs-serv4808/src/freenet/node/rt
Modified Files:
RoutingPointStore.java StandardNodeEstimator.java
ResponseTimeEstimator.java TimeEstimatorFactory.java
NGRoutingTable.java HistoryKeepingRoutingPointStore.java
Log Message:
Put upper and lower boundaries on estimators read from serialization.
Index: RoutingPointStore.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/RoutingPointStore.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -w -r1.7 -r1.8
--- RoutingPointStore.java 4 Nov 2003 16:11:21 -0000 1.7
+++ RoutingPointStore.java 4 Nov 2003 17:05:39 -0000 1.8
@@ -7,6 +7,8 @@
import java.math.BigInteger;
import java.util.ConcurrentModificationException;
+import javax.swing.text.html.MinimalHTMLWriter;
+
import freenet.support.sort.QuickSorter;
import freenet.support.sort.Sortable;
import freenet.Core;
@@ -160,7 +162,7 @@
}
//Create a store by reading a serialization
- public RoutingPointStore(DataInputStream i) throws IOException {
+ public RoutingPointStore(DataInputStream i, int maxAllowedTime,int
minAllowedTime) throws IOException {
logDEBUG = Core.logger.shouldLog(Logger.DEBUG,this);
int accuracy = i.readInt();
if (accuracy < 0)
@@ -177,6 +179,14 @@
//time[x] = i.readInt();
if (time < 0)
throw new IOException("negative value");
+ if(time < minAllowedTime){
+ Core.logger.log(this, "Smaller than allowed time
"+time+" detected, will use "+minAllowedTime+" instead", Logger.ERROR);
+ time = minAllowedTime;
+ }
+ if(time > maxAllowedTime){
+ Core.logger.log(this, "Larger than allowed time
"+time+" detected, will use "+maxAllowedTime+" instead", Logger.ERROR);
+ time = maxAllowedTime;
+ }
byte[] b = new byte[Key.KEYBYTES];
i.readFully(b);
BigInteger key = new BigInteger(1, b);
Index: StandardNodeEstimator.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/StandardNodeEstimator.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -w -r1.19 -r1.20
--- StandardNodeEstimator.java 4 Nov 2003 16:07:27 -0000 1.19
+++ StandardNodeEstimator.java 4 Nov 2003 17:05:39 -0000 1.20
@@ -69,16 +69,16 @@
rtSearchFailed = raf.create(dis);
Core.logger.log(this, "Serialized in all RunningAverage's",
Logger.DEBUG);
- etSuccessSearch = rtef.create(dis);
+ etSuccessSearch =
rtef.create(dis,ResponseTimeEstimator.convertTime(1000000),ResponseTimeEstimator.convertTime(1));
//1 millisecond to ~20 minutes
Core.logger.log(this, "Serialized in etSuccessSearch",
Logger.DEBUG);
- etTransferRate = rtef.create(dis);
+ etTransferRate =
rtef.create(dis,ResponseTimeEstimator.convertRate(10000000.0),ResponseTimeEstimator.convertRate(0.001));
//1 byte/s to ~10 megabyte/s
Core.logger.log(this, "Serialized in etTransferRate",
Logger.DEBUG);
- epDNFGivenConnectionAndNotRejectedOrSearchFailed = rtef.create(dis);
+ epDNFGivenConnectionAndNotRejectedOrSearchFailed =
rtef.create(dis,ResponseTimeEstimator.convertProbability(1.0),ResponseTimeEstimator.convertProbability(0.0));
Core.logger.log(this, "Serialized in etDNF",
Logger.DEBUG);
- etDNF = rtef.create(dis);
+ etDNF =
rtef.create(dis,ResponseTimeEstimator.convertTime(1000000),ResponseTimeEstimator.convertTime(1));
//1 millisecond to ~20 minutes
Core.logger.log(this, "Serialized in "+this,
Logger.MINOR);
successes = dis.readInt();
Index: ResponseTimeEstimator.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/ResponseTimeEstimator.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -w -r1.33 -r1.34
--- ResponseTimeEstimator.java 4 Nov 2003 12:32:11 -0000 1.33
+++ ResponseTimeEstimator.java 4 Nov 2003 17:05:40 -0000 1.34
@@ -53,13 +53,13 @@
return store.getDataLength();
}
- public ResponseTimeEstimator(DataInputStream i) throws IOException {
+ public ResponseTimeEstimator(DataInputStream i,int maxAllowedTime,int
minAllowedTime) throws IOException {
int version = i.readInt();
if(version != 1) throw new IOException("unrecognized version "+i);
if(keepHistory)
- store = new HistoryKeepingRoutingPointStore(i);
+ store = new
HistoryKeepingRoutingPointStore(i,maxAllowedTime,minAllowedTime);
else
- store = new RoutingPointStore(i);
+ store = new RoutingPointStore(i,maxAllowedTime,minAllowedTime);
try {
recent = new RecentReports(i);
} catch (IOException e) {
@@ -397,7 +397,7 @@
return p;
}
- private static int convertTime(long millis) {
+ public static int convertTime(long millis) {
int x;
if(millis < 0)
throw new IllegalArgumentException("Negative time "+millis);
@@ -414,11 +414,7 @@
}
public void reportProbability(Key k, double p) {
- if(p < 0.0)
- throw new IllegalArgumentException("Negative probability");
- if(p > 1.0)
- throw new IllegalArgumentException("Probability over 1.0");
- int x = (int) (p * (1<<30));
+ int x = convertProbability(p);
report(k, x);
}
@@ -427,7 +423,7 @@
report(k, x);
}
- private static int convertRate(double rate) {
+ public static int convertRate(double rate) {
if(rate < 0.0)
throw new IllegalArgumentException("Negative transfer rate");
rate = rate * 1000; // convert to bytes per second
@@ -441,6 +437,15 @@
return x;
}
+ public static int convertProbability(double p) {
+ if (p < 0.0)
+ throw new IllegalArgumentException("Negative probability");
+ if (p > 1.0)
+ throw new IllegalArgumentException("Probability over 1.0");
+ int x = (int) (p * (1 << 30));
+ return x;
+ }
+
public long guessRaw(Key k) {
return (long)guess(k);
}
@@ -490,8 +495,8 @@
this.accuracy = accuracy;
}
- public TimeEstimator create(DataInputStream dis) throws IOException {
- return new ResponseTimeEstimator(dis);
+ public TimeEstimator create(DataInputStream dis, int
maxAllowedTime,int minAllowedTime) throws IOException {
+ return new
ResponseTimeEstimator(dis,maxAllowedTime,minAllowedTime);
}
public TimeEstimator create(Key k, long high, long low) {
Index: TimeEstimatorFactory.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/TimeEstimatorFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -r1.2 -r1.3
--- TimeEstimatorFactory.java 30 Aug 2003 23:16:52 -0000 1.2
+++ TimeEstimatorFactory.java 4 Nov 2003 17:05:40 -0000 1.3
@@ -15,5 +15,5 @@
public TimeEstimator create(Key k, long high, long low);
public TimeEstimator createZero();
public TimeEstimator createInitTransfer(double initRate);
- public TimeEstimator create(DataInputStream dis) throws IOException;
+ public TimeEstimator create(DataInputStream dis, int maxAllowedTime,int
minAllowedTime) throws IOException;
}
Index: NGRoutingTable.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/NGRoutingTable.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -w -r1.24 -r1.25
--- NGRoutingTable.java 4 Nov 2003 15:48:17 -0000 1.24
+++ NGRoutingTable.java 4 Nov 2003 17:05:40 -0000 1.25
@@ -82,7 +82,7 @@
try {
fi = new FileInputStream(globalFiles[i]);
dis = new DataInputStream(fi);
- globalEstimator = timeFactory.create(dis);
+ globalEstimator =
timeFactory.create(dis,ResponseTimeEstimator.convertTime(10000000),ResponseTimeEstimator.convertTime(1));//1
ms to ~20 minutes
break;
} catch (IOException e) {
if(Core.logger.shouldLog(Logger.MINOR))
Index: HistoryKeepingRoutingPointStore.java
===================================================================
RCS file:
/cvsroot/freenet/freenet/src/freenet/node/rt/HistoryKeepingRoutingPointStore.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -r1.3 -r1.4
--- HistoryKeepingRoutingPointStore.java 4 Nov 2003 08:24:59 -0000 1.3
+++ HistoryKeepingRoutingPointStore.java 4 Nov 2003 17:05:40 -0000 1.4
@@ -23,8 +23,8 @@
boolean initialized = false;
final int MAX_HISTORY_LENGTH =20;
- public HistoryKeepingRoutingPointStore(DataInputStream i) throws IOException {
- super(i);
+ public HistoryKeepingRoutingPointStore(DataInputStream i, int
maxAllowedTime,int minAllowedTime) throws IOException {
+ super(i,maxAllowedTime,minAllowedTime);
initialized = true;
}
public HistoryKeepingRoutingPointStore(int accuracy, int initTime) {
_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs