[Fix] now correct iota ID loading
This commit is contained in:
parent
56d21b6d38
commit
75b0c05455
2 changed files with 62 additions and 80 deletions
18
Cargo.lock
generated
18
Cargo.lock
generated
|
|
@ -404,7 +404,7 @@ checksum = "c96bf972d85afc50bf5ab8fe2d54d1586b4e0b46c97c50a0c9e71e2f7bcd812a"
|
|||
dependencies = [
|
||||
"async-task",
|
||||
"concurrent-queue",
|
||||
"fastrand 2.4.0",
|
||||
"fastrand 2.4.1",
|
||||
"futures-lite 2.6.1",
|
||||
"pin-project-lite",
|
||||
"slab",
|
||||
|
|
@ -1088,9 +1088,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "2.4.0"
|
||||
version = "2.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a043dc74da1e37d6afe657061213aa6f425f855399a11d3463c6ecccc4dfda1f"
|
||||
checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6"
|
||||
|
||||
[[package]]
|
||||
name = "fiat-crypto"
|
||||
|
|
@ -1218,7 +1218,7 @@ version = "2.6.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad"
|
||||
dependencies = [
|
||||
"fastrand 2.4.0",
|
||||
"fastrand 2.4.1",
|
||||
"futures-core",
|
||||
"futures-io",
|
||||
"parking",
|
||||
|
|
@ -2196,7 +2196,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "c835479a4443ded371d6c535cbfd8d31ad92c5d23ae9770a61bc155e4992a3c1"
|
||||
dependencies = [
|
||||
"atomic-waker",
|
||||
"fastrand 2.4.0",
|
||||
"fastrand 2.4.1",
|
||||
"futures-io",
|
||||
]
|
||||
|
||||
|
|
@ -3376,9 +3376,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
|||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.51.0"
|
||||
version = "1.51.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2bd1c4c0fc4a7ab90fc15ef6daaa3ec3b893f004f915f2392557ed23237820cd"
|
||||
checksum = "f66bf9585cda4b724d3e78ab34b73fb2bbaba9011b9bfdf69dc836382ea13b8c"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"libc",
|
||||
|
|
@ -3511,7 +3511,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
|||
[[package]]
|
||||
name = "ttp-core"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.methanium.net/Tensamin/TTP.git#82b71c1be1fa73aeb0f228c4af364206fda8d712"
|
||||
source = "git+https://git.methanium.net/Tensamin/TTP.git#2322bdced8183e970405d5017cd87ba805309a4c"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"byteorder",
|
||||
|
|
@ -3523,7 +3523,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ttp-native"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.methanium.net/Tensamin/TTP.git#82b71c1be1fa73aeb0f228c4af364206fda8d712"
|
||||
source = "git+https://git.methanium.net/Tensamin/TTP.git#2322bdced8183e970405d5017cd87ba805309a4c"
|
||||
dependencies = [
|
||||
"quinn",
|
||||
"rustls",
|
||||
|
|
|
|||
|
|
@ -433,44 +433,40 @@ impl OmikronConnection {
|
|||
|
||||
async fn handle_iota_connected(self: Arc<Self>, cv: CommunicationValue, omikron_id: i64) {
|
||||
log_in!(PrintType::Omega, "IOTA connected");
|
||||
if let Some(iota_id) = cv.get_data(DataTypes::iota_id).as_number() {
|
||||
let iota_id = iota_id as i64;
|
||||
user_online_tracker::track_iota_connection(iota_id, omikron_id, true);
|
||||
let iota_id = cv.get_sender();
|
||||
let iota_id = iota_id as i64;
|
||||
user_online_tracker::track_iota_connection(iota_id, omikron_id, true);
|
||||
|
||||
let mut user_ids = Vec::new();
|
||||
if let Ok(users) = sql::get_users_by_iota_id(iota_id).await {
|
||||
for (user_id, _, _, _, _, _, _, _, _, _, _, _) in users {
|
||||
user_ids.push(DataValue::Number(user_id));
|
||||
user_online_tracker::track_user_status(
|
||||
user_id,
|
||||
UserStatus::user_offline,
|
||||
omikron_id,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
log_in!(PrintType::General, "SQL error loading users for IOTA");
|
||||
let mut user_ids = Vec::new();
|
||||
if let Ok(users) = sql::get_users_by_iota_id(iota_id).await {
|
||||
for (user_id, _, _, _, _, _, _, _, _, _, _, _) in users {
|
||||
user_ids.push(DataValue::Number(user_id));
|
||||
user_online_tracker::track_user_status(
|
||||
user_id,
|
||||
UserStatus::user_offline,
|
||||
omikron_id,
|
||||
);
|
||||
}
|
||||
|
||||
let response = CommunicationValue::new(CommunicationType::iota_user_data)
|
||||
.with_id(cv.get_id())
|
||||
.add_data(DataTypes::user_ids, DataValue::Array(user_ids));
|
||||
|
||||
let _ = self.send(&response).await;
|
||||
} else {
|
||||
log_in!(PrintType::General, "No IOTA ID found");
|
||||
log_in!(PrintType::General, "SQL error loading users for IOTA");
|
||||
}
|
||||
|
||||
let response = CommunicationValue::new(CommunicationType::iota_user_data)
|
||||
.with_id(cv.get_id())
|
||||
.add_data(DataTypes::user_ids, DataValue::Array(user_ids));
|
||||
|
||||
let _ = self.send(&response).await;
|
||||
}
|
||||
|
||||
async fn handle_iota_disconnected(self: Arc<Self>, cv: CommunicationValue, omikron_id: i64) {
|
||||
log_in!(PrintType::Omega, "IOTA disconnected");
|
||||
if let Some(iota_id) = cv.get_data(DataTypes::iota_id).as_number() {
|
||||
let iota_id = iota_id as i64;
|
||||
let iota_offline = user_online_tracker::untrack_iota_connection(iota_id, omikron_id);
|
||||
if iota_offline {
|
||||
if let Ok(users) = sql::get_users_by_iota_id(iota_id).await {
|
||||
let user_ids: Vec<i64> = users.iter().map(|u| u.0).collect();
|
||||
user_online_tracker::untrack_many_users(&user_ids);
|
||||
}
|
||||
let iota_id = cv.get_sender();
|
||||
let iota_id = iota_id as i64;
|
||||
let iota_offline = user_online_tracker::untrack_iota_connection(iota_id, omikron_id);
|
||||
if iota_offline {
|
||||
if let Ok(users) = sql::get_users_by_iota_id(iota_id).await {
|
||||
let user_ids: Vec<i64> = users.iter().map(|u| u.0).collect();
|
||||
user_online_tracker::untrack_many_users(&user_ids);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -616,14 +612,13 @@ impl OmikronConnection {
|
|||
|
||||
async fn handle_get_iota_data(self: Arc<Self>, cv: CommunicationValue) -> OmikronResult<()> {
|
||||
// Try by iota_id
|
||||
if let Some(iota_id) = cv.get_data(DataTypes::iota_id).as_number() {
|
||||
if let Ok((iota_id, public_key)) = get_iota_by_id(iota_id as i64).await {
|
||||
let response = self
|
||||
.clone()
|
||||
.build_iota_data_response(cv.get_id(), iota_id, public_key, None, None)
|
||||
.await;
|
||||
return self.send(&response).await;
|
||||
}
|
||||
let iota_id = cv.get_sender();
|
||||
if let Ok((iota_id, public_key)) = get_iota_by_id(iota_id as i64).await {
|
||||
let response = self
|
||||
.clone()
|
||||
.build_iota_data_response(cv.get_id(), iota_id, public_key, None, None)
|
||||
.await;
|
||||
return self.send(&response).await;
|
||||
}
|
||||
|
||||
// Try by user_id
|
||||
|
|
@ -780,19 +775,16 @@ impl OmikronConnection {
|
|||
.get_data(DataTypes::public_key)
|
||||
.as_str()
|
||||
.map(|s| s.to_string());
|
||||
let iota_id = cv
|
||||
.get_data(DataTypes::iota_id)
|
||||
.as_number()
|
||||
.map(|n| n as i64);
|
||||
let iota_id = cv.get_sender();
|
||||
let reset_token = cv
|
||||
.get_data(DataTypes::reset_token)
|
||||
.as_str()
|
||||
.map(|s| s.to_string());
|
||||
|
||||
if let (Some(uid), Some(uname), Some(pk), Some(iid), Some(rt)) =
|
||||
(user_id, username, public_key, iota_id, reset_token)
|
||||
if let (Some(uid), Some(uname), Some(pk), Some(rt)) =
|
||||
(user_id, username, public_key, reset_token)
|
||||
{
|
||||
match sql::register_complete_user(uid, uname, pk, iid, rt).await {
|
||||
match sql::register_complete_user(uid, uname, pk, iota_id as i64, rt).await {
|
||||
Ok(_) => {
|
||||
let response =
|
||||
CommunicationValue::new(CommunicationType::success).with_id(cv.get_id());
|
||||
|
|
@ -877,10 +869,8 @@ impl OmikronConnection {
|
|||
async fn handle_change_iota_data(self: Arc<Self>, cv: CommunicationValue) -> OmikronResult<()> {
|
||||
let user_id = cv.get_sender() as i64;
|
||||
|
||||
if let (Some(iota_id), Some(reset_token), Some(new_token)) = (
|
||||
cv.get_data(DataTypes::iota_id)
|
||||
.as_number()
|
||||
.map(|n| n as i64),
|
||||
if let (iota_id, Some(reset_token), Some(new_token)) = (
|
||||
cv.get_sender(),
|
||||
cv.get_data(DataTypes::reset_token).as_str(),
|
||||
cv.get_data(DataTypes::new_token).as_str(),
|
||||
) {
|
||||
|
|
@ -891,7 +881,7 @@ impl OmikronConnection {
|
|||
let mut success = true;
|
||||
let mut error_message = String::new();
|
||||
|
||||
if let Err(e) = sql::change_iota_id(user_id, iota_id).await {
|
||||
if let Err(e) = sql::change_iota_id(user_id, iota_id as i64).await {
|
||||
success = false;
|
||||
error_message = e.to_string();
|
||||
}
|
||||
|
|
@ -950,27 +940,19 @@ impl OmikronConnection {
|
|||
}
|
||||
|
||||
async fn handle_delete_iota(self: Arc<Self>, cv: CommunicationValue) -> OmikronResult<()> {
|
||||
if let Some(iota_id) = cv
|
||||
.get_data(DataTypes::iota_id)
|
||||
.as_number()
|
||||
.map(|n| n as i64)
|
||||
{
|
||||
match sql::delete_iota(iota_id).await {
|
||||
Ok(_) => {
|
||||
let response =
|
||||
CommunicationValue::new(CommunicationType::success).with_id(cv.get_id());
|
||||
self.send(&response).await
|
||||
}
|
||||
Err(e) => {
|
||||
let response = CommunicationValue::new(CommunicationType::error)
|
||||
.with_id(cv.get_id())
|
||||
.add_data(DataTypes::error_type, DataValue::Str(e.to_string()));
|
||||
self.send(&response).await
|
||||
}
|
||||
let iota_id = cv.get_sender();
|
||||
match sql::delete_iota(iota_id as i64).await {
|
||||
Ok(_) => {
|
||||
let response =
|
||||
CommunicationValue::new(CommunicationType::success).with_id(cv.get_id());
|
||||
self.send(&response).await
|
||||
}
|
||||
Err(e) => {
|
||||
let response = CommunicationValue::new(CommunicationType::error)
|
||||
.with_id(cv.get_id())
|
||||
.add_data(DataTypes::error_type, DataValue::Str(e.to_string()));
|
||||
self.send(&response).await
|
||||
}
|
||||
} else {
|
||||
self.send_error_response(cv.get_id(), CommunicationType::error_invalid_data)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue