rsipstack - A SIP Stack written in Rust
A RFC 3261/3262 compliant SIP stack written in Rust. The goal of this project is to provide a high-performance, reliable, and easy-to-use SIP stack that can be used in various scenarios.
Features
- RFC 3261/3262 Compliant: Full compliance with SIP specification
- Multiple Transport Support: UDP, TCP, TLS, WebSocket (TLS/WebSocket require the
rustlsandwebsocketfeatures, enabled by default). The TLS client goes through a backend seam (platform::tls) — host default is the built-in rustls; embedded stacks can register their own connector - IPv6 & Dual-Stack: listeners on
::serve IPv4 and IPv6 (explicitIPV6_V6ONLY), IPv4-mapped peer addresses are canonicalized, and UDP sends pick a listener that can reach the target's address family (see Behavior & Compatibility Notes) - Transaction Layer: Complete SIP transaction state machine
- Dialog Layer: SIP dialog management
- Reliable Provisionals: PRACK (RFC 3262 / 100rel) support
- Digest Authentication: Built-in authentication support
- High Performance: Built with Rust for maximum performance
- Easy to Use: Simple and intuitive API design
no_std / Embedded Support
rsipstack compiles without std (alloc-only) for embassy-based targets —
verified on xtensa-esp32s3-none-elf (ESP32-S3):
-
Core SIP codec, transaction, dialog, and UDP transport layers are
no_std+alloc. -
The
platform-embassybackend maps the runtime seams ontoembassy-time/embassy-sync(critical-section based); task spawning is injected once at startup:set_spawn_fn; -
Concurrent waits use the backend-agnostic
select2/select3helpers instead oftokio::select!. -
SIPS (SIP over TLS, client role) goes through the
platform::tls::TlsConnectorseam: register a backend withplatform::tls::set_client_connectorand everyTlsConnection::connectrides it. Host builds without a registered connector keep using the built-in rustls path. -
TCP / WebSocket transports still require
platform-tokio; on embedded, use UDP or SIPS today. -
On no_std, register a
DomainResolverinstead of the tokio DNS resolver.
TODO
- Transport support
- UDP
- TCP
- TLS
- WebSocket
- Digest Authentication
- Transaction Layer
- Dialog Layer
- WASM target
- no_std embassy-based targets
Behavior & Compatibility Notes
rsipstack targets RFC 3261 strictly; where peers are lenient, rsipstack stays compliant. Recent releases tightened a few behaviours — if you upgrade from 0.7.8 or earlier, review the CHANGELOG. The most visible points:
- Stream transports require
Content-Length(RFC 3261 §18.3): TCP/TLS/WS messages without a valid, singleContent-Length(compactl:counts) are rejected instead of assumed body-less. UDP treats a missing header as "the rest of the datagram is the body". Via receivedis bare for IPv6 (§20.42):received=2001:db8::7, no brackets; bracketed input (RFC 5118) is still parsed.- Dialogs follow target refreshes: an in-dialog INVITE/UPDATE (or a reliable INVITE provisional) with a valid Contact retargets the dialog; rejected refreshes keep the old target, malformed Contacts get 400.
- Transactions match per RFC: server = Via branch + sent-by + method, client = branch + CSeq method; RFC 2543 (cookie-less branch) requests are still matched, and unmatched CANCELs are answered 481.
Use Cases
This SIP stack can be used in various scenarios, including but not limited to:
- Integration with WebRTC for browser-based communication, such as WebRTC SBC.
- Building custom SIP proxies or registrars
- Building custom SIP user agents (SIP.js alternative)
Why Rust?
We are a group of developers who are passionate about SIP and Rust. We believe that Rust is a great language for building high-performance network applications, and we want to bring the power of Rust to the SIP/WebRTC/SFU world.
Quick Start Examples
SIP Proxy Server
A stateful SIP proxy that routes calls between registered users:
# Run proxy server
# Run with external IP
This example demonstrates:
- SIP user registration and location service
- Call routing between registered users
- Transaction forwarding and response handling
- Session management for active calls
- Handling INVITE, BYE, REGISTER, and ACK methods
SIP User Agent Client
A complete SIP client with registration, calling, and media support:
# Local demo proxy
# Register with a SIP server
API Usage Guide
1. Simple SIP Connection
use ;
use ;
use CancellationToken;
// Create UDP connection bound to an ephemeral local port
let cancel_token = new;
let connection = create_connection
.await?;
// Prepare the remote target
let target_addr = new;
// Send raw SIP message
let sip_message = "OPTIONS sip:test@example.com SIP/2.0\r\n...";
connection
.send_raw
.await?;
2. Using Transport Listeners
use ;
use CancellationToken;
// Build a transport layer and register listeners
let cancel_token = new;
let transport_layer = new;
let tcp_listener = new
.await?;
transport_layer.add_transport;
To add TLS or WebSocket listeners, construct a TlsListenerConnection or
WebSocketListenerConnection and register it with transport_layer.add_transport(...).
rustls crypto provider. rsipstack's TLS uses rustls's process-wide crypto provider and builds rustls with
ring. If your application also links theaws-lc-rsbackend (for example throughreqwest's default rustls setup), rustls cannot pick one on its own and the first TLS connection panics with "Could not automatically determine the process-level CryptoProvider". Install a provider once at startup, before creating any TLS transport:default_provider .install_default .expect; // or: rustls::crypto::aws_lc_rs::default_provider().install_default()The installed provider is used for every rustls user in the process, rsipstack included, so it is also where to restrict cipher suites.
The raw TransportEvent stream is an internal API consumed by Endpoint::serve.
To process incoming SIP messages, build an Endpoint around the transport layer and
drive it with endpoint.serve() while consuming transactions via
endpoint.incoming_transactions() (see the next section).
3. Using Endpoint and Transactions
use ;
use ;
use CancellationToken;
// Build endpoint with transport layer
let cancel_token = new;
let transport_layer = new;
let endpoint = new
.with_transport_layer
.with_cancel_token
.build;
// Start endpoint background task
let endpoint_inner = endpoint.inner.clone;
spawn;
// Handle incoming transactions
let mut incoming = endpoint
.incoming_transactions
.expect;
while let Some = incoming.recv.await
4. Creating a User Agent Client
use DialogLayer;
use Registration;
use Credential;
use InviteOption;
use Arc;
// Create dialog layer
let dialog_layer = new;
// Register with server
let credential = Credential ;
let mut registration = new;
let response = registration.register.await?;
// Make outgoing call
let invite_option = InviteOption ;
// Create the dialog state channel (drives `process_dialog`-style loops)
let = dialog_layer.new_dialog_state_channel;
let = dialog_layer.do_invite.await?;
5. Implementing a Proxy
use ;
use ;
use HeadersExt;
use HashMap;
// Handle incoming requests
while let Some = incoming.recv.await
This is a simplified sketch: User, users and incoming are types/values you define yourself
(incoming comes from endpoint.incoming_transactions()?, and User is a struct you implement
that holds the registered user's username and destination SipAddr). A complete, working proxy
is provided in examples/proxy.rs.
Running Tests
Unit Tests
Benchmark Tests
# Run server
# Run client with 1000 calls
The test monitor:
===
============================
Documentation
Contributing
We welcome contributions! Please see our Contributing Guide for details.
License
This project is licensed under the MIT License - see the LICENSE file for details.