pub mod actor;
pub mod event;
pub(crate) mod wire;
pub use wire::WireDhtOpData;
pub use wire::WireMessage;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum HolochainP2pError {
#[error(transparent)]
K2Error(#[from] kitsune2_api::K2Error),
#[error("Routing Dna Error: {0}")]
RoutingDnaError(holo_hash::DnaHash),
#[error("Routing Agent Error: {0}")]
RoutingAgentError(holo_hash::AgentPubKey),
#[error("InvalidP2pMessage: {0}")]
InvalidP2pMessage(String),
#[error("{0}: No peers available for DHT location: {1}")]
NoPeersForLocation(String, u32),
#[error("Other: {0}")]
Other(Box<dyn std::error::Error + Send + Sync>),
#[error(transparent)]
ChcError(#[from] holochain_chc::ChcError),
}
pub type HolochainP2pResult<T> = std::result::Result<T, HolochainP2pError>;
impl HolochainP2pError {
pub fn other(e: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Self {
Self::Other(e.into())
}
pub fn invalid_p2p_message(s: String) -> Self {
Self::InvalidP2pMessage(s)
}
}
impl From<String> for HolochainP2pError {
fn from(s: String) -> Self {
#[derive(Debug, thiserror::Error)]
struct OtherError(String);
impl std::fmt::Display for OtherError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
HolochainP2pError::other(OtherError(s))
}
}
impl From<&str> for HolochainP2pError {
fn from(s: &str) -> Self {
s.to_string().into()
}
}