… | |
… | |
202 | // only do action once every x seconds per host whole allowing bursts. |
202 | // only do action once every x seconds per host whole allowing bursts. |
203 | // this implementation ("splay list" ;) is inefficient, |
203 | // this implementation ("splay list" ;) is inefficient, |
204 | // but low on resources. |
204 | // but low on resources. |
205 | struct net_rate_limiter : list<net_rateinfo> |
205 | struct net_rate_limiter : list<net_rateinfo> |
206 | { |
206 | { |
207 | # define NRL_ALPHA 1. - 1. / 600. // allow bursts |
207 | # define NRL_ALPHA (1. - 1. / 600.) // allow bursts |
208 | # define NRL_CUTOFF 10. // one event every CUTOFF seconds |
208 | # define NRL_CUTOFF 10. // one event every CUTOFF seconds |
209 | # define NRL_EXPIRE NRL_CUTOFF * 30. // expire entries after this time |
209 | # define NRL_EXPIRE (NRL_CUTOFF * 30.) // expire entries after this time |
210 | # define NRL_MAXDIF NRL_CUTOFF * (1. / (1. - NRL_ALPHA)) // maximum diff /count value |
210 | # define NRL_MAXDIF (NRL_CUTOFF * (1. / (1. - NRL_ALPHA))) // maximum diff /count value |
211 | |
211 | |
212 | bool can (const sockinfo &si) { return can((u32)si.host); } |
212 | bool can (const sockinfo &si) { return can((u32)si.host); } |
213 | bool can (u32 host); |
213 | bool can (u32 host); |
214 | }; |
214 | }; |
215 | |
215 | |