Skip to main content

prns_runtime/runtime/
identity_blackhole.rs

1use crate::identity::IdentityHash;
2use crate::routing::{
3    BlackholeIdentityOutcome, BlackholeInsertFailure, BlackholedIdentity,
4    UnblackholeIdentityOutcome,
5};
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum IdentityBlackholeSourceError {
9    NodeStopped,
10    Busy,
11}
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub enum IdentityBlackholeControlError {
15    NodeStopped,
16    Busy,
17    CapacityExhausted,
18    ReasonTooLong,
19    DurabilityFailed,
20}
21
22impl From<BlackholeInsertFailure> for IdentityBlackholeControlError {
23    fn from(failure: BlackholeInsertFailure) -> Self {
24        match failure {
25            BlackholeInsertFailure::CapacityExhausted => Self::CapacityExhausted,
26            BlackholeInsertFailure::ReasonTooLong => Self::ReasonTooLong,
27        }
28    }
29}
30
31pub trait IdentityBlackholeSource {
32    type Reason: AsRef<str> + Send;
33    type Entries: IntoIterator<Item = BlackholedIdentity<Self::Reason>> + Send;
34
35    fn blackholed_identities(
36        &self,
37    ) -> impl core::future::Future<Output = Result<Self::Entries, IdentityBlackholeSourceError>> + Send;
38
39    fn is_blackholed(
40        &self,
41        identity: IdentityHash,
42    ) -> impl core::future::Future<Output = Result<bool, IdentityBlackholeSourceError>> + Send;
43}
44
45pub trait IdentityBlackholeControl {
46    fn blackhole_identity<'a>(
47        &'a self,
48        entry: BlackholedIdentity<&'a str>,
49    ) -> impl core::future::Future<
50        Output = Result<BlackholeIdentityOutcome, IdentityBlackholeControlError>,
51    > + Send
52           + 'a;
53
54    fn unblackhole_identity(
55        &self,
56        identity: IdentityHash,
57    ) -> impl core::future::Future<
58        Output = Result<UnblackholeIdentityOutcome, IdentityBlackholeControlError>,
59    > + Send;
60}