pub mod wrtc;
pub mod ws;
use super::*;
use std::io;
#[derive(Debug)]
pub(in crate::network_manager) enum ProtocolNetworkConnection {
Ws(ws::WebsocketNetworkConnection),
}
impl ProtocolNetworkConnection {
pub async fn connect(
registry: VeilidComponentRegistry,
_local_address: Option<SocketAddr>,
dial_info: &DialInfo,
timeout_ms: u32,
address_filter: &AddressFilter,
) -> io::Result<NetworkResult<ProtocolNetworkConnection>> {
if address_filter.is_ip_addr_punished(dial_info.address().ip_addr()) {
return Ok(NetworkResult::no_connection_other("punished"));
}
match dial_info.protocol_type() {
ProtocolType::UDP => {
panic!("UDP dial info is not supported on WASM targets");
}
ProtocolType::TCP => {
panic!("TCP dial info is not supported on WASM targets");
}
ProtocolType::WS => {
ws::WebsocketProtocolHandler::connect(registry, dial_info, timeout_ms).await
}
#[cfg(feature = "enable-protocol-wss")]
ProtocolType::WSS => {
ws::WebsocketProtocolHandler::connect(registry, dial_info, timeout_ms).await
}
}
}
pub fn flow(&self) -> Flow {
match self {
Self::Ws(w) => w.flow(),
}
}
pub async fn close(&self) -> io::Result<NetworkResult<()>> {
match self {
Self::Ws(w) => w.close().await,
}
}
pub async fn send(&self, message: Bytes) -> io::Result<NetworkResult<()>> {
match self {
Self::Ws(w) => w.send(message).await,
}
}
pub async fn recv(&self) -> io::Result<NetworkResult<Bytes>> {
match self {
Self::Ws(w) => w.recv().await,
}
}
}