[WIP] MTP migration

This commit is contained in:
Alex Emmet 2026-07-03 20:17:19 +02:00
commit bc43ee43e4
4 changed files with 143 additions and 46 deletions

68
Cargo.lock generated
View file

@ -1813,7 +1813,7 @@ dependencies = [
"libc",
"percent-encoding",
"pin-project-lite",
"socket2 0.5.10",
"socket2 0.6.4",
"system-configuration",
"tokio",
"tower-service",
@ -2655,22 +2655,40 @@ dependencies = [
[[package]]
name = "mtp"
version = "0.1.0"
source = "git+https://git.methanium.net/Methanium/mtp.git#5bfcccc056a2a491a72e4315aa95effb2243ad3c"
source = "git+https://git.methanium.net/Methanium/mtp.git#b96c072a0f87de7828e45cf3dcd44aef4a9e459d"
dependencies = [
"mtp-client",
"mtp-codec",
"mtp-common",
"mtp-crypto",
"mtp-files",
"mtp-host",
"mtp-transport",
"mtp-type-map",
]
[[package]]
name = "mtp-client"
version = "0.1.0"
source = "git+https://git.methanium.net/Methanium/mtp.git#b96c072a0f87de7828e45cf3dcd44aef4a9e459d"
dependencies = [
"mtp-codec",
"mtp-common",
"mtp-crypto",
"mtp-transport",
"rand 0.8.6",
"tokio",
]
[[package]]
name = "mtp-codec"
version = "0.1.0"
source = "git+https://git.methanium.net/Methanium/mtp.git#5bfcccc056a2a491a72e4315aa95effb2243ad3c"
source = "git+https://git.methanium.net/Methanium/mtp.git#b96c072a0f87de7828e45cf3dcd44aef4a9e459d"
dependencies = [
"base64",
"byteorder",
"mtp-common",
"mtp-crypto",
"mtp-type-map",
"rand 0.8.6",
]
@ -2678,7 +2696,7 @@ dependencies = [
[[package]]
name = "mtp-common"
version = "0.1.0"
source = "git+https://git.methanium.net/Methanium/mtp.git#5bfcccc056a2a491a72e4315aa95effb2243ad3c"
source = "git+https://git.methanium.net/Methanium/mtp.git#b96c072a0f87de7828e45cf3dcd44aef4a9e459d"
dependencies = [
"quinn",
"rustls",
@ -2689,8 +2707,9 @@ dependencies = [
[[package]]
name = "mtp-crypto"
version = "0.1.0"
source = "git+https://git.methanium.net/Methanium/mtp.git#5bfcccc056a2a491a72e4315aa95effb2243ad3c"
source = "git+https://git.methanium.net/Methanium/mtp.git#b96c072a0f87de7828e45cf3dcd44aef4a9e459d"
dependencies = [
"base64",
"chacha20poly1305",
"ed25519-dalek",
"getrandom 0.4.3",
@ -2698,15 +2717,38 @@ dependencies = [
"ml-dsa",
"mlkem-tls",
"rand_core 0.6.4",
"serde",
"sha2 0.11.0",
"thiserror 1.0.69",
"zeroize",
]
[[package]]
name = "mtp-files"
version = "0.1.0"
source = "git+https://git.methanium.net/Methanium/mtp.git#b96c072a0f87de7828e45cf3dcd44aef4a9e459d"
dependencies = [
"mtp-crypto",
"thiserror 1.0.69",
]
[[package]]
name = "mtp-host"
version = "0.1.0"
source = "git+https://git.methanium.net/Methanium/mtp.git#b96c072a0f87de7828e45cf3dcd44aef4a9e459d"
dependencies = [
"mtp-codec",
"mtp-common",
"mtp-crypto",
"mtp-transport",
"rand 0.8.6",
"tokio",
]
[[package]]
name = "mtp-transport"
version = "0.1.0"
source = "git+https://git.methanium.net/Methanium/mtp.git#5bfcccc056a2a491a72e4315aa95effb2243ad3c"
source = "git+https://git.methanium.net/Methanium/mtp.git#b96c072a0f87de7828e45cf3dcd44aef4a9e459d"
dependencies = [
"log",
"mtp-codec",
@ -2720,7 +2762,7 @@ dependencies = [
[[package]]
name = "mtp-type-map"
version = "0.1.0"
source = "git+https://git.methanium.net/Methanium/mtp.git#5bfcccc056a2a491a72e4315aa95effb2243ad3c"
source = "git+https://git.methanium.net/Methanium/mtp.git#b96c072a0f87de7828e45cf3dcd44aef4a9e459d"
dependencies = [
"serde",
"serde_yaml",
@ -2783,9 +2825,9 @@ dependencies = [
[[package]]
name = "num-bigint"
version = "0.4.6"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9"
checksum = "c863e9ab5e7bf9c99ba75e1050f1e4d624ae87ed3532d6238ffbdc7b585dbbe6"
dependencies = [
"num-integer",
"num-traits",
@ -3416,7 +3458,7 @@ dependencies = [
"quinn-udp",
"rustc-hash",
"rustls",
"socket2 0.5.10",
"socket2 0.6.4",
"thiserror 2.0.18",
"tokio",
"tracing",
@ -3454,7 +3496,7 @@ dependencies = [
"cfg_aliases",
"libc",
"once_cell",
"socket2 0.5.10",
"socket2 0.6.4",
"tracing",
"windows-sys 0.60.2",
]
@ -3799,9 +3841,9 @@ dependencies = [
[[package]]
name = "rustc-hash"
version = "2.1.2"
version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe"
checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d"
[[package]]
name = "rustc_version"

View file

@ -10,8 +10,8 @@ use iota_storage::util::{chat_files, chats_util};
use iota_util::crypto_helper::keyring_from_base64;
use iota_util::crypto_util::{self};
use iota_util::file_util::{get_children, load_file, save_file};
use mtp::client::{Receiver, Sender};
use mtp::codec::{CommunicationType, CommunicationValue, DataType, DataValue};
use mtp::transport::{Receiver, Sender};
use std::sync::Arc;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use tokio::sync::{Mutex, RwLock, mpsc, watch};
@ -231,7 +231,10 @@ impl ClientConnection {
for (i, contact) in contacts.iter().enumerate() {
let mut contact_container = Vec::new();
contact_container.push((DataType::UserId, DataValue::SignedNumber(contact.user_id as i128)));
contact_container.push((
DataType::UserId,
DataValue::SignedNumber(contact.user_id as i128),
));
contact_container.push((
DataType::LastMessageAt,
DataValue::SignedNumber(contact.last_message_at.unwrap_or(0) as i128),
@ -253,7 +256,10 @@ impl ClientConnection {
let message_state = m["message_state"].as_str().unwrap_or("").to_string();
let mut msg_container = Vec::new();
msg_container.push((DataType::SendTime, DataValue::SignedNumber(message_time as i128)));
msg_container.push((
DataType::SendTime,
DataValue::SignedNumber(message_time as i128),
));
msg_container.push((DataType::Content, DataValue::Str(content.clone())));
msg_container.push((DataType::MessageState, DataValue::Str(message_state)));
msg_container.push((DataType::Height, DataValue::SignedNumber(height as i128)));
@ -268,9 +274,11 @@ impl ClientConnection {
};
let mut last_msg = Vec::new();
last_msg.push((DataType::Content, DataValue::Str(content)));
last_msg.push((DataType::SenderId, DataValue::SignedNumber(sender_id as i128)));
contact_container
.push((DataType::LastMessage, typed_container(last_msg)));
last_msg.push((
DataType::SenderId,
DataValue::SignedNumber(sender_id as i128),
));
contact_container.push((DataType::LastMessage, typed_container(last_msg)));
}
}
contact_container.push((DataType::Messages, DataValue::Array(msg_array)));
@ -391,7 +399,10 @@ impl ClientConnection {
.with_sender(sender_id as u64)
.add_typed_default(DataType::Height, DataValue::SignedNumber(height as i128))
.add_typed_default(DataType::Content, DataValue::Str(content))
.add_typed_default(DataType::SendTime, DataValue::SignedNumber(timestamp_i64 as i128));
.add_typed_default(
DataType::SendTime,
DataValue::SignedNumber(timestamp_i64 as i128),
);
let other_iota_resp = self
.clone()
@ -421,7 +432,10 @@ impl ClientConnection {
DataType::ChatPartnerId,
DataValue::SignedNumber(receiver_id as i128),
)
.add_typed_default(DataType::SendTime, DataValue::SignedNumber(timestamp_i64 as i128))
.add_typed_default(
DataType::SendTime,
DataValue::SignedNumber(timestamp_i64 as i128),
)
.add_typed_default(
DataType::MessageState,
DataValue::Str(ms.as_str().to_string()),
@ -445,7 +459,10 @@ impl ClientConnection {
DataType::ChatPartnerId,
DataValue::SignedNumber(receiver_id as i128),
)
.add_typed_default(DataType::SendTime, DataValue::SignedNumber(timestamp_i64 as i128))
.add_typed_default(
DataType::SendTime,
DataValue::SignedNumber(timestamp_i64 as i128),
)
.add_typed_default(
DataType::MessageState,
DataValue::Str(MessageState::Sent.as_str().to_string()),
@ -459,12 +476,18 @@ impl ClientConnection {
let user_forward = CommunicationValue::new(CommunicationType::MessageLive)
.with_id(cv.get_id())
.with_receiver(receiver_id as u64)
.add_typed_default(DataType::SenderId, DataValue::SignedNumber(sender_id as i128))
.add_typed_default(
DataType::SenderId,
DataValue::SignedNumber(sender_id as i128),
)
.add_typed_default(
DataType::Message,
typed_container(vec![
(DataType::Content, DataValue::Str(content.clone())),
(DataType::SendTime, DataValue::SignedNumber(timestamp_i64 as i128)),
(
DataType::SendTime,
DataValue::SignedNumber(timestamp_i64 as i128),
),
(DataType::Height, DataValue::SignedNumber(height as i128)),
]),
);
@ -508,7 +531,10 @@ impl ClientConnection {
DataType::ChatPartnerId,
DataValue::SignedNumber(receiver_id as i128),
)
.add_typed_default(DataType::SendTime, DataValue::SignedNumber(timestamp_i64 as i128))
.add_typed_default(
DataType::SendTime,
DataValue::SignedNumber(timestamp_i64 as i128),
)
.add_typed_default(
DataType::MessageState,
DataValue::Str(ms.as_str().to_string()),
@ -537,7 +563,10 @@ impl ClientConnection {
.with_id(cv.get_id())
.with_receiver(sender_id as u64)
.with_sender(receiver_id as u64)
.add_typed_default(DataType::SendTime, DataValue::SignedNumber(timestamp_i64 as i128))
.add_typed_default(
DataType::SendTime,
DataValue::SignedNumber(timestamp_i64 as i128),
)
.add_typed_default(
DataType::ChatPartnerId,
DataValue::SignedNumber(receiver_id as i128),
@ -593,12 +622,18 @@ impl ClientConnection {
let user_forward = CommunicationValue::new(CommunicationType::MessageLive)
.with_id(cv.get_id())
.with_receiver(*receiver_id)
.add_typed_default(DataType::SenderId, DataValue::SignedNumber(*sender_id as i128))
.add_typed_default(
DataType::SenderId,
DataValue::SignedNumber(*sender_id as i128),
)
.add_typed_default(
DataType::Message,
typed_container(vec![
(DataType::Content, DataValue::Str(content.clone())),
(DataType::SendTime, DataValue::SignedNumber(timestamp as i128)),
(
DataType::SendTime,
DataValue::SignedNumber(timestamp as i128),
),
(DataType::Height, DataValue::SignedNumber(height as i128)),
]),
);
@ -627,7 +662,10 @@ impl ClientConnection {
.with_id(cv.get_id())
.with_receiver(*sender_id)
.with_sender(*receiver_id)
.add_typed_default(DataType::SendTime, DataValue::SignedNumber(timestamp as i128))
.add_typed_default(
DataType::SendTime,
DataValue::SignedNumber(timestamp as i128),
)
.add_typed_default(
DataType::ChatPartnerId,
DataValue::SignedNumber(*sender_id as i128),
@ -652,7 +690,10 @@ impl ClientConnection {
.with_id(cv.get_id())
.with_receiver(*sender_id)
.with_sender(*receiver_id)
.add_typed_default(DataType::SendTime, DataValue::SignedNumber(timestamp as i128))
.add_typed_default(
DataType::SendTime,
DataValue::SignedNumber(timestamp as i128),
)
.add_typed_default(
DataType::ChatPartnerId,
DataValue::SignedNumber(*receiver_id as i128),
@ -672,7 +713,12 @@ impl ClientConnection {
let partner_id = cv.get_data(DataType::UserId).as_number().unwrap_or(0);
let offset = cv.get_data(DataType::Offset).as_number().unwrap_or(0);
let amount = cv.get_data(DataType::Amount).as_number().unwrap_or(0);
let messages = chat_files::get_messages(my_id as i64, partner_id as i64, offset as i64, amount as i64);
let messages = chat_files::get_messages(
my_id as i64,
partner_id as i64,
offset as i64,
amount as i64,
);
let mut msg_array: Vec<DataValue> = Vec::new();
for m in messages.members() {
let message_time: i64 = m["message_time"].as_i64().unwrap_or(0);
@ -693,9 +739,15 @@ impl ClientConnection {
let message_state: String = m["message_state"].as_str().unwrap_or("").to_string();
let mut container = Vec::new();
container.push((DataType::SendTime, DataValue::SignedNumber(message_time as i128)));
container.push((
DataType::SendTime,
DataValue::SignedNumber(message_time as i128),
));
container.push((DataType::Content, DataValue::Str(content)));
container.push((DataType::SenderId, DataValue::SignedNumber(sender_id as i128)));
container.push((
DataType::SenderId,
DataValue::SignedNumber(sender_id as i128),
));
container.push((DataType::MessageState, DataValue::Str(message_state)));
container.push((DataType::Height, DataValue::SignedNumber(height as i128)));
container.push((DataType::SentBySelf, DataValue::Bool(sent_by_self)));
@ -717,7 +769,10 @@ impl ClientConnection {
let mut user_array = Vec::new();
for user in users {
let mut container = Vec::new();
container.push((DataType::UserId, DataValue::SignedNumber(user.user_id as i128)));
container.push((
DataType::UserId,
DataValue::SignedNumber(user.user_id as i128),
));
if let Some(name) = user.user_name {
container.push((DataType::Username, DataValue::Str(name)));
}

View file

@ -8,9 +8,13 @@ iota-logger = { path = "../iota-logger" }
iota-state = { path = "../iota-state" }
iota-storage = { path = "../iota-storage" }
iota-util = { path = "../iota-util" }
mtp = { git = "https://git.methanium.net/Methanium/mtp.git" }
mtp = { git = "https://git.methanium.net/Methanium/mtp.git", features = [
"client",
"crypto",
"files",
] }
dashmap = "6.1.0"
dashmap = "6.2.1"
json = "*"
tokio = { version = "1.50.0", features = ["full"] }
uuid = { version = "*", features = ["v4"] }

View file

@ -10,8 +10,8 @@ use iota_util::crypto_helper::{self, keyring_from_base64};
use iota_util::crypto_util::{self};
use iota_util::file_util::{get_children, has_file, load_file, save_file};
use json::JsonValue;
use mtp::client::{Policy, Receiver, SendMode, Sender};
use mtp::codec::{CommunicationType, CommunicationValue, DataType, DataValue};
use mtp::transport::{Policy, Receiver, SendMode, Sender};
use std::collections::HashMap;
use std::sync::{Arc, LazyLock};
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
@ -251,7 +251,7 @@ impl OmikronConnection {
let addr_str = format!("https://{}:{}/ws/iota/", self.host, self.port);
let (sender, mut receiver) = mtp::transport::client::connect(
let (sender, mut receiver) = mtp::client::client::connect(
&addr_str,
None,
Policy {
@ -552,20 +552,16 @@ impl OmikronConnection {
drop(conf);
if let Some(keyring) = keyring_from_base64(&kr_str) {
if let Ok(encrypted_challenge) = crypto_util::encrypt_challenge(
&challenge,
&app_pub_bundle,
) {
if let Ok(encrypted_challenge) =
crypto_util::encrypt_challenge(&challenge, &app_pub_bundle)
{
let bundle = keyring.public_key_bundle();
let pub_k_b64 = crypto_helper::public_key_bundle_to_base64(&bundle);
let res = CommunicationValue::new(CommunicationType::AppChallenge)
.with_id(cv.get_id())
.with_receiver(sender_id)
.add_typed_default(
DataType::PublicKey,
DataValue::Str(pub_k_b64),
)
.add_typed_default(DataType::PublicKey, DataValue::Str(pub_k_b64))
.add_typed_default(
DataType::Challenge,
DataValue::Str(encrypted_challenge),