Author: toad
Date: 2007-06-26 14:10:56 +0000 (Tue, 26 Jun 2007)
New Revision: 13762

Modified:
   trunk/freenet/src/freenet/io/comm/DMT.java
   trunk/freenet/src/freenet/node/GlobalProbe.java
   trunk/freenet/src/freenet/node/NodeDispatcher.java
   trunk/freenet/src/freenet/node/ProbeCallback.java
   trunk/freenet/src/freenet/node/TextModeClientInterface.java
Log:
Add linear hop count, reason (rejected/backtracking/request), prev node UID to 
probe requests (makes probe requests incompatible, will put out a mandatory 
build for it sometime today).

Modified: trunk/freenet/src/freenet/io/comm/DMT.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/DMT.java  2007-06-26 13:50:20 UTC (rev 
13761)
+++ trunk/freenet/src/freenet/io/comm/DMT.java  2007-06-26 14:10:56 UTC (rev 
13762)
@@ -78,6 +78,7 @@
        public static final String TYPE = "type";
        public static final String PAYLOAD = "payload";
        public static final String COUNTER = "counter";
+       public static final String LINEAR_COUNTER = "linearCounter";
        public static final String RETURN_LOCATION = "returnLocation";
        public static final String BLOCK_HEADERS = "blockHeaders";
        public static final String DATA_INSERT_REJECTED_REASON = 
"dataInsertRejectedReason";
@@ -113,6 +114,7 @@
        public static final String TIME = "time";
        public static final String FORK_COUNT = "forkCount";
        public static final String TIME_LEFT = "timeLeft";
+       public static final String PREV_UID = "prevUID";

        //Diagnostic
        public static final MessageType ping = new MessageType("ping") {{
@@ -771,10 +773,11 @@
                addField(BEST_LOCATION, Double.class);
                addField(HTL, Short.class);
                addField(COUNTER, Short.class);
+               addField(LINEAR_COUNTER, Short.class);
        }};

        public static final Message createFNPProbeRequest(long uid, double 
target, double nearest, 
-                       double best, short htl, short counter) {
+                       double best, short htl, short counter, short 
linearCounter) {
                Message msg = new Message(FNPProbeRequest);
                msg.set(UID, uid);
                msg.set(TARGET_LOCATION, target);
@@ -782,6 +785,7 @@
                msg.set(BEST_LOCATION, best);
                msg.set(HTL, htl);
                msg.set(COUNTER, counter);
+               msg.set(LINEAR_COUNTER, linearCounter);
                return msg;
        }

@@ -797,9 +801,12 @@
                addField(PEER_LOCATIONS, ShortBuffer.class);
                addField(PEER_UIDS, ShortBuffer.class);
                addField(FORK_COUNT, Short.class);
+               addField(LINEAR_COUNTER, Short.class);
+               addField(REASON, String.class);
+               addField(PREV_UID, Long.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, short forkCount) {
+       public static Message createFNPProbeTrace(long uid, double target, 
double nearest, double best, short htl, short counter, double myLoc, long 
swapIdentifier, double[] peerLocs, long[] peerUIDs, short forkCount, short 
linearCounter, String reason, long prevUID) {
                Message msg = new Message(FNPProbeTrace);
                msg.set(UID, uid);
                msg.set(TARGET_LOCATION, target);
@@ -812,6 +819,9 @@
                msg.set(PEER_LOCATIONS, new 
ShortBuffer(Fields.doublesToBytes(peerLocs)));
                msg.set(PEER_UIDS, new 
ShortBuffer(Fields.longsToBytes(peerUIDs)));
                msg.set(FORK_COUNT, forkCount);
+               msg.set(LINEAR_COUNTER, linearCounter);
+               msg.set(REASON, reason);
+               msg.set(PREV_UID, prevUID);
                return msg;
        }

@@ -821,16 +831,18 @@
                addField(NEAREST_LOCATION, Double.class);
                addField(BEST_LOCATION, Double.class);
                addField(COUNTER, Short.class);
+               addField(LINEAR_COUNTER, Short.class);
        }};

        public static final Message createFNPProbeReply(long uid, double 
target, double nearest, 
-                       double best, short counter) {
+                       double best, short counter, short linearCounter) {
                Message msg = new Message(FNPProbeReply);
                msg.set(UID, uid);
                msg.set(TARGET_LOCATION, target);
                msg.set(NEAREST_LOCATION, nearest);
                msg.set(BEST_LOCATION, best);
                msg.set(COUNTER, counter);
+               msg.set(LINEAR_COUNTER, linearCounter);
                return msg;
        }

