Author: toad
Date: 2007-06-01 11:15:19 +0000 (Fri, 01 Jun 2007)
New Revision: 13434

Modified:
   trunk/freenet/src/freenet/io/comm/MessageFilter.java
   trunk/freenet/src/freenet/io/comm/UdpSocketManager.java
   trunk/freenet/src/freenet/node/PeerNode.java
Log:
Match by default on node restarts as well as node disconnection

Modified: trunk/freenet/src/freenet/io/comm/MessageFilter.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/MessageFilter.java        2007-06-01 
11:13:53 UTC (rev 13433)
+++ trunk/freenet/src/freenet/io/comm/MessageFilter.java        2007-06-01 
11:15:19 UTC (rev 13434)
@@ -45,11 +45,13 @@
     private MessageFilter _or;
     private Message _message;
     private boolean _matchesDroppedConnections;
+    private boolean _matchesRestartedConnections;
     private AsyncMessageFilterCallback _callback;

     private MessageFilter() {
         setTimeout(DEFAULT_TIMEOUT);
         _matchesDroppedConnections = true; // on by default
+        _matchesRestartedConnections = true; // also on by default
     }

     public static MessageFilter create() {
@@ -129,6 +131,11 @@
            return this;
        }

+       public MessageFilter setMatchesRestartedConnections(boolean m) {
+               _matchesRestartedConnections = m;
+               return this;
+       }
+       
        public MessageFilter setAsyncCallback(AsyncMessageFilterCallback cb) {
                _callback = cb;
                return this;
@@ -208,6 +215,10 @@
         return _matchesDroppedConnections && _source == ctx;
     }

+    public boolean matchesRestartedConnection(PeerContext ctx) {
+       return _matchesRestartedConnections && _source == ctx;
+    }
+    
     /**
      * Notify because of a dropped connection.
      * Caller must verify _matchesDroppedConnection and _source.
@@ -218,6 +229,15 @@
     }

     /**
+     * Notify because of a restarted connection.
+     * Caller must verify _matchesDroppedConnection and _source.
+     * @param ctx
+     */
+    public synchronized void onRestartedConnection(PeerContext ctx) {
+               notifyAll();
+    }
+
+    /**
      * Notify waiters that we have been matched.
      * Hopefully no locks will be held at this point by the caller.
      */

Modified: trunk/freenet/src/freenet/io/comm/UdpSocketManager.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/UdpSocketManager.java     2007-06-01 
11:13:53 UTC (rev 13433)
+++ trunk/freenet/src/freenet/io/comm/UdpSocketManager.java     2007-06-01 
11:15:19 UTC (rev 13434)
@@ -472,6 +472,28 @@
            }
        }

+       /** IncomingPacketFilter should call this when a node connects with a 
new boot ID */
+       public void onRestart(PeerContext ctx) {
+               Vector droppedFilters = null; // rare operation, we can waste 
objects for better locking
+           synchronized(_filters) {
+                       ListIterator i = _filters.listIterator();
+                       while (i.hasNext()) {
+                           MessageFilter f = (MessageFilter) i.next();
+                           if(f.matchesRestartedConnection(ctx)) {
+                               if(droppedFilters == null)
+                                       droppedFilters = new Vector();
+                               droppedFilters.add(f);
+                               i.remove();
+                           }
+                       }
+           }
+           if(droppedFilters != null) {
+               for(int i=0;i<droppedFilters.size();i++) {
+                       MessageFilter mf = (MessageFilter) 
droppedFilters.get(i);
+                       mf.onRestartedConnection(ctx);
+               }
+           }
+       }

        public void addAsyncFilter(MessageFilter filter, 
AsyncMessageFilterCallback callback) throws DisconnectedException {
                filter.setAsyncCallback(callback);

Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java        2007-06-01 11:13:53 UTC 
(rev 13433)
+++ trunk/freenet/src/freenet/node/PeerNode.java        2007-06-01 11:15:19 UTC 
(rev 13434)
@@ -1550,8 +1550,10 @@
                        sentInitialMessages = false;
                }

-       if(bootIDChanged)
+       if(bootIDChanged) {
                        node.lm.lostOrRestartedNode(this);
+                       node.usm.onRestart(this);
+       }
                if(oldPrev != null) oldPrev.completelyDeprecated(newTracker);
                if(oldCur != null) oldCur.completelyDeprecated(newTracker);
                if(prev != null) prev.deprecated();


Reply via email to