Author: toad
Date: 2007-04-20 15:09:27 +0000 (Fri, 20 Apr 2007)
New Revision: 12810
Modified:
trunk/freenet/src/freenet/io/comm/DMT.java
trunk/freenet/src/freenet/node/GlobalProbe.java
trunk/freenet/src/freenet/node/LocationManager.java
trunk/freenet/src/freenet/node/NodeDispatcher.java
trunk/freenet/src/freenet/node/PeerManager.java
trunk/freenet/src/freenet/node/ProbeCallback.java
trunk/freenet/src/freenet/node/TextModeClientInterface.java
trunk/freenet/src/freenet/support/Fields.java
Log:
Probe tracing
Modified: trunk/freenet/src/freenet/io/comm/DMT.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/DMT.java 2007-04-19 22:29:12 UTC (rev
12809)
+++ trunk/freenet/src/freenet/io/comm/DMT.java 2007-04-20 15:09:27 UTC (rev
12810)
@@ -26,6 +26,7 @@
import freenet.keys.NodeSSK;
import freenet.support.BitArray;
import freenet.support.Buffer;
+import freenet.support.Fields;
import freenet.support.ShortBuffer;
@@ -91,6 +92,9 @@
public static final String NODE_TO_NODE_MESSAGE_TEXT =
"nodeToNodeMessageText";
public static final String NODE_TO_NODE_MESSAGE_DATA =
"nodeToNodeMessageData";
public static final String NODE_UIDS = "nodeUIDs";
+ public static final String MY_UID = "myUID";
+ public static final String PEER_LOCATIONS = "peerLocations";
+ public static final String PEER_UIDS = "peerUIDs";
//Diagnostic
public static final MessageType ping = new MessageType("ping") {{
@@ -706,6 +710,34 @@
return msg;
}
+ public static final MessageType FNPProbeTrace = new
MessageType("FNPProbeTrace") {{
+ addField(UID, Long.class);
+ addField(TARGET_LOCATION, Double.class);
+ addField(NEAREST_LOCATION, Double.class);
+ addField(BEST_LOCATION, Double.class);
+ addField(HTL, Short.class);
+ addField(COUNTER, Short.class);
+ addField(LOCATION, Double.class);
+ addField(MY_UID, Long.class);
+ addField(PEER_LOCATIONS, ShortBuffer.class);
+ addField(PEER_UIDS, ShortBuffer.class);
+ }};
+
+ public static Message createFNPProbeTrace(long uid, double target,
double nearest, double best, short htl, short counter, double myLoc, long
swapIdentifier, double[] peerLocs, long[] peerUIDs) {
+ Message msg = new Message(FNPProbeRequest);
+ msg.set(UID, uid);
+ msg.set(TARGET_LOCATION, target);
+ msg.set(NEAREST_LOCATION, nearest);
+ msg.set(BEST_LOCATION, best);
+ msg.set(HTL, htl);
+ msg.set(COUNTER, counter);
+ msg.set(LOCATION, myLoc);
+ msg.set(MY_UID, swapIdentifier);
+ msg.set(PEER_LOCATIONS, new
ShortBuffer(Fields.doublesToBytes(peerLocs)));
+ msg.set(PEER_UIDS, new
ShortBuffer(Fields.longsToBytes(peerUIDs)));
+ return msg;
+ }
+
public static final MessageType FNPProbeReply = new
MessageType("FNPProbeReply") {{
addField(UID, Long.class);
addField(TARGET_LOCATION, Double.class);
Modified: trunk/freenet/src/freenet/node/GlobalProbe.java
===================================================================
--- trunk/freenet/src/freenet/node/GlobalProbe.java 2007-04-19 22:29:12 UTC
(rev 12809)
+++ trunk/freenet/src/freenet/node/GlobalProbe.java 2007-04-20 15:09:27 UTC
(rev 12810)
@@ -28,6 +28,11 @@
GlobalProbe.this.notifyAll();
}
}
+
+ public void onTrace(long uid, double target, double
nearest, double best, short htl, short counter, double location, long nodeUID,
double[] peerLocs, long[] peerUIDs) {
+ String msg = "Probe trace: UID="+uid+"
target="+target+" nearest="+nearest+" best="+best+" htl="+htl+"
counter="+counter+" location="+location+"node UID="+nodeUID+" peer
locs="+peerLocs+" peer UIDs="+peerUIDs;
+ Logger.error(this, msg);
+ }
};
}
Modified: trunk/freenet/src/freenet/node/LocationManager.java
===================================================================
--- trunk/freenet/src/freenet/node/LocationManager.java 2007-04-19 22:29:12 UTC
(rev 12809)
+++ trunk/freenet/src/freenet/node/LocationManager.java 2007-04-20 15:09:27 UTC
(rev 12810)
@@ -1108,17 +1108,31 @@
}
}
- private static double[] extractLocs(LocationUIDPair[] pairs) {
+ static double[] extractLocs(LocationUIDPair[] pairs) {
double[] locs = new double[pairs.length];
for(int i=0;i<pairs.length;i++)
locs[i] = pairs[i].location;
return locs;
}
- private static long[] extractUIDs(LocationUIDPair[] pairs) {
+ static long[] extractUIDs(LocationUIDPair[] pairs) {
long[] uids = new long[pairs.length];
for(int i=0;i<pairs.length;i++)
uids[i] = pairs[i].uid;
return uids;
}
+
+ public static double[] extractLocs(PeerNode[] peers) {
+ double[] locs = new double[peers.length];
+ for(int i=0;i<peers.length;i++)
+ locs[i] = peers[i].getLocation().getValue();
+ return locs;
+ }
+
+ public static long[] extractUIDs(PeerNode[] peers) {
+ long[] uids = new long[peers.length];
+ for(int i=0;i<peers.length;i++)
+ uids[i] = peers[i].swapIdentifier;
+ return uids;
+ }
}
Modified: trunk/freenet/src/freenet/node/NodeDispatcher.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeDispatcher.java 2007-04-19 22:29:12 UTC
(rev 12809)
+++ trunk/freenet/src/freenet/node/NodeDispatcher.java 2007-04-20 15:09:27 UTC
(rev 12810)
@@ -12,9 +12,11 @@
import freenet.io.comm.MessageType;
import freenet.io.comm.NotConnectedException;
import freenet.io.comm.Peer;
+import freenet.support.Fields;
import freenet.support.LRUHashtable;
import freenet.support.LRUQueue;
import freenet.support.Logger;
+import freenet.support.ShortBuffer;
/**
* @author amphibian
@@ -549,7 +551,7 @@
}
Logger.minor(this, "htl="+htl+", nearest="+nearest+",
ctx.htl="+ctx.htl+", ctx.nearest="+ctx.nearest);
- PeerNode[] peers = node.peers.myPeers;
+ PeerNode[] peers = node.peers.connectedPeers;
double myLoc = node.getLocation();
// Update best
@@ -561,11 +563,6 @@
best = ctx.best;
for(int i=0;i<peers.length;i++) {
- if(!peers[i].isConnected()) {
- if(logMINOR)
- Logger.minor(this, "Not connected:
"+peers[i]);
- continue;
- }
double loc = peers[i].getLocation().getValue();
if(logMINOR) Logger.minor(this, "Location: "+loc);
// We are only interested in locations greater than the
target
@@ -639,6 +636,15 @@
visited.add(pn);
+ Message trace =
+ DMT.createFNPProbeTrace(id, target, nearest,
best, htl, counter, myLoc, node.swapIdentifier,
LocationManager.extractLocs(peers), LocationManager.extractUIDs(peers));
+ if(src != null)
+ try {
+ src.sendAsync(trace, null, 0, null);
+ } catch (NotConnectedException e1) {
+ // Ignore
+ }
+
Message forwarded =
DMT.createFNPProbeRequest(id, target, nearest,
best, htl, counter++);
try {
@@ -657,6 +663,20 @@
ctx.cb.onCompleted(msg, target, best, nearest, id, counter);
}
+ 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);
+ double[] peerLocs =
Fields.bytesToDoubles(((ShortBuffer)msg.getObject(DMT.PEER_LOCATIONS)).getData());
+ long[] peerUIDs =
Fields.bytesToLongs(((ShortBuffer)msg.getObject(DMT.PEER_UIDS)).getData());
+ ctx.cb.onTrace(uid, target, nearest, best, htl, counter,
location, nodeUID, peerLocs, peerUIDs);
+ }
+
private boolean handleProbeReply(Message m, PeerNode src) {
long id = m.getLong(DMT.UID);
Long lid = new Long(id);
@@ -693,6 +713,41 @@
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);
+ if(logMINOR)
+ Logger.minor(this, "Probe trace: "+id+ ' ' +target+ ' '
+best+ ' ' +nearest);
+ // 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();
+ }
+
+ if(ctx.src != null) {
+ try {
+ ctx.src.sendAsync(m, null, 0, null);
+ } catch (NotConnectedException e) {
+ Logger.error(this, "Not connected forwarding
trace to "+ctx.src+" (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);
Modified: trunk/freenet/src/freenet/node/PeerManager.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerManager.java 2007-04-19 22:29:12 UTC
(rev 12809)
+++ trunk/freenet/src/freenet/node/PeerManager.java 2007-04-20 15:09:27 UTC
(rev 12810)
@@ -383,7 +383,7 @@
PeerNode[] conns;
LocationUIDPair[] locPairs;
synchronized (this) {
- conns = connectedPeers;
+ conns = myPeers;
}
locPairs = new LocationUIDPair[conns.length];
int x = 0;
Modified: trunk/freenet/src/freenet/node/ProbeCallback.java
===================================================================
--- trunk/freenet/src/freenet/node/ProbeCallback.java 2007-04-19 22:29:12 UTC
(rev 12809)
+++ trunk/freenet/src/freenet/node/ProbeCallback.java 2007-04-20 15:09:27 UTC
(rev 12810)
@@ -8,4 +8,6 @@
void onCompleted(String reason, double target, double best, double
nearest, long id, short counter);
+ void onTrace(long uid, double target, double nearest, double best,
short htl, short counter, double location, long nodeUID, double[] peerLocs,
long[] peerUIDs);
+
}
Modified: trunk/freenet/src/freenet/node/TextModeClientInterface.java
===================================================================
--- trunk/freenet/src/freenet/node/TextModeClientInterface.java 2007-04-19
22:29:12 UTC (rev 12809)
+++ trunk/freenet/src/freenet/node/TextModeClientInterface.java 2007-04-20
15:09:27 UTC (rev 12810)
@@ -828,6 +828,11 @@
TextModeClientInterface.this.notifyAll();
}
}
+
+ public void onTrace(long uid, double target,
double nearest, double best, short htl, short counter, double location, long
nodeUID, double[] peerLocs, long[] peerUIDs) {
+ String msg = "Probe trace: UID="+uid+"
target="+target+" nearest="+nearest+" best="+best+" htl="+htl+"
counter="+counter+" location="+location+"node UID="+nodeUID+" peer
locs="+peerLocs+" peer UIDs="+peerUIDs;
+ System.err.println(msg);
+ }
};
n.dispatcher.startProbe(d, cb);
synchronized(this) {
Modified: trunk/freenet/src/freenet/support/Fields.java
===================================================================
--- trunk/freenet/src/freenet/support/Fields.java 2007-04-19 22:29:12 UTC
(rev 12809)
+++ trunk/freenet/src/freenet/support/Fields.java 2007-04-20 15:09:27 UTC
(rev 12810)
@@ -1,5 +1,6 @@
package freenet.support;
+import java.io.DataInputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
@@ -642,4 +643,15 @@
return doubles;
}
+ public static byte[] doublesToBytes(double[] doubles) {
+ long[] longs = new long[doubles.length];
+ for(int i=0;i<longs.length;i++)
+ longs[i] = Double.doubleToLongBits(doubles[i]);
+ return longsToBytes(longs);
+ }
+
+ public static double[] bytesToDoubles(byte[] data) {
+ return bytesToDoubles(data, 0, data.length);
+ }
+
}