pub mod akka_protocol;
mod failure_injector;
mod tcp;
mod test_transport;
mod throttle;
pub use akka_protocol::AkkaProtocolTransport;
pub use failure_injector::{FailureInjectorTransport, InjectionMode};
pub use tcp::TcpTransport;
pub use test_transport::TestTransport;
pub use throttle::{ThrottleMode, ThrottleTransport};
use async_trait::async_trait;
use thiserror::Error;
use tokio::sync::mpsc;
use atomr_core::actor::Address;
use crate::pdu::AkkaPdu;
#[derive(Debug, Error)]
pub enum TransportError {
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("codec: {0}")]
Codec(#[from] crate::codec::CodecError),
#[error("not associated with `{0}`")]
NotAssociated(String),
#[error("transport closed")]
Closed,
#[error("handshake rejected: {0}")]
HandshakeRejected(String),
#[error("transport-specific: {0}")]
Other(String),
}
#[derive(Debug)]
pub struct InboundFrame {
pub from: Address,
pub pdu: AkkaPdu,
}
#[async_trait]
pub trait Transport: Send + Sync {
async fn listen(&self) -> Result<Address, TransportError>;
async fn associate(&self, target: &Address) -> Result<(), TransportError>;
async fn send(&self, target: &Address, pdu: AkkaPdu) -> Result<(), TransportError>;
fn inbound(&self) -> mpsc::UnboundedReceiver<InboundFrame>;
async fn disassociate(&self, target: &Address) -> Result<(), TransportError>;
async fn shutdown(&self) -> Result<(), TransportError>;
}