tags:

views:

47

answers:

1

Is there any way to limit connection rate in Python Twisted? I need to simulate the slow dataline, with timeouts and optionally data loss and use twisted framework.

A: 

this post proposes three solutions and discusses the two feasible ones -- the best one is to use iptables (or other, equally powerful and flexible firewall software, of course) if your OS supports such software (i.e., do the data rate limiting outside of twisted); if your OS has no such power at your disposal, a less preferable but workable solution mentioned there is

1) Create an dictionary {ip1:count1, ip2: count2, .} in the server, and check the counts for each incoming connection. Disconnect with transport.loseConnection() if the threshold for ip:count is exceeded. Reset this dictionary to empty dict {} every minute with reactor.callLater timer.

whose limitation is explained in the post as

approach (1) will do an accept() of the connection and then drop it, giving the host on the other end a syn/ack transaction followed by a closed connection, and then it will probably attempt to reconnect immediately.

Alex Martelli
Yes, I saw this post.. Iptables is the last option.
DominiCane