From 96d62399b4cd2ad4f662b5e56f8c72d96e67063a Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 3 Mar 2026 09:08:07 -0500 Subject: [PATCH] Warn for short dupes But not block them --- lib/customer_usage.rb | 5 +---- sgx_jmp.rb | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/customer_usage.rb b/lib/customer_usage.rb index 242e8388b27e8a42044acbb8975fa1a1fb86eb33..ec3d1eecc3f24314d5a34ff6279f8f97e2c6a0b7 100644 --- a/lib/customer_usage.rb +++ b/lib/customer_usage.rb @@ -42,14 +42,11 @@ class CustomerUsage end def incr_body(amount, body) - # Short message like "hello" we can't block dupes - return 0 if body.to_s.length < 30 - hash = Digest::SHA2.hexdigest(body[0..100]) EMPromise.all([ REDIS.incrby("jmp_outbound_body-#{hash}", amount), - REDIS.expire("jmp_outbound_body-#{hash}", 120) + REDIS.expire("jmp_outbound_body-#{hash}", 180) ]).then(&:first) end diff --git a/sgx_jmp.rb b/sgx_jmp.rb index c4acf4f3932b1159a27db536a256f76e633ece62..6da1672e7c4ccf77a21089502196039b1cb7a60d 100644 --- a/sgx_jmp.rb +++ b/sgx_jmp.rb @@ -400,6 +400,18 @@ def find_from_and_to_customer(from, to) } end +def usage_guard(m, customer, trust_level, usage) + next if trust_level.send_message?(usage[:today]) && usage[:body] < 5 + + if m.body.to_s.length < 30 || (usage[:body] >= 5 && usage[:body] < 10) + OverLimit.new(customer, usage).notify_admin + return + end + + log.warn "OverLimit", m + raise OverLimit.new(customer, usage) +end + message do |m| StatsD.increment("message") @@ -417,10 +429,7 @@ message do |m| TrustLevelRepo.new.find(customer), customer.incr_message_usage(1, m.body) ]).then { |(tl, usage)| - next if tl.send_message?(usage[:today]) && usage[:body] < 10 - - log.warn "OverLimit", m - raise OverLimit.new(customer, usage) + usage_guard(m, customer, tl, usage) }.then do customer.stanza_from(m) end