Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

15
LINES

< > BotCompany Repo | #1014077 // simpleSpamClientDetect

JavaX fragment (include)

static int simpleSpamClientDetect_interval = 60000;
static double simpleSpamClientDetect_perSecondThreshold = 2.0; // per IP + URI
static int simpleSpamClientDetect_spamMax;

// ip + uri -> count
static ExpiringHashMap<Pair<S>, Int> simpleSpamClientDetect_ipsAndUris = new ExpiringHashMap(simpleSpamClientDetect_interval);

// returns pair(count, bad)
static Pair<Int, Bool> simpleSpamClientDetect(S clientIP, S uri) {
  Pair<S> pair = pair(clientIP, uri);
  int ipCount = toInt(simpleSpamClientDetect_ipsAndUris.get(pair));
  simpleSpamClientDetect_ipsAndUris.put(pair, ipCount+1);
simpleSpamClientDetect_spamMax = iround(simpleSpamClientDetect_perSecondThreshold*simpleSpamClientDetect_interval/1000);
  ret pair(ipCount, ipCount >= simpleSpamClientDetect_spamMax);
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1014077
Snippet name: simpleSpamClientDetect
Eternal ID of this version: #1014077/2
Text MD5: bbc21d0042aafb98eb13009cd8a9257a
Author: stefan
Category: javax / http
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-03-28 16:11:06
Source code size: 783 bytes / 15 lines
Pitched / IR pitched: No / No
Views / Downloads: 350 / 392
Version history: 1 change(s)
Referenced in: [show references]