Reconnection
This commit is contained in:
parent
e07ea9ea7e
commit
b910178f35
6 changed files with 32 additions and 25 deletions
|
|
@ -210,7 +210,7 @@ impl Community {
|
||||||
for interactable in target_interactables.iter() {
|
for interactable in target_interactables.iter() {
|
||||||
if interactable.get_name() == name {
|
if interactable.get_name() == name {
|
||||||
if interactable.get_codec() == "category" {
|
if interactable.get_codec() == "category" {
|
||||||
return CommunicationValue::new(CommunicationType::error);
|
return CommunicationValue::new(CommunicationType::error_internal);
|
||||||
} else {
|
} else {
|
||||||
// cannot move a value of type dyn Interactable the size of dyn Interactable cannot be statically determined (rustc E0161)
|
// 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;
|
return interactable.run_function(cv.clone()).await;
|
||||||
|
|
@ -231,7 +231,7 @@ impl Community {
|
||||||
.run_function(cv.clone())
|
.run_function(cv.clone())
|
||||||
.await;
|
.await;
|
||||||
} else {
|
} else {
|
||||||
return CommunicationValue::new(CommunicationType::error);
|
return CommunicationValue::new(CommunicationType::error_internal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ impl CommunityConnection {
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(community) = self.community.read().await.clone() else {
|
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;
|
.await;
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
@ -178,7 +178,7 @@ impl CommunityConnection {
|
||||||
let shared_secret = match community_private_key.to_diffie_hellman(&user_pub_key) {
|
let shared_secret = match community_private_key.to_diffie_hellman(&user_pub_key) {
|
||||||
Some(secret) => secret,
|
Some(secret) => secret,
|
||||||
_ => {
|
_ => {
|
||||||
self.send_error_response(&cv.get_id(), CommunicationType::error)
|
self.send_error_response(&cv.get_id(), CommunicationType::error_internal)
|
||||||
.await;
|
.await;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -200,7 +200,7 @@ impl CommunityConnection {
|
||||||
let encrypted_challenge = match cipher.encrypt(nonce, challenge_str.as_bytes()) {
|
let encrypted_challenge = match cipher.encrypt(nonce, challenge_str.as_bytes()) {
|
||||||
Ok(data) => data,
|
Ok(data) => data,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
self.send_error_response(&cv.get_id(), CommunicationType::error)
|
self.send_error_response(&cv.get_id(), CommunicationType::error_internal)
|
||||||
.await;
|
.await;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -223,7 +223,7 @@ impl CommunityConnection {
|
||||||
let client_challenge_response_b64 = match cv.get_data(DataTypes::challenge) {
|
let client_challenge_response_b64 = match cv.get_data(DataTypes::challenge) {
|
||||||
Some(data) => data.to_string(),
|
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;
|
.await;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -232,38 +232,38 @@ impl CommunityConnection {
|
||||||
let challenge_response_bytes = match STANDARD.decode(&client_challenge_response_b64) {
|
let challenge_response_bytes = match STANDARD.decode(&client_challenge_response_b64) {
|
||||||
Ok(bytes) => bytes,
|
Ok(bytes) => bytes,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
self.send_error_response(&cv.get_id(), CommunicationType::error)
|
self.send_error_response(&cv.get_id(), CommunicationType::error_invalid_data)
|
||||||
.await;
|
.await;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if challenge_response_bytes.len() < 12 {
|
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;
|
.await;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some(user) = self.auth.read().await.clone() else {
|
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;
|
.await;
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(user_pub_bytes) = STANDARD.decode(&user.public_key).ok() else {
|
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;
|
.await;
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(user_pub_key) = PublicKey::from_bytes(&user_pub_bytes) else {
|
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;
|
.await;
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(community) = self.community.read().await.clone() else {
|
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;
|
.await;
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
@ -273,7 +273,7 @@ impl CommunityConnection {
|
||||||
let shared_secret = match community_private_key.to_diffie_hellman(&user_pub_key) {
|
let shared_secret = match community_private_key.to_diffie_hellman(&user_pub_key) {
|
||||||
Some(secret) => secret,
|
Some(secret) => secret,
|
||||||
_ => {
|
_ => {
|
||||||
self.send_error_response(&cv.get_id(), CommunicationType::error)
|
self.send_error_response(&cv.get_id(), CommunicationType::error_internal)
|
||||||
.await;
|
.await;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -297,7 +297,7 @@ impl CommunityConnection {
|
||||||
let decrypted_bytes = match cipher.decrypt(nonce, ciphertext) {
|
let decrypted_bytes = match cipher.decrypt(nonce, ciphertext) {
|
||||||
Ok(pt) => pt,
|
Ok(pt) => pt,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
self.send_error_response(&cv.get_id(), CommunicationType::error)
|
self.send_error_response(&cv.get_id(), CommunicationType::error_invalid_challenge)
|
||||||
.await;
|
.await;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -306,7 +306,7 @@ impl CommunityConnection {
|
||||||
let client_response = match String::from_utf8(decrypted_bytes) {
|
let client_response = match String::from_utf8(decrypted_bytes) {
|
||||||
Ok(str) => str,
|
Ok(str) => str,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
self.send_error_response(&cv.get_id(), CommunicationType::error)
|
self.send_error_response(&cv.get_id(), CommunicationType::error_invalid_data)
|
||||||
.await;
|
.await;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -315,7 +315,7 @@ impl CommunityConnection {
|
||||||
let expected_challenge = self.challenge.read().await.clone();
|
let expected_challenge = self.challenge.read().await.clone();
|
||||||
|
|
||||||
if client_response != expected_challenge {
|
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;
|
.await;
|
||||||
self.close().await;
|
self.close().await;
|
||||||
return;
|
return;
|
||||||
|
|
@ -327,7 +327,7 @@ impl CommunityConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some(community) = self.community.read().await.clone() else {
|
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;
|
.await;
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
@ -335,7 +335,7 @@ impl CommunityConnection {
|
||||||
|
|
||||||
let user_id = self.get_user_id().await;
|
let user_id = self.get_user_id().await;
|
||||||
if user_id == 0 {
|
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;
|
.await;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ impl Interactable for Category {
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
async fn run_function(&self, _cv: CommunicationValue) -> CommunicationValue {
|
async fn run_function(&self, _cv: CommunicationValue) -> CommunicationValue {
|
||||||
CommunicationValue::new(CommunicationType::error)
|
CommunicationValue::new(CommunicationType::error_internal)
|
||||||
}
|
}
|
||||||
fn to_json(&self) -> JsonValue {
|
fn to_json(&self) -> JsonValue {
|
||||||
let mut v = JsonValue::new_object();
|
let mut v = JsonValue::new_object();
|
||||||
|
|
|
||||||
|
|
@ -243,7 +243,7 @@ impl Interactable for TextChat {
|
||||||
.add_data_str(DataTypes::result, "message_received".to_string())
|
.add_data_str(DataTypes::result, "message_received".to_string())
|
||||||
.add_data(DataTypes::payload, JsonValue::new_object());
|
.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 {
|
fn to_json(&self) -> JsonValue {
|
||||||
JsonValue::new_object()
|
JsonValue::new_object()
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ impl Interactable for VoiceChat {
|
||||||
.add_data_str(DataTypes::result, "user_changed".to_string())
|
.add_data_str(DataTypes::result, "user_changed".to_string())
|
||||||
.add_data(DataTypes::payload, response_payload);
|
.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 {
|
fn to_json(&self) -> JsonValue {
|
||||||
|
|
|
||||||
|
|
@ -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_id(cv.get_id())
|
||||||
.with_receiver(sender_id);
|
.with_receiver(sender_id);
|
||||||
self.send_message(&res).await;
|
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_id(cv.get_id())
|
||||||
.with_receiver(sender_id);
|
.with_receiver(sender_id);
|
||||||
self.send_message(&res).await;
|
self.send_message(&res).await;
|
||||||
|
|
@ -1475,7 +1475,7 @@ impl OmikronConnection {
|
||||||
|
|
||||||
for key in keys {
|
for key in keys {
|
||||||
if let Some((_, waiting_task)) = WAITING_TASKS.remove(&key) {
|
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)
|
.with_id(key)
|
||||||
.add_data(DataTypes::message, DataValue::Str(reason.clone()));
|
.add_data(DataTypes::message, DataValue::Str(reason.clone()));
|
||||||
let _ = (waiting_task.task)(OMIKRON_CONNECTION.clone(), response);
|
let _ = (waiting_task.task)(OMIKRON_CONNECTION.clone(), response);
|
||||||
|
|
@ -1525,7 +1525,14 @@ impl OmikronConnection {
|
||||||
|
|
||||||
match tokio::time::timeout(timeout, rx.recv()).await {
|
match tokio::time::timeout(timeout, rx.recv()).await {
|
||||||
Ok(Some(response_cv)) => {
|
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
|
let reason = response_cv
|
||||||
.get_data(DataTypes::message)
|
.get_data(DataTypes::message)
|
||||||
.as_str()
|
.as_str()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue