Initial MTP Migration [Broken]
This commit is contained in:
parent
a4ec766351
commit
b2a22456ff
30 changed files with 1886 additions and 1574 deletions
|
|
@ -8,8 +8,7 @@ iota-logger = { path = "../iota-logger" }
|
|||
iota-state = { path = "../iota-state" }
|
||||
iota-storage = { path = "../iota-storage" }
|
||||
iota-util = { path = "../iota-util" }
|
||||
ttp-core = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-core" }
|
||||
ttp-native = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-native" }
|
||||
mtp = { git = "https://git.methanium.net/Methanium/mtp.git" }
|
||||
|
||||
dashmap = "6.1.0"
|
||||
json = "*"
|
||||
|
|
@ -17,6 +16,7 @@ tokio = { version = "1.50.0", features = ["full"] }
|
|||
uuid = { version = "*", features = ["v4"] }
|
||||
base64 = "0.22.1"
|
||||
hex = "*"
|
||||
rand = "0.8"
|
||||
rand_core = { version = "0.6", features = ["getrandom", "std"] }
|
||||
sha2 = "0.10.9"
|
||||
x448 = { version = "*" }
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,26 +1,26 @@
|
|||
use crate::omikron_connection::OmikronConnection;
|
||||
use dashmap::DashMap;
|
||||
use iota_state::APP_STATE;
|
||||
use mtp::codec::{CommunicationType, CommunicationValue, DataType, DataValue};
|
||||
use std::sync::LazyLock;
|
||||
use std::time::Instant;
|
||||
use tokio::time::Duration;
|
||||
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue, rand_u32};
|
||||
|
||||
static PING_TIMES: LazyLock<DashMap<u32, Instant>> = LazyLock::new(|| DashMap::new());
|
||||
|
||||
impl OmikronConnection {
|
||||
pub async fn send_ping(&self) {
|
||||
let id = rand_u32();
|
||||
let id = rand::random();
|
||||
|
||||
PING_TIMES.insert(id, Instant::now());
|
||||
|
||||
PING_TIMES.retain(|_, v| v.elapsed() < Duration::from_secs(30));
|
||||
|
||||
let ping_message = CommunicationValue::new(CommunicationType::ping)
|
||||
let ping_message = CommunicationValue::new(CommunicationType::Ping)
|
||||
.with_id(id)
|
||||
.add_data(
|
||||
DataTypes::last_ping,
|
||||
DataValue::Array(vec![DataValue::Number(*self.last_ping.lock().await)]),
|
||||
.add_typed_default(
|
||||
DataType::LastPing,
|
||||
DataValue::Array(vec![DataValue::SignedNumber(*self.last_ping.lock().await as i128)]),
|
||||
);
|
||||
|
||||
self.send_message(&ping_message).await;
|
||||
|
|
|
|||
|
|
@ -6,16 +6,16 @@ use iota_storage::users::user_manager::{add_user, save_users};
|
|||
use iota_storage::users::user_profile::UserProfile;
|
||||
use iota_util::crypto_helper::public_key_to_base64;
|
||||
use iota_util::file_util::save_file;
|
||||
use mtp::codec::{CommunicationType, CommunicationValue, DataType, DataValue};
|
||||
use rand_core::{OsRng, RngCore};
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::time::Duration;
|
||||
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
|
||||
use x448::{PublicKey, Secret};
|
||||
|
||||
use crate::omikron_connection::OMIKRON_CONNECTION;
|
||||
|
||||
pub async fn create_user(username: &str) -> (Option<UserProfile>, Option<String>) {
|
||||
let register_communication_value = CommunicationValue::new(CommunicationType::get_register);
|
||||
let register_communication_value = CommunicationValue::new(CommunicationType::GetRegister);
|
||||
|
||||
let connection = OMIKRON_CONNECTION.clone();
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ pub async fn create_user(username: &str) -> (Option<UserProfile>, Option<String>
|
|||
log_cv!(PrintType::Omega, response_communication_value);
|
||||
|
||||
let user_id = match response_communication_value
|
||||
.get_data(DataTypes::user_id)
|
||||
.get_data(DataType::UserId)
|
||||
.as_number()
|
||||
{
|
||||
Some(id) => id,
|
||||
|
|
@ -57,7 +57,7 @@ pub async fn create_user(username: &str) -> (Option<UserProfile>, Option<String>
|
|||
let reset_token = STANDARD.encode(&bytes);
|
||||
|
||||
let user_profile = UserProfile::new(
|
||||
user_id,
|
||||
user_id as i64,
|
||||
username.to_string(),
|
||||
None,
|
||||
STANDARD.encode(&public_key.as_bytes()),
|
||||
|
|
@ -65,15 +65,15 @@ pub async fn create_user(username: &str) -> (Option<UserProfile>, Option<String>
|
|||
reset_token.clone(),
|
||||
);
|
||||
|
||||
let communication_value = CommunicationValue::new(CommunicationType::complete_register_user)
|
||||
.add_data(DataTypes::user_id, DataValue::Number(user_id))
|
||||
.add_data(DataTypes::username, DataValue::Str(username.to_string()))
|
||||
.add_data(
|
||||
DataTypes::public_key,
|
||||
let communication_value = CommunicationValue::new(CommunicationType::CompleteRegisterUser)
|
||||
.add_typed_default(DataType::UserId, DataValue::SignedNumber(user_id as i128))
|
||||
.add_typed_default(DataType::Username, DataValue::Str(username.to_string()))
|
||||
.add_typed_default(
|
||||
DataType::PublicKey,
|
||||
DataValue::Str(public_key_to_base64(&public_key)),
|
||||
)
|
||||
.add_data(DataTypes::iota_id, DataValue::Number(user_id))
|
||||
.add_data(DataTypes::reset_token, DataValue::Str(reset_token));
|
||||
.add_typed_default(DataType::IotaId, DataValue::SignedNumber(user_id as i128))
|
||||
.add_typed_default(DataType::ResetToken, DataValue::Str(reset_token));
|
||||
|
||||
let response_communication_value = connection
|
||||
.await_response(&communication_value, Some(Duration::from_secs(20)))
|
||||
|
|
@ -81,7 +81,7 @@ pub async fn create_user(username: &str) -> (Option<UserProfile>, Option<String>
|
|||
|
||||
if let Ok(response) = response_communication_value {
|
||||
log_cv!(PrintType::Omega, response);
|
||||
if !response.is_type(CommunicationType::success) {
|
||||
if !response.is_type(CommunicationType::Success) {
|
||||
return (None, None);
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue