Author: toad
Date: 2007-12-08 19:36:46 +0000 (Sat, 08 Dec 2007)
New Revision: 16424

Modified:
   trunk/freenet/src/freenet/node/NodeDispatcher.java
   trunk/freenet/src/freenet/node/PacketSender.java
   trunk/freenet/src/freenet/node/PeerNode.java
Log:
When we receive an FNPDisconnect, send an ack before disconnecting.

Modified: trunk/freenet/src/freenet/node/NodeDispatcher.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeDispatcher.java  2007-12-08 19:22:27 UTC 
(rev 16423)
+++ trunk/freenet/src/freenet/node/NodeDispatcher.java  2007-12-08 19:36:46 UTC 
(rev 16424)
@@ -160,7 +160,22 @@
                return false;
        }

-       private void handleDisconnect(Message m, PeerNode source) {
+       private void handleDisconnect(final Message m, final PeerNode source) {
+               // Must run ON the packet sender thread as it sends a packet 
directly
+               node.getTicker().queueTimedJob(new FastRunnable() {
+                       public void run() {
+                               // Send the ack
+                               try {
+                                       source.sendAnyUrgentNotifications(true);
+                               } catch (PacketSequenceException e) {
+                                       // Ignore
+                               }
+                               finishDisconnect(m, source);
+                       }
+               }, 0);
+       }
+       
+       private void finishDisconnect(final Message m, final PeerNode source) {
                source.disconnected(true, true);
                // If true, remove from active routing table, likely to be down 
for a while.
                // Otherwise just dump all current connection state and keep 
trying to connect.

Modified: trunk/freenet/src/freenet/node/PacketSender.java
===================================================================
--- trunk/freenet/src/freenet/node/PacketSender.java    2007-12-08 19:22:27 UTC 
(rev 16423)
+++ trunk/freenet/src/freenet/node/PacketSender.java    2007-12-08 19:36:46 UTC 
(rev 16424)
@@ -294,7 +294,7 @@
                                        // Send them

                                        try {
-                                               pn.sendAnyUrgentNotifications();
+                                               
pn.sendAnyUrgentNotifications(false);
                                        } catch(PacketSequenceException e) {
                                                Logger.error(this, "Caught " + 
e + " - while sending urgent notifications : disconnecting", e);
                                                pn.forceDisconnect(false);

Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java        2007-12-08 19:22:27 UTC 
(rev 16423)
+++ trunk/freenet/src/freenet/node/PeerNode.java        2007-12-08 19:36:46 UTC 
(rev 16424)
@@ -2070,7 +2070,7 @@
        * @throws PacketSequenceException If there is an error sending the 
packet
        * caused by a sequence inconsistency. 
        */
-       public void sendAnyUrgentNotifications() throws PacketSequenceException 
{
+       public void sendAnyUrgentNotifications(boolean forceSendPrimary) throws 
PacketSequenceException {
                if(logMINOR)
                        Logger.minor(this, "sendAnyUrgentNotifications");
                long now = System.currentTimeMillis();
@@ -2083,7 +2083,7 @@
                KeyTracker tracker = cur;
                if(tracker != null) {
                        long t = tracker.getNextUrgentTime();
-                       if(t < now) {
+                       if(t < now || forceSendPrimary) {
                                try {
                                        outgoingMangler.processOutgoing(null, 
0, 0, tracker, 0);
                                } catch(NotConnectedException e) {


Reply via email to