Skip to content

Commit edb4647

Browse files
docs(Mist): Normalise doc-comment sections and add missing module-level docs
Standardise doc-comment formatting across all six public source files. The primary change is upgrading section headings from single-hash to double-hash (`# Parameters` → `## Parameters`, `# Returns` → `## Returns`, `# Example` → `## Example`) so they nest correctly under the outer item-level doc comment delimiter. Add module-level doc comments with `## Functions` or `## Types` listings to Resolver.rs, Server.rs, and Zone.rs, matching the pattern already established in the crate's earlier source files. Add missing `## Parameters` and `## Returns` sections to `LandResolver`, `LandDnsResolver::New`, `LandDnsResolver::new`, `SharedSecret::random`, `SharedSecret::as_hex`, and `reqwest::dns::Resolve::resolve`. Add `## Errors` sections to `Serve` and `ServeSync` documenting the failure conditions (non-loopback bind, hickory runtime errors). Fix indentation in doc-example code blocks in Library.rs (tabs to spaces) and mark a TODO-style note in ForwardSecurity.rs with the currently authorised allowlist domain (`update.editor.land`). No functional changes — documentation and formatting only.
1 parent c8c7bfe commit edb4647

6 files changed

Lines changed: 124 additions & 42 deletions

File tree

Source/ForwardSecurity.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ use hickory_proto::rr::Name;
1919
/// Returns the default DNS forward allowlist.
2020
///
2121
/// Domains in the allowlist may be forwarded to upstream DNS servers.
22-
/// All other domains receive `REFUSED`.
22+
/// All other domains receive `REFUSED`. Currently authorizes
23+
/// `update.editor.land` as the sole forwarded domain.
2324
///
24-
/// # Returns
25+
/// ## Returns
2526
///
2627
/// An iterator of parseable `Name` values for allowed forward domains.
2728
pub fn DefaultForwardAllowlist() -> impl Iterator<Item = Result<Name>> {

Source/Library.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ pub mod WebSocket;
8686
///
8787
/// ```rust
8888
/// use Mist::dns_port;
89-
///
9089
/// let port = dns_port();
9190
/// ```
9291
pub static DNS_PORT:OnceCell<u16> = OnceCell::new();
@@ -96,20 +95,19 @@ pub static DNS_PORT:OnceCell<u16> = OnceCell::new();
9695
/// Provides the port that the DNS server is listening on, or `0` if the
9796
/// server has not been started yet.
9897
///
99-
/// # Returns
98+
/// ## Returns
10099
///
101-
/// The port number (0-65535), or 0 if the server hasn't started.
100+
/// The port number (065535), or `0` if the server hasn't been started.
102101
///
103-
/// # Example
102+
/// ## Example
104103
///
105104
/// ```rust
106105
/// use Mist::dns_port;
107-
///
108106
/// let port = dns_port();
109107
/// if port > 0 {
110-
/// println!("DNS server is running on port {}", port);
108+
/// println!("DNS server is running on port {}", port);
111109
/// } else {
112-
/// println!("DNS server has not been started");
110+
/// println!("DNS server has not been started");
113111
/// }
114112
/// ```
115113
pub fn dns_port() -> u16 { *DNS_PORT.get().unwrap_or(&0) }
@@ -126,28 +124,28 @@ pub fn dns_port() -> u16 { *DNS_PORT.get().unwrap_or(&0) }
126124
/// The DNS server runs in the background and can be stopped by dropping
127125
/// the application.
128126
///
129-
/// # Parameters
127+
/// ## Parameters
130128
///
131-
/// * `preferred_port` - The preferred port number to use. If this port is
129+
/// * `preferred_port` The preferred port number to use. If this port is
132130
/// already in use, portpicker will find an alternative available port.
133131
///
134-
/// # Returns
132+
/// ## Returns
135133
///
136-
/// Returns `Ok(port)` with the port number the server is listening on,
134+
/// `Ok(port)` with the port number the server is listening on,
137135
/// or an error if the server failed to start.
138136
///
139-
/// # Example
137+
/// ## Example
140138
///
141139
/// ```rust,no_run
142140
/// use Mist::start;
143141
///
144142
/// #[tokio::main]
145143
/// async fn main() -> anyhow::Result<()> {
146-
/// // Start DNS server, preferring port 5353
147-
/// let port = start(5353)?;
148-
/// println!("DNS server started on port {}", port);
149-
/// tokio::signal::ctrl_c().await?;
150-
/// Ok(())
144+
/// // Start DNS server, preferring port 5353
145+
/// let port = start(5353)?;
146+
/// println!("DNS server started on port {}", port);
147+
/// tokio::signal::ctrl_c().await?;
148+
/// Ok(())
151149
/// }
152150
/// ```
153151
pub fn start(preferred_port:u16) -> Result<u16> {

Source/Resolver.rs

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,30 @@
33
//! Provides DNS resolution for the CodeEditorLand private network.
44
//! Routes `*.editor.land` queries to loopback; other domains fall back
55
//! to system DNS.
6+
//!
7+
//! ## Types
8+
//!
9+
//! * [`TokioResolver`] — Stub resolver that queries the local DNS server.
10+
//! * [`LandDnsResolver`] — Secured resolver for `reqwest` DNS override.
611
712
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
813

914
/// Stub DNS resolver type.
1015
///
1116
/// In production this wraps a real hickory-client resolver connected
12-
/// to the local DNS server.
17+
/// to the local DNS server. Currently a zero-size placeholder awaiting
18+
/// integration with the running Mist server port.
1319
pub struct TokioResolver;
1420

1521
/// Builds a `TokioResolver` stub that queries the local DNS server.
22+
///
23+
/// ## Parameters
24+
///
25+
/// * `_DNSPort` — Port number of the running Mist server (currently unused).
26+
///
27+
/// ## Returns
28+
///
29+
/// A new `TokioResolver` instance.
1630
pub fn LandResolver(_DNSPort:u16) -> TokioResolver { TokioResolver }
1731

1832
/// Secured DNS resolver for use with `reqwest`'s DNS override.
@@ -22,21 +36,51 @@ pub fn LandResolver(_DNSPort:u16) -> TokioResolver { TokioResolver }
2236
pub struct LandDnsResolver;
2337

2438
impl LandDnsResolver {
25-
/// Builds a new `LandDnsResolver` connected to the given DNS port.
39+
/// Builds a new `LandDnsResolver` connected to the given DNS port (PascalCase).
40+
///
41+
/// Matches the project's naming convention for constructors.
42+
/// See also [`new`](Self::new).
43+
///
44+
/// ## Parameters
45+
///
46+
/// * `_Port` — Port number of the running Mist server (currently unused).
47+
///
48+
/// ## Returns
2649
///
27-
/// This is the PascalCase variant, matching the project's naming
28-
/// convention for constructors. See also [`new`](Self::new).
50+
/// A new `LandDnsResolver` instance.
2951
pub fn New(_Port:u16) -> Self { Self }
3052

3153
/// Builds a new `LandDnsResolver` (snake_case alias for reqwest).
3254
///
33-
/// This variant exists for compatibility with the `reqwest::dns::Resolve`
55+
/// Exists for compatibility with the `reqwest::dns::Resolve`
3456
/// trait's expected construction pattern. Both this and [`New`](Self::New)
3557
/// are identical.
58+
///
59+
/// ## Parameters
60+
///
61+
/// * `_Port` — Port number of the running Mist server (currently unused).
62+
///
63+
/// ## Returns
64+
///
65+
/// A new `LandDnsResolver` instance.
3666
pub fn new(_Port:u16) -> Self { Self }
3767
}
3868

3969
impl reqwest::dns::Resolve for LandDnsResolver {
70+
/// Resolves a domain name to IP addresses.
71+
///
72+
/// Routes `*.editor.land` queries to `127.0.0.1`. Returns an empty
73+
/// iterator for all other domains so that `reqwest` falls through to
74+
/// its system DNS resolver.
75+
///
76+
/// ## Parameters
77+
///
78+
/// * `Name` — The domain name to resolve.
79+
///
80+
/// ## Returns
81+
///
82+
/// A resolving future that yields socket addresses (loopback for
83+
/// `editor.land` domains, empty otherwise).
4084
fn resolve(&self, Name:reqwest::dns::Name) -> reqwest::dns::Resolving {
4185
let NameString = Name.as_str().to_string();
4286

Source/Server.rs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
//!
33
//! Builds and serves the private DNS catalog for CodeEditorLand.
44
//! Binds exclusively to loopback (`127.0.0.1`) to prevent LAN exposure.
5+
//!
6+
//! ## Functions
7+
//!
8+
//! * [`BuildCatalog`] — Constructs the DNS catalog with `editor.land` zone.
9+
//! * [`Serve`] — Runs the async DNS server on a loopback port.
10+
//! * [`ServeSync`] — Blocking convenience wrapper around [`Serve`].
511
612
use std::{
713
net::{IpAddr, Ipv4Addr, SocketAddr},
@@ -25,24 +31,25 @@ use hickory_server::{
2531
};
2632
use tokio::net::UdpSocket;
2733

28-
/// Buffer capacity for outgoing DNS TCP responses per connection. 65 535 is
29-
/// the upper bound a single DNS message can reach over TCP (the 16-bit
30-
/// length prefix cap from RFC 1035 §4.2.2). Picking the cap avoids any
31-
/// truncation for zone-transfer or large TXT responses while staying well
32-
/// within memory for the dozen-or-so concurrent connections a local
33-
/// `editor.land` catalog ever sees.
34+
/// Buffer capacity for outgoing DNS TCP responses per connection.
35+
///
36+
/// 65 535 is the upper bound a single DNS message can reach over TCP
37+
/// (the 16-bit length prefix cap from RFC 1035 §4.2.2). Picking the cap
38+
/// avoids any truncation for zone-transfer or large TXT responses while
39+
/// staying well within memory for the dozen-or-so concurrent connections
40+
/// a local `editor.land` catalog ever sees.
3441
const DNS_TCP_RESPONSE_BUFFER_SIZE:usize = 65_535;
3542

3643
/// Builds a DNS catalog for the CodeEditorLand private network.
3744
///
3845
/// Creates a catalog with an authoritative zone for `editor.land` that
3946
/// resolves all queries locally to loopback addresses.
4047
///
41-
/// # Parameters
48+
/// ## Parameters
4249
///
43-
/// * `_DNSPort` — Unused, reserved for future port-based catalog configuration.
50+
/// * `_DNSPort` — Reserved for future port-based catalog configuration.
4451
///
45-
/// # Returns
52+
/// ## Returns
4653
///
4754
/// A `Catalog` configured with the `editor.land` zone.
4855
pub fn BuildCatalog(_DNSPort:u16) -> Result<Catalog> {
@@ -77,14 +84,19 @@ pub fn BuildCatalog(_DNSPort:u16) -> Result<Catalog> {
7784
/// Binds to `127.0.0.1:{Port}` for both UDP and TCP. Validates that the
7885
/// socket is bound to a loopback address before accepting connections.
7986
///
80-
/// # Parameters
87+
/// ## Parameters
8188
///
8289
/// * `Catalog` — The DNS catalog (zone configuration) to serve.
8390
/// * `Port` — The loopback port number to bind to.
8491
///
85-
/// # Returns
92+
/// ## Returns
8693
///
8794
/// `Ok(())` on graceful shutdown, or an error if binding or serving fails.
95+
///
96+
/// ## Errors
97+
///
98+
/// Returns an error if the socket binds to a non-loopback address or
99+
/// if the hickory-server runtime encounters a failure.
88100
pub async fn Serve(Catalog:Catalog, Port:u16) -> Result<()> {
89101
let Address:SocketAddr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), Port);
90102

@@ -176,14 +188,19 @@ pub async fn Serve(Catalog:Catalog, Port:u16) -> Result<()> {
176188
/// Creates a temporary Tokio runtime and runs [`Serve`] on it. Useful for
177189
/// threads or environments that do not manage their own async runtime.
178190
///
179-
/// # Parameters
191+
/// ## Parameters
180192
///
181193
/// * `Catalog` — The DNS catalog (zone configuration) to serve.
182194
/// * `Port` — The loopback port number to bind to.
183195
///
184-
/// # Returns
196+
/// ## Returns
185197
///
186198
/// `Ok(())` on graceful shutdown, or an error if binding or serving fails.
199+
///
200+
/// ## Errors
201+
///
202+
/// Propagates errors from [`Serve`], including binding failures and
203+
/// non-loopback address rejections.
187204
pub fn ServeSync(Catalog:Catalog, Port:u16) -> Result<()> {
188205
let Runtime = tokio::runtime::Runtime::new()?;
189206

Source/WebSocket.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,23 @@ use tokio_tungstenite::{
7777
},
7878
};
7979

80-
/// Per-spawn shared secret for WebSocket connection auth.
80+
/// Per-spawn shared secret for WebSocket connection authentication.
81+
///
82+
/// A cryptographically random 32-byte value used to authenticate
83+
/// WebSocket upgrade requests from native clients. Exchange happens
84+
/// out-of-band (environment variable from Mountain to Cocoon,
85+
/// Tauri invoke from Mountain to Sky).
8186
#[derive(Clone)]
8287
pub struct SharedSecret(pub [u8; 32]);
8388

8489
impl SharedSecret {
8590
/// Generates a cryptographically random 32-byte shared secret.
8691
///
8792
/// Uses the thread-local RNG from `rand` 0.10 via `rand::random`.
93+
///
94+
/// ## Returns
95+
///
96+
/// A new `SharedSecret` with 32 random bytes.
8897
pub fn random() -> Self {
8998
// rand 0.10: `rand::random::<[u8; N]>()` fills via the
9099
// thread-local RNG without needing the deprecated
@@ -97,6 +106,10 @@ impl SharedSecret {
97106
/// Each byte is encoded as two hexadecimal characters, producing a
98107
/// 64-character string. Useful for transmitting the secret over HTTP
99108
/// headers or environment variables.
109+
///
110+
/// ## Returns
111+
///
112+
/// A 64-character hex string.
100113
pub fn as_hex(&self) -> String { hex::encode(self.0) }
101114

102115
/// Parses a hex-encoded string back into a `SharedSecret`.

Source/Zone.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
//! Provides DNS zone configuration for the CodeEditorLand private network.
44
//! Creates an authoritative zone for `editor.land` that resolves to
55
//! loopback addresses.
6+
//!
7+
//! ## Functions
8+
//!
9+
//! * [`EditorLandZone`] — Generates the zone records (SOA, NS, A).
10+
//! * [`EditorLandAuthority`] — Builds an `InMemoryZoneHandler` for `editor.land`.
11+
//! * [`CustomAuthority`] — Builds a handler for an arbitrary DNS origin.
612
713
use anyhow::Result;
814
use hickory_proto::rr::{
@@ -26,7 +32,7 @@ use hickory_server::{
2632
///
2733
/// All `*.editor.land` domains resolve to `127.x.x.x` (loopback).
2834
///
29-
/// # Returns
35+
/// ## Returns
3036
///
3137
/// A vector of DNS records (SOA, NS, A) for the `editor.land` zone.
3238
pub fn EditorLandZone() -> Result<Vec<Record>> {
@@ -85,7 +91,10 @@ pub fn EditorLandZone() -> Result<Vec<Record>> {
8591

8692
/// Builds an `InMemoryZoneHandler` for the `editor.land` zone.
8793
///
88-
/// # Returns
94+
/// Creates a primary zone authority that serves the `editor.land` domain
95+
/// with AXFR transfers disabled.
96+
///
97+
/// ## Returns
8998
///
9099
/// An `InMemoryZoneHandler` configured as primary for `editor.land`.
91100
pub fn EditorLandAuthority() -> Result<InMemoryZoneHandler<TokioRuntimeProvider>> {
@@ -101,13 +110,13 @@ pub fn EditorLandAuthority() -> Result<InMemoryZoneHandler<TokioRuntimeProvider>
101110

102111
/// Builds an `InMemoryZoneHandler` for a custom origin with specified records.
103112
///
104-
/// # Parameters
113+
/// ## Parameters
105114
///
106115
/// * `Origin` — The DNS origin name (e.g. `example.com.`).
107116
/// * `_Records` — DNS records for the zone (currently unused; the handler
108117
/// is created empty regardless).
109118
///
110-
/// # Returns
119+
/// ## Returns
111120
///
112121
/// An `InMemoryZoneHandler` configured as primary for the given origin.
113122
pub fn CustomAuthority(Origin:&Name, _Records:Vec<Record>) -> Result<InMemoryZoneHandler<TokioRuntimeProvider>> {

0 commit comments

Comments
 (0)