@@ -842,10 +854,11 @@
                addField(HTL, Short.class);
                addField(COUNTER, Short.class);
                addField(REASON, Short.class);
+               addField(LINEAR_COUNTER, Short.class);
        }};

        public static final Message createFNPProbeRejected(long uid, double 
target, double nearest, 
-                       double best, short counter, short htl, short reason) {
+                       double best, short counter, short htl, short reason, 
short linearCounter) {
                Message msg = new Message(FNPProbeRejected);
                msg.set(UID, uid);
                msg.set(TARGET_LOCATION, target);
@@ -854,6 +867,7 @@
                msg.set(HTL, htl);
                msg.set(COUNTER, counter);
                msg.set(REASON, reason);
+               msg.set(LINEAR_COUNTER, linearCounter);
                return msg;
        }


Modified: trunk/freenet/src/freenet/node/GlobalProbe.java
===================================================================
--- trunk/freenet/src/freenet/node/GlobalProbe.java     2007-06-26 13:50:20 UTC 
(rev 13761)
+++ trunk/freenet/src/freenet/node/GlobalProbe.java     2007-06-26 14:10:56 UTC 
(rev 13762)
@@ -19,8 +19,8 @@
        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 in 
"+(System.currentTimeMillis() - lastTime)+", id "+id+"\r\n";
+                       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";
                                Logger.error(this, msg);
                                synchronized(GlobalProbe.this) {
                                        doneSomething = true;
@@ -30,8 +30,8 @@
                                }
                        }

-                       public void onTrace(long uid, double target, double 
nearest, double best, short htl, short counter, double location, long nodeUID, 
double[] peerLocs, long[] peerUIDs, double[] locsNotVisited, short forkCount) {
-                               String msg = "Probe trace: UID="+uid+" 
target="+target+" nearest="+nearest+" best="+best+" htl="+htl+" 
counter="+counter+" location="+location+" node UID="+nodeUID+" peer 
locs="+StringArray.toString(peerLocs)+" peer 
UIDs="+StringArray.toString(peerUIDs)+" locs not visited: 
"+StringArray.toString(locsNotVisited)+" fork count: "+forkCount;
+                       public void onTrace(long uid, double target, double 
nearest, double best, short htl, short counter, double location, long nodeUID, 
double[] peerLocs, long[] peerUIDs, double[] locsNotVisited, short forkCount, 
short linearCount, String reason, long prevUID) {
+                               String msg = "Probe trace: UID="+uid+" 
target="+target+" nearest="+nearest+" best="+best+" htl="+htl+" 
counter="+counter+" location="+location+" node UID="+nodeUID+" prev 
UID="+prevUID+" peer locs="+StringArray.toString(peerLocs)+" peer 
UIDs="+StringArray.toString(peerUIDs)+" locs not visited: 
"+StringArray.toString(locsNotVisited)+" fork count: "+forkCount+" linear 
count: "+linearCount+" from "+reason;
                                Logger.error(this, msg);
                        }
        };

Modified: trunk/freenet/src/freenet/node/NodeDispatcher.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeDispatcher.java  2007-06-26 13:50:20 UTC 
(rev 13761)
+++ trunk/freenet/src/freenet/node/NodeDispatcher.java  2007-06-26 14:10:56 UTC 
(rev 13762)
@@ -441,6 +441,7 @@
                final WeakHashSet visitedPeers;
                final ProbeCallback cb;
                short counter;
+               short linearCounter;
                short htl;
                double nearest;
                double best;
@@ -483,12 +484,13 @@
                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);
+                               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) {
@@ -511,7 +513,7 @@
                        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, null, notVisitedList, 2.0, false);
+               innerHandleProbeRequest(src, id, lid, target, best, nearest, 
htl, counter, true, true, false, null, notVisitedList, 2.0, false, 
++linearCounter, "request");
                return true;
        }

@@ -539,7 +541,8 @@
         */
        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, ProbeCallback cb, Vector 
locsNotVisited, double maxDistance, boolean dontReject) {
+                       boolean fromRejection, ProbeCallback cb, Vector 
locsNotVisited, double maxDistance, 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
@@ -570,6 +573,7 @@
                                        recentProbeContexts.popValue();
                        }
                }
