Let our peers send up to 100 messages a second after which point we will

politely complain that they're talking a lot but not disconnect them.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4871 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2007-11-12 21:29:57 +00:00
parent ae6e8f1bdb
commit f471da8a49
2 changed files with 44 additions and 7 deletions
@@ -360,10 +360,7 @@ public class PresentsClient
return;
} else if (_throttle.throttleOp(message.received)) {
Log.warning("Client sent more than 100 messages in 10 seconds, forcing " +
"disconnect " + this + ".");
safeEndSession();
_throttle = null;
handleThrottleExceeded();
}
// we dispatch to a message dispatcher that is specialized for the particular class of
@@ -502,6 +499,25 @@ public class PresentsClient
});
}
/**
* Creates our incoming messaeg throttle.
*/
protected Throttle createIncomingMessageThrottle ()
{
// more than 100 messages in 10 seconds and you're audi like 5000
return new Throttle(100, 10 * 1000L);
}
/**
* Called when a client exceeds their allotted incoming messages per second throttle.
*/
protected void handleThrottleExceeded ()
{
Log.warning("Client sent more than 100 messages in 10 seconds, disconnecting " + this + ".");
safeEndSession();
_throttle = null;
}
/**
* Makes a note that this client is no longer subscribed to this object. The subscription map
* is used to clean up after the client when it goes away.
@@ -970,9 +986,8 @@ public class PresentsClient
* session. */
protected int _connectTime;
/** Prevent the client from sending too many messages too frequently. 100 messages in 10
* seconds and you're audi like 5000. */
protected Throttle _throttle = new Throttle(100, 10 * 1000L);
/** Prevent the client from sending too many messages too frequently. */
protected Throttle _throttle = createIncomingMessageThrottle();
// keep these for kicks and giggles
protected int _messagesIn;