pub struct TimerManager { /* private fields */ }Expand description
Manages active timers for SIP transactions.
The TimerManager is a central component of the SIP transaction layer that handles:
- Timer Registration: Associates transactions with their command channels
- Timer Scheduling: Creates and manages one-shot timers
- Event Delivery: Notifies transactions when their timers expire
When a timer fires, the TimerManager sends an InternalTransactionCommand::Timer message
to the mpsc::Sender<InternalTransactionCommand> that was registered for that transaction.
It does not directly manage Timer struct instances but rather the spawned tasks for each active timer.
§RFC 3261 Compliance
This implementation satisfies the timing requirements of RFC 3261 Section 17, which
defines the behavior of client and server transaction state machines. The TimerManager
provides the underlying mechanism for:
- Retransmission timers (A, E, G)
- Transaction timeout timers (B, F, H)
- Wait timers for absorbing retransmissions (D, I, J, K)
Implementations§
Source§impl TimerManager
impl TimerManager
Sourcepub fn new(settings: Option<TimerSettings>) -> Self
pub fn new(settings: Option<TimerSettings>) -> Self
Creates a new TimerManager.
§Arguments
settings- OptionalTimerSettings. IfNone, default settings are used. The default settings follow RFC 3261 recommendations (T1=500ms, etc.).
Sourcepub async fn register_transaction(
&self,
transaction_id: TransactionKey,
command_tx: Sender<InternalTransactionCommand>,
)
pub async fn register_transaction( &self, transaction_id: TransactionKey, command_tx: Sender<InternalTransactionCommand>, )
Registers a transaction with the TimerManager.
This allows the TimerManager to send timer-fired events to the transaction via the provided command_tx channel.
Typically called when a new transaction is created and needs timer supervision.
If a transaction with the same ID is already registered, this method will replace the existing command channel with the new one. This is a normal operation in some cases, such as when a transaction is being processed through multiple functions or when timers are reset.
§Arguments
transaction_id- TheTransactionKeyof the transaction to register.command_tx- Thempsc::Senderchannel for sendingInternalTransactionCommands to the transaction.
§SIP Transaction Lifecycle
In the SIP transaction model, registration occurs when a transaction is created, either by a client initiating a request or a server receiving one. The registration enables timer management for the transaction’s entire lifecycle.
Sourcepub async fn unregister_transaction(&self, transaction_id: &TransactionKey)
pub async fn unregister_transaction(&self, transaction_id: &TransactionKey)
Unregisters a transaction from the TimerManager.
After unregistering, the transaction will no longer receive timer events. Active timer tasks for this transaction might still complete their sleep, but they will not be able to send an event. Typically called when a transaction terminates.
§Arguments
transaction_id- TheTransactionKeyof the transaction to unregister.
§SIP Transaction Termination
In SIP, transactions eventually reach a terminated state when:
- A final response is received (client transactions)
- An ACK is received or timeout occurs (server INVITE transactions)
- Cleanup timers expire (all transaction types)
This method should be called when a transaction reaches its terminated state to prevent memory leaks and ensure proper cleanup.
Sourcepub async fn start_timer(
&self,
transaction_id: TransactionKey,
timer_type: TimerType,
duration: Duration,
) -> Result<JoinHandle<()>, Error>
pub async fn start_timer( &self, transaction_id: TransactionKey, timer_type: TimerType, duration: Duration, ) -> Result<JoinHandle<()>, Error>
Starts a one-shot timer for a specific transaction.
A new asynchronous task is spawned that will sleep for the given duration.
Upon waking, it sends an InternalTransactionCommand::Timer containing the timer_type
(as a string) to the registered channel for the transaction_id.
If the transaction is unregistered before the timer fires, or if its command channel is closed, the event delivery will fail silently or log an error, respectively.
§Arguments
transaction_id- TheTransactionKeyof the transaction this timer belongs to.timer_type- TheTimerTypeof this timer, used for generating the event payload.duration- TheDurationfor which the timer should sleep before firing.
§Returns
Ok(JoinHandle<()>) for the spawned timer task. The caller can use this handle
to await the timer task’s completion or to abort it (though aborting is not
explicitly managed by TimerManager beyond providing the handle).
Returns crate::error::Error if the underlying transaction channel is not found immediately
(though the current implementation spawns and checks later).
The primary error source would be if transaction_channels.lock() fails, which is unlikely.
The current implementation always returns Ok, as the check happens in spawned task.
§RFC 3261 Timer Types
RFC 3261 defines several timer types that will commonly be used with this method:
- For INVITE client transactions: Timers A, B, and D
- For non-INVITE client transactions: Timers E, F, and K
- For INVITE server transactions: Timers G, H, and I
- For non-INVITE server transactions: Timer J
Sourcepub fn settings(&self) -> &TimerSettings
pub fn settings(&self) -> &TimerSettings
Returns a reference to the TimerSettings used by this manager.
Trait Implementations§
Source§impl Debug for TimerManager
impl Debug for TimerManager
Source§impl Default for TimerManager
Provides a default TimerManager with default TimerSettings.
impl Default for TimerManager
Provides a default TimerManager with default TimerSettings.