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).

sclass HTTPSpamBlocker1 {
  Set<S> blockedIPs = expiringSet(10*60.0); // 10 minutes
  
  bool isBadRequest(S uri, S ip) {
    ret pairB(checkRequest(uri, ip));
  }
  
  // pair(count, bad)
  Pair<Int, Bool> checkRequest(S uri, S ip) {
    bool bad = eq(uri, "/simulate-bad-client");
    Pair<Int, Bool> pair = simpleSpamClientDetect2(ip, uri);
    if (pair.b) {
      if (eq(ip, pcall_myFirewallIP()))
        print("Not blocking myself.");
      else {
        print("Blocking IP " + ip);
        blockedIPs.add(ip);
      }
    }
    
    if (blockedIPs.contains(ip)) {
      bad = true;
      print(t3("an HTTP request from a blocked IP", "came in at", dateWithTimeGMT()));
    }
    
    ret pair(pair.a, bad);
  }
  
  void markNoSpam(S uri, S ip) {
    simpleSpamClientDetect2_markNoSpam(ip, uri);
  }
}

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: 364 / 808
Version history: 3 change(s)
Referenced in: [show references]