<div dir="ltr"><div><br></div><div><br></div><div>I was inspired by Daniels ClueCon 2013 talk and have decide to try to add simple rate limiting using a HTable.</div><div>$var(srcgroup) is an id that identifies the invites source/ I wish to limit invites from a given source.<br>
</div><div><br></div><div>$var(rateHashMin) was added just to allow simple monitoring.</div><div>I query the table via XML-RPC to get an idea of current load. </div><div>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.</div>
<div><br></div><div><br></div><div><br></div><div>I am interested in any comments.<br></div><div><br></div><div> <br></div><div>----------------------</div><div><div>modparam("htable", "htable", "htable_source_group_rates=>size=8;dbtable=htable_source_group_rates;initval=0;autoexpire=300;")</div>
<div>modparam("htable", "htable", "htable_source_group_limits=>size=8;dbtable=htable_source_group_limits;initval=500;")</div></div><div>----------------------<br></div><div>----------------------<br>
</div><div>route[SOURCE_GROUP_LIMIT] {</div><div><br></div><div><span class="" style="white-space:pre"> </span>if (is_method("INVITE")){</div><div><span class="" style="white-space:pre"> </span>$var(rateHashSec) = (str)$var(srcgroup)+":sec:"+$timef(%Y/%m/%d_%H_%M_%S);</div>
<div><span class="" style="white-space:pre"> </span>$var(rateHashMin) = (str)$var(srcgroup)+":min:"+$timef(%Y/%m/%d_%H_%M_00);</div><div><span class="" style="white-space:pre"> </span></div><div><span class="" style="white-space:pre"> </span></div>
<div><span class="" style="white-space:pre"> </span>$sht(htable_source_group_rates=>$var(rateHashSec)) = $sht(htable_source_group_rates=>$var(rateHashSec)) + 1;</div><div><span class="" style="white-space:pre"> </span>$sht(htable_source_group_rates=>$var(rateHashMin)) = $sht(htable_source_group_rates=>$var(rateHashMin)) + 1;<span class="" style="white-space:pre"> </span></div>
<div><span class="" style="white-space:pre"> </span></div><div><span class="" style="white-space:pre"> </span>if($sht(htable_source_group_rates=>$var(rateHashSec)) > $sht(htable_source_group_limits=>$var(srcgroup)))</div>
<div><span class="" style="white-space:pre"> </span>{</div><div><span class="" style="white-space:pre"> </span>sl_send_reply("503", "$si over source Limit of $sht(htable_source_group_rates=>$var(rateHashSec)) / $sht(htable_source_group_limits=>$var(srcgroup)");</div>
<div><span class="" style="white-space:pre"> </span>exit;</div><div><span class="" style="white-space:pre"> </span>}</div><div><span class="" style="white-space:pre"> </span>}</div><div>}</div><div>----------------------<br>
</div><div><br></div><div><br></div><div><br></div><div>Thanks Gareth</div></div>