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

32
LINES

< > BotCompany Repo | #1023394 // HTTPSpamBlocker1

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4731L/31K).

1  
sclass HTTPSpamBlocker1 {
2  
  Set<S> blockedIPs = expiringSet(10*60.0); // 10 minutes
3  
  
4  
  bool isBadRequest(S uri, S ip) {
5  
    ret pairB(checkRequest(uri, ip));
6  
  }
7  
  
8  
  // pair(count, bad)
9  
  Pair<Int, Bool> checkRequest(S uri, S ip) {
10  
    bool bad = eq(uri, "/simulate-bad-client");
11  
    Pair<Int, Bool> pair = simpleSpamClientDetect2(ip, uri);
12  
    if (pair.b) {
13  
      if (eq(ip, pcall_myFirewallIP()))
14  
        print("Not blocking myself.");
15  
      else {
16  
        print("Blocking IP " + ip);
17  
        blockedIPs.add(ip);
18  
      }
19  
    }
20  
    
21  
    if (blockedIPs.contains(ip)) {
22  
      bad = true;
23  
      print(t3("an HTTP request from a blocked IP", "came in at", dateWithTimeGMT()));
24  
    }
25  
    
26  
    ret pair(pair.a, bad);
27  
  }
28  
  
29  
  void markNoSpam(S uri, S ip) {
30  
    simpleSpamClientDetect2_markNoSpam(ip, uri);
31  
  }
32  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1023394
Snippet name: HTTPSpamBlocker1
Eternal ID of this version: #1023394/4
Text MD5: 7be6e35e2e911233b6000b50c01edfbb
Transpilation MD5: 56789a30cb865a8991974937d1e9a7a7
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-10-27 13:04:36
Source code size: 840 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 280 / 706
Version history: 3 change(s)
Referenced in: [show references]