Skip to main content

Transaction

Struct Transaction 

Source
pub struct Transaction {
Show 17 fields pub transaction_type: TransactionType, pub key: TransactionKey, pub original: Request, pub destination: Option<SipAddr>, pub state: TransactionState, pub endpoint_inner: EndpointInnerRef, pub connection: Option<SipConnection>, pub last_response: Option<Response>, pub last_ack: Option<Request>, pub tu_receiver: TransactionEventReceiver, pub tu_sender: TransactionEventSender, pub timer_a: Option<u64>, pub timer_b: Option<u64>, pub timer_c: Option<u64>, pub timer_d: Option<u64>, pub timer_k: Option<u64>, pub timer_g: Option<u64>, /* private fields */
}
Expand description

SIP Transaction

Transaction implements the SIP transaction layer as defined in RFC 3261. A transaction consists of a client transaction (sends requests) or server transaction (receives requests) that handles the reliable delivery of SIP messages and manages retransmissions and timeouts.

§Key Features

  • Automatic retransmission handling
  • Timer management per RFC 3261
  • State machine implementation
  • Reliable message delivery
  • Connection management

§Transaction Types

  • ClientInvite - Client INVITE transaction
  • ClientNonInvite - Client non-INVITE transaction
  • ServerInvite - Server INVITE transaction
  • ServerNonInvite - Server non-INVITE transaction

§State Machine

Transactions follow the state machines defined in RFC 3261:

  • Calling → Trying → Proceeding → Completed → Terminated
  • Additional states for INVITE transactions: Confirmed

§Examples

use rsipstack::transaction::{
    transaction::Transaction,
    key::{TransactionKey, TransactionRole}
};
use rsipstack::sip::SipMessage;

// Create a mock request
let request = rsipstack::sip::Request {
    method: rsipstack::sip::Method::Register,
    uri: rsipstack::sip::Uri::try_from("sip:example.com")?,
    headers: vec![
        rsipstack::sip::Header::Via("SIP/2.0/UDP example.com:5060;branch=z9hG4bKnashds".into()),
        rsipstack::sip::Header::CSeq("1 REGISTER".into()),
        rsipstack::sip::Header::From("Alice <sip:alice@example.com>;tag=1928301774".into()),
        rsipstack::sip::Header::CallId("a84b4c76e66710@pc33.atlanta.com".into()),
    ].into(),
    version: rsipstack::sip::Version::V2,
    body: Default::default(),
};
let key = TransactionKey::from_request(&request, TransactionRole::Client)?;

// Create a client transaction
let mut transaction = Transaction::new_client(
    key,
    request,
    endpoint_inner,
    connection
);

// Send the request
transaction.send().await?;

// Receive responses
while let Some(message) = transaction.receive().await {
    match message {
        SipMessage::Response(response) => {
            // Handle response
        },
        _ => {}
    }
}

§Timer Handling

The transaction automatically manages SIP timers:

  • Timer A: Retransmission timer for unreliable transports
  • Timer B: Transaction timeout timer
  • Timer D: Wait time for response retransmissions
  • Timer E: Non-INVITE retransmission timer
  • Timer F: Non-INVITE transaction timeout
  • Timer G: INVITE response retransmission timer
  • Timer K: Wait time for ACK

Fields§

§transaction_type: TransactionType§key: TransactionKey§original: Request§destination: Option<SipAddr>§state: TransactionState§endpoint_inner: EndpointInnerRef§connection: Option<SipConnection>§last_response: Option<Response>§last_ack: Option<Request>§tu_receiver: TransactionEventReceiver§tu_sender: TransactionEventSender§timer_a: Option<u64>§timer_b: Option<u64>§timer_c: Option<u64>§timer_d: Option<u64>§timer_k: Option<u64>§timer_g: Option<u64>

Implementations§

Source§

impl Transaction

Source

pub fn new_client( key: TransactionKey, original: Request, endpoint_inner: EndpointInnerRef, connection: Option<SipConnection>, ) -> Self

Source

pub fn new_server( key: TransactionKey, original: Request, endpoint_inner: EndpointInnerRef, connection: Option<SipConnection>, ) -> Self

Source

pub async fn send(&mut self) -> Result<()>

Source

pub async fn reply_with( &mut self, status_code: StatusCode, headers: Vec<Header>, body: Option<Vec<u8>>, ) -> Result<()>

Source

pub async fn reply(&mut self, status_code: StatusCode) -> Result<()>

Quick reply with status code

Source

pub async fn respond(&mut self, response: Response) -> Result<()>

Source

pub async fn send_cancel(&mut self, cancel: Request) -> Result<()>

Source

pub async fn send_ack( &mut self, connection: Option<SipConnection>, ) -> Result<()>

Source

pub async fn receive(&mut self) -> Option<SipMessage>

Source

pub async fn send_trying(&mut self) -> Result<()>

Source

pub fn is_terminated(&self) -> bool

Source§

impl Transaction

Source

pub fn role(&self) -> TransactionRole

Trait Implementations§

Source§

impl Drop for Transaction

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl TryFrom<&Transaction> for DialogId

Source§

type Error = Error

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

fn try_from(value: &Transaction) -> Result<Self, Self::Error>

Performs the conversion.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,