scope simpleSpamClientDetect2. static int simpleSpamClientDetect2_interval = 60000; static double #perSecondThreshold = 2.0; // per IP + URI static int #spamMax; static Set #excludedIPs = syncSet(myIPs()); // ip + uri -> time, count static Map, Pair> #ipsAndUris = synchroMap(); // returns pair(count, bad) static Pair simpleSpamClientDetect2(S clientIP, S uri) { // 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, value.b >= spamMax); } end scope