+               if(linearCounter < 0) linearCounter = ctx.linearCounter;
                if(locsNotVisited != null) {
                        if(logMINOR)
                                Logger.minor(this, "Locs not visited: 
"+locsNotVisited);
@@ -585,7 +589,7 @@
                if(rejected) {
                        if(!dontReject) {
                                // Reject: rate limit
-                               Message reject = DMT.createFNPProbeRejected(id, 
target, nearest, best, counter, htl, DMT.PROBE_REJECTED_OVERLOAD);
+                               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) {
@@ -664,7 +668,7 @@
                if(htl == 0) {
                        if(src != null) {
                                // Complete
-                               Message complete = DMT.createFNPProbeReply(id, 
target, nearest, best, counter++);
+                               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 {
@@ -674,7 +678,7 @@
                                }
                                return true; // counts as success
                        } else {
-                               complete("success", target, best, nearest, id, 
ctx, counter);
+                               complete("success", target, best, nearest, id, 
ctx, counter, linearCounter);
                        }
                }

@@ -719,7 +723,7 @@
                                // Reject: RNF
                                if(!dontReject) {
                                        if(src != null) {
-                                               Message reject = 
DMT.createFNPProbeRejected(id, target, nearest, best, counter, htl, 
DMT.PROBE_REJECTED_RNF);
+                                               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);
@@ -727,7 +731,7 @@
                                                        Logger.error(this, "Not 
connected rejecting a probe request from "+src);
                                                }
                                        } else {
-                                               complete("RNF", target, best, 
nearest, id, ctx, counter);
+                                               complete("RNF", target, best, 
nearest, id, ctx, counter, linearCounter);
                                        }
                                }
                                return false;
@@ -737,7 +741,7 @@

                        if(src != null) {
                                Message trace =
-                                       DMT.createFNPProbeTrace(id, target, 
nearest, best, htl, counter, myLoc, node.swapIdentifier, 
LocationManager.extractLocs(peers, true), LocationManager.extractUIDs(peers), 
ctx.forkCount);
+                                       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 {
                                        src.sendAsync(trace, null, 0, null);
@@ -747,7 +751,7 @@
                        }

                        Message forwarded =
-                               DMT.createFNPProbeRequest(id, target, nearest, 
best, htl, counter++);
+                               DMT.createFNPProbeRequest(id, target, nearest, 
best, htl, counter++, linearCounter);
                        forwarded.addSubMessage(sub);
                        try {
                                pn.sendAsync(forwarded, null, 0, null);
@@ -760,9 +764,9 @@

        }

-       private void complete(String msg, double target, double best, double 
nearest, long id, ProbeContext ctx, short counter) {
+       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);
+               ctx.cb.onCompleted(msg, target, best, nearest, id, counter, 
linearHops);
        }

        private void reportTrace(ProbeContext ctx, Message msg) {
@@ -774,6 +778,7 @@
                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);
@@ -782,7 +787,9 @@
                        locsNotVisited = 
Fields.bytesToDoubles(((ShortBuffer)notVisited.getObject(DMT.BEST_LOCATIONS_NOT_VISITED)).getData());
                }
                short forkCount = msg.getShort(DMT.FORK_COUNT);
-               ctx.cb.onTrace(uid, target, nearest, best, htl, counter, 
location, nodeUID, peerLocs, peerUIDs, locsNotVisited, forkCount);
+               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) {
@@ -792,6 +799,7 @@
                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);

@@ -852,7 +860,7 @@
                                                furthestDist = dist;
                                        }
                                }
-                               if(innerHandleProbeRequest(src, id, lid, 
target, best, nearest, ctx.htl, counter, false, false, false, null, 
notVisitedList, mustBeBetterThan, true))
+                               if(innerHandleProbeRequest(src, id, lid, 
target, best, nearest, ctx.htl, counter, false, false, false, null, 
notVisitedList, mustBeBetterThan, true, linearCounter, "backtracking"))
                                        return true;
                        }
                }
@@ -860,7 +868,7 @@
                // Just propagate back to source
                PeerNode origSource = (PeerNode) ctx.getSource();
                if(src != null) {
-                       Message complete = DMT.createFNPProbeReply(id, target, 
nearest, best, counter++);
+                       Message complete = DMT.createFNPProbeReply(id, target, 
nearest, best, counter++, linearCounter);
                        Message sub = 
m.getSubMessage(DMT.FNPBestRoutesNotTaken);
                        if(sub != null) complete.addSubMessage(sub);
                        try {
@@ -870,7 +878,7 @@
                        }
                } else {
                        if(ctx.cb != null)
-                               complete("Completed", target, best, nearest, 
id, ctx, counter);
+                               complete("Completed", target, best, nearest, 
id, ctx, counter, linearCounter);
                }
                return true;
        }
