• @BT_User3OP
    link
    fedilink
    11 year ago

    ok, so inserting something into the Rust code at the API front door

    The rate-limit logic is something to trace in the code and understand, as I assume that blocks before getting into SQL?

      /// Returns true if the request passed the rate limit, false if it failed and should be rejected.
      pub fn check(self, ip_addr: IpAddr) -> bool {
        // Does not need to be blocking because the RwLock in settings never held across await points,
        // and the operation here locks only long enough to clone
        let mut guard = self
          .rate_limit
          .lock()
          .expect("Failed to lock rate limit mutex for reading");
        let rate_limit = &guard.rate_limit_config;
    
        let (kind, interval) = match self.type_ {
          RateLimitType::Message => (rate_limit.message, rate_limit.message_per_second),
          RateLimitType::Post => (rate_limit.post, rate_limit.post_per_second),
          RateLimitType::Register => (rate_limit.register, rate_limit.register_per_second),
          RateLimitType::Image => (rate_limit.image, rate_limit.image_per_second),
          RateLimitType::Comment => (rate_limit.comment, rate_limit.comment_per_second),
          RateLimitType::Search => (rate_limit.search, rate_limit.search_per_second),
        };
        let limiter = &mut guard.rate_limiter;
    
        limiter.check_rate_limit_full(self.type_, ip_addr, kind, interval, InstantSecs::now())
      }
    
    • @BT_User3OP
      link
      fedilink
      11 year ago

      Ok, so there is a log:

      if !result {
        debug!("Rate limited IP: {ip}");
      }
      

      would be ideal to bubble this up to server operators