Warning: session_start(): open(/var/lib/php/sessions/sess_4rcvhrs3vo95st061orbt6rvln, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
scope simpleSpamClientDetect2.
static int #interval = 60000;
static double #perSecondThreshold = 2.0; // per IP + URI
static int #spamMax;
static Set #whiteList = syncSet(myIPs());
static Lock #myLock = lock();
// ip + uri -> time, count
static Map> #ipsAndUris = synchroMap();
// returns pair(count, bad)
static Pair simpleSpamClientDetect2(S clientIP, S uri) {
lock myLock;
// TODO: clean up map sometimes
Pair pair = pair(clientIP, uri);
Pair value = ipsAndUris.get(pair);
if (value == null || now() > value.a+interval)
ipsAndUris.put(pair, value = pair(now(), 1));
else
value.b++;
spamMax = iround(perSecondThreshold*interval/1000);
ret pair(value.b, !contains(whiteList, clientIP) && value.b >= spamMax);
}
// returns new count
static int #markNoSpam(S clientIP, S uri) {
lock myLock;
PairS pair = pair(clientIP, uri);
Pair value = ipsAndUris.get(pair);
if (value != null && value.b > 0) ret --value.b;
ret -1;
}
end scope