Author: toad
Date: 2007-11-28 19:55:04 +0000 (Wed, 28 Nov 2007)
New Revision: 16038

Modified:
   trunk/freenet/src/freenet/io/comm/DMT.java
   trunk/freenet/src/freenet/node/PeerNode.java
Log:
Send time deltas (as ints) and hashes (as longs).

Modified: trunk/freenet/src/freenet/io/comm/DMT.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/DMT.java  2007-11-28 19:28:12 UTC (rev 
16037)
+++ trunk/freenet/src/freenet/io/comm/DMT.java  2007-11-28 19:55:04 UTC (rev 
16038)
@@ -121,6 +121,8 @@
        public static final String TRANSFER_UID = "transferUID";
        public static final String NODEREF_LENGTH = "noderefLength";
        public static final String PADDED_LENGTH = "paddedLength";
+       public static final String TIME_DELTAS = "timeDeltas";
+       public static final String HASHES = "hashes";

        //Diagnostic
        public static final MessageType ping = new MessageType("ping") {{
@@ -1077,6 +1079,18 @@
                return msg;
        }

+       public static final MessageType FNPSentPackets = new 
MessageType("FNPSentPackets") {{
+               addField(TIME_DELTAS, ShortBuffer.class);
+               addField(HASHES, ShortBuffer.class);
+       }};
+       
+       public static final Message createFNPSentPackets(int[] timeDeltas, 
long[] hashes) {
+               Message msg = new Message(FNPSentPackets);
+               msg.set(TIME_DELTAS, new 
ShortBuffer(Fields.intsToBytes(timeDeltas)));
+               msg.set(HASHES, new ShortBuffer(Fields.longsToBytes(hashes)));
+               return msg;
+       }
+       
        public static final MessageType FNPVoid = new MessageType("FNPVoid") {{
        }};


Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java        2007-11-28 19:28:12 UTC 
(rev 16037)
+++ trunk/freenet/src/freenet/node/PeerNode.java        2007-11-28 19:55:04 UTC 
(rev 16038)
@@ -1646,12 +1646,14 @@
         Message locMsg = 
DMT.createFNPLocChangeNotification(node.lm.getLocation());
         Message ipMsg = DMT.createFNPDetectedIPAddress(detectedPeer);
         Message timeMsg = DMT.createFNPTime(System.currentTimeMillis());
+        Message packetsMsg = createSentPacketsMessage();

         try {
                if(isRoutable())
                         sendAsync(locMsg, null, 0, null);
             sendAsync(ipMsg, null, 0, null);
             sendAsync(timeMsg, null, 0, null);
+            sendAsync(packetsMsg, null, 0, null);
         } catch (NotConnectedException e) {
             Logger.error(this, "Completed handshake with "+getPeer()+" but 
disconnected ("+isConnected+ ':' +currentTracker+"!!!: "+e, e);
         }
@@ -1660,7 +1662,32 @@
                node.nodeUpdater.maybeSendUOMAnnounce(this);
     }

-    private void sendIPAddressMessage() {
+    private Message createSentPacketsMessage() {
+       long[][] sent = getSentPacketTimesHashes();
+       long[] times = sent[0];
+       long[] hashes = sent[1];
+       long now = System.currentTimeMillis();
+       long horizon = now - Integer.MAX_VALUE;
+       int skip = 0;
+       for(int i=0;i<times.length;i++) {
+               long time = times[i];
+               if(time < horizon) skip++;
+               else break;
+       }
+       int[] timeDeltas = new int[times.length-skip];
+       for(int i=skip;i<times.length;i++) {
+               timeDeltas[i] = (int) (now - times[i]);
+       }
+       if(skip != 0) {
+               // Unlikely code path, only happens with very long uptime.
+               // Trim hashes too.
+               long[] newHashes = new long[hashes.length - skip];
+               System.arraycopy(hashes, skip, newHashes, 0, hashes.length - 
skip);
+       }
+       return DMT.createFNPSentPackets(timeDeltas, hashes);
+       }
+
+       private void sendIPAddressMessage() {
         Message ipMsg = DMT.createFNPDetectedIPAddress(detectedPeer);
         try {
             sendAsync(ipMsg, null, 0, null);


Reply via email to