Author: toad
Date: 2008-12-04 20:05:52 +0000 (Thu, 04 Dec 2008)
New Revision: 24044

Modified:
   trunk/freenet/src/freenet/node/PacketTracker.java
Log:
Fix some packet number allocation problems causing disconnects etc:
If the other side asks us to resend a packet which we've already had acked, log 
an ERROR, and tell them we've forgotten the packet (which is true; we don't 
have the data any more since it's been acked.
Recent debugging suggests that the packet may not actually have been acked, we 
may have skipped the packet number.
Mostly this results from PacketSequenceException's, which are themselves often 
caused by skipping packets...!
If we haven't sent it yet, that is also bad, and impossible as we allocate 
packet numbers just before using them.
When we send a packet, throw an IllegalStateException if we can't add record 
its contents because it's out of range.


Modified: trunk/freenet/src/freenet/node/PacketTracker.java
===================================================================
--- trunk/freenet/src/freenet/node/PacketTracker.java   2008-12-04 19:15:44 UTC 
(rev 24043)
+++ trunk/freenet/src/freenet/node/PacketTracker.java   2008-12-04 20:05:52 UTC 
(rev 24044)
@@ -610,14 +610,17 @@
                        }
                        pn.node.ps.wakeUp();
                } else {
-                       String msg = "Asking me to resend packet " + seqNumber +
-                               " which we haven't sent yet or which they have 
already acked (next=" + nextPacketNumber + ')';
-                       // Might just be late, but could indicate something 
serious.
-                       if(isDeprecated) {
-                               if(logMINOR)
-                                       Logger.minor(this, "Other side wants us 
to resend packet " + seqNumber + " for " + this + " - we cannot do this because 
we are deprecated");
-                       } else
-                               Logger.normal(this, msg);
+                       synchronized(this) {
+                               if(nextPacketNumber <= seqNumber) {
+                                       Logger.error(this, "Asking me to resend 
packet "+seqNumber+" which I haven't sent yet (next="+nextPacketNumber+") on 
"+this);
+                                       // FIXME forceDisconnect when sure this 
won't be catastrophic
+                                       return;
+                               } else {
+                                       Logger.error(this, "Asking me to resend 
packet "+seqNumber+" which has already been acked or we skipped the packet 
number (next="+nextPacketNumber+") on "+this+" - will tell other side we have 
forgotten it");
+                                       // Can't resend it. Tell other side we 
forgot it.
+                               }
+                       }
+                       queueForgotten(seqNumber); // Happens to be true... or 
maybe it didn't exist in the first place?
                }
        }
 
@@ -930,7 +933,8 @@
                                if(callbacks[i] == null)
                                        throw new NullPointerException();
                        }
-               sentPacketsContents.add(seqNumber, data, callbacks, priority);
+               if(!sentPacketsContents.add(seqNumber, data, callbacks, 
priority))
+                       throw new IllegalStateException("Cannot add data for 
packet "+seqNumber);
                try {
                        queueAckRequest(seqNumber);
                } catch(UpdatableSortedLinkedListKilledException e) {

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to