[Fix]
Some checks failed
CI / rustfmt (push) Failing after 31s
CI / wasm build (push) Successful in 1m23s
CI / clippy (push) Failing after 1m44s
CI / example (push) Successful in 1m32s
CI / test (push) Successful in 2m6s
CI / duplicate code (push) Failing after 30s
CI / web client (push) Failing after 31s
CI / cargo-machete (push) Successful in 1m6s
CI / cargo-deny (push) Failing after 2m24s
Some checks failed
CI / rustfmt (push) Failing after 31s
CI / wasm build (push) Successful in 1m23s
CI / clippy (push) Failing after 1m44s
CI / example (push) Successful in 1m32s
CI / test (push) Successful in 2m6s
CI / duplicate code (push) Failing after 30s
CI / web client (push) Failing after 31s
CI / cargo-machete (push) Successful in 1m6s
CI / cargo-deny (push) Failing after 2m24s
This commit is contained in:
parent
6ef1293603
commit
41528ef717
6 changed files with 49 additions and 37 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -667,9 +667,9 @@ checksum = "1a9fcbcc408c5526c3ab80d534e5c86e7967c1fb7aa0a8c76abd1edc27deb877"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hybrid-array"
|
name = "hybrid-array"
|
||||||
version = "0.4.12"
|
version = "0.4.13"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9155a582abd142abc056962c29e3ce5ff2ad5469f4246b537ed42c5deba857da"
|
checksum = "818356c5132c1fede50f837ca96afbe78ff42413047f4abb886217845e1b6c8c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ctutils",
|
"ctutils",
|
||||||
"typenum",
|
"typenum",
|
||||||
|
|
|
||||||
2
example/Cargo.lock
generated
2
example/Cargo.lock
generated
|
|
@ -908,6 +908,7 @@ dependencies = [
|
||||||
"mtp-crypto",
|
"mtp-crypto",
|
||||||
"mtp-transport",
|
"mtp-transport",
|
||||||
"rand 0.8.6",
|
"rand 0.8.6",
|
||||||
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -957,6 +958,7 @@ dependencies = [
|
||||||
"mtp-crypto",
|
"mtp-crypto",
|
||||||
"mtp-transport",
|
"mtp-transport",
|
||||||
"rand 0.8.6",
|
"rand 0.8.6",
|
||||||
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,9 @@ pub fn process_and_respond(
|
||||||
let value_id = DataTypeId(tm.data_id_enum(DataType::Value).unwrap());
|
let value_id = DataTypeId(tm.data_id_enum(DataType::Value).unwrap());
|
||||||
let bin_id = DataTypeId(tm.data_id_enum(DataType::BinaryData).unwrap());
|
let bin_id = DataTypeId(tm.data_id_enum(DataType::BinaryData).unwrap());
|
||||||
let items_id = DataTypeId(tm.data_id_enum(DataType::Items).unwrap());
|
let items_id = DataTypeId(tm.data_id_enum(DataType::Items).unwrap());
|
||||||
let enc_id = DataTypeId(tm.data_id_enum(DataType::EncryptedPayload).unwrap());
|
let _enc_id = DataTypeId(tm.data_id_enum(DataType::EncryptedPayload).unwrap());
|
||||||
let sig_id = DataTypeId(tm.data_id_enum(DataType::SignedPayload).unwrap());
|
let _sig_id = DataTypeId(tm.data_id_enum(DataType::SignedPayload).unwrap());
|
||||||
let secure_id = DataTypeId(tm.data_id_enum(DataType::SecurePayload).unwrap());
|
let _secure_id = DataTypeId(tm.data_id_enum(DataType::SecurePayload).unwrap());
|
||||||
|
|
||||||
let description = msg.get_data(DataType::Description);
|
let description = msg.get_data(DataType::Description);
|
||||||
let timestamp = msg.get_data(DataType::Timestamp);
|
let timestamp = msg.get_data(DataType::Timestamp);
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,9 @@ mod tls;
|
||||||
|
|
||||||
use mtp::host::{HostConfig, MTPHost};
|
use mtp::host::{HostConfig, MTPHost};
|
||||||
use mtp::type_map::TypeMap;
|
use mtp::type_map::TypeMap;
|
||||||
|
use std::future::Future;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use std::pin::Pin;
|
||||||
|
|
||||||
fn dev_cert_paths() -> (String, String) {
|
fn dev_cert_paths() -> (String, String) {
|
||||||
let cert = std::env::var("MTP_DEV_CERT").unwrap_or_else(|_| {
|
let cert = std::env::var("MTP_DEV_CERT").unwrap_or_else(|_| {
|
||||||
|
|
@ -44,34 +46,42 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let (clients, next_id) = clients::load_client_db("clients.json")?;
|
let (clients, next_id) = clients::load_client_db("clients.json")?;
|
||||||
|
|
||||||
let clients_for_get = clients.clone();
|
let clients_for_get = clients.clone();
|
||||||
let get_existing_user = move |id: u64| -> Option<mtp::crypto::PublicKeyBundle> {
|
let get_existing_user = move |id: u64| {
|
||||||
let result = clients_for_get.lock().unwrap().get(&id).cloned();
|
let clients = clients_for_get.clone();
|
||||||
if result.is_some() {
|
Box::pin(async move {
|
||||||
println!("Auth lookup: client ID {id} found");
|
let result = clients.lock().unwrap().get(&id).cloned();
|
||||||
} else {
|
if result.is_some() {
|
||||||
eprintln!("Auth lookup: unknown client ID {id}");
|
println!("Auth lookup: client ID {id} found");
|
||||||
}
|
} else {
|
||||||
result
|
eprintln!("Auth lookup: unknown client ID {id}");
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}) as Pin<Box<dyn Future<Output = Option<mtp::crypto::PublicKeyBundle>> + Send>>
|
||||||
};
|
};
|
||||||
|
|
||||||
let clients_for_register = clients.clone();
|
let clients_for_register = clients.clone();
|
||||||
let next_id_for_register = next_id.clone();
|
let next_id_for_register = next_id.clone();
|
||||||
let clients_path = "clients.json".to_string();
|
let clients_path = "clients.json".to_string();
|
||||||
let complete_register = move |bundle: mtp::crypto::PublicKeyBundle| -> u64 {
|
let complete_register = move |bundle: mtp::crypto::PublicKeyBundle| {
|
||||||
let mut db = clients_for_register.lock().unwrap();
|
let db_arc = clients_for_register.clone();
|
||||||
let mut nid = next_id_for_register.lock().unwrap();
|
let nid_arc = next_id_for_register.clone();
|
||||||
let id = *nid;
|
let path = clients_path.clone();
|
||||||
*nid += 1;
|
Box::pin(async move {
|
||||||
db.insert(id, bundle);
|
let mut db = db_arc.lock().unwrap();
|
||||||
match serde_json::to_string_pretty(&*db) {
|
let mut nid = nid_arc.lock().unwrap();
|
||||||
Ok(json) => match std::fs::write(&clients_path, json) {
|
let id = *nid;
|
||||||
Ok(()) => {}
|
*nid += 1;
|
||||||
Err(e) => eprintln!("Failed to persist client database to {clients_path}: {e}"),
|
db.insert(id, bundle);
|
||||||
},
|
match serde_json::to_string_pretty(&*db) {
|
||||||
Err(e) => eprintln!("Failed to serialize client database after registering {id}: {e}"),
|
Ok(json) => match std::fs::write(&path, json) {
|
||||||
}
|
Ok(()) => {}
|
||||||
println!("Registered new client with ID: {}", id);
|
Err(e) => eprintln!("Failed to persist client database to {path}: {e}"),
|
||||||
id
|
},
|
||||||
|
Err(e) => eprintln!("Failed to serialize client database after registering {id}: {e}"),
|
||||||
|
}
|
||||||
|
println!("Registered new client with ID: {}", id);
|
||||||
|
id
|
||||||
|
}) as Pin<Box<dyn Future<Output = u64> + Send>>
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("Starting MTP server on port 8080 ...");
|
println!("Starting MTP server on port 8080 ...");
|
||||||
|
|
|
||||||
|
|
@ -905,7 +905,7 @@ fn generate_all_types_methods(
|
||||||
write!(out, "CommunicationType::{}", entry.name).unwrap();
|
write!(out, "CommunicationType::{}", entry.name).unwrap();
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
for (name, _) in &tm_cfg.communication_types {
|
for name in tm_cfg.communication_types.keys() {
|
||||||
if !first {
|
if !first {
|
||||||
write!(out, ", ").unwrap();
|
write!(out, ", ").unwrap();
|
||||||
}
|
}
|
||||||
|
|
@ -936,7 +936,7 @@ fn generate_all_types_methods(
|
||||||
write!(out, "DataType::{}", entry.name).unwrap();
|
write!(out, "DataType::{}", entry.name).unwrap();
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
for (name, _) in &tm_cfg.data_types {
|
for name in tm_cfg.data_types.keys() {
|
||||||
if !first {
|
if !first {
|
||||||
write!(out, ", ").unwrap();
|
write!(out, ", ").unwrap();
|
||||||
}
|
}
|
||||||
|
|
@ -973,7 +973,7 @@ fn generate_all_types_methods_single(out: &mut String, config: &Config) {
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
if let Some(tm_cfg) = tm_cfg {
|
if let Some(tm_cfg) = tm_cfg {
|
||||||
for (name, _) in &tm_cfg.communication_types {
|
for name in tm_cfg.communication_types.keys() {
|
||||||
if !first {
|
if !first {
|
||||||
write!(out, ", ").unwrap();
|
write!(out, ", ").unwrap();
|
||||||
}
|
}
|
||||||
|
|
@ -1003,7 +1003,7 @@ fn generate_all_types_methods_single(out: &mut String, config: &Config) {
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
if let Some(tm_cfg) = tm_cfg {
|
if let Some(tm_cfg) = tm_cfg {
|
||||||
for (name, _) in &tm_cfg.data_types {
|
for name in tm_cfg.data_types.keys() {
|
||||||
if !first {
|
if !first {
|
||||||
write!(out, ", ").unwrap();
|
write!(out, ", ").unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -254,26 +254,26 @@ pub fn parse_auth_response(response: &[u8]) -> Result<JsValue, JsValue> {
|
||||||
.map_err(|e| js_error(&format!("parse failed: {}", e)))?;
|
.map_err(|e| js_error(&format!("parse failed: {}", e)))?;
|
||||||
|
|
||||||
let connected = matches!(
|
let connected = matches!(
|
||||||
comm.get_data(DataType::Connected)),
|
comm.get_data(DataType::Connected),
|
||||||
DataValue::BoolTrue
|
DataValue::BoolTrue
|
||||||
);
|
);
|
||||||
|
|
||||||
let client_nonce = match comm.get_data(DataType::ClientNonce)) {
|
let client_nonce = match comm.get_data(DataType::ClientNonce) {
|
||||||
DataValue::UnsignedNumber(n) => Some(*n),
|
DataValue::UnsignedNumber(n) => Some(*n),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let assigned_id = match comm.get_data(DataType::Id)) {
|
let assigned_id = match comm.get_data(DataType::Id) {
|
||||||
DataValue::UnsignedNumber(n) => Some(*n as u64),
|
DataValue::UnsignedNumber(n) => Some(*n as u64),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let timestamp = match comm.get_data(DataType::Timestamp)) {
|
let timestamp = match comm.get_data(DataType::Timestamp) {
|
||||||
DataValue::UnsignedNumber(n) => Some(*n),
|
DataValue::UnsignedNumber(n) => Some(*n),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let signature = match comm.get_data(DataType::Signature)) {
|
let signature = match comm.get_data(DataType::Signature) {
|
||||||
DataValue::Bytes(b) => Some(b.clone()),
|
DataValue::Bytes(b) => Some(b.clone()),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue