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
@@ -21,6 +21,8 @@
package com.threerings.presents.peer.server;
import com.samskivert.util.Throttle;
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.net.BootstrapData;
import com.threerings.presents.server.PresentsClient;
@@ -28,6 +30,8 @@ import com.threerings.presents.server.PresentsClient;
import com.threerings.presents.peer.data.NodeObject;
import com.threerings.presents.peer.net.PeerBootstrapData;
import static com.threerings.presents.Log.log;
/**
* Manages a peer connection.
*/
@@ -98,6 +102,24 @@ public class PeerClient extends PresentsClient
}
}
@Override // from PresentsClient
protected Throttle createIncomingMessageThrottle ()
{
// more than 100 messages per second and we complain about it
return new Throttle(100, 1000L);
}
@Override // from PresentsClient
protected void handleThrottleExceeded ()
{
long now = System.currentTimeMillis();
if (now > _nextThrottleWarning) {
log.warning("Peer sent more than 100 messages in one second " + this + ".");
_nextThrottleWarning = now + 5000L; // don't warn more than once every 5 seconds
}
}
protected PeerManager _peermgr;
protected int _cloid;
protected long _nextThrottleWarning;
}