From f972d6f1176ccdee0ff7876a3069cdfbaa8af5e5 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 20 Apr 2026 19:36:51 -0600 Subject: [PATCH] refactor(formmailer): use *dataset.View directly, tighter timeouts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Drop CohortSource interface — it had exactly one implementation. Blacklist is now *dataset.View[ipcohort.Cohort] directly, matching check-ip's usage. One concrete type, no premature abstraction. - SMTP 15s → 5s, MX 3s → 2s. A relay or resolver that isn't responding inside those bounds isn't going to deliver the mail; faster failure is better than holding the request goroutine. --- net/formmailer/formmailer.go | 15 +++++---------- net/formmailer/go.mod | 1 + 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/net/formmailer/formmailer.go b/net/formmailer/formmailer.go index 259001e..c0667e0 100644 --- a/net/formmailer/formmailer.go +++ b/net/formmailer/formmailer.go @@ -43,6 +43,7 @@ import ( "golang.org/x/time/rate" "github.com/therootcompany/golib/net/ipcohort" + "github.com/therootcompany/golib/sync/dataset" ) const ( @@ -55,8 +56,8 @@ const ( defaultRPM = 5 defaultBurst = 3 - defaultSMTPTimeout = 15 * time.Second - defaultMXTimeout = 3 * time.Second + defaultSMTPTimeout = 5 * time.Second + defaultMXTimeout = 2 * time.Second limiterTTL = 10 * time.Minute limiterSweepEvery = 1024 // sweep once every N handler invocations @@ -72,12 +73,6 @@ var ( phoneRe = regexp.MustCompile(`^[0-9+\-\(\) ]{7,20}$`) ) -// CohortSource returns the current cohort snapshot, or nil if not yet loaded. -// *dataset.View[ipcohort.Cohort] satisfies this interface directly. -type CohortSource interface { - Value() *ipcohort.Cohort -} - // FormFields maps logical field names to the HTML form field names. // Zero values use GravityForms-compatible defaults (input_1, input_3, etc.). type FormFields struct { @@ -119,8 +114,8 @@ type FormMailer struct { ContentType string // inferred from SuccessBody if empty // Blacklist — if set, matching IPs are rejected before any other processing. - // *dataset.View[ipcohort.Cohort] satisfies this interface. - Blacklist CohortSource + // Value() returns nil before the first successful load (no blocks applied). + Blacklist *dataset.View[ipcohort.Cohort] // AllowedCountries — if non-nil, only requests from listed ISO codes are // accepted. Unknown country ("") is always allowed. diff --git a/net/formmailer/go.mod b/net/formmailer/go.mod index e088eac..7923182 100644 --- a/net/formmailer/go.mod +++ b/net/formmailer/go.mod @@ -5,5 +5,6 @@ go 1.26.0 require ( github.com/phuslu/iploc v1.0.20260415 github.com/therootcompany/golib/net/ipcohort v0.0.0 + github.com/therootcompany/golib/sync/dataset v0.0.0 golang.org/x/time v0.15.0 )