Crates.io | rvoip-sip-transport |
lib.rs | rvoip-sip-transport |
version | 0.1.26 |
created_at | 2025-07-03 05:40:20.812145+00 |
updated_at | 2025-08-15 17:49:03.081586+00 |
description | Transport layer for SIP - UDP, TCP, TLS support |
homepage | https://github.com/eisenzopf/rvoip |
repository | https://github.com/eisenzopf/rvoip |
max_upload_size | |
id | 1735844 |
size | 235,745 |
SIP transport layer implementation for the rvoip VoIP stack, providing reliable and efficient transport mechanisms for SIP messages across different network protocols.
rvoip-sip-transport
is the transport layer of the rvoip stack that handles the reliable transmission and reception of SIP messages over various network protocols. It abstracts away the complexities of different transport types while providing a unified interface for higher-level SIP components.
Multiple Transport Types
Transport Management
Transport
trait for all transport typesError Handling & Reliability
Performance Optimizations
Integration
transaction-core
TransportEvent
Enhanced Management
Scalability Improvements
Event System Integration
All transport implementations share a common Transport
trait:
#[async_trait::async_trait]
pub trait Transport: Send + Sync + fmt::Debug {
fn local_addr(&self) -> Result<SocketAddr>;
async fn send_message(&self, message: Message, destination: SocketAddr) -> Result<()>;
async fn close(&self) -> Result<()>;
fn is_closed(&self) -> bool;
// ... additional methods for transport capabilities
}
UdpTransport
): Connection-less, best-effort deliveryTcpTransport
): Reliable, connection-oriented with message framingTlsTransport
): Secure TCP with encryption and certificate validationWebSocketTransport
): Full-duplex communication over HTTPThe transport layer emits events through the TransportEvent
enum:
pub enum TransportEvent {
MessageReceived { message: Message, source: SocketAddr, destination: SocketAddr },
Error { error: String },
Closed,
}
use rvoip_sip_transport::prelude::*;
use rvoip_sip_core::Message;
#[tokio::main]
async fn main() -> Result<()> {
// Create a UDP transport
let (transport, mut events) = bind_udp("127.0.0.1:5060".parse()?).await?;
// Listen for incoming messages
tokio::spawn(async move {
while let Some(event) = events.recv().await {
match event {
TransportEvent::MessageReceived { message, source, .. } => {
println!("Received message from {}: {}", source, message);
}
TransportEvent::Error { error } => {
eprintln!("Transport error: {}", error);
}
TransportEvent::Closed => {
println!("Transport closed");
break;
}
}
}
});
// Send a message
let message = Message::new_request(/* ... */);
transport.send_message(message, "127.0.0.1:5061".parse()?).await?;
Ok(())
}
use rvoip_sip_transport::factory::TransportFactory;
let factory = TransportFactory::new();
// Create transport based on URI scheme
let (transport, events) = factory
.create_from_uri("sip:example.com:5060;transport=tcp")
.await?;
use rvoip_sip_transport::manager::TransportManager;
let mut manager = TransportManager::new();
// Add multiple transports
manager.add_transport("udp", udp_transport).await?;
manager.add_transport("tcp", tcp_transport).await?;
// Send message with automatic transport selection
manager.send_message(message, destination).await?;
rvoip-sip-core
: Provides SIP message types and parsingtokio
: Async runtime for network operationsasync-trait
: Async trait supporttokio-rustls
: TLS transport supporttokio-tungstenite
: WebSocket transport support┌─────────────────────────────────────────┐
│ Application Layer │
├─────────────────────────────────────────┤
│ rvoip-session-core │
├─────────────────────────────────────────┤
│ rvoip-transaction-core │
├─────────────────────────────────────────┤
│ rvoip-sip-transport ⬅️ YOU ARE HERE
├─────────────────────────────────────────┤
│ Network Layer │
└─────────────────────────────────────────┘
The transport layer sits between the transaction layer and the network, providing:
Run the test suite:
# Run all tests
cargo test -p rvoip-sip-transport
# Run with specific features
cargo test -p rvoip-sip-transport --features "tls ws"
# Run integration tests
cargo test -p rvoip-sip-transport --test integration_tests
The crate supports the following optional features:
udp
(default): UDP transport supporttcp
(default): TCP transport supporttls
(default): TLS transport supportws
(default): WebSocket transport supportDisable default features and enable only what you need:
[dependencies]
rvoip-sip-transport = { version = "0.1", default-features = false, features = ["udp", "tcp"] }
The crate provides comprehensive error handling with categorized error types:
use rvoip_sip_transport::Error;
match transport_result {
Err(Error::ConnectionTimeout(addr)) => {
// Handle timeout - often recoverable
if error.is_recoverable() {
retry_connection(addr).await?;
}
}
Err(Error::TlsCertificateError(msg)) => {
// Handle TLS errors - typically not recoverable
log::error!("Certificate validation failed: {}", msg);
}
Err(Error::MessageTooLarge(size)) => {
// Handle protocol violations - not recoverable
return Err(error);
}
Ok(result) => {
// Handle success
}
}
See TODO.md for a comprehensive list of planned enhancements, including:
Contributions are welcome! Please see the main rvoip contributing guidelines for details.
This project is licensed under either of
at your option.