Author: toad
Date: 2008-01-17 12:33:03 +0000 (Thu, 17 Jan 2008)
New Revision: 17087
Modified:
trunk/freenet/src/freenet/io/comm/MessageCore.java
trunk/freenet/src/freenet/io/comm/MessageFilter.java
Log:
Properly support matching disconnections on multiple connections in
MessageFilter's.
This clobbers some of robert's code, but the original code was also wrong.
Modified: trunk/freenet/src/freenet/io/comm/MessageCore.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/MessageCore.java 2008-01-17 11:51:00 UTC
(rev 17086)
+++ trunk/freenet/src/freenet/io/comm/MessageCore.java 2008-01-17 12:33:03 UTC
(rev 17087)
@@ -291,10 +291,8 @@
boolean logDEBUG = Logger.shouldLog(Logger.DEBUG, this);
if(logDEBUG) Logger.debug(this, "Adding async filter "+filter+"
for "+callback);
Message ret = null;
- PeerContext filter_source=filter.getSource();
- if(filter_source != null && (!filter_source.isConnected()) &&
- filter.matchesDroppedConnection(filter_source))
- throw new DisconnectedException();
+ if(filter.anyConnectionsDropped())
+ 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
long now = System.currentTimeMillis();
@@ -343,6 +341,9 @@
filter.setMessage(ret);
filter.onMatched();
filter.clearMatched();
+ } else {
+ // Might have disconnected between check above and
locking _filters.
+ filter.anyConnectionsDropped();
}
}
@@ -360,10 +361,8 @@
long startTime = System.currentTimeMillis();
filter.onStartWaiting();
Message ret = null;
- PeerContext filter_source=filter.getSource();
- if(filter_source != null && (!filter_source.isConnected()) &&
- filter.matchesDroppedConnection(filter_source))
- throw new DisconnectedException();
+ if(filter.anyConnectionsDropped())
+ 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
long now = System.currentTimeMillis();
Modified: trunk/freenet/src/freenet/io/comm/MessageFilter.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/MessageFilter.java 2008-01-17
11:51:00 UTC (rev 17086)
+++ trunk/freenet/src/freenet/io/comm/MessageFilter.java 2008-01-17
12:33:03 UTC (rev 17087)
@@ -114,11 +114,7 @@
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;
+ return _source;
}
public MessageFilter setField(String fieldName, boolean value) {
@@ -252,11 +248,15 @@
}
public boolean matchesDroppedConnection(PeerContext ctx) {
- return _matchesDroppedConnections && getSource() == ctx;
+ if(_matchesDroppedConnections && _source == ctx) return true;
+ if(_or != null) return _or.matchesDroppedConnection(ctx);
+ return false;
}
public boolean matchesRestartedConnection(PeerContext ctx) {
- return _matchesRestartedConnections && getSource() == ctx;
+ if(_matchesRestartedConnections && _source == ctx) return true;
+ if(_or != null) return _or.matchesRestartedConnection(ctx);
+ return false;
}
/**
@@ -302,4 +302,15 @@
if(_callback != null)
_callback.onTimeout();
}
+
+ public boolean anyConnectionsDropped() {
+ if(_matched) return false;
+ if(_source != null && !_source.isConnected()) {
+ onDroppedConnection(_source);
+ return true;
+ }
+ if(_or != null)
+ return _or.anyConnectionsDropped();
+ return false;
+ }
}