Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0b5d38094f |
@@ -4,6 +4,7 @@
|
|||||||
use crate::client::mix_traffic::transceiver::ErasedGatewayError;
|
use crate::client::mix_traffic::transceiver::ErasedGatewayError;
|
||||||
use nym_crypto::asymmetric::identity::Ed25519RecoveryError;
|
use nym_crypto::asymmetric::identity::Ed25519RecoveryError;
|
||||||
use nym_gateway_client::error::GatewayClientError;
|
use nym_gateway_client::error::GatewayClientError;
|
||||||
|
use nym_task::manager::TaskStatusTrait;
|
||||||
use nym_topology::gateway::GatewayConversionError;
|
use nym_topology::gateway::GatewayConversionError;
|
||||||
use nym_topology::NymTopologyError;
|
use nym_topology::NymTopologyError;
|
||||||
use nym_validator_client::ValidatorClientError;
|
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")]
|
#[error("The connected gateway is very slow, or the connection to it is very slow")]
|
||||||
GatewayIsVerySlow,
|
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
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use crate::socks::types::SocksProxyError;
|
use crate::socks::types::SocksProxyError;
|
||||||
use nym_client_core::error::ClientCoreError;
|
use nym_client_core::error::ClientCoreError;
|
||||||
use nym_socks5_requests::{ConnectionError, ConnectionId};
|
use nym_socks5_requests::{ConnectionError, ConnectionId};
|
||||||
|
use nym_task::manager::TaskStatusTrait;
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
pub enum Socks5ClientCoreError {
|
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 {
|
impl From<ConnectionError> for Socks5ClientCoreError {
|
||||||
fn from(value: ConnectionError) -> Self {
|
fn from(value: ConnectionError) -> Self {
|
||||||
Socks5ClientCoreError::NetworkRequesterError {
|
Socks5ClientCoreError::NetworkRequesterError {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright 2020-2023 - Nym Technologies SA <contact@nymtech.net>
|
// Copyright 2020-2023 - Nym Technologies SA <contact@nymtech.net>
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
use crate::error::Socks5ClientCoreError;
|
use crate::error::{Socks5ClientCoreError, Socks5ClientCoreStatusMessage};
|
||||||
use futures::channel::mpsc;
|
use futures::channel::mpsc;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use log::*;
|
use log::*;
|
||||||
@@ -136,7 +136,8 @@ impl MixnetResponseListener {
|
|||||||
if let Some(received_responses) = received_responses {
|
if let Some(received_responses) = received_responses {
|
||||||
for reconstructed_message in received_responses {
|
for reconstructed_message in received_responses {
|
||||||
if let Err(err) = self.on_message(reconstructed_message) {
|
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 {
|
} else {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
use futures::{future::pending, FutureExt, SinkExt, StreamExt};
|
use futures::{future::pending, FutureExt, SinkExt, StreamExt};
|
||||||
use log::{log, Level};
|
use log::{log, Level};
|
||||||
|
use std::any::Any;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::{error::Error, time::Duration};
|
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 ErrorSender = mpsc::UnboundedSender<SentError>;
|
||||||
type ErrorReceiver = mpsc::UnboundedReceiver<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 StatusSender = futures::channel::mpsc::Sender<SentStatus>;
|
||||||
pub type StatusReceiver = futures::channel::mpsc::Receiver<SentStatus>;
|
pub type StatusReceiver = futures::channel::mpsc::Receiver<SentStatus>;
|
||||||
|
|
||||||
@@ -48,6 +49,30 @@ pub enum TaskStatus {
|
|||||||
Ready,
|
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
|
/// 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.
|
/// shutdown. Keeps track of if task stop unexpectedly, such as in a panic.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|||||||
@@ -655,6 +655,7 @@ where
|
|||||||
.next()
|
.next()
|
||||||
.await
|
.await
|
||||||
.ok_or(Error::Socks5NotStarted)?
|
.ok_or(Error::Socks5NotStarted)?
|
||||||
|
.as_any()
|
||||||
.downcast_ref::<TaskStatus>()
|
.downcast_ref::<TaskStatus>()
|
||||||
.ok_or(Error::Socks5NotStarted)?
|
.ok_or(Error::Socks5NotStarted)?
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user