@@ -952,7 +960,7 @@
                        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, null, notVisitedList, 2.0, false);
+               innerHandleProbeRequest(src, id, lid, target, best, nearest, 
htl, counter, false, false, true, null, notVisitedList, 2.0, false, (short)-1, 
"rejected");
                return true;
        }

@@ -963,7 +971,7 @@
                        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, 
cb, new Vector(), 2.0, false);
+               innerHandleProbeRequest(null, l, ll, d, (nodeLoc > d) ? nodeLoc 
: furthestGreater(d), nodeLoc, node.maxHTL(), (short)0, false, false, false, 
cb, new Vector(), 2.0, false, (short)-1, "start");
        }

        private double furthestLoc(double d) {

Modified: trunk/freenet/src/freenet/node/ProbeCallback.java
===================================================================
--- trunk/freenet/src/freenet/node/ProbeCallback.java   2007-06-26 13:50:20 UTC 
(rev 13761)
+++ trunk/freenet/src/freenet/node/ProbeCallback.java   2007-06-26 14:10:56 UTC 
(rev 13762)
@@ -6,8 +6,8 @@
 /** Callback for a locally initiated probe request */
 public interface ProbeCallback {

-       void onCompleted(String reason, double target, double best, double 
nearest, long id, short counter);
+       void onCompleted(String reason, double target, double best, double 
nearest, long id, short counter, short linearCount);

-       void onTrace(long uid, double target, double nearest, double best, 
short htl, short counter, double location, long nodeUID, double[] peerLocs, 
long[] peerUIDs, double[] locsNotVisited, short forkCount);
+       void onTrace(long uid, double target, double nearest, double best, 
short htl, short counter, double location, long nodeUID, double[] peerLocs, 
long[] peerUIDs, double[] locsNotVisited, short forkCount, short linearCount, 
String reason, long prevUID);

 }

Modified: trunk/freenet/src/freenet/node/TextModeClientInterface.java
===================================================================
--- trunk/freenet/src/freenet/node/TextModeClientInterface.java 2007-06-26 
13:50:20 UTC (rev 13761)
+++ trunk/freenet/src/freenet/node/TextModeClientInterface.java 2007-06-26 
14:10:56 UTC (rev 13762)
@@ -817,8 +817,8 @@
                String s = uline.substring("PROBE:".length()).trim();
                double d = Double.parseDouble(s);
                ProbeCallback 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";
+                               public void onCompleted(String reason, double 
target, double best, double nearest, long id, short counter, short 
linearCounter) {
+                                       String msg = "Completed probe request: 
"+target+" -> "+best+"\r\nNearest actually hit "+nearest+", "+counter+" nodes 
("+linearCounter+" hops), id "+id+"\r\n";
                                        try {
                                                out.write(msg.getBytes());
                                                out.flush();
@@ -831,8 +831,8 @@
                                        }
                                }

-                               public void onTrace(long uid, double target, 
double nearest, double best, short htl, short counter, double location, long 
nodeUID, double[] peerLocs, long[] peerUIDs, double[] locsNotVisited, short 
forkCount) {
-                                       String msg = "Probe trace: UID="+uid+" 
target="+target+" nearest="+nearest+" best="+best+" htl="+htl+" 
counter="+counter+" location="+location+"node UID="+nodeUID+" peer 
locs="+StringArray.toString(peerLocs)+" peer 
UIDs="+StringArray.toString(peerUIDs)+" locs not visited = 
"+StringArray.toString(locsNotVisited)+" forks: "+forkCount+'\n';
+                               public void onTrace(long uid, double target, 
double nearest, double best, short htl, short counter, double location, long 
nodeUID, double[] peerLocs, long[] peerUIDs, double[] locsNotVisited, short 
forkCount, short linearCounter, String reason, long prevUID) {
+                                       String msg = "Probe trace: UID="+uid+" 
target="+target+" nearest="+nearest+" best="+best+" htl="+htl+" 
counter="+counter+" linear="+linearCounter+" location="+location+"node 
UID="+nodeUID+" prev UID="+prevUID+" peer 
locs="+StringArray.toString(peerLocs)+" peer 
UIDs="+StringArray.toString(peerUIDs)+" locs not visited = 
"+StringArray.toString(locsNotVisited)+" forks: "+forkCount+" 
reason="+reason+'\n';
                                        try {
                                                
out.write(msg.toString().getBytes());
                                                out.flush();


Reply via email to