Skip to content

Conversation

@0x46616c6b
Copy link
Member

@0x46616c6b 0x46616c6b commented Jan 7, 2026

This pull request introduces a major architectural refactor and new features to the Postfix adapter for Userli. The most significant change is the addition of a new Policy Server for rate limiting via Postfix SMTP Access Policy Delegation, alongside the original lookup server. The documentation, configuration, metrics, and codebase have been updated to reflect this expanded functionality and improved structure. The code now uses a shared TCP server infrastructure, separates lookup and policy logic, and enhances observability with new metrics.

New Features and Architecture:

  • Added a Policy Server (policy.go) for Postfix rate limiting using SMTP Access Policy Delegation, configurable via POLICY_LISTEN_ADDR and documented in both .github/copilot-instructions.md and README.md. [1] [2] [3] [4] [5] [6] [7]
  • Refactored architecture to use a shared TCP server (tcpserver.go) and a ConnectionHandler interface, with LookupServer handling socketmap requests and PolicyServer handling policy requests. Documentation and diagrams updated accordingly. [1] [2]

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a major architectural enhancement to the Postfix adapter for Userli, adding a new Policy Server for rate limiting alongside the existing lookup functionality. The codebase has been refactored to use a shared TCP server infrastructure with a clean ConnectionHandler interface pattern, improving code reusability and maintainability.

Key changes:

  • Added Policy Server (:10003) implementing Postfix SMTP Access Policy Delegation for rate limiting outgoing mail
  • Introduced sliding-window rate limiter with per-sender quota tracking (hourly/daily limits)
  • Refactored to shared tcpserver.go with connection pooling, graceful shutdown, and TCP keep-alive
  • Renamed SocketmapAdapter to LookupServer for clarity and consistency

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tcpserver.go New shared TCP server infrastructure with connection pooling and graceful shutdown support
policy.go New Policy Server implementing Postfix policy delegation protocol for rate limiting
ratelimit.go Sliding window rate limiter with timestamp tracking and background cleanup
lookup.go Refactored lookup server (formerly adapter.go), now implements ConnectionHandler interface
userli.go Added GetQuota() method to fetch per-user rate limit quotas from Userli API
prometheus.go Added policy server metrics (requests, duration, quota checks, tracked senders)
config.go Added POLICY_LISTEN_ADDR configuration with default :10003
main.go Initialize both lookup and policy servers with shared context and WaitGroup
policy_test.go Comprehensive test coverage for policy server functionality
ratelimit_test.go Unit tests for rate limiter logic including edge cases
lookup_test.go Migrated tests from server_test.go with updated naming
docker-compose.yml Added port 10003 and policy delegation configuration for Postfix
README.md Documented new policy server and rate limiting configuration
.github/copilot-instructions.md Updated architecture documentation with new server patterns
Comments suppressed due to low confidence (1)

lookup.go:53

  • The OnConnectionPoolFull callback is defined in the TCPServerConfig struct but is never set when creating configs in either StartLookupServer or StartPolicyServer. This means when the connection pool is full, the corresponding metric won't be updated.

For consistency and observability, you should add callbacks for both servers. For the lookup server, this could increment a connectionPoolFull metric similar to how the old server.go would have handled it.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.

@0x46616c6b 0x46616c6b force-pushed the Add-Policy-Server-for-Rate-Limiting branch from c82557d to a55749c Compare January 8, 2026 10:50
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 8, 2026

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants