Author: toad
Date: 2007-06-21 17:09:55 +0000 (Thu, 21 Jun 2007)
New Revision: 13685

Modified:
   trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
   trunk/freenet/src/freenet/io/comm/DMT.java
   trunk/freenet/src/freenet/node/NodeDispatcher.java
   trunk/freenet/src/freenet/node/PeerNode.java
   trunk/freenet/src/freenet/node/PeerNodeStatus.java
Log:
Exchange clock time on connect, display it on the darknet page when in advanced 
mode.

Modified: trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java       
2007-06-21 16:29:34 UTC (rev 13684)
+++ trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java       
2007-06-21 17:09:55 UTC (rev 13685)
@@ -367,6 +367,7 @@
                                        peerTableHeaderRow.addChild("th", 
"%\u00a0Time Routable");
                                        peerTableHeaderRow.addChild("th", 
"Total\u00a0Traffic\u00a0(in/out)");
                                        peerTableHeaderRow.addChild("th", 
"Congestion\u00a0Control");
+                                       peerTableHeaderRow.addChild("th", 
"Time\u00a0Delta");
                                }

                                for (int peerIndex = 0, peerCount = 
peerNodeStatuses.length; peerIndex < peerCount; peerIndex++) {
@@ -458,6 +459,8 @@
                                                        val = (int)((1000.0 / 
t.getDelay()) * 1024.0)+"B/sec delay "+
                                                                
t.getDelay()+"ms (RTT "+t.getRoundTripTime()+"ms window "+t.getWindowSize();
                                                peerRow.addChild("td", "class", 
"peer-idle" /* FIXME */).addChild("#", val);
+                                               // time delta
+                                               peerRow.addChild("td", "class", 
"peer-idle" /* FIXME */).addChild("#", 
TimeUtil.formatTime(peerNodeStatus.getClockDelta()));
                                        }

                                        if 
(path.endsWith("displaymessagetypes.html")) {

Modified: trunk/freenet/src/freenet/io/comm/DMT.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/DMT.java  2007-06-21 16:29:34 UTC (rev 
13684)
+++ trunk/freenet/src/freenet/io/comm/DMT.java  2007-06-21 17:09:55 UTC (rev 
13685)
@@ -110,6 +110,7 @@
        public static final String EXTRA_JAR_FILE_LENGTH = "extraJarFileLength";
        public static final String PING_TIME = "pingTime";
        public static final String BWLIMIT_DELAY_TIME = "bwlimitDelayTime";
+       public static final String TIME = "time";

        //Diagnostic
        public static final MessageType ping = new MessageType("ping") {{
@@ -950,6 +951,16 @@
                return msg;
        }

+       public static final MessageType FNPTime = new MessageType("FNPTime") {{
+               addField(TIME, Long.class);
+       }};
+       
+       public static final Message createFNPTime(long time) {
+               Message msg = new Message(FNPTime);
+               msg.set(TIME, time);
+               return msg;
+       }
+       
        public static final MessageType FNPVoid = new MessageType("FNPVoid") {{
        }};


Modified: trunk/freenet/src/freenet/node/NodeDispatcher.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeDispatcher.java  2007-06-21 16:29:34 UTC 
(rev 13684)
+++ trunk/freenet/src/freenet/node/NodeDispatcher.java  2007-06-21 17:09:55 UTC 
(rev 13685)
@@ -81,6 +81,8 @@
                        source.setRemoteDetectedPeer(p);
                        node.ipDetector.redetectAddress();
                        return true;
+               } else if(spec == DMT.FNPTime) {
+                       return handleTime(m, source);
                } else if(spec == DMT.FNPVoid) {
                        return true;
                } else if(spec == DMT.nodeToNodeMessage) {
@@ -140,6 +142,12 @@
                return false;
        }

+       private boolean handleTime(Message m, PeerNode source) {
+               long delta = m.getLong(DMT.TIME) - System.currentTimeMillis();
+               source.setTimeDelta(delta);
+               return true;
+       }
+
        /**
         * Handle an incoming FNPDataRequest.
         */

Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java        2007-06-21 16:29:34 UTC 
(rev 13684)
+++ trunk/freenet/src/freenet/node/PeerNode.java        2007-06-21 17:09:55 UTC 
(rev 13685)
@@ -348,6 +348,9 @@
     /** Times checked for routable connection */
     private long routableConnectionCheckCount;

+    /** Delta between our clock and his clock (positive = his clock is fast, 
negative = our clock is fast) */
+    private long clockDelta;
+    
     private static boolean logMINOR;

     /**
@@ -1643,11 +1646,13 @@
     private void sendInitialMessages() {
         Message locMsg = 
DMT.createFNPLocChangeNotification(node.lm.loc.getValue());
         Message ipMsg = DMT.createFNPDetectedIPAddress(detectedPeer);
+        Message timeMsg = DMT.createFNPTime(System.currentTimeMillis());

         try {
                if(isRoutable())
                         sendAsync(locMsg, null, 0, null);
             sendAsync(ipMsg, null, 0, null);
+            sendAsync(timeMsg, null, 0, null);
         } catch (NotConnectedException e) {
             Logger.error(this, "Completed handshake with "+getPeer()+" but 
disconnected ("+isConnected+ ':' +currentTracker+"!!!: "+e, e);
         }
@@ -3911,4 +3916,12 @@
        public String userToString() {
                return ""+getPeer()+" : "+getName();
        }
+
+       public synchronized void setTimeDelta(long delta) {
+               clockDelta = delta;
+       }
+
+       public long getClockDelta() {
+               return clockDelta;
+       }
 }

Modified: trunk/freenet/src/freenet/node/PeerNodeStatus.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNodeStatus.java  2007-06-21 16:29:34 UTC 
(rev 13684)
+++ trunk/freenet/src/freenet/node/PeerNodeStatus.java  2007-06-21 17:09:55 UTC 
(rev 13685)
@@ -87,6 +87,8 @@
        private double percentTimeRoutableConnection;

        private PacketThrottle throttle;
+       
+       private long clockDelta;

        public PeerNodeStatus(PeerNode peerNode) {
                this.name = peerNode.getName();
@@ -129,6 +131,7 @@
                this.totalBytesOut = peerNode.getTotalOutputBytes();
                this.percentTimeRoutableConnection = 
peerNode.getPercentTimeRoutableConnection();
                this.throttle = peerNode.getThrottle();
+               this.clockDelta = peerNode.getClockDelta();
        }

        /**
@@ -371,4 +374,8 @@
        public PacketThrottle getThrottle() {
                return throttle;
        }
+
+       public long getClockDelta() {
+               return clockDelta;
+       }
 }


Reply via email to