Update of /cvsroot/freenet/freenet/src/freenet/node/rt In directory sc8-pr-cvs1:/tmp/cvs-serv14642/src/freenet/node/rt
Modified Files: RoutingPointStore.java ResponseTimeEstimator.java HistoryKeepingRoutingPointStore.java Log Message: Start using keyspace and halfkeyspace from the Key class instead of homegrown variants of the same. Index: RoutingPointStore.java =================================================================== RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/RoutingPointStore.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -w -r1.3 -r1.4 --- RoutingPointStore.java 3 Nov 2003 16:32:24 -0000 1.3 +++ RoutingPointStore.java 4 Nov 2003 08:24:59 -0000 1.4 @@ -22,7 +22,6 @@ RoutingPoint points[]; final RoutingPointStore.RoutingPointKeySorter ms = new RoutingPointKeySorter(); boolean logDEBUG = true; - final BigInteger keyspace; //TODO: Keyspace should probably be located in the 'Key' class or somthing static final int MAX_ACCURACY = 32; //Represents a point in a routing graph @@ -148,8 +147,7 @@ } //Create fresh routing store with 'accuracy' number of default-valued RoutingPoints - public RoutingPointStore(int accuracy,int initTime,BigInteger keyspace) { - this.keyspace = keyspace; + public RoutingPointStore(int accuracy,int initTime) { points = new RoutingPoint[accuracy]; if(initTime < 0) throw new IllegalArgumentException("negative initTime"); for (int x = 0; x < points.length; x++) { @@ -160,8 +158,7 @@ } //Create a store by reading a serialization - public RoutingPointStore(DataInputStream i,BigInteger keyspace) throws IOException { - this.keyspace = keyspace; + public RoutingPointStore(DataInputStream i) throws IOException { logDEBUG = Core.logger.shouldLog(Logger.DEBUG,this); int accuracy = i.readInt(); if (accuracy < 0) @@ -183,7 +180,7 @@ BigInteger key = new BigInteger(1, b); if (key.signum() == -1) throw new IOException("negative key"); - if (key.compareTo(keyspace) == 1) + if (key.compareTo(Key.keyspace) == 1) throw new IOException("exceeded keyspace"); if (key.compareTo(prev) == -1) throw new IOException("smaller than prev"); @@ -193,8 +190,8 @@ } } //TODO: Documentation - public RoutingPointStore(Key k, int high, int low, int accuracy,BigInteger keyspace) { - this(accuracy,-1,keyspace); + public RoutingPointStore(Key k, int high, int low, int accuracy) { + this(accuracy,-1); //We will overwrite the initTime:s in a second so they doesn't really matter. //Make sure that we detect any assignment problems but setting initTime to -1 if (high < 0 || low < 0) @@ -203,7 +200,7 @@ // b = keyspace / accuracy // c = k % c // Then set keys as in monadic constructor, except adding k - BigInteger a = keyspace.subtract(BigInteger.ONE); + BigInteger a = Key.keyspace.subtract(BigInteger.ONE); BigInteger b = a.divide(BigInteger.valueOf(accuracy)); BigInteger ik = k.toBigInteger(); BigInteger[] dr = ik.divideAndRemainder(b); @@ -421,7 +418,7 @@ //distributes the keys evenly throughout all of the keyspace synchronized void distributeKeysEvenly() { - BigInteger a = keyspace.subtract(BigInteger.ONE); + BigInteger a = Key.keyspace.subtract(BigInteger.ONE); BigInteger b = a.divide(BigInteger.valueOf(points.length)); for (int i = points.length; --i >= 0; a = a.subtract(b)){ notifyPrePointModified(i); @@ -429,13 +426,13 @@ } } synchronized NeighbourRoutingPointPair findKeyBeforeAndAfter(BigInteger n){ - return findKeyBeforeAndAfter(n,points,keyspace); + return findKeyBeforeAndAfter(n,points); } //Locates the RoutingPoints who are keywise located right before and right after the supplied BigInteger //Handles keyspace wrap situations. The returned class contains information wheter or not a wrap occurred //Caller is responsible for making sure that there is proper synchronization //to prevent simultaneous access to 'points' - static NeighbourRoutingPointPair findKeyBeforeAndAfter(BigInteger n,RoutingPoint[] points,BigInteger keyspace) { + static NeighbourRoutingPointPair findKeyBeforeAndAfter(BigInteger n,RoutingPoint[] points) { NeighbourRoutingPointPair retval = new NeighbourRoutingPointPair(); int pos = search(n,points); @@ -447,7 +444,7 @@ retval.includesKeyspaceWrap = true; pos = points.length - 1; //Yes, beforeKey should be negative - retval.left = new RoutingPoint(lastPoint(points).key.subtract(keyspace), points[pos].time, points[pos].sensitivity); + retval.left = new RoutingPoint(lastPoint(points).key.subtract(Key.keyspace), points[pos].time, points[pos].sensitivity); retval.right = firstPoint(points); } else {//else in the middle retval.includesKeyspaceWrap = false; Index: ResponseTimeEstimator.java =================================================================== RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/ResponseTimeEstimator.java,v retrieving revision 1.31 retrieving revision 1.32 diff -u -w -r1.31 -r1.32 --- ResponseTimeEstimator.java 3 Nov 2003 21:36:30 -0000 1.31 +++ ResponseTimeEstimator.java 4 Nov 2003 08:24:59 -0000 1.32 @@ -46,9 +46,6 @@ BYTES = Key.KEYBYTES + TIMEBYTES; static final int DEFAULT_ACCURACY = 16; - static final BigInteger keyspace = BigInteger.ONE.shiftLeft(Key.KEYBYTES << 3); - static final BigInteger halfkeyspace = - BigInteger.ONE.shiftLeft((Key.KEYBYTES << 3) - 1); boolean logDEBUG = true; public int getDataLength() { @@ -59,9 +56,9 @@ int version = i.readInt(); if(version != 1) throw new IOException("unrecognized version "+i); if(keepHistory) - store = new HistoryKeepingRoutingPointStore(i,keyspace); + store = new HistoryKeepingRoutingPointStore(i); else - store = new RoutingPointStore(i,keyspace); + store = new RoutingPointStore(i); try { recent = new RecentReports(i); } catch (IOException e) { @@ -108,17 +105,17 @@ public ResponseTimeEstimator(int initTime, int accuracy) { if(keepHistory) - store = new HistoryKeepingRoutingPointStore(accuracy,initTime,keyspace); + store = new HistoryKeepingRoutingPointStore(accuracy,initTime); else - store = new RoutingPointStore(accuracy,initTime,keyspace); + store = new RoutingPointStore(accuracy,initTime); recent = new RecentReports(); } public ResponseTimeEstimator(Key k, int high, int low, int accuracy) { if(keepHistory) - store = new HistoryKeepingRoutingPointStore(k,high,low,accuracy,keyspace); + store = new HistoryKeepingRoutingPointStore(k,high,low,accuracy); else - store = new RoutingPointStore(k,high,low,accuracy,keyspace); + store = new RoutingPointStore(k,high,low,accuracy); recent = new RecentReports(); } @@ -220,9 +217,9 @@ //one calculation anywhere? If not then the recursion //is unnessecary if (key.signum() == -1) //If the value has fallen below 0 - return handleKeyspaceWrap(key.add(keyspace)); //Then move upwards (at least) one keyspace - else if (key.compareTo(keyspace) == 1) //else, if the value has become larger than the keyspace max - return handleKeyspaceWrap(key.subtract(keyspace)); //then move downwards (at least) one keyspace + return handleKeyspaceWrap(key.add(Key.keyspace)); //Then move upwards (at least) one keyspace + else if (key.compareTo(Key.keyspace) == 1) //else, if the value has become larger than the keyspace max + return handleKeyspaceWrap(key.subtract(Key.keyspace)); //then move downwards (at least) one keyspace else return key; //else do nothing } @@ -314,7 +311,7 @@ Logger.DEBUG); store.dumpLog(); - int x = n.compareTo(halfkeyspace); + int x = n.compareTo(Key.halfkeyspace); if(x == 1) { if(logDEBUG) Core.logger.log(this, "Above half keyspace", @@ -322,9 +319,9 @@ // We are above the half way point // n ... keyspace, 0 ... n-halfkeyspace moved left // n-halfkeyspace ... n moved right - BigInteger m = n.subtract(halfkeyspace); + BigInteger m = n.subtract(Key.halfkeyspace); int mpos = store.search(m); - int steps = reportDecreasing(n, keyspace, n, usec, 0, pos+1, store.length()-1); + int steps = reportDecreasing(n, Key.keyspace, n, usec, 0, pos+1, store.length()-1); reportDecreasing(BigInteger.ZERO, m, n, usec, steps, 0, mpos); reportIncreasing(m, n, n, usec, 0, mpos+1, store.length()-1); store.sortByKey(); // if the edge wraps, over the next section, then we orderKeys before the next section is done, we are stuffed @@ -336,21 +333,21 @@ // n ... n+halfkeyspace moved left // 0 ... n moved right // n+halfkeyspace .. keyspace moved right - BigInteger c = n.add(halfkeyspace); + BigInteger c = n.add(Key.halfkeyspace); int cpos = store.search(c); reportDecreasing(n, c, n, usec, 0, pos+1, cpos); int steps = reportIncreasing(BigInteger.ZERO, n, n, usec, 0, 0, pos); - reportIncreasing(c, keyspace, n, usec, steps, cpos+1, store.length()-1); + reportIncreasing(c, Key.keyspace, n, usec, steps, cpos+1, store.length()-1); store.sortByKey(); } else { if(logDEBUG) Core.logger.log(this, "Dead on half keyspace", Logger.DEBUG); // We are in the exact center - int mpos = store.search(halfkeyspace); - reportIncreasing(BigInteger.ZERO, halfkeyspace, halfkeyspace, usec, + int mpos = store.search(Key.halfkeyspace); + reportIncreasing(BigInteger.ZERO, Key.halfkeyspace, Key.halfkeyspace, usec, 0, 0, mpos); - reportDecreasing(halfkeyspace, keyspace, halfkeyspace, usec, + reportDecreasing(Key.halfkeyspace, Key.keyspace, Key.halfkeyspace, usec, 0, mpos+1, store.length()-1); store.sortByKey(); } @@ -466,7 +463,7 @@ if(b.includesKeyspaceWrap) if(b.nPos == store.length() -1) //TODO: What to do to get rid of this uglyness. Can we just skip it maybe? - n = n.subtract(keyspace); + n = n.subtract(Key.keyspace); // Solve for the time given key and two bounding points. BigInteger i = BigInteger.valueOf(b.right.getTime() - b.left.getTime()) @@ -581,7 +578,7 @@ recentKeys[x] = new BigInteger(1, b); if (recentKeys[x].signum() == -1) throw new IOException("negative key"); - if (recentKeys[x].compareTo(keyspace) == 1) + if (recentKeys[x].compareTo(Key.keyspace) == 1) throw new IOException("exceeded keyspace"); } } catch (IOException ioe) { @@ -693,7 +690,7 @@ store.dumpHtml(pw); pw.println("<tr><td>Maximum</td><td colspan=\"2\">"+ - keyspace.toString(16)+ + Key.keyspace.toString(16)+ "</td></tr>"); // I hope there is an optimized toString(16) ... pw.println("</table>"); @@ -717,7 +714,7 @@ } public void drapGraphOnImage(boolean dontClipPoints, Bitmap bmp,boolean drawHistoryIfPossible, Color lineCol, Color crossCol) { - BigInteger a = keyspace.subtract(BigInteger.ONE); + BigInteger a = Key.keyspace.subtract(BigInteger.ONE); BigInteger b = a.divide(BigInteger.valueOf(bmp.getWidth())); LinkedList l = new LinkedList(); int lowest=Integer.MAX_VALUE; Index: HistoryKeepingRoutingPointStore.java =================================================================== RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/HistoryKeepingRoutingPointStore.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -w -r1.2 -r1.3 --- HistoryKeepingRoutingPointStore.java 3 Nov 2003 21:36:31 -0000 1.2 +++ HistoryKeepingRoutingPointStore.java 4 Nov 2003 08:24:59 -0000 1.3 @@ -23,16 +23,16 @@ boolean initialized = false; final int MAX_HISTORY_LENGTH =20; - public HistoryKeepingRoutingPointStore(DataInputStream i, BigInteger keyspace) throws IOException { - super(i, keyspace); + public HistoryKeepingRoutingPointStore(DataInputStream i) throws IOException { + super(i); initialized = true; } - public HistoryKeepingRoutingPointStore(int accuracy, int initTime, BigInteger keyspace) { - super(accuracy, initTime, keyspace); + public HistoryKeepingRoutingPointStore(int accuracy, int initTime) { + super(accuracy, initTime); initialized = true; } - public HistoryKeepingRoutingPointStore(Key k, int high, int low, int accuracy, BigInteger keyspace) { - super(k, high, low, accuracy, keyspace); + public HistoryKeepingRoutingPointStore(Key k, int high, int low, int accuracy) { + super(k, high, low, accuracy); initialized = true; } //Returns the length of the history @@ -73,7 +73,7 @@ if(age == 0) return super.findKeyBeforeAndAfter(n); RoutingPoint[] p =(RoutingPoint[])history.get(history.size() - age); - return RoutingPointStore.findKeyBeforeAndAfter(n,p,keyspace); + return RoutingPointStore.findKeyBeforeAndAfter(n,p); } } _______________________________________________ cvs mailing list [EMAIL PROTECTED] http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs