| Crates.io | codive-relay |
| lib.rs | codive-relay |
| version | 0.1.0 |
| created_at | 2026-01-05 19:20:48.3272+00 |
| updated_at | 2026-01-05 19:20:48.3272+00 |
| description | Relay server for secure tunneling |
| homepage | |
| repository | https://github.com/toliaqat/codive |
| max_upload_size | |
| id | 2024414 |
| size | 154,640 |
A production-ready relay server that enables secure remote access to local Codive servers through encrypted WebSocket tunnels. Similar to ngrok, but self-hostable with end-to-end encryption.
# Terminal 1: Start relay server
cargo run -p codive-relay -- -v
# Terminal 2: Start codive with tunnel
cargo run -p codive-cli -- --serve --tunnel -v
# Terminal 3: Connect as client (use URL from Terminal 2)
cargo run -p codive-cli -- --connect "http://abc123.localhost:3001#<key>"
# Build release binary
cargo build -p codive-relay --release
# Run with production settings
./target/release/codive-relay \
--host 0.0.0.0 \
--port 443 \
--domain relay.yourdomain.com \
--https \
--require-auth \
--jwt-secret "your-secret-key" \
-v
For a public relay where users don't need to authenticate:
./target/release/codive-relay \
--host 0.0.0.0 \
--domain relay.yourdomain.com \
--https \
--random-ids-only \
--max-tunnel-age 28800 \
--max-idle-time 1800 \
--max-tunnels-per-ip 3 \
-v
Users can then simply run:
codive --serve --tunnel
# Tunnel URL displayed, no auth needed!
codive-relay [OPTIONS]
Options:
--host <HOST> Host to bind to [default: 127.0.0.1]
--port <PORT> Port to bind to [default: 3001]
--domain <DOMAIN> Base domain for tunnel URLs [default: localhost:3001]
--https Use HTTPS for tunnel URLs
--timeout <SECONDS> Request timeout [default: 30]
Rate Limiting:
--max-tunnels-per-ip <N> Max tunnels per IP [default: 10]
--max-tunnel-age <SECONDS> Tunnel TTL (0 = no limit) [default: 0]
--max-idle-time <SECONDS> Idle timeout (0 = no limit) [default: 0]
--random-ids-only Force random tunnel IDs only
Authentication:
--require-auth Require authentication for connections
--auth-token <TOKEN> Valid auth token (can specify multiple)
--jwt-secret <SECRET> JWT secret (enables JWT mode)
--jwt-validity <SECONDS> JWT token validity [default: 3600]
--max-auth-failures <N> Failed attempts before ban [default: 5]
--auth-ban-duration <SECONDS> Ban duration [default: 300]
Other:
-v, --verbose Increase verbosity (can repeat)
-h, --help Print help
-V, --version Print version
┌─────────────────┐ ┌─────────────────────────┐ ┌──────────────────┐
│ Remote Client │────▶│ Relay Server │────▶│ Agent Server │
│ │ │ relay.yourdomain.com │ │ (local machine) │
└─────────────────┘ └─────────────────────────┘ └──────────────────┘
│ │ │
HTTPS request Routes by subdomain WebSocket tunnel
to tunnel URL (abc123.relay...) to local agent
│ │ │
└─────────────────────────┴──────────────────────────────┘
End-to-end encrypted (key in URL fragment)
GET /agent)Hello message with optional auth tokenWelcome with tunnel URLHttpRequest messagescodive-relay
codive-relay \
--require-auth \
--auth-token "secret-token-1" \
--auth-token "secret-token-2"
codive-relay \
--require-auth \
--jwt-secret "your-256-bit-secret" \
--jwt-validity 7200
codive-relay \
--host 0.0.0.0 \
--domain relay.example.com \
--https \
--random-ids-only \
--max-tunnel-age 28800 \
--max-idle-time 1800 \
--max-tunnels-per-ip 3 \
--max-auth-failures 5 \
--auth-ban-duration 300
server {
listen 443 ssl http2;
server_name relay.yourdomain.com *.relay.yourdomain.com;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
location / {
proxy_pass http://127.0.0.1:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 86400;
}
}
*.relay.yourdomain.com, relay.yourdomain.com {
reverse_proxy localhost:3001
}
FROM rust:1.75 as builder
WORKDIR /app
COPY . .
RUN cargo build -p codive-relay --release
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/codive-relay /usr/local/bin/
EXPOSE 3001
CMD ["codive-relay", "--host", "0.0.0.0"]
# Run all tunnel tests
cargo test -p codive-tunnel -p codive-relay
# Run specific test
cargo test -p codive-relay test_jwt_token
# With output
cargo test -p codive-relay -- --nocapture
Current test coverage: 109 tests (47 relay + 62 tunnel)
/metrics)git checkout -b feature/my-featurecargo test -p codive-tunnel -p codive-relaycargo clippy -p codive-tunnel -p codive-relaycargo fmtcrates/
├── codive-tunnel/ # Shared library
│ ├── src/
│ │ ├── lib.rs # Public exports
│ │ ├── crypto.rs # XChaCha20-Poly1305 encryption
│ │ └── protocol.rs # Wire protocol, message types
│ └── Cargo.toml
│
└── codive-relay/ # Relay server
├── src/
│ ├── main.rs # CLI and server startup
│ ├── lib.rs # Router and middleware
│ ├── state.rs # Shared state, auth, rate limiting
│ ├── tunnel.rs # Tunnel connection management
│ └── routes/
│ ├── mod.rs # Route definitions
│ ├── agent.rs # WebSocket handler
│ └── proxy.rs # HTTP proxy handler
└── Cargo.toml
codive-tunnel/src/protocol.rscodive-relay/src/routes/ or state.rscodive-relay/src/main.rs#[cfg(test)] module in relevant file<type>: <description>
<body>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: <name> <email>
Types: feat, fix, docs, test, refactor, perf
This project is licensed under the MIT License - see the LICENSE file for details.