Reconnection

This commit is contained in:
Alex Emmet 2026-05-21 23:26:16 +02:00
commit b910178f35
6 changed files with 32 additions and 25 deletions

View file

@ -210,7 +210,7 @@ impl Community {
for interactable in target_interactables.iter() {
if interactable.get_name() == name {
if interactable.get_codec() == "category" {
return CommunicationValue::new(CommunicationType::error);
return CommunicationValue::new(CommunicationType::error_internal);
} else {
// cannot move a value of type dyn Interactable the size of dyn Interactable cannot be statically determined (rustc E0161)
return interactable.run_function(cv.clone()).await;
@ -231,7 +231,7 @@ impl Community {
.run_function(cv.clone())
.await;
} else {
return CommunicationValue::new(CommunicationType::error);
return CommunicationValue::new(CommunicationType::error_internal);
}
}
}

View file

@ -167,7 +167,7 @@ impl CommunityConnection {
};
let Some(community) = self.community.read().await.clone() else {
self.send_error_response(&cv.get_id(), CommunicationType::error)
self.send_error_response(&cv.get_id(), CommunicationType::error_internal)
.await;
return;
};
@ -178,7 +178,7 @@ impl CommunityConnection {
let shared_secret = match community_private_key.to_diffie_hellman(&user_pub_key) {
Some(secret) => secret,
_ => {
self.send_error_response(&cv.get_id(), CommunicationType::error)
self.send_error_response(&cv.get_id(), CommunicationType::error_internal)
.await;
return;
}
@ -200,7 +200,7 @@ impl CommunityConnection {
let encrypted_challenge = match cipher.encrypt(nonce, challenge_str.as_bytes()) {
Ok(data) => data,
Err(_) => {
self.send_error_response(&cv.get_id(), CommunicationType::error)
self.send_error_response(&cv.get_id(), CommunicationType::error_internal)
.await;
return;
}
@ -223,7 +223,7 @@ impl CommunityConnection {
let client_challenge_response_b64 = match cv.get_data(DataTypes::challenge) {
Some(data) => data.to_string(),
_ => {
self.send_error_response(&cv.get_id(), CommunicationType::error)
self.send_error_response(&cv.get_id(), CommunicationType::error_invalid_data)
.await;
return;
}
@ -232,38 +232,38 @@ impl CommunityConnection {
let challenge_response_bytes = match STANDARD.decode(&client_challenge_response_b64) {
Ok(bytes) => bytes,
Err(_) => {
self.send_error_response(&cv.get_id(), CommunicationType::error)
self.send_error_response(&cv.get_id(), CommunicationType::error_invalid_data)
.await;
return;
}
};
if challenge_response_bytes.len() < 12 {
self.send_error_response(&cv.get_id(), CommunicationType::error)
self.send_error_response(&cv.get_id(), CommunicationType::error_invalid_data)
.await;
return;
}
let Some(user) = self.auth.read().await.clone() else {
self.send_error_response(&cv.get_id(), CommunicationType::error)
self.send_error_response(&cv.get_id(), CommunicationType::error_internal)
.await;
return;
};
let Some(user_pub_bytes) = STANDARD.decode(&user.public_key).ok() else {
self.send_error_response(&cv.get_id(), CommunicationType::error)
self.send_error_response(&cv.get_id(), CommunicationType::error_invalid_data)
.await;
return;
};
let Some(user_pub_key) = PublicKey::from_bytes(&user_pub_bytes) else {
self.send_error_response(&cv.get_id(), CommunicationType::error)
self.send_error_response(&cv.get_id(), CommunicationType::error_invalid_public_key)
.await;
return;
};
let Some(community) = self.community.read().await.clone() else {
self.send_error_response(&cv.get_id(), CommunicationType::error)
self.send_error_response(&cv.get_id(), CommunicationType::error_internal)
.await;
return;
};
@ -273,7 +273,7 @@ impl CommunityConnection {
let shared_secret = match community_private_key.to_diffie_hellman(&user_pub_key) {
Some(secret) => secret,
_ => {
self.send_error_response(&cv.get_id(), CommunicationType::error)
self.send_error_response(&cv.get_id(), CommunicationType::error_internal)
.await;
return;
}
@ -297,7 +297,7 @@ impl CommunityConnection {
let decrypted_bytes = match cipher.decrypt(nonce, ciphertext) {
Ok(pt) => pt,
Err(_) => {
self.send_error_response(&cv.get_id(), CommunicationType::error)
self.send_error_response(&cv.get_id(), CommunicationType::error_invalid_challenge)
.await;
return;
}
@ -306,7 +306,7 @@ impl CommunityConnection {
let client_response = match String::from_utf8(decrypted_bytes) {
Ok(str) => str,
Err(_) => {
self.send_error_response(&cv.get_id(), CommunicationType::error)
self.send_error_response(&cv.get_id(), CommunicationType::error_invalid_data)
.await;
return;
}
@ -315,7 +315,7 @@ impl CommunityConnection {
let expected_challenge = self.challenge.read().await.clone();
if client_response != expected_challenge {
self.send_error_response(&cv.get_id(), CommunicationType::error)
self.send_error_response(&cv.get_id(), CommunicationType::error_invalid_challenge)
.await;
self.close().await;
return;
@ -327,7 +327,7 @@ impl CommunityConnection {
}
let Some(community) = self.community.read().await.clone() else {
self.send_error_response(&cv.get_id(), CommunicationType::error)
self.send_error_response(&cv.get_id(), CommunicationType::error_internal)
.await;
return;
};
@ -335,7 +335,7 @@ impl CommunityConnection {
let user_id = self.get_user_id().await;
if user_id == 0 {
self.send_error_response(&cv.get_id(), CommunicationType::error)
self.send_error_response(&cv.get_id(), CommunicationType::error_invalid_user_id)
.await;
return;
}

View file

@ -95,7 +95,7 @@ impl Interactable for Category {
v
}
async fn run_function(&self, _cv: CommunicationValue) -> CommunicationValue {
CommunicationValue::new(CommunicationType::error)
CommunicationValue::new(CommunicationType::error_internal)
}
fn to_json(&self) -> JsonValue {
let mut v = JsonValue::new_object();

View file

@ -243,7 +243,7 @@ impl Interactable for TextChat {
.add_data_str(DataTypes::result, "message_received".to_string())
.add_data(DataTypes::payload, JsonValue::new_object());
}
CommunicationValue::new(CommunicationType::error).with_id(cv.get_id())
CommunicationValue::new(CommunicationType::error_internal).with_id(cv.get_id())
}
fn to_json(&self) -> JsonValue {
JsonValue::new_object()

View file

@ -164,7 +164,7 @@ impl Interactable for VoiceChat {
.add_data_str(DataTypes::result, "user_changed".to_string())
.add_data(DataTypes::payload, response_payload);
}
CommunicationValue::new(CommunicationType::error).with_id(cv.get_id())
CommunicationValue::new(CommunicationType::error_internal).with_id(cv.get_id())
}
fn to_json(&self) -> JsonValue {

View file

@ -536,7 +536,7 @@ impl OmikronConnection {
}
}
let res = CommunicationValue::new(CommunicationType::error)
let res = CommunicationValue::new(CommunicationType::error_invalid_challenge)
.with_id(cv.get_id())
.with_receiver(sender_id);
self.send_message(&res).await;
@ -558,7 +558,7 @@ impl OmikronConnection {
}
}
}
let res = CommunicationValue::new(CommunicationType::error)
let res = CommunicationValue::new(CommunicationType::error_invalid_challenge)
.with_id(cv.get_id())
.with_receiver(sender_id);
self.send_message(&res).await;
@ -1475,7 +1475,7 @@ impl OmikronConnection {
for key in keys {
if let Some((_, waiting_task)) = WAITING_TASKS.remove(&key) {
let response = CommunicationValue::new(CommunicationType::error)
let response = CommunicationValue::new(CommunicationType::error_internal)
.with_id(key)
.add_data(DataTypes::message, DataValue::Str(reason.clone()));
let _ = (waiting_task.task)(OMIKRON_CONNECTION.clone(), response);
@ -1525,7 +1525,14 @@ impl OmikronConnection {
match tokio::time::timeout(timeout, rx.recv()).await {
Ok(Some(response_cv)) => {
if response_cv.is_type(CommunicationType::error) {
let resp_type = response_cv.get_type();
let is_error = resp_type == CommunicationType::error
|| resp_type == CommunicationType::error_internal
|| resp_type == CommunicationType::error_not_found
|| resp_type == CommunicationType::error_invalid_data
|| resp_type == CommunicationType::error_invalid_challenge
|| resp_type == CommunicationType::error_not_authenticated;
if is_error {
let reason = response_cv
.get_data(DataTypes::message)
.as_str()