Author: toad
Date: 2006-09-06 18:36:37 +0000 (Wed, 06 Sep 2006)
New Revision: 10413
Added:
trunk/freenet/src/freenet/node/GlobalProbe.java
Modified:
trunk/freenet/src/freenet/node/TextModeClientInterface.java
Log:
Add PROBEALL command. Not tested yet.
Added: trunk/freenet/src/freenet/node/GlobalProbe.java
===================================================================
--- trunk/freenet/src/freenet/node/GlobalProbe.java 2006-09-06 18:10:55 UTC
(rev 10412)
+++ trunk/freenet/src/freenet/node/GlobalProbe.java 2006-09-06 18:36:37 UTC
(rev 10413)
@@ -0,0 +1,90 @@
+package freenet.node;
+
+import freenet.support.Logger;
+
+public class GlobalProbe implements Runnable {
+
+ double lastLocation = 0.0;
+ boolean doneSomething = false;
+ final ProbeCallback cb;
+ final Node node;
+ int ctr;
+
+ GlobalProbe(Node n) {
+ this.node = n;
+ cb = new ProbeCallback() {
+ public void onCompleted(String reason, double target,
double best, double nearest, long id, short counter) {
+ String msg = "Completed probe request:
"+target+" -> "+best+"\r\nNearest actually hit "+nearest+", "+counter+" hops,
id "+id+"\r\n";
+ Logger.error(this, msg);
+ synchronized(GlobalProbe.this) {
+ doneSomething = true;
+ lastLocation = best;
+ GlobalProbe.this.notifyAll();
+ }
+ }
+ };
+
+ }
+
+ public void run() {
+ synchronized(this) {
+ lastLocation = 0.0;
+ double prevLoc = lastLocation;
+ while(true) {
+ doneSomething = false;
+ node.dispatcher.startProbe(lastLocation, cb);
+ for(int i=0;i<20 && !doneSomething;i++) {
+ try {
+ wait(1000*10);
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ // All vars should be updated by
resynchronizing here, right?
+ }
+ if(!doneSomething) {
+ error("Stalled on "+lastLocation+" , waiting
some more.");
+ try {
+ wait(100*1000);
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ if(!doneSomething) {
+ error("Still no response to probe
request, trying again.");
+ continue;
+ }
+ }
+ if(Math.abs(lastLocation-prevLoc) <
(Double.MIN_VALUE*2)) {
+ error("Location is same as previous ! Sleeping
then trying again");
+ try {
+ wait(100*1000);
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ continue;
+ }
+ output(lastLocation);
+ prevLoc = lastLocation;
+ ctr++;
+ // Sleep 10 seconds so we don't flood
+ try {
+ wait(10*1000);
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ }
+ }
+
+ }
+
+ private void output(double loc) {
+ Logger.error(this, "LOCATION "+ctr+": " + loc);
+ System.out.println("LOCATION "+ctr+": " + loc);
+ }
+
+ private void error(String string) {
+ Logger.error(this, string);
+ System.out.println("GlobalProbe error: "+string);
+ }
+
+
+}
Modified: trunk/freenet/src/freenet/node/TextModeClientInterface.java
===================================================================
--- trunk/freenet/src/freenet/node/TextModeClientInterface.java 2006-09-06
18:10:55 UTC (rev 10412)
+++ trunk/freenet/src/freenet/node/TextModeClientInterface.java 2006-09-06
18:36:37 UTC (rev 10413)
@@ -768,6 +768,8 @@
}
doneSomething = false;
}
+ } else if(uline.startsWith("PROBEALL")) {
+ probeAll();
} else if(uline.startsWith("PLUGLOAD:")) {
if (line.substring("PLUGLOAD:".length()).trim().equals("?")) {
outsb.append(" PLUGLOAD: pkg.Class -
Load plugin from current classpath");
@@ -801,7 +803,14 @@
return false;
}
- /**
+ private void probeAll() {
+ GlobalProbe p = new GlobalProbe(n);
+ Thread t = new Thread(p);
+ t.setDaemon(true);
+ t.start();
+ }
+
+ /**
* Create a map of String -> Bucket for every file in a directory
* and its subdirs.
*/