Author: mwebb
Date: Mon Jul 2 16:26:06 2007
New Revision: 552626
URL: http://svn.apache.org/viewvc?view=rev&rev=552626
Log:
changed the private field 'clients' to a synchronized map. Making this a
concurrent field, there was a chance that connections could come in so fast
that connections may get allowed to be accepted because the IP address could
not be added to the blacklist fast enough.
...I hope to re-visit this problem soon.
Modified:
mina/trunk/core/src/main/java/org/apache/mina/filter/ConnectionThrottleFilter.java
Modified:
mina/trunk/core/src/main/java/org/apache/mina/filter/ConnectionThrottleFilter.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/ConnectionThrottleFilter.java?view=diff&rev=552626&r1=552625&r2=552626
==============================================================================
---
mina/trunk/core/src/main/java/org/apache/mina/filter/ConnectionThrottleFilter.java
(original)
+++
mina/trunk/core/src/main/java/org/apache/mina/filter/ConnectionThrottleFilter.java
Mon Jul 2 16:26:06 2007
@@ -21,8 +21,9 @@
import java.net.InetSocketAddress;
import java.net.SocketAddress;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
import org.apache.mina.common.IoFilter;
import org.apache.mina.common.IoFilterAdapter;
@@ -58,7 +59,7 @@
*/
public ConnectionThrottleFilter( long allowedInterval ){
this.allowedInterval = allowedInterval;
- clients = new ConcurrentHashMap<String,Long>();
+ clients = Collections.synchronizedMap( new HashMap<String,Long>());
}
/**
@@ -90,18 +91,21 @@
long now = System.currentTimeMillis();
if( clients.containsKey(addr.getAddress().getHostAddress())){
+
+ clients.put(addr.getAddress().getHostAddress(), now);
+ SessionLog.info( session, "This is not a new client");
Long lastConnTime =
clients.get(addr.getAddress().getHostAddress());
- clients.put(addr.getAddress().getHostAddress(), now);
-
+
// if the interval between now and the last connection is
// less than the allowed interval, return false
if( (now-lastConnTime) < allowedInterval ){
+ SessionLog.error(session, "Session connection interval
too short");
return false;
} else {
return true;
}
} else {
- clients.put( addr.getAddress().getHostAddress(), now );
+ clients.put( addr.getAddress().getHostAddress(), now );
return true;
}
}
@@ -114,6 +118,6 @@
if( ! isConnectionOk(session)){
SessionLog.info( session, "Connections coming in too fast;
closing." );
session.close();
- }
+ }
}
}