Author: robert
Date: 2008-01-16 21:59:55 +0000 (Wed, 16 Jan 2008)
New Revision: 17081

Modified:
   trunk/freenet/src/freenet/io/comm/MessageCore.java
   trunk/freenet/src/freenet/io/comm/MessageFilter.java
Log:
correctness: don't rely on every message filter setting a source


Modified: trunk/freenet/src/freenet/io/comm/MessageCore.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/MessageCore.java  2008-01-16 19:24:54 UTC 
(rev 17080)
+++ trunk/freenet/src/freenet/io/comm/MessageCore.java  2008-01-16 21:59:55 UTC 
(rev 17081)
@@ -291,8 +291,9 @@
                boolean logDEBUG = Logger.shouldLog(Logger.DEBUG, this);
                if(logDEBUG) Logger.debug(this, "Adding async filter "+filter+" 
for "+callback);
                Message ret = null;
-               if(filter._source != null && (!filter._source.isConnected()) &&
-                       filter.matchesDroppedConnection(filter._source))
+               PeerContext filter_source=filter.getSource();
+               if(filter_source != null && (!filter_source.isConnected()) &&
+                       filter.matchesDroppedConnection(filter_source))
                    throw new DisconnectedException();
                // Check to see whether the filter matches any of the recently 
_unclaimed messages
                // Drop any _unclaimed messages that the filter doesn't match 
that are also older than MAX_UNCLAIMED_FIFO_ITEM_LIFETIME
@@ -359,8 +360,9 @@
                long startTime = System.currentTimeMillis();
                filter.onStartWaiting();
                Message ret = null;
-               if(filter._source != null && (!filter._source.isConnected()) &&
-                       filter.matchesDroppedConnection(filter._source))
+               PeerContext filter_source=filter.getSource();
+               if(filter_source != null && (!filter_source.isConnected()) &&
+                       filter.matchesDroppedConnection(filter_source))
                    throw new DisconnectedException();
                // Check to see whether the filter matches any of the recently 
_unclaimed messages
                // Drop any _unclaimed messages that the filter doesn't match 
that are also older than MAX_UNCLAIMED_FIFO_ITEM_LIFETIME

Modified: trunk/freenet/src/freenet/io/comm/MessageFilter.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/MessageFilter.java        2008-01-16 
19:24:54 UTC (rev 17080)
+++ trunk/freenet/src/freenet/io/comm/MessageFilter.java        2008-01-16 
21:59:55 UTC (rev 17081)
@@ -39,7 +39,7 @@
        private MessageType _type;
     private HashMap _fields = new HashMap();
     private Vector _fieldList = new Vector(1,1);
-    PeerContext _source;
+    private PeerContext _source;
     private long _timeout;
     /** If true, timeouts are relative to the start of waiting, if false, they 
are relative to
      * the time of calling setTimeout() */
@@ -109,6 +109,17 @@
                _source = source;
                return this;
        }
+       
+       /**
+        Returns the source that this filter (or chain) matches
+        */
+       public PeerContext getSource() {
+               if (_source!=null)
+                       return _source;
+               if (_or!=null)
+                       return _or.getSource();
+               return null;
+       }

        public MessageFilter setField(String fieldName, boolean value) {
                return setField(fieldName, Boolean.valueOf(value));
@@ -241,11 +252,11 @@
     }

     public boolean matchesDroppedConnection(PeerContext ctx) {
-        return _matchesDroppedConnections && _source == ctx;
+        return _matchesDroppedConnections && getSource() == ctx;
     }

     public boolean matchesRestartedConnection(PeerContext ctx) {
-       return _matchesRestartedConnections && _source == ctx;
+       return _matchesRestartedConnections && getSource() == ctx;
     }

     /**


Reply via email to