On Wednesday 16 January 2008 21:59, robert at freenetproject.org wrote:
> 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

Both this and the original code are wrong with regards to 
disconnections/reconnections. MessageCore gets a callback when a connection 
is disconnected or restarted. We check the filters list to see if this 
affects any of our waiting filters, and if it does we trigger them. In order 
to prevent a race condition, we check for disconnection before adding them to 
the _filters list. We should check droppedConnection() at the end of 
addAsyncFilter() but we don't. All of this assumes there is one connection 
per filter. There are places in the code where this assumption is incorrect. 
We should either make it work with multiple connections per filter, or we 
should document and enforce the fact that it only works with one connection 
per filter.

Obviously I prefer the latter. I apologise for implementing it myself but it 
was rather convoluted - by the time I'd figured out what was going on I'd 
done it. :)
> 
> 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;
>      }
>      
>      /**
> 
> _______________________________________________
> cvs mailing list
> cvs at freenetproject.org
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
> 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 
<https://emu.freenetproject.org/pipermail/devl/attachments/20080117/a4bea04d/attachment.pgp>

Reply via email to