use crate::engine::{
AnnounceAppData, AnnounceNow, AnnounceTarget, CommandId, PacketReceiptDelivered, PrnsCommand,
SendSinglePacketFailure,
};
pub use crate::engine::{DropRouteOutcome, DropRoutesViaOutcome};
use crate::identity::{
IdentityHash, MarkDestinationUsedOutcome, ReleaseDestinationOutcome, RetainDestinationOutcome,
RetainIdentityOutcome,
};
use crate::routing::links::LinkId;
use crate::wire::{DestinationHash, TransportId};
use super::request_endpoints::RespondToken;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ClearAnnounceQueuesOutcome {
pub dropped_announces: u32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SendError<F> {
PayloadTooLarge,
NodeStopped,
Busy,
Failed(F),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RoutingControlError {
NodeStopped,
Busy,
}
pub trait RoutingControl {
fn drop_route(
&self,
destination: DestinationHash,
) -> impl core::future::Future<Output = Result<DropRouteOutcome, RoutingControlError>> + Send;
fn drop_routes_via(
&self,
transport: TransportId,
) -> impl core::future::Future<Output = Result<DropRoutesViaOutcome, RoutingControlError>> + Send;
fn clear_announce_queues(
&self,
) -> impl core::future::Future<Output = Result<ClearAnnounceQueuesOutcome, RoutingControlError>> + Send;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DestinationIdentityRetentionControlError {
NodeStopped,
Busy,
}
pub trait DestinationIdentityRetentionControl {
fn mark_destination_used(
&self,
destination: DestinationHash,
) -> impl core::future::Future<
Output = Result<MarkDestinationUsedOutcome, DestinationIdentityRetentionControlError>,
> + Send;
fn retain_destination(
&self,
destination: DestinationHash,
) -> impl core::future::Future<
Output = Result<RetainDestinationOutcome, DestinationIdentityRetentionControlError>,
> + Send;
fn release_destination(
&self,
destination: DestinationHash,
) -> impl core::future::Future<
Output = Result<ReleaseDestinationOutcome, DestinationIdentityRetentionControlError>,
> + Send;
fn retain_identity(
&self,
identity: IdentityHash,
) -> impl core::future::Future<
Output = Result<RetainIdentityOutcome, DestinationIdentityRetentionControlError>,
> + Send;
}
#[allow(async_fn_in_trait)]
pub trait PrnsNodeApi {
fn issue(&self, command: PrnsCommand) -> Option<CommandId>;
fn announce(&self, destination: DestinationHash) -> Option<CommandId> {
self.issue(PrnsCommand::AnnounceNow(AnnounceNow {
destination,
target: AnnounceTarget::AllInterfaces,
app_data: AnnounceAppData::Registered,
}))
}
async fn send_single_packet(
&self,
destination: DestinationHash,
data: &[u8],
) -> Result<PacketReceiptDelivered, SendError<SendSinglePacketFailure>>;
fn respond_packed(&self, responder: RespondToken, packed: &[u8]) -> bool;
fn close_link(&self, link_id: LinkId) -> bool;
}