Struct TimerManager

Source
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:

  1. Timer Registration: Associates transactions with their command channels
  2. Timer Scheduling: Creates and manages one-shot timers
  3. 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

Source

pub fn new(settings: Option<TimerSettings>) -> Self

Creates a new TimerManager.

§Arguments
  • settings - Optional TimerSettings. If None, default settings are used. The default settings follow RFC 3261 recommendations (T1=500ms, etc.).
Source

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
§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.

Source

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 - The TransactionKey of 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.

Source

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 - The TransactionKey of the transaction this timer belongs to.
  • timer_type - The TimerType of this timer, used for generating the event payload.
  • duration - The Duration for 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
Source

pub fn settings(&self) -> &TimerSettings

Returns a reference to the TimerSettings used by this manager.

Trait Implementations§

Source§

impl Debug for TimerManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TimerManager

Provides a default TimerManager with default TimerSettings.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,