I was inspired by Daniels ClueCon 2013 talk and have decide to try to add
simple rate limiting using a HTable.
$var(srcgroup) is an id that identifies the invites source/ I wish to limit
invites from a given source.
$var(rateHashMin) was added just to allow simple monitoring.
I query the table via XML-RPC to get an idea of current load.
I think it would be better to add it to a seperate table and then I could
increase the exprires time to capture more of the course grain points.
I am interested in any comments.
----------------------
modparam("htable", "htable",
"htable_source_group_rates=>size=8;dbtable=htable_source_group_rates;initval=0;autoexpire=300;")
modparam("htable", "htable",
"htable_source_group_limits=>size=8;dbtable=htable_source_group_limits;initval=500;")
----------------------
----------------------
route[SOURCE_GROUP_LIMIT] {
if (is_method("INVITE")){
$var(rateHashSec) = (str)$var(srcgroup)+":sec:"+$timef(%Y/%m/%d_%H_%M_%S);
$var(rateHashMin) = (str)$var(srcgroup)+":min:"+$timef(%Y/%m/%d_%H_%M_00);
$sht(htable_source_group_rates=>$var(rateHashSec)) =
$sht(htable_source_group_rates=>$var(rateHashSec)) + 1;
$sht(htable_source_group_rates=>$var(rateHashMin)) =
$sht(htable_source_group_rates=>$var(rateHashMin)) + 1;
if($sht(htable_source_group_rates=>$var(rateHashSec)) >
$sht(htable_source_group_limits=>$var(srcgroup)))
{
sl_send_reply("503", "$si over source Limit of
$sht(htable_source_group_rates=>$var(rateHashSec)) /
$sht(htable_source_group_limits=>$var(srcgroup)");
exit;
}
}
}
----------------------
Thanks Gareth