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 transactionClientNonInvite- Client non-INVITE transactionServerInvite- Server INVITE transactionServerNonInvite- 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
impl Transaction
pub fn new_client( key: TransactionKey, original: Request, endpoint_inner: EndpointInnerRef, connection: Option<SipConnection>, ) -> Self
pub fn new_server( key: TransactionKey, original: Request, endpoint_inner: EndpointInnerRef, connection: Option<SipConnection>, ) -> Self
pub async fn send(&mut self) -> Result<()>
pub async fn reply_with( &mut self, status_code: StatusCode, headers: Vec<Header>, body: Option<Vec<u8>>, ) -> Result<()>
Sourcepub async fn reply(&mut self, status_code: StatusCode) -> Result<()>
pub async fn reply(&mut self, status_code: StatusCode) -> Result<()>
Quick reply with status code
pub async fn respond(&mut self, response: Response) -> Result<()>
pub async fn send_cancel(&mut self, cancel: Request) -> Result<()>
pub async fn send_ack( &mut self, connection: Option<SipConnection>, ) -> Result<()>
pub async fn receive(&mut self) -> Option<SipMessage>
pub async fn send_trying(&mut self) -> Result<()>
pub fn is_terminated(&self) -> bool
Source§impl Transaction
impl Transaction
pub fn role(&self) -> TransactionRole
Trait Implementations§
Source§impl Drop for Transaction
impl Drop for Transaction
Auto Trait Implementations§
impl Freeze for Transaction
impl !RefUnwindSafe for Transaction
impl Send for Transaction
impl Sync for Transaction
impl Unpin for Transaction
impl UnsafeUnpin for Transaction
impl !UnwindSafe for Transaction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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