Compare commits

...

1 Commits

Author SHA1 Message Date
Jon Häggblad 0b5d38094f wip 2024-03-08 21:40:05 +01:00
5 changed files with 51 additions and 3 deletions
+12
View File
@@ -4,6 +4,7 @@
use crate::client::mix_traffic::transceiver::ErasedGatewayError;
use nym_crypto::asymmetric::identity::Ed25519RecoveryError;
use nym_gateway_client::error::GatewayClientError;
use nym_task::manager::TaskStatusTrait;
use nym_topology::gateway::GatewayConversionError;
use nym_topology::NymTopologyError;
use nym_validator_client::ValidatorClientError;
@@ -165,3 +166,14 @@ pub enum ClientCoreStatusMessage {
#[error("The connected gateway is very slow, or the connection to it is very slow")]
GatewayIsVerySlow,
}
// impl TaskStatusTrait for ClientCoreStatusMessage {}
// impl<T: std::fmt::Debug + std::fmt::Display + Send + Sync + Any + 'static> TaskStatusTrait for T {
// fn as_any(&self) -> &dyn Any {
// self
// }
//
// fn as_any_mut(&mut self) -> &mut dyn Any {
// self
// }
// }
+9
View File
@@ -1,6 +1,7 @@
use crate::socks::types::SocksProxyError;
use nym_client_core::error::ClientCoreError;
use nym_socks5_requests::{ConnectionError, ConnectionId};
use nym_task::manager::TaskStatusTrait;
#[derive(thiserror::Error, Debug)]
pub enum Socks5ClientCoreError {
@@ -20,6 +21,14 @@ pub enum Socks5ClientCoreError {
},
}
#[derive(thiserror::Error, Debug)]
pub enum Socks5ClientCoreStatusMessage {
#[error(transparent)]
Socks5Error(#[from] Socks5ClientCoreError),
}
// impl TaskStatusTrait for Socks5ClientCoreStatusMessage {}
impl From<ConnectionError> for Socks5ClientCoreError {
fn from(value: ConnectionError) -> Self {
Socks5ClientCoreError::NetworkRequesterError {
@@ -1,7 +1,7 @@
// Copyright 2020-2023 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use crate::error::Socks5ClientCoreError;
use crate::error::{Socks5ClientCoreError, Socks5ClientCoreStatusMessage};
use futures::channel::mpsc;
use futures::StreamExt;
use log::*;
@@ -136,7 +136,8 @@ impl MixnetResponseListener {
if let Some(received_responses) = received_responses {
for reconstructed_message in received_responses {
if let Err(err) = self.on_message(reconstructed_message) {
self.shutdown.send_status_msg(Box::new(err));
let msg = Socks5ClientCoreStatusMessage::from(err);
self.shutdown.send_status_msg(Box::new(msg));
}
}
} else {
+26 -1
View File
@@ -3,6 +3,7 @@
use futures::{future::pending, FutureExt, SinkExt, StreamExt};
use log::{log, Level};
use std::any::Any;
use std::future::Future;
use std::sync::atomic::{AtomicBool, Ordering};
use std::{error::Error, time::Duration};
@@ -23,7 +24,7 @@ pub(crate) type SentError = Box<dyn Error + Send + Sync>;
type ErrorSender = mpsc::UnboundedSender<SentError>;
type ErrorReceiver = mpsc::UnboundedReceiver<SentError>;
pub type SentStatus = Box<dyn Error + Send + Sync>;
pub type SentStatus = Box<dyn TaskStatusTrait + Send + Sync>;
pub type StatusSender = futures::channel::mpsc::Sender<SentStatus>;
pub type StatusReceiver = futures::channel::mpsc::Receiver<SentStatus>;
@@ -48,6 +49,30 @@ pub enum TaskStatus {
Ready,
}
pub trait TaskStatusTrait:
std::fmt::Debug + std::fmt::Display + Send + Sync + 'static + Any
{
// As Any requires 'static, it implicitly enforces the 'static lifetime here as well.
// This method tries to cast the trait object back to a reference of its concrete type.
fn as_any(&self) -> &dyn Any;
// Optionally, for downcasting to mutable references.
fn as_any_mut(&mut self) -> &mut dyn Any;
}
impl<T: std::fmt::Debug + std::fmt::Display + Send + Sync + Any + 'static> TaskStatusTrait for T {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
// impl TaskStatusTrait for TaskStatus {}
/// Listens to status and error messages from tasks, as well as notifying them to gracefully
/// shutdown. Keeps track of if task stop unexpectedly, such as in a panic.
#[derive(Debug)]
+1
View File
@@ -655,6 +655,7 @@ where
.next()
.await
.ok_or(Error::Socks5NotStarted)?
.as_any()
.downcast_ref::<TaskStatus>()
.ok_or(Error::Socks5NotStarted)?
{