pub struct NotAuthenticatedClient { /* private fields */ }
Expand description
A connected but not yet authenticated RCON client.
Clients must successfully authenticate before sending commands and receiving logs, which is enforced by this type.
To make an authentication attempt, use authenticate
.
§Example
use northstar_rcon_client::connect;
#[tokio::main]
async fn main() {
let client = connect("localhost:37015")
.await
.unwrap();
match client.authenticate("password123").await {
Ok(_) => println!("Authentication successful!"),
Err((_, err)) => println!("Authentication failed: {}", err),
}
}
Implementations§
Source§impl NotAuthenticatedClient
impl NotAuthenticatedClient
Sourcepub async fn authenticate(
self,
pass: &str,
) -> Result<(ClientRead, ClientWrite), (NotAuthenticatedClient, AuthError)>
pub async fn authenticate( self, pass: &str, ) -> Result<(ClientRead, ClientWrite), (NotAuthenticatedClient, AuthError)>
Attempt to authenticate with the RCON server.
If the authentication attempt is successful this client will become a
ClientRead
/ClientWrite
pair, allowing executing commands and reading log lines.
If authentication fails the function will return the reason, as well as the client to allow repeated authentication attempts.
§Example
use std::io::BufRead;
use northstar_rcon_client::connect;
#[tokio::main]
async fn main() {
let mut client = connect("localhost:37015")
.await
.unwrap();
let mut lines = std::io::stdin().lock().lines();
// Keep reading passwords until authentication succeeds
let (read, write) = loop {
print!("Enter password: ");
let password = lines.next()
.unwrap()
.unwrap();
match client.authenticate(&password).await {
Ok((read, write)) => break (read, write),
Err((new_client, err)) => {
println!("Authentication failed: {}", err);
client = new_client;
}
}
};
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NotAuthenticatedClient
impl RefUnwindSafe for NotAuthenticatedClient
impl Send for NotAuthenticatedClient
impl Sync for NotAuthenticatedClient
impl Unpin for NotAuthenticatedClient
impl UnwindSafe for NotAuthenticatedClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more