MoosicBox Tunnel
Core types and data structures for MoosicBox's tunneling protocol. This package defines the message formats and stream handling for communication between tunnel clients and servers in the MoosicBox ecosystem.
Features
- Tunnel Protocol Types: Request and response message types for tunnel communication
- Stream Handling: Asynchronous stream for receiving chunked tunnel responses
- Multiple Encodings: Support for binary and base64-encoded messages
- Request Types: HTTP, WebSocket, and abort request handling
- Packet Ordering: Automatic packet reordering for out-of-sequence responses
Installation
Add this to your Cargo.toml:
[]
= "0.1.4"
Usage
Tunnel Request Types
use ;
use Method;
use json;
// HTTP request through tunnel
let http_request = Http;
// WebSocket request through tunnel
let ws_request = Ws;
// Abort a request
let abort_request = Abort;
Tunnel Response Handling
use TunnelResponse;
use Bytes;
// Parse binary tunnel response
let bytes = from;
let response: TunnelResponse = bytes.try_into?;
println!;
println!;
println!;
if let Some = response.status
Base64 Encoded Responses
use TunnelResponse;
Tunnel Stream
use TunnelStream;
use mpsc;
use CancellationToken;
use StreamExt;
async
Core Types
TunnelRequest
TunnelResponse
TunnelWsResponse
TunnelStream
A Stream implementation that:
- Receives
TunnelResponsepackets via an unbounded channel - Automatically reorders out-of-sequence packets
- Tracks metrics (packet count, byte count, timing)
- Supports cancellation via
CancellationToken - Calls an
on_endcallback when the stream completes
TunnelEncoding
Features
base64 (default)
Enables base64 encoding/decoding support for tunnel responses.
[]
= { = "0.1.4", = false }
Error Types
TryFromBytesError
Errors when converting bytes to TunnelResponse:
TryFromSlice: Invalid byte slice lengthSerde: JSON deserialization error
Base64DecodeError
Errors when decoding base64-encoded tunnel responses:
InvalidContent: Malformed base64 stringDecode: Base64 decoding error
TunnelStreamError
Errors during stream processing:
Aborted: Stream was cancelledEndOfStream: Stream ended unexpectedly
Dependencies
Core dependencies (from Cargo.toml):
bytes- Efficient byte buffer handlingfutures-util- Stream trait implementationserde/serde_json- Serialization supportswitchy_async- Cancellation token supportswitchy_http- HTTP method typestokio- Async runtime support
See Also
moosicbox_tunnel_server- Server-side tunnel implementationmoosicbox_tunnel_sender- Client-side tunnel sendermoosicbox_ws- WebSocket communication layer