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

15
LINES

< > BotCompany Repo | #1014077 // simpleSpamClientDetect

JavaX fragment (include)

1  
static int simpleSpamClientDetect_interval = 60000;
2  
static double simpleSpamClientDetect_perSecondThreshold = 2.0; // per IP + URI
3  
static int simpleSpamClientDetect_spamMax;
4  
5  
// ip + uri -> count
6  
static ExpiringHashMap<Pair<S>, Int> simpleSpamClientDetect_ipsAndUris = new ExpiringHashMap(simpleSpamClientDetect_interval);
7  
8  
// returns pair(count, bad)
9  
static Pair<Int, Bool> simpleSpamClientDetect(S clientIP, S uri) {
10  
  Pair<S> pair = pair(clientIP, uri);
11  
  int ipCount = toInt(simpleSpamClientDetect_ipsAndUris.get(pair));
12  
  simpleSpamClientDetect_ipsAndUris.put(pair, ipCount+1);
13  
simpleSpamClientDetect_spamMax = iround(simpleSpamClientDetect_perSecondThreshold*simpleSpamClientDetect_interval/1000);
14  
  ret pair(ipCount, ipCount >= simpleSpamClientDetect_spamMax);
15  
}

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: 351 / 393
Version history: 1 change(s)
Referenced in: [show references]