mumble_server_runtime_gateway/config.rs
1//! What the gateway advertises during the handshake.
2//!
3//! Fixed for the life of the process. Everything a *flavor* would want to change
4//! at runtime - names, trees, who hears whom - lives in the shard's render, not
5//! here: this struct holds only the handful of values the Mumble handshake
6//! demands before any view exists.
7
8use std::net::SocketAddr;
9
10/// Server-wide configuration advertised during the handshake.
11#[derive(Debug, Clone)]
12pub struct GatewayConfig {
13 /// Where the TLS control plane listens. The voice plane binds the same port
14 /// on UDP, as Murmur does.
15 pub bind: SocketAddr,
16 /// Welcome text sent in `ServerSync`. Empty means "omit the field".
17 pub welcome_text: String,
18 /// Advertised maximum bandwidth (bits/s), echoed to the client in
19 /// `ServerSync` and `ServerConfig`.
20 pub max_bandwidth: u32,
21 /// Advertised maximum number of users (`ServerConfig.max_users`). Also the
22 /// admission ceiling: past it, connections are refused rather than accepted
23 /// into a runtime that advertised a smaller number.
24 pub max_users: u32,
25 /// Whether the client's built-in recording feature is announced as allowed
26 /// (`ServerConfig.recording_allowed`). Advisory only (spec 21.8).
27 pub recording_allowed: bool,
28 /// Whether HTML is allowed in text (`ServerConfig.allow_html`).
29 pub allow_html: bool,
30 /// Maximum text-message length (`ServerConfig.message_length`).
31 pub message_length: u32,
32 /// Advertised server version (major, minor, patch). Defaults to 1.5.0 so a
33 /// real client negotiates the protobuf UDP format (introduced in 1.5.0).
34 pub version: (u16, u16, u16),
35}
36
37impl Default for GatewayConfig {
38 fn default() -> GatewayConfig {
39 GatewayConfig {
40 // 64738 is Mumble's registered port; binding all interfaces is what
41 // makes the demo reachable from another machine on the LAN.
42 bind: SocketAddr::from(([0, 0, 0, 0], 64738)),
43 welcome_text: String::new(),
44 // 72 kbit/s is Murmur's default per-user bandwidth ceiling.
45 max_bandwidth: 72_000,
46 max_users: 100,
47 recording_allowed: true,
48 allow_html: true,
49 message_length: 5_000,
50 version: (1, 5, 0),
51 }
52 }
53}
54
55impl GatewayConfig {
56 /// Encode the advertised version in the Mumble v2 format.
57 ///
58 /// REF: references/mumble/src/Version.h : `fromComponents` -
59 /// `version_v2 = (major << 48) | (minor << 32) | (patch << 16)`.
60 #[must_use]
61 pub fn version_v2(&self) -> u64 {
62 let (major, minor, patch) = self.version;
63 (u64::from(major) << 48) | (u64::from(minor) << 32) | (u64::from(patch) << 16)
64 }
65}