pub struct AuthClient { /* private fields */ }Expand description
DPlus TCP authentication client.
Performs the mandatory TCP auth step against auth.dstargateway.org
and returns the [HostList] cached by the auth server. Caller
then hands the host list to the sans-io session to transition the
typestate to [dstar_gateway_core::session::client::Authenticated].
Implementations§
Source§impl AuthClient
impl AuthClient
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Create a new auth client with defaults.
The endpoint is None (resolve auth.dstargateway.org:20001
via DNS at call time), the connect timeout is 10 s, and the
per-read timeout is 5 s.
Sourcepub const fn with_endpoint(self, endpoint: SocketAddr) -> Self
pub const fn with_endpoint(self, endpoint: SocketAddr) -> Self
Override the TCP auth endpoint.
Used by integration tests to point the client at a local fake auth server on an ephemeral port.
Sourcepub const fn with_connect_timeout(self, dur: Duration) -> Self
pub const fn with_connect_timeout(self, dur: Duration) -> Self
Override the TCP connect timeout.
Sourcepub const fn with_read_timeout(self, dur: Duration) -> Self
pub const fn with_read_timeout(self, dur: Duration) -> Self
Override the per-read timeout while draining the response.
Sourcepub const fn endpoint(&self) -> Option<SocketAddr>
pub const fn endpoint(&self) -> Option<SocketAddr>
Current endpoint override, if any.
Sourcepub async fn authenticate(
&self,
callsign: Callsign,
) -> Result<HostList, AuthError>
pub async fn authenticate( &self, callsign: Callsign, ) -> Result<HostList, AuthError>
Perform the TCP auth against the configured endpoint.
Builds the 56-byte auth packet per
ircDDBGateway/Common/DPlusAuthenticator.cpp:111-143, sends it
over a fresh TCP connection, and accumulates the framed
response until the server closes the socket. The accumulated
bytes are then parsed via
[dstar_gateway_core::codec::dplus::parse_auth_response] with
a [NullSink] for diagnostics.
§Errors
AuthError::Timeoutif any phase (connect, write, read) exceeds the configured timeoutAuthError::Ioif the underlying socket call failsAuthError::Parseif the response body is malformed
§Cancellation safety
This method is not cancel-safe. Cancelling the future may
leave a half-written request on the wire or an auth TCP session
dangling from the upstream host list server’s perspective. The
method owns a transient [tokio::net::TcpStream] internally
and relies on drop-on-cancel to close it, but the upstream
server may briefly see the partial packet. Callers should
either await the future to completion or apply an outer
[tokio::time::timeout] that matches the configured
connect_timeout.
§Example
use dstar_gateway::auth::AuthClient;
use dstar_gateway_core::types::Callsign;
let client = AuthClient::new();
let hosts = client.authenticate(Callsign::try_from_str("W1AW")?).await?;
println!("{} known REF hosts", hosts.len());§See also
ircDDBGateway/Common/DPlusAuthenticator.cpp:111-143 — the
reference 56-byte packet layout this client mirrors.
Trait Implementations§
Source§impl Clone for AuthClient
impl Clone for AuthClient
Source§fn clone(&self) -> AuthClient
fn clone(&self) -> AuthClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more