Author: toad
Date: 2007-11-28 16:43:39 +0000 (Wed, 28 Nov 2007)
New Revision: 16028
Modified:
trunk/freenet/src/freenet/node/GlobalProbe.java
trunk/freenet/src/freenet/node/NodeDispatcher.java
trunk/freenet/src/freenet/node/TextModeClientInterface.java
Log:
Delete probe requests, for now.
Old code is a horrible mess mainly due to being a state machine.
Modified: trunk/freenet/src/freenet/node/GlobalProbe.java
===================================================================
--- trunk/freenet/src/freenet/node/GlobalProbe.java 2007-11-28 16:04:00 UTC
(rev 16027)
+++ trunk/freenet/src/freenet/node/GlobalProbe.java 2007-11-28 16:43:39 UTC
(rev 16028)
@@ -15,9 +15,11 @@
final ProbeCallback cb;
final Node node;
int ctr;
+ final int probeType;
- GlobalProbe(Node n) {
+ GlobalProbe(Node n, int probeType) {
this.node = n;
+ this.probeType = probeType;
cb = new ProbeCallback() {
public void onCompleted(String reason, double target,
double best, double nearest, long id, short counter, short linearCount) {
String msg = "Completed probe request:
"+target+" -> "+best+"\r\nNearest actually hit "+nearest+", "+counter+" nodes
("+linearCount+" hops) in "+(System.currentTimeMillis() - lastTime)+", id
"+id+"\r\n";
@@ -46,7 +48,7 @@
while(true) {
doneSomething = false;
lastTime = System.currentTimeMillis();
- node.dispatcher.startProbe(lastLocation, cb);
+ node.dispatcher.startProbe(lastLocation, cb, probeType);
for(int i=0;i<20 && !doneSomething;i++) {
try {
wait(1000*10);
Modified: trunk/freenet/src/freenet/node/NodeDispatcher.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeDispatcher.java 2007-11-28 16:04:00 UTC
(rev 16027)
+++ trunk/freenet/src/freenet/node/NodeDispatcher.java 2007-11-28 16:43:39 UTC
(rev 16028)
@@ -135,14 +135,18 @@
return handleRoutedReply(m);
} else if(spec == DMT.FNPRoutedRejected) {
return handleRoutedRejected(m);
- } else if(spec == DMT.FNPProbeRequest) {
- return handleProbeRequest(m, source);
- } else if(spec == DMT.FNPProbeReply) {
- return handleProbeReply(m, source);
- } else if(spec == DMT.FNPProbeRejected) {
- return handleProbeRejected(m, source);
- } else if(spec == DMT.FNPProbeTrace) {
- return handleProbeTrace(m, source);
+ // FIXME implement threaded probe requests of various
kinds.
+ // Old probe request code was a major pain, never
really worked.
+ // We should have threaded probe requests (for simple
code),
+ // and one for each routing strategy.
+// } else if(spec == DMT.FNPProbeRequest) {
+// return handleProbeRequest(m, source);
+// } else if(spec == DMT.FNPProbeReply) {
+// return handleProbeReply(m, source);
+// } else if(spec == DMT.FNPProbeRejected) {
+// return handleProbeRejected(m, source);
+// } else if(spec == DMT.FNPProbeTrace) {
+// return handleProbeTrace(m, source);
}
return false;
}
@@ -448,585 +452,6 @@
return false;
}
- // Probe request handling
-
- long tLastReceivedProbeRequest;
-
- static final int MAX_PROBE_CONTEXTS = 1000;
- static final int MAX_PROBE_IDS = 10000;
-
- class ProbeContext {
-
- private final WeakReference /* <PeerNode> */ srcRef;
- final WeakHashSet visitedPeers;
- final ProbeCallback cb;
- short counter;
- short linearCounter;
- short htl;
- double nearest;
- double best;
- Vector notVisitedList; // List of best locations not yet
visited by this request
- short forkCount;
- double maxDistance;
-
- public ProbeContext(long id, double target, double best, double
nearest, short htl, short counter, PeerNode src, ProbeCallback cb) {
- visitedPeers = new WeakHashSet();
- this.counter = counter;
- this.htl = htl;
- this.nearest = nearest;
- this.best = best;
- this.srcRef = (src == null) ? null : src.myRef;
- this.cb = cb;
- maxDistance = 2.0;
- }
-
- public PeerNode getSource() {
- if(srcRef != null) return (PeerNode) srcRef.get();
- return null;
- }
-
- }
-
- final LRUQueue recentProbeRequestIDs = new LRUQueue();
- final LRUHashtable recentProbeContexts = new LRUHashtable();
-
- /**
- * Handle a probe request.
- * Reject it if it's looped.
- * Look up (and promote) its context object.
- * Update its HTL, nearest-seen and best-seen.
- * Complete it if it has run out of HTL.
- * Otherwise forward it.
- **/
- private boolean handleProbeRequest(Message m, PeerNode src) {
- long id = m.getLong(DMT.UID);
- Long lid = new Long(id);
- double target = m.getDouble(DMT.TARGET_LOCATION);
- double best = m.getDouble(DMT.BEST_LOCATION);
- double nearest = m.getDouble(DMT.NEAREST_LOCATION);
- short htl = m.getShort(DMT.HTL);
- short counter = m.getShort(DMT.COUNTER);
- short linearCounter = m.getShort(DMT.LINEAR_COUNTER);
- if(logMINOR)
- Logger.minor(this, "Probe request: "+id+ ' ' +target+ '
' +best+ ' ' +nearest+ ' ' +htl+ ' ' +counter);
- synchronized(recentProbeContexts) {
- if(recentProbeRequestIDs.contains(lid)) {
- // Reject: Loop
- Message reject = DMT.createFNPProbeRejected(id,
target, nearest, best, counter, htl, DMT.PROBE_REJECTED_LOOP, linearCounter);
- try {
- src.sendAsync(reject, null, 0, null);
- } catch (NotConnectedException e) {
- Logger.error(this, "Not connected
rejecting a Probe request from "+src);
- }
- return true;
- } else
- Logger.minor(this, "Probe request "+id+" not
already present");
- recentProbeRequestIDs.push(lid);
- while(recentProbeRequestIDs.size() > MAX_PROBE_IDS) {
- Object o = recentProbeRequestIDs.pop();
- Logger.minor(this, "Probe request popped "+o);
- }
- }
- Message notVisited = m.getSubMessage(DMT.FNPBestRoutesNotTaken);
- double[] locsNotVisited = null;
- Vector notVisitedList = new Vector();
- if(notVisited != null) {
- locsNotVisited =
Fields.bytesToDoubles(((ShortBuffer)notVisited.getObject(DMT.BEST_LOCATIONS_NOT_VISITED)).getData());
- for(int i=0;i<locsNotVisited.length;i++)
- notVisitedList.add(new
Double(locsNotVisited[i]));
- }
- innerHandleProbeRequest(src, id, lid, target, best, nearest,
htl, counter, true, true, false, true, null, notVisitedList, false,
++linearCounter, "request");
- return true;
- }
-
- static final int MAX_LOCS_NOT_VISITED = 10;
- static final int MAX_FORKS = 2;
-
- /**
- *
- * @param src
- * @param id
- * @param lid
- * @param target
- * @param best
- * @param nearest Best-so-far for normal routing purposes.
- * @param htl
- * @param counter
- * @param checkRecent
- * @param loadLimitRequest True if this is a new request which can be
rejected due to load, false if it's an existing
- * request which we should handle anyway.
- * @param cb
- * @param locsNotVisited
- * @param maxDistance Don't route to any nodes further away from the
target than this distance.
- * Note that it is a distance, NOT A LOCATION.
- * @param dontReject If true, don't reject the request, simply return
false and the caller will handle it.
- * @return True unless we rejected the request (due to load, route not
found etc), or would have if it weren't for dontReject.
- */
- private boolean innerHandleProbeRequest(PeerNode src, long id, Long
lid, final double target, double best,
- double nearest, short htl, short counter, boolean
checkRecent, boolean loadLimitRequest,
- boolean fromRejection, boolean isNew, ProbeCallback cb,
Vector locsNotVisited, boolean dontReject,
- short linearCounter, String callerReason) {
- if(fromRejection) {
- nearest = furthestLoc(target); // reject CANNOT change
nearest, because it's from a dead-end; "improving"
- // nearest will only result in the request being
truncated
- // However it CAN improve best, because we want an
accurate "best"
- }
- short max = node.maxHTL();
- if(htl > max) htl = max;
- if(htl <= 1) htl = 1;
- ProbeContext ctx = null;
- boolean rejected = false;
- synchronized(recentProbeContexts) {
- if(checkRecent) {
- long now = System.currentTimeMillis();
- if(now - tLastReceivedProbeRequest < 500 &&
loadLimitRequest) {
- rejected = true;
- } else {
- tLastReceivedProbeRequest = now;
- }
- }
- counter++; // Increment on every hop even if we reject
it, this makes it easier to read the trace
- if(!rejected) {
- ctx = (ProbeContext)
recentProbeContexts.get(lid);
- if(ctx == null) {
- if(isNew) {
- ctx = new ProbeContext(id,
target, best, nearest, htl, counter, src, cb);
- } else {
- Logger.error(this, "Not
creating new context for: "+id);
- return false;
- }
- }
- recentProbeContexts.push(lid, ctx); // promote
or add
- while(recentProbeContexts.size() >
MAX_PROBE_CONTEXTS)
- recentProbeContexts.popValue();
- }
- }
- double maxDistance = ctx.maxDistance;
- PeerNode origSource = ctx.getSource();
- if(linearCounter < 0) linearCounter = ctx.linearCounter;
- ctx.linearCounter = linearCounter;
- if(locsNotVisited != null) {
- if(logMINOR)
- Logger.minor(this, "Locs not visited:
"+locsNotVisited);
- }
- if(fromRejection) {
- // Rejected by a dead-end, will not return us a
notVisitedList.
- // Would be pointless.
- locsNotVisited = ctx.notVisitedList;
- }
-
- // Add source
- if(src != null) ctx.visitedPeers.add(src);
- if(rejected) {
- if(!dontReject) {
- // Reject: rate limit
- Message reject = DMT.createFNPProbeRejected(id,
target, nearest, best, counter, htl, DMT.PROBE_REJECTED_OVERLOAD,
linearCounter);
- try {
- src.sendAsync(reject, null, 0, null);
- } catch (NotConnectedException e) {
- Logger.error(this, "Not connected
rejecting a probe request from "+src);
- }
- }
- return false;
- }
- if(ctx.counter < counter) ctx.counter = counter;
- if(logMINOR)
- Logger.minor(this, "ctx.nearest="+ctx.nearest+",
nearest="+nearest+", target="+target+", htl="+htl+", ctx.htl="+ctx.htl);
- if(ctx.htl > htl) {
- // Rejected can reduce HTL
- ctx.htl = htl;
- }
- Logger.minor(this, "htl="+htl+", nearest="+nearest+",
ctx.htl="+ctx.htl+", ctx.nearest="+ctx.nearest);
-
- PeerNode[] peers = node.peers.connectedPeers;
-
- double myLoc = node.getLocation();
- for(int i=0;i<locsNotVisited.size();i++) {
- double loc = ((Double)
locsNotVisited.get(i)).doubleValue();
- if(Math.abs(loc - myLoc) < Double.MIN_VALUE * 2) {
- locsNotVisited.remove(i);
- break;
- }
- }
- // Update best
-
- if(myLoc > target && myLoc < best)
- best = myLoc;
-
- if(ctx.best > target && ctx.best < best)
- best = ctx.best;
-
- for(int i=0;i<peers.length;i++) {
- double loc = peers[i].getLocation();
- if(logMINOR) Logger.minor(this, "Location: "+loc);
- // We are only interested in locations greater than the
target
- if(loc <= (target + 2*Double.MIN_VALUE)) {
- if(logMINOR) Logger.minor(this, "Location is
under target");
- continue;
- }
- if(loc < best) {
- if(logMINOR) Logger.minor(this, "New best:
"+loc+" was "+best);
- best = loc;
- }
- }
-
- // Update nearest, htl
-
- // Rejected, or even reply, cannot make nearest *worse* and
thereby prolong the request.
- // In fact, rejected probe requests result in clearing nearest
at the beginning of the function, so it is vital
- // that we restore it here.
- if(Location.distance(ctx.nearest, target, true) <
Location.distance(nearest, target, true)) {
- nearest = ctx.nearest;
- }
-
- // If we are closer to the target than nearest, update nearest
and reset HTL, else decrement HTL
- if(Location.distance(myLoc, target, true) <
Location.distance(nearest, target, true)) {
- if(logMINOR)
- Logger.minor(this, "Updating nearest to
"+myLoc+" from "+nearest+" for "+target+" and resetting htl from "+htl+" to
"+max);
- if(Math.abs(nearest - myLoc) > Double.MIN_VALUE * 2)
- nearest = myLoc;
- htl = max;
- ctx.nearest = nearest;
- ctx.htl = htl;
- } else {
- htl = node.decrementHTL(origSource, htl);
- ctx.htl = htl;
- if(logMINOR)
- Logger.minor(this, "Updated htl to "+htl+" -
myLoc="+myLoc+", target="+target+", nearest="+nearest);
- }
-
- // Complete ?
- if(htl == 0) {
- if(origSource != null) {
- // Complete
- Message complete = DMT.createFNPProbeReply(id,
target, nearest, best, counter++, linearCounter);
- Message sub =
DMT.createFNPBestRoutesNotTaken((Double[])locsNotVisited.toArray(new
Double[locsNotVisited.size()]));
- complete.addSubMessage(sub);
- try {
- origSource.sendAsync(complete, null, 0,
null);
- } catch (NotConnectedException e) {
- Logger.error(this, "Not connected
completing a probe request from "+src);
- }
- return true; // counts as success
- } else {
- complete("success", target, best, nearest, id,
ctx, counter, linearCounter);
- }
- }
-
- // Otherwise route it
-
- WeakHashSet visited = ctx.visitedPeers;
-
- while(true) {
-
- Vector newBestLocs = new Vector();
- newBestLocs.addAll(locsNotVisited);
- PeerNode pn = node.peers.closerPeer(src, visited, null,
target, true, false, 965, newBestLocs, maxDistance);
-
- if(logMINOR)
- Logger.minor(this, "newBestLocs (unsorted):
"+newBestLocs);
-
- Double[] locs = (Double[]) newBestLocs.toArray(new
Double[newBestLocs.size()]);
- Arrays.sort(locs, new Comparator() {
- public int compare(Object arg0, Object arg1) {
- double d0 = ((Double)
arg0).doubleValue();
- double d1 = ((Double)
arg1).doubleValue();
- double dist0 = Location.distance(d0,
target, true);
- double dist1 = Location.distance(d1,
target, true);
- if(dist0 < dist1) return -1; // best at
the beginning
- if(dist0 > dist1) return 1;
- return 0; // should not happen
- }
- });
- locsNotVisited.clear();
- for(int i=0;i<Math.min(MAX_LOCS_NOT_VISITED,
locs.length);i++)
- locsNotVisited.add(locs[i]);
-
- if(logMINOR)
- Logger.minor(this, "newBestLocs:
"+locsNotVisited);
-
- Message sub =
DMT.createFNPBestRoutesNotTaken((Double[])locsNotVisited.toArray(new
Double[locsNotVisited.size()]));
-
- ctx.notVisitedList = locsNotVisited;
-
- if(pn == null) {
- // Can't complete, because some HTL left
- // Reject: RNF
- if(!dontReject) {
- if(src != null) {
- Message reject =
DMT.createFNPProbeRejected(id, target, nearest, best, counter, htl,
DMT.PROBE_REJECTED_RNF, linearCounter);
- reject.addSubMessage(sub);
- try {
- src.sendAsync(reject,
null, 0, null);
- } catch (NotConnectedException
e) {
- Logger.error(this, "Not
connected rejecting a probe request from "+src);
- }
- } else {
- complete("RNF", target, best,
nearest, id, ctx, counter, linearCounter);
- }
- }
- return false;
- }
-
- visited.add(pn);
-
- if(origSource != null) {
- Message trace =
- DMT.createFNPProbeTrace(id, target,
nearest, best, htl, counter, myLoc, node.swapIdentifier,
LocationManager.extractLocs(peers, true), LocationManager.extractUIDs(peers),
ctx.forkCount, linearCounter, callerReason, src == null ? -1 :
src.swapIdentifier);
- trace.addSubMessage(sub);
- try {
- origSource.sendAsync(trace, null, 0,
null);
- } catch (NotConnectedException e1) {
- // Ignore
- }
- }
-
- Message forwarded =
- DMT.createFNPProbeRequest(id, target, nearest,
best, htl, counter++, linearCounter);
- forwarded.addSubMessage(sub);
- try {
- pn.sendAsync(forwarded, null, 0, null);
- return true;
- } catch (NotConnectedException e) {
- Logger.error(this, "Could not forward message:
disconnected: "+pn+" : "+e, e);
- // Try another one
- }
- }
-
- }
-
- private void complete(String msg, double target, double best, double
nearest, long id, ProbeContext ctx, short counter, short linearHops) {
- Logger.normal(this, "Completed Probe request # "+id+" - RNF -
"+msg+": "+best);
- ctx.cb.onCompleted(msg, target, best, nearest, id, counter,
linearHops);
- }
-
- private void reportTrace(ProbeContext ctx, Message msg) {
- long uid = msg.getLong(DMT.UID);
- double target = msg.getDouble(DMT.TARGET_LOCATION);
- double nearest = msg.getDouble(DMT.NEAREST_LOCATION);
- double best = msg.getDouble(DMT.BEST_LOCATION);
- short htl = msg.getShort(DMT.HTL);
- short counter = msg.getShort(DMT.COUNTER);
- double location = msg.getDouble(DMT.LOCATION);
- long nodeUID = msg.getLong(DMT.MY_UID);
- short linearCount = msg.getShort(DMT.LINEAR_COUNTER);
- double[] peerLocs =
Fields.bytesToDoubles(((ShortBuffer)msg.getObject(DMT.PEER_LOCATIONS)).getData());
- long[] peerUIDs =
Fields.bytesToLongs(((ShortBuffer)msg.getObject(DMT.PEER_UIDS)).getData());
- Message notVisited =
msg.getSubMessage(DMT.FNPBestRoutesNotTaken);
- double[] locsNotVisited = null;
- if(notVisited != null) {
- locsNotVisited =
Fields.bytesToDoubles(((ShortBuffer)notVisited.getObject(DMT.BEST_LOCATIONS_NOT_VISITED)).getData());
- }
- short forkCount = msg.getShort(DMT.FORK_COUNT);
- String reason = msg.getString(DMT.REASON);
- long prevUID = msg.getLong(DMT.PREV_UID);
- ctx.cb.onTrace(uid, target, nearest, best, htl, counter,
location, nodeUID, peerLocs, peerUIDs, locsNotVisited, forkCount, linearCount,
reason, prevUID);
- }
-
- private boolean handleProbeReply(Message m, PeerNode src) {
- long id = m.getLong(DMT.UID);
- Long lid = new Long(id);
- final double target = m.getDouble(DMT.TARGET_LOCATION);
- double best = m.getDouble(DMT.BEST_LOCATION);
- double nearest = m.getDouble(DMT.NEAREST_LOCATION);
- short counter = m.getShort(DMT.COUNTER);
- short linearCounter = m.getShort(DMT.LINEAR_COUNTER);
- if(logMINOR)
- Logger.minor(this, "Probe reply: "+id+ ' ' +target+ ' '
+best+ ' ' +nearest);
-
- // New backtracking algorithm
-
- // Allow forking on the way home - but only if the location
we'd fork to would be at least as good as the third best location seen but not
visited so far.
-
- // First get the list of not visited so far nodes
-
- Message notVisited = m.getSubMessage(DMT.FNPBestRoutesNotTaken);
- double[] locsNotVisited = null;
- Vector notVisitedList = new Vector();
- if(notVisited != null) {
- locsNotVisited =
Fields.bytesToDoubles(((ShortBuffer)notVisited.getObject(DMT.BEST_LOCATIONS_NOT_VISITED)).getData());
- for(int i=0;i<locsNotVisited.length;i++)
- notVisitedList.add(new
Double(locsNotVisited[i]));
- }
- // notVisitedList == locsNotVisited
-
- // Find it
- ProbeContext ctx;
- synchronized(recentProbeContexts) {
- ctx = (ProbeContext) recentProbeContexts.get(lid);
- if(ctx == null) {
- Logger.normal(this, "Could not forward probe
reply back to source for ID "+id);
- return false;
- }
- recentProbeContexts.push(lid, ctx); // promote
- while(recentProbeContexts.size() > MAX_PROBE_CONTEXTS)
- recentProbeContexts.popValue();
- }
- PeerNode origSource = (PeerNode) ctx.getSource();
-
- Message sub = m.getSubMessage(DMT.FNPBestRoutesNotTaken);
-
- try {
- if(origSource != null) {
- // Send a completion trace - before forking
- PeerNode[] peers = node.getConnectedPeers();
- Message trace =
- DMT.createFNPProbeTrace(id, target,
nearest, best, ctx.htl, counter, node.getLocation(), node.swapIdentifier,
LocationManager.extractLocs(peers, true), LocationManager.extractUIDs(peers),
ctx.forkCount, linearCounter, "replying", src == null ? -1 :
src.swapIdentifier);
- trace.addSubMessage(sub);
- try {
- origSource.sendAsync(trace, null, 0,
null);
- } catch (NotConnectedException e1) {
- // Ignore
- }
- }
- } catch (Throwable t) {
- Logger.error(this, "Could not send completion trace:
"+t, t);
- }
-
- // Maybe fork
-
- try {
- if(locsNotVisited.length > 0) {
- if(ctx.forkCount < MAX_FORKS) {
- ctx.forkCount++;
-
- double[] dists = new
double[locsNotVisited.length];
- for(int i=0;i<dists.length;i++) {
- dists[i] =
Location.distance(locsNotVisited[i], target, true);
- }
- Arrays.sort(dists);
-
- double mustBeBetterThan =
dists[Math.min(3,dists.length)];
- double maxDistance =
Location.distance(mustBeBetterThan, target, true);
-
- ctx.maxDistance = Math.min(maxDistance,
ctx.maxDistance);
-
- if(innerHandleProbeRequest(src, id,
lid, target, best, nearest, ctx.htl, counter, false, false, false, false, null,
notVisitedList, true, linearCounter, "backtracking"))
- return true;
- }
- }
- } catch (Throwable t) {
- // If something happens during the fork attempt, just
propagate it
- Logger.error(this, "Caught "+t+" while trying to fork",
t);
- }
-
- // Just propagate back to source
- if(origSource != null) {
- Message complete = DMT.createFNPProbeReply(id, target,
nearest, best, counter++, linearCounter);
- if(sub != null) complete.addSubMessage(sub);
- try {
- origSource.sendAsync(complete, null, 0, null);
- } catch (NotConnectedException e) {
- Logger.error(this, "Not connected completing a
probe request from "+origSource+" (forwarding completion from "+src+ ')');
- }
- } else {
- if(ctx.cb != null)
- complete("Completed", target, best, nearest,
id, ctx, counter, linearCounter);
- }
- return true;
- }
-
- private boolean handleProbeTrace(Message m, PeerNode src) {
- long id = m.getLong(DMT.UID);
- Long lid = new Long(id);
- double target = m.getDouble(DMT.TARGET_LOCATION);
- double best = m.getDouble(DMT.BEST_LOCATION);
- double nearest = m.getDouble(DMT.NEAREST_LOCATION);
- short counter = m.getShort(DMT.COUNTER);
- Message notVisited = m.getSubMessage(DMT.FNPBestRoutesNotTaken);
- double[] locsNotVisited = null;
- if(notVisited != null) {
- locsNotVisited =
Fields.bytesToDoubles(((ShortBuffer)notVisited.getObject(DMT.BEST_LOCATIONS_NOT_VISITED)).getData());
- }
- if(logMINOR)
- Logger.minor(this, "Probe trace: "+id+ ' ' +target+ ' '
+best+ ' ' +nearest+' '+counter);
- if(locsNotVisited != null) {
- if(logMINOR)
- Logger.minor(this, "Locs not visited:
"+StringArray.toString(locsNotVisited));
- }
- // Just propagate back to source
- ProbeContext ctx;
- synchronized(recentProbeContexts) {
- ctx = (ProbeContext) recentProbeContexts.get(lid);
- if(ctx == null) {
- Logger.normal(this, "Could not forward probe
reply back to source for ID "+id);
- return false;
- }
- recentProbeContexts.push(lid, ctx); // promote or add
- while(recentProbeContexts.size() > MAX_PROBE_CONTEXTS)
- recentProbeContexts.popValue();
- }
-
- PeerNode origSource = ctx.getSource();
- if(origSource != null) {
- try {
- origSource.sendAsync(m, null, 0, null);
- } catch (NotConnectedException e) {
- Logger.error(this, "Not connected forwarding
trace to "+origSource+" (from "+src+ ')');
- }
- } else {
- if(ctx.cb != null)
- reportTrace(ctx, m);
- }
- return true;
- }
-
- private boolean handleProbeRejected(Message m, PeerNode src) {
- long id = m.getLong(DMT.UID);
- Long lid = new Long(id);
- double target = m.getDouble(DMT.TARGET_LOCATION);
- double best = m.getDouble(DMT.BEST_LOCATION);
- double nearest = m.getDouble(DMT.NEAREST_LOCATION);
- short htl = m.getShort(DMT.HTL);
- short counter = m.getShort(DMT.COUNTER);
- short reason = m.getShort(DMT.REASON);
- if(logMINOR)
- Logger.minor(this, "Probe rejected: "+id+ ' ' +target+
' ' +best+ ' ' +nearest+ ' ' +htl+ ' ' +counter+ ' ' +reason);
-
- ProbeContext ctx;
- synchronized(recentProbeContexts) {
- ctx = (ProbeContext) recentProbeContexts.get(lid);
- if(ctx == null) {
- Logger.normal(this, "Unknown rejected probe
request ID "+id);
- return false;
- }
- recentProbeContexts.push(lid, ctx); // promote or add
- while(recentProbeContexts.size() > MAX_PROBE_CONTEXTS)
- recentProbeContexts.popValue();
- }
-
- Message notVisited = m.getSubMessage(DMT.FNPBestRoutesNotTaken);
- double[] locsNotVisited = null;
- Vector notVisitedList = new Vector();
- if(notVisited != null) {
- locsNotVisited =
Fields.bytesToDoubles(((ShortBuffer)notVisited.getObject(DMT.BEST_LOCATIONS_NOT_VISITED)).getData());
- for(int i=0;i<locsNotVisited.length;i++)
- notVisitedList.add(new
Double(locsNotVisited[i]));
- }
- innerHandleProbeRequest(src, id, lid, target, best, nearest,
htl, counter, false, false, true, false, null, notVisitedList, true, (short)-1,
"rejected");
- return true;
- }
-
- public void startProbe(double d, ProbeCallback cb) {
- long l = node.random.nextLong();
- Long ll = new Long(l);
- synchronized(recentProbeRequestIDs) {
- recentProbeRequestIDs.push(ll);
- }
- double nodeLoc = node.getLocation();
- innerHandleProbeRequest(null, l, ll, d, (nodeLoc > d) ? nodeLoc
: furthestGreater(d), nodeLoc, node.maxHTL(), (short)0, false, false, false,
true, cb, new Vector(), false, (short)-1, "start");
- }
-
- private double furthestLoc(double d) {
- if(d > 0.5) return d - 0.5;
- return d + 0.5;
- }
-
- private double furthestGreater(double d) {
- if(d < 0.5) return d + 0.5;
- return 1.0;
- }
-
void start(NodeStats stats) {
this.nodeStats = stats;
}
@@ -1056,4 +481,15 @@
}
return sb.toString();
}
+
+ // Probe requests
+
+ // FIXME
+ public static final int PROBE_TYPE_DEFAULT = 0;
+
+ public void startProbe(double d, ProbeCallback cb, int probeType) {
+ long l = node.random.nextLong();
+ // FIXME implement!
+ throw new UnsupportedOperationException();
+ }
}
\ No newline at end of file
Modified: trunk/freenet/src/freenet/node/TextModeClientInterface.java
===================================================================
--- trunk/freenet/src/freenet/node/TextModeClientInterface.java 2007-11-28
16:04:00 UTC (rev 16027)
+++ trunk/freenet/src/freenet/node/TextModeClientInterface.java 2007-11-28
16:43:39 UTC (rev 16028)
@@ -863,7 +863,7 @@
}
};
System.err.println("Probing keyspace around "+d+" ...");
- n.dispatcher.startProbe(d, cb);
+ n.dispatcher.startProbe(d, cb,
NodeDispatcher.PROBE_TYPE_DEFAULT);
synchronized(this) {
while(!doneSomething) {
try {
@@ -875,7 +875,13 @@
doneSomething = false;
}
} else if(uline.startsWith("PROBEALL")) {
- probeAll();
+ uline = uline.substring("PROBEALL".length());
+ if(uline.startsWith(":")) uline = uline.substring(1);
+ if(uline.length() == 0) {
+ probeAll(NodeDispatcher.PROBE_TYPE_DEFAULT);
+ } else {
+ probeAll(Integer.parseInt(uline));
+ }
} else if(uline.startsWith("PLUGLOAD:")) {
if (line.substring("PLUGLOAD:".length()).trim().equals("?")) {
outsb.append(" PLUGLOAD: pluginName - Load
official plugin from freenetproject.org");
@@ -899,8 +905,8 @@
return false;
}
- private void probeAll() {
- GlobalProbe p = new GlobalProbe(n);
+ private void probeAll(int probeType) {
+ GlobalProbe p = new GlobalProbe(n, probeType);
n.executor.execute(p, "GlobalProbe");
}