Skip to main content

Module timer

Module timer 

Source
Expand description

Timing math (SPEC §6) — interval negotiation, the sender’s effective interval + additive jitter, and the receiver’s anti-flood minimum inter-arrival floor.

All engine timestamps are Unix epoch milliseconds (now_ms); the protocol’s interval constants are seconds, converted here. Keeping the timing pure + separately testable is what makes the receiver’s enforcement (SPEC §6.4) exact: a sender’s jitter is additive only, so a conformant sender never sends earlier than its effective interval, and the receiver’s floor can be a hard discard.

Functions§

arrival_floor_ms
The receiver’s minimum inter-arrival floor in milliseconds for data messages, given the sender’s handshake-declared interval (SPEC §6.4): max(declared, PEX_MIN_INTERVAL) − PEX_ARRIVAL_GRACE, in ms. A data message arriving less than this after the previous one is a rate violation.
clamp_interval
Clamp a declared interval (seconds) into the legal [PEX_MIN_INTERVAL, PEX_MAX_INTERVAL] range (SPEC §6.2). Both a sender’s own declaration and a remote’s declaration are clamped for use.
effective_interval_secs
A sender’s effective interval (seconds) — the minimum spacing it must honor for its own data messages (SPEC §6.2): max(own declared, remote declared once known, PEX_MIN_INTERVAL). The remote’s declaration is a floor (“don’t tell me more often than this”) once its handshake arrives.
jitter_ms
Additive send jitter in milliseconds: a uniformly random 0..=10% of the effective interval (SPEC §6.3), to decorrelate network-wide ticks. Additive only — a sender MUST NOT send earlier than its effective interval.