Skip to main content

Module push_service

Module push_service 

Source
Expand description

Web Push notification service.

Stores push subscriptions per wallet in Postgres and delivers notifications via the Web Push protocol (VAPID-signed, RFC 8291).

Subscriptions are cached in memory (DashMap) to avoid a DB query on every fill. The cache is invalidated on subscribe/unsubscribe.

Push delivery is decoupled from the event forwarder via a bounded mpsc channel. A single background task drains the queue and sends up to MAX_CONCURRENT_SENDS push messages in parallel.

StructsΒ§

PushJob πŸ”’
Internal message sent through the bounded channel from the event forwarder to the background push sender task.
PushNotificationService
PushPayload
JSON payload sent inside the push message. The service worker parses this to decide what to show.

EnumsΒ§

NotificationType
Notification category. The backend checks the user’s preferences before sending a push for each category.

ConstantsΒ§

ALLOWED_PUSH_ENDPOINT_PREFIXES πŸ”’
Allowed push endpoint URL prefixes. Rejects anything that isn’t a known browser push service to prevent SSRF.
CACHE_MAX_ENTRIES πŸ”’
Maximum number of wallets to cache. When exceeded, the cache is cleared entirely (simple eviction strategy suitable for this use case since most entries are empty vecs and re-population is cheap).
MAX_CONCURRENT_SENDS πŸ”’
Maximum number of push HTTP requests in flight at once.
MAX_SUBSCRIPTIONS_PER_WALLET πŸ”’
Maximum push subscriptions per wallet. Prevents a single wallet from registering thousands of endpoints.
PUSH_QUEUE_CAPACITY πŸ”’
Bounded channel capacity for pending push jobs. If the sender task falls behind, new jobs are dropped (best-effort delivery).

FunctionsΒ§

default_preferences
Default preferences: everything enabled.
get_subscriptions πŸ”’
Load subscriptions for a wallet, using cache when available.
is_enabled πŸ”’
Check whether a subscription has a given notification type enabled. Missing keys default to enabled. Non-boolean values are treated as disabled (reject malformed preferences rather than silently enabling).
push_sender_loop πŸ”’
Single background task that drains the push job queue and sends notifications with bounded concurrency.
remove_stale πŸ”’
to_base64url πŸ”’
Normalize a base64 or base64url string to base64url (no padding).