use crate::outbound::message::SendFailure;
use futures::channel::mpsc::SendError;
use tari_comms::message::MessageError;
use tari_crypto::{
signatures::SchnorrSignatureError,
tari_utilities::{ciphers::cipher::CipherError, message_format::MessageFormatError},
};
use thiserror::Error;
#[derive(Debug, Error)]
pub enum DhtOutboundError {
#[error("SendError: {0}")]
SendError(#[from] SendError),
#[error("MessageSerializationError: {0}")]
MessageSerializationError(#[from] MessageError),
#[error("MessageFormatError: {0}")]
MessageFormatError(#[from] MessageFormatError),
#[error("SignatureError: {0}")]
SignatureError(#[from] SchnorrSignatureError),
#[error("CipherError: {0}")]
CipherError(#[from] CipherError),
#[error("Requester reply channel closed before response was received")]
RequesterReplyChannelClosed,
#[error("Peer selection failed")]
PeerSelectionFailed,
#[error("Failed to send broadcast message")]
BroadcastFailed,
#[error("Reply channel cancelled")]
ReplyChannelCanceled,
#[error("Attempted to send a message to ourselves")]
SendToOurselves,
#[error("Discovery process failed")]
DiscoveryFailed,
#[error("Failed to insert message hash")]
FailedToInsertMessageHash,
#[error("Failed to send message: {0}")]
SendMessageFailed(SendFailure),
#[error("No messages were queued for sending")]
NoMessagesQueued,
}
impl From<SendFailure> for DhtOutboundError {
fn from(err: SendFailure) -> Self {
match err {
SendFailure::NoMessagesQueued => DhtOutboundError::NoMessagesQueued,
err => Self::SendMessageFailed(err),
}
}
}