Files
VoelinClient/crates/tsc-gateway/src/main.rs
T
Claude 120d3dfc82 M4: tsgw gateway and tsc-gateway-proto
- tsc-gateway-proto: versioned JSON envelope (tsgw.v1+json), client and
  server messages, identity-challenge auth (ECDSA P-256 over a signed
  challenge), unique ids for TS3 (SHA-1) and TS6 (SHA-256, verified on
  6.0.0-beta13.1), hash-cash level.
- tsc-gateway (tsgw): axum WebSocket server; hub with one observer, a
  relay pool and a lookup query session; login by signature or token;
  permission mirroring via permoverview (server group/client/channel
  group/channel-client levels, skip and negate); per-user filtered
  presence (snapshot + diff deltas); channel/server chat relay with
  server-known nicknames, rate limit, idle relay teardown, pinned
  channels; SQLite tokens, history and audit; Dockerfile; admin guide.
- tsctl gateway client; smoke test covers gateway presence, chat both
  ways and refusal of unknown identities on TS3 and TS6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
2026-09-25 14:30:44 +00:00

66 lines
1.7 KiB
Rust

//! tsgw: companion gateway for TeamSpeak 3/6 servers.
//!
//! Gives app users invisible presence (who is in which channel) and channel
//! chat without joining voice, through ServerQuery. See
//! docs/gateway-admin.md and the protocol in `tsc-gateway-proto`.
mod config;
mod db;
mod hub;
mod perms;
mod session;
use std::path::PathBuf;
use std::sync::Arc;
use anyhow::Result;
use axum::Router;
use axum::extract::{State, WebSocketUpgrade};
use axum::response::IntoResponse;
use axum::routing::get;
use clap::Parser;
use tracing::info;
use tracing_subscriber::EnvFilter;
use crate::hub::Hub;
#[derive(Parser, Debug)]
#[command(version, about)]
struct Args {
/// Configuration file.
#[arg(long, short, default_value = "tsgw.toml", env = "TSGW_CONFIG")]
config: PathBuf,
}
#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
)
.init();
let args = Args::parse();
let config = config::Config::load(&args.config)?;
let bind = config.listen.bind;
let hub = Hub::start(config).await?;
let app = Router::new()
.route("/v1", get(ws))
.route("/health", get(|| async { "ok" }))
.with_state(hub);
let listener = tokio::net::TcpListener::bind(bind).await?;
info!(%bind, "listening");
axum::serve(listener, app).with_graceful_shutdown(shutdown()).await?;
Ok(())
}
async fn ws(State(hub): State<Arc<Hub>>, upgrade: WebSocketUpgrade) -> impl IntoResponse {
upgrade
.protocols([tsc_gateway_proto::SUBPROTOCOL])
.on_upgrade(move |socket| session::run(hub, socket))
}
async fn shutdown() {
let _ = tokio::signal::ctrl_c().await;
info!("shutting down");
}