This commit is contained in:
parent
6e5c985719
commit
1b796d0ce7
46 changed files with 1755 additions and 691 deletions
|
|
@ -1,4 +1,6 @@
|
|||
use std::fs;
|
||||
use std::time::Instant;
|
||||
|
||||
use tokio::fs;
|
||||
|
||||
use mtp::client::{ClientConfig, MTPClient, MTPConnection};
|
||||
use mtp::crypto::{
|
||||
|
|
@ -14,16 +16,25 @@ pub async fn connect_or_register(
|
|||
let keyring_path = format!("{key_prefix}.mk");
|
||||
let id_path = format!("{key_prefix}.id");
|
||||
|
||||
let file_load_started = Instant::now();
|
||||
if let (Ok(keyring), Ok(id)) = (
|
||||
load_keyring_raw(&keyring_path),
|
||||
fs::read_to_string(&id_path),
|
||||
fs::read_to_string(&id_path).await,
|
||||
) {
|
||||
let client_id: u64 = id.trim().parse()?;
|
||||
println!("Loaded client keys (ID: {client_id})");
|
||||
println!(
|
||||
"Loaded client keys (ID: {client_id}) in {:?}",
|
||||
file_load_started.elapsed()
|
||||
);
|
||||
|
||||
config.client_id = client_id;
|
||||
let auth_started = Instant::now();
|
||||
let conn = MTPClient::auth_connect(config, &keyring, &host_public_key).await?;
|
||||
println!("Authenticated (version {})", conn.version);
|
||||
println!(
|
||||
"Authenticated (version {}) in {:?}",
|
||||
conn.version,
|
||||
auth_started.elapsed()
|
||||
);
|
||||
return Ok((conn, keyring));
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +56,7 @@ pub async fn connect_or_register(
|
|||
println!("Registered with ID: {}", conn.client_id);
|
||||
|
||||
save_keyring_raw(&keyring, &keyring_path)?;
|
||||
fs::write(&id_path, conn.client_id.to_string())?;
|
||||
fs::write(&id_path, conn.client_id.to_string()).await?;
|
||||
println!("Saved client keys -> {keyring_path}");
|
||||
|
||||
Ok((conn, keyring))
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ fn dev_cert_path() -> String {
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
tracing_subscriber::fmt::init();
|
||||
let cert_path = dev_cert_path();
|
||||
let cert_pem = fs::read(&cert_path).unwrap_or_else(|e| {
|
||||
panic!(
|
||||
|
|
@ -29,10 +30,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let host_public_key = match load_public_key_bundle("host.mpkb") {
|
||||
Ok(bundle) => bundle,
|
||||
Err(e) => {
|
||||
return Err(format!(
|
||||
"Missing host.mpkb: run the server first to export it ({e})"
|
||||
)
|
||||
.into());
|
||||
return Err(
|
||||
format!("Missing host.mpkb: run the server first to export it ({e})").into(),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
println!("\n--- Pipe demo ---");
|
||||
pipes::run_pipe_demo(&conn, 1).await?;
|
||||
|
||||
conn.sender.close();
|
||||
conn.sender.close().await;
|
||||
println!("\nDone");
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,6 @@ pub async fn run_pipe_demo(
|
|||
.finish()
|
||||
.await
|
||||
.map_err(|e| mtp::common::PipeError::IoError(e.to_string()))?;
|
||||
println!(" [pipe {i}.{run}] writer: data sent and finished");
|
||||
Ok::<(), mtp::common::PipeError>(())
|
||||
}
|
||||
Ok(None) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue