use super::error::NetworkResult;
use super::lane::DataLane;
use super::wire_pool::ConnType;
use actr_protocol::{ActrId, PayloadType};
use async_trait::async_trait;
use std::sync::Arc;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum WireIdentity {
WebRtc { peer_id: ActrId, session_id: u64 },
}
#[async_trait]
pub trait WireHandle: Send + Sync + std::fmt::Debug {
fn connection_type(&self) -> ConnType;
#[allow(dead_code)]
fn priority(&self) -> u8;
async fn connect(&self) -> NetworkResult<()>;
#[allow(dead_code)]
fn is_connected(&self) -> bool;
async fn close(&self) -> NetworkResult<()>;
async fn get_lane(&self, payload_type: PayloadType) -> NetworkResult<Arc<dyn DataLane>>;
async fn invalidate_lane(&self, _payload_type: PayloadType) {}
fn identity(&self) -> Option<WireIdentity> {
None
}
}
#[derive(Debug)]
pub enum WireStatus {
Connecting,
Ready(Arc<dyn WireHandle>),
Failed,
}
impl Clone for WireStatus {
fn clone(&self) -> Self {
match self {
WireStatus::Connecting => WireStatus::Connecting,
WireStatus::Ready(handle) => WireStatus::Ready(Arc::clone(handle)),
WireStatus::Failed => WireStatus::Failed,
}
}
}