Author: toad
Date: 2008-09-04 22:07:09 +0000 (Thu, 04 Sep 2008)
New Revision: 22440

Modified:
   trunk/freenet/src/freenet/node/PeerNode.java
Log:
IMHO FNPSentPackets isn't viable.


Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java        2008-09-04 21:13:15 UTC 
(rev 22439)
+++ trunk/freenet/src/freenet/node/PeerNode.java        2008-09-04 22:07:09 UTC 
(rev 22440)
@@ -3609,109 +3609,114 @@
         * Handle an FNPSentPackets message
         */
        public void handleSentPackets(Message m) {
-               long now = System.currentTimeMillis();
-               synchronized(this) {
-                       if(forceDisconnectCalled)
-                               return;
-                       /*
-                        * I've had some very strange results from seed clients!
-                        * One showed deltas of over 10 minutes... how is that 
possible? The PN wouldn't reconnect?!
-                        */
-                       if(!isRealConnection())
-                               return; // The packets wouldn't have been 
assigned to this PeerNode!
-//                     if(now - this.timeLastConnected < 
SENT_PACKETS_MAX_TIME_AFTER_CONNECT)
+               
+               // IMHO it's impossible to make this work reliably on lossy 
connections, especially highly saturated upstreams.
+               // If it was possible it would likely involve a lot of work, 
refactoring, voting between peers, marginal results,
+               // very slow accumulation of data etc.
+               
+//             long now = System.currentTimeMillis();
+//             synchronized(this) {
+//                     if(forceDisconnectCalled)
 //                             return;
-               }
-               long baseTime = m.getLong(DMT.TIME);
-               baseTime += this.clockDelta;
-               // Should be a reasonable approximation now
-               int[] timeDeltas = Fields.bytesToInts(((ShortBuffer) 
m.getObject(DMT.TIME_DELTAS)).getData());
-               long[] packetHashes = Fields.bytesToLongs(((ShortBuffer) 
m.getObject(DMT.HASHES)).getData());
-               long[] times = new long[timeDeltas.length];
-               for(int i = 0; i < times.length; i++)
-                       times[i] = baseTime - timeDeltas[i];
-               long tolerance = 60 * 1000 + (Math.abs(timeDeltas[0]) / 20); // 
1 minute or 5% of full interval
-               synchronized(this) {
-                       // They are in increasing order
-                       // Loop backwards
-                       long otime = Long.MAX_VALUE;
-                       long[][] sent = getRecvPacketTimesHashes();
-                       long[] sentTimes = sent[0];
-                       long[] sentHashes = sent[1];
-                       short sentPtr = (short) (sent.length - 1);
-                       short notFoundCount = 0;
-                       short consecutiveNotFound = 0;
-                       short longestConsecutiveNotFound = 0;
-                       short ignoredUptimeCount = 0;
-                       short found = 0;
-                       //The arrays are constructed from received data, don't 
throw an ArrayIndexOutOfBoundsException if they are different sizes.
-                       int shortestArray=times.length;
-                       if (shortestArray > packetHashes.length)
-                               shortestArray = packetHashes.length;
-                       for(short i = (short) (shortestArray-1); i >= 0; i--) { 
-                               long time = times[i];
-                               if(time > otime) {
-                                       Logger.error(this, "Inconsistent time 
order: [" + i + "]=" + time + " but [" + (i + 1) + "] is " + otime);
-                                       return;
-                               } else
-                                       otime = time;
-                               long hash = packetHashes[i];
-                               // Search for the hash.
-                               short match = -1;
-                               // First try forwards
-                               for(short j = sentPtr; j < sentTimes.length; 
j++) {
-                                       long ttime = sentTimes[j];
-                                       if(sentHashes[j] == hash) {
-                                               match = j;
-                                               sentPtr = j;
-                                               break;
-                                       }
-                                       if(ttime - time > tolerance)
-                                               break;
-                               }
-                               if(match == -1)
-                                       for(short j = (short) (sentPtr - 1); j 
>= 0; j--) {
-                                               long ttime = sentTimes[j];
-                                               if(sentHashes[j] == hash) {
-                                                       match = j;
-                                                       sentPtr = j;
-                                                       break;
-                                               }
-                                               if(time - ttime > tolerance)
-                                                       break;
-                                       }
-                               if(match == -1) {
-                                       long mustHaveBeenUpAt = now - 
(int)(timeDeltas[i] * 1.1) - 100;
-                                       if(this.crypto.socket.getStartTime() > 
mustHaveBeenUpAt) {
-                                               ignoredUptimeCount++;
-                                       } else {
-                                               // Not found
-                                               consecutiveNotFound++;
-                                               notFoundCount++;
-                                       }
-                               } else {
-                                       if(consecutiveNotFound > 
longestConsecutiveNotFound)
-                                               longestConsecutiveNotFound = 
consecutiveNotFound;
-                                       consecutiveNotFound = 0;
-                                       found++;
-                               }
-                       }
-                       if(consecutiveNotFound > longestConsecutiveNotFound)
-                               longestConsecutiveNotFound = 
consecutiveNotFound;
-                       Logger.error(this, "Packets: "+packetHashes.length+" 
not found "+notFoundCount+" consecutive not found "+consecutiveNotFound+" 
longest consecutive not found "+longestConsecutiveNotFound+" ignored due to 
uptime: "+ignoredUptimeCount+" found: "+found);
-                       if(longestConsecutiveNotFound > TRACK_PACKETS / 2) {
-                               manyPacketsClaimedSentNotReceived = true;
-                               timeManyPacketsClaimedSentNotReceived = now;
-                               Logger.error(this, "" + consecutiveNotFound + " 
consecutive packets not found on " + userToString());
-                               SocketHandler handler = 
outgoingMangler.getSocketHandler();
-                               if(handler instanceof 
PortForwardSensitiveSocketHandler) {
-                                       ((PortForwardSensitiveSocketHandler) 
handler).rescanPortForward();
-                               }
-                       }
-               }
-               if(manyPacketsClaimedSentNotReceived) {
-                       outgoingMangler.setPortForwardingBroken();
-               }
+//                     /*
+//                      * I've had some very strange results from seed clients!
+//                      * One showed deltas of over 10 minutes... how is that 
possible? The PN wouldn't reconnect?!
+//                      */
+//                     if(!isRealConnection())
+//                             return; // The packets wouldn't have been 
assigned to this PeerNode!
+////                   if(now - this.timeLastConnected < 
SENT_PACKETS_MAX_TIME_AFTER_CONNECT)
+////                           return;
+//             }
+//             long baseTime = m.getLong(DMT.TIME);
+//             baseTime += this.clockDelta;
+//             // Should be a reasonable approximation now
+//             int[] timeDeltas = Fields.bytesToInts(((ShortBuffer) 
m.getObject(DMT.TIME_DELTAS)).getData());
+//             long[] packetHashes = Fields.bytesToLongs(((ShortBuffer) 
m.getObject(DMT.HASHES)).getData());
+//             long[] times = new long[timeDeltas.length];
+//             for(int i = 0; i < times.length; i++)
+//                     times[i] = baseTime - timeDeltas[i];
+//             long tolerance = 60 * 1000 + (Math.abs(timeDeltas[0]) / 20); // 
1 minute or 5% of full interval
+//             synchronized(this) {
+//                     // They are in increasing order
+//                     // Loop backwards
+//                     long otime = Long.MAX_VALUE;
+//                     long[][] sent = getRecvPacketTimesHashes();
+//                     long[] sentTimes = sent[0];
+//                     long[] sentHashes = sent[1];
+//                     short sentPtr = (short) (sent.length - 1);
+//                     short notFoundCount = 0;
+//                     short consecutiveNotFound = 0;
+//                     short longestConsecutiveNotFound = 0;
+//                     short ignoredUptimeCount = 0;
+//                     short found = 0;
+//                     //The arrays are constructed from received data, don't 
throw an ArrayIndexOutOfBoundsException if they are different sizes.
+//                     int shortestArray=times.length;
+//                     if (shortestArray > packetHashes.length)
+//                             shortestArray = packetHashes.length;
+//                     for(short i = (short) (shortestArray-1); i >= 0; i--) { 
+//                             long time = times[i];
+//                             if(time > otime) {
+//                                     Logger.error(this, "Inconsistent time 
order: [" + i + "]=" + time + " but [" + (i + 1) + "] is " + otime);
+//                                     return;
+//                             } else
+//                                     otime = time;
+//                             long hash = packetHashes[i];
+//                             // Search for the hash.
+//                             short match = -1;
+//                             // First try forwards
+//                             for(short j = sentPtr; j < sentTimes.length; 
j++) {
+//                                     long ttime = sentTimes[j];
+//                                     if(sentHashes[j] == hash) {
+//                                             match = j;
+//                                             sentPtr = j;
+//                                             break;
+//                                     }
+//                                     if(ttime - time > tolerance)
+//                                             break;
+//                             }
+//                             if(match == -1)
+//                                     for(short j = (short) (sentPtr - 1); j 
>= 0; j--) {
+//                                             long ttime = sentTimes[j];
+//                                             if(sentHashes[j] == hash) {
+//                                                     match = j;
+//                                                     sentPtr = j;
+//                                                     break;
+//                                             }
+//                                             if(time - ttime > tolerance)
+//                                                     break;
+//                                     }
+//                             if(match == -1) {
+//                                     long mustHaveBeenUpAt = now - 
(int)(timeDeltas[i] * 1.1) - 100;
+//                                     if(this.crypto.socket.getStartTime() > 
mustHaveBeenUpAt) {
+//                                             ignoredUptimeCount++;
+//                                     } else {
+//                                             // Not found
+//                                             consecutiveNotFound++;
+//                                             notFoundCount++;
+//                                     }
+//                             } else {
+//                                     if(consecutiveNotFound > 
longestConsecutiveNotFound)
+//                                             longestConsecutiveNotFound = 
consecutiveNotFound;
+//                                     consecutiveNotFound = 0;
+//                                     found++;
+//                             }
+//                     }
+//                     if(consecutiveNotFound > longestConsecutiveNotFound)
+//                             longestConsecutiveNotFound = 
consecutiveNotFound;
+//                     Logger.error(this, "Packets: "+packetHashes.length+" 
not found "+notFoundCount+" consecutive not found "+consecutiveNotFound+" 
longest consecutive not found "+longestConsecutiveNotFound+" ignored due to 
uptime: "+ignoredUptimeCount+" found: "+found);
+//                     if(longestConsecutiveNotFound > TRACK_PACKETS / 2) {
+//                             manyPacketsClaimedSentNotReceived = true;
+//                             timeManyPacketsClaimedSentNotReceived = now;
+//                             Logger.error(this, "" + consecutiveNotFound + " 
consecutive packets not found on " + userToString());
+//                             SocketHandler handler = 
outgoingMangler.getSocketHandler();
+//                             if(handler instanceof 
PortForwardSensitiveSocketHandler) {
+//                                     ((PortForwardSensitiveSocketHandler) 
handler).rescanPortForward();
+//                             }
+//                     }
+//             }
+//             if(manyPacketsClaimedSentNotReceived) {
+//                     outgoingMangler.setPortForwardingBroken();
+//             }
        }
        private boolean manyPacketsClaimedSentNotReceived = false;



Reply via email to