hexz-server
HTTP and NBD server for streaming Hexz snapshot data over the network.
Overview
hexz-server provides network-facing interfaces for accessing compressed Hexz snapshots via standard protocols. It enables remote access to snapshot data without requiring clients to download entire files, making it ideal for forensics, VM hosting, and distributed data access.
Supported Protocols
HTTP Range Server
Exposes snapshots via HTTP 1.1 with range request support (RFC 7233). Clients can fetch specific byte ranges using standard HTTP GET requests with Range headers.
NBD (Network Block Device)
Allows mounting snapshots as Linux block devices using the NBD protocol. This enables transparent filesystem access and use of standard tools (mount, dd, fsck).
S3 Gateway (Planned)
Future S3-compatible API for cloud integration (not yet implemented).
Quick Examples
Starting an HTTP Server
use Arc;
use File;
use FileBackend;
use Lz4Compressor;
use serve_http;
async
Starting an NBD Server
use Arc;
use File;
use FileBackend;
use Lz4Compressor;
use serve_nbd;
async
Command-Line Usage
# Start HTTP server (via hexz CLI)
# Start NBD server
HTTP Server
Endpoints
- GET /disk - Serves the disk stream (persistent storage)
- GET /memory - Serves the memory stream (RAM snapshot)
Range Request Support
# Fetch first 4KB of disk stream
# Fetch 1MB starting at offset 1MB
# Fetch from offset to EOF (clamped to 32 MiB)
Response Codes
- 206 Partial Content - Successful range request
- 416 Range Not Satisfiable - Invalid range or out of bounds
- 500 Internal Server Error - Snapshot read failure
Python Client Example
# Fetch a range
=
=
assert == 206
# Parse Content-Range header
=
=
NBD Server
Client Usage (Linux)
# Connect NBD client to server
# Mount the block device (read-only)
# Access files normally
# Disconnect when done
Use Cases
- VM Hosting: Boot VMs directly from NBD-mounted snapshots
- Forensics: Mount disk images for analysis without full download
- File Access: Browse snapshot contents with standard Linux tools
Architecture
hexz-server/
├── src/
│ ├── lib.rs # HTTP server implementation (Axum)
│ └── nbd.rs # NBD protocol implementation
Key design decisions:
- Axum Framework: Modern async HTTP server with excellent performance
- Tokio Runtime: Async I/O for handling thousands of concurrent connections
- Localhost-Only: Binds to 127.0.0.1 by default for security
- DoS Protection: Request size clamping (32 MiB max per request)
Performance
HTTP Server
| Metric | Value |
|---|---|
| Throughput (localhost) | 500-2000 MB/s |
| Latency (cache hit) | ~80 μs |
| Latency (cache miss) | ~1-5 ms |
| Concurrency | 1000+ connections |
| Memory per connection | ~100 KB |
NBD Server
| Metric | Value |
|---|---|
| Throughput | 500-1000 MB/s |
| Latency | ~2-10 ms |
| Concurrency | Multiple clients |
| Memory per client | ~100 KB |
Performance is primarily limited by decompression CPU time, not network bandwidth.
Security
Current Security Posture
- Localhost-only: Binds to 127.0.0.1, not accessible from network
- No authentication: Anyone with local access can read snapshots
- No TLS: Plaintext protocols (acceptable for loopback)
- DoS protection: Request size clamping to prevent memory exhaustion
Remote Access
For remote access, use:
- SSH tunnel:
ssh -L 8080:localhost:8080 user@server - VPN: WireGuard, OpenVPN, etc.
- Reverse proxy: nginx with TLS + authentication
Future Enhancements (Planned)
- TLS/HTTPS support
- Bearer token authentication
- Rate limiting per IP
- Configurable bind addresses
- Audit logging
DoS Protection
Request Size Clamping
All HTTP requests are clamped to 32 MiB (MAX_CHUNK_SIZE) to prevent:
- Memory exhaustion from huge reads
- CPU exhaustion from excessive decompression
Example:
Client requests: Range: bytes=0-67108863 (64 MiB)
Server clamps to: Content-Range: bytes 0-33554431/total (32 MiB)
Clients must check the Content-Range header and issue follow-up requests for remaining data.
Protocol Limitations
HTTP Server
Supported:
- Bounded ranges:
bytes=0-1023 - Unbounded ranges:
bytes=1024-
Not supported:
- Suffix ranges:
bytes=-1024(last 1KB) - Multi-part ranges:
bytes=0-100,200-300
Returns HTTP 416 for unsupported range types.
NBD Server
Supported:
- Read operations
- Block-level access
- Multiple concurrent clients
Not supported:
- Write operations (always read-only)
- Trim/discard commands
Development
From the repository root:
# Build server crate
# Run tests
# Run HTTP server example
Testing
# Unit tests
# Integration tests with actual servers
Examples
The crate includes example programs:
# HTTP server example
# NBD server example
Dependencies
- axum: HTTP server framework
- tokio: Async runtime
- tower: Middleware and utilities
- hexz-core: Core snapshot engine
See Also
- hexz-core - Core engine (provides File)
- hexz-cli - CLI tool (serve command)
- User Documentation - Server configuration guides
- Project README - Main project overview