rsipstack - A SIP Stack written in Rust
A RFC 3261 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 Compliant: Full compliance with SIP specification
- Multiple Transport Support: UDP, TCP, TLS, WebSocket (TLS/WebSocket require the
rustls
andwebsocket
features, enabled by default) - Transaction Layer: Complete SIP transaction state machine
- Dialog Layer: SIP dialog management
- Digest Authentication: Built-in authentication support
- High Performance: Built with Rust for maximum performance
- Easy to Use: Simple and intuitive API design
TODO
- Transport support
- UDP
- TCP
- TLS
- WebSocket
- Digest Authentication
- Transaction Layer
- Dialog Layer
- WASM target
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 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;
// Access the transport event stream
let mut events = transport_layer
.inner
.transport_rx
.lock
.unwrap
.take
.expect;
spawn;
// Start accepting connections (this is normally driven by `Endpoint::serve`)
transport_layer
.serve_listens
.await
.expect;
To add TLS or WebSocket listeners, construct a TlsListenerConnection
or
WebSocketListenerConnection
and register it with transport_layer.add_transport(...)
.
3. Using Endpoint and Transactions
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 ;
use Credential;
use InviteOption;
use Arc;
use unbounded_channel;
// 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 ;
let = unbounded_channel;
let = dialog_layer.do_invite.await?;
5. Implementing a Proxy
use ;
use RsipHeadersExt;
use HeadersExt;
use HashMap;
// Handle incoming requests
while let Some = incoming.recv.await
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.