Skip to content

Commit 152d82c

Browse files
committed
feat(mmserver): mDNS service discovery
1 parent 211dbcd commit 152d82c

File tree

6 files changed

+270
-0
lines changed

6 files changed

+270
-0
lines changed

mm-server/Cargo.lock

Lines changed: 140 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mm-server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ lazy_static = "1.4"
3838
libc = "0.2"
3939
libloading = "0.8"
4040
listenfd = "1"
41+
mdns-sd = "0.11"
4142
mio = { version = "1", features = ["net", "os-ext", "os-poll"] }
4243
mio-timerfd = "0.2"
4344
mktemp = "0.5"

mm-server/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ mod parsed {
8484
pub(super) tls_key: Option<PathBuf>,
8585
pub(super) worker_threads: Option<NonZeroU32>,
8686
pub(super) max_connections: Option<MaxConnections>,
87+
pub(super) mdns: Option<bool>,
88+
pub(super) mdns_hostname: Option<String>,
8789
}
8890

8991
#[derive(Debug, Clone, PartialEq, Deserialize, Converge)]
@@ -126,6 +128,8 @@ pub struct ServerConfig {
126128
pub tls_key: Option<PathBuf>,
127129
pub worker_threads: NonZeroU32,
128130
pub max_connections: Option<NonZeroU32>,
131+
pub mdns: bool,
132+
pub mdns_hostname: Option<String>,
129133
}
130134

131135
#[derive(Debug, Clone, PartialEq)]
@@ -216,6 +220,8 @@ impl Config {
216220
parsed::MaxConnections::Value(n) => Some(n),
217221
parsed::MaxConnections::Infinity => None,
218222
},
223+
mdns: server.mdns.unwrap(),
224+
mdns_hostname: server.mdns_hostname,
219225
},
220226
data_home: data_home.clone(),
221227
apps: BTreeMap::new(), // Handled below.

mm-server/src/server.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: BUSL-1.1
44

55
mod handlers;
6+
mod mdns;
67
mod sendmmsg;
78

89
use std::collections::{BTreeMap, VecDeque};
@@ -50,6 +51,8 @@ pub struct Server {
5051
state: SharedState,
5152
close_recv: Receiver<()>,
5253
close_send: WakingSender<()>,
54+
55+
_mdns: Option<mdns::MdnsService>,
5356
shutting_down: bool,
5457
}
5558

@@ -138,6 +141,19 @@ impl Server {
138141

139142
let thread_pool = threadpool::ThreadPool::new(server_config.worker_threads.get() as usize);
140143

144+
let addr = socket.local_addr()?;
145+
let mdns = if server_config.mdns {
146+
match mdns::MdnsService::new(addr, server_config.mdns_hostname.as_deref()) {
147+
Ok(sd) => Some(sd),
148+
Err(e) => {
149+
error!("failed to enable mDNS service discovery: {e:#}");
150+
None
151+
}
152+
}
153+
} else {
154+
None
155+
};
156+
141157
Ok(Self {
142158
server_config,
143159
quiche_config: config,
@@ -155,6 +171,8 @@ impl Server {
155171
state,
156172
close_send,
157173
close_recv,
174+
175+
_mdns: mdns,
158176
shutting_down: false,
159177
})
160178
}

0 commit comments

Comments
 (0)