use crate::*;
pub use kitsune_p2p_types::tls::TlsConfig;
pub type AcceptProxyCallbackFn =
Arc<dyn Fn(CertDigest) -> MustBoxFuture<'static, bool> + 'static + Send + Sync>;
#[derive(Clone, Deref, AsRef)]
pub struct AcceptProxyCallback(pub AcceptProxyCallbackFn);
impl AcceptProxyCallback {
pub fn reject_all() -> Self {
Self(Arc::new(|_| async { false }.boxed().into()))
}
pub fn accept_all() -> Self {
Self(Arc::new(|_| async { true }.boxed().into()))
}
}
pub enum ProxyConfig {
RemoteProxyClient {
tls: TlsConfig,
proxy_url: ProxyUrl,
},
LocalProxyServer {
tls: TlsConfig,
accept_proxy_cb: AcceptProxyCallback,
},
}
impl ProxyConfig {
pub fn remote_proxy_client(tls: TlsConfig, proxy_url: ProxyUrl) -> Arc<Self> {
Arc::new(Self::RemoteProxyClient { tls, proxy_url })
}
pub fn local_proxy_server(tls: TlsConfig, accept_proxy_cb: AcceptProxyCallback) -> Arc<Self> {
Arc::new(Self::LocalProxyServer {
tls,
accept_proxy_cb,
})
}
}
const ALPN_KITSUNE_PROXY_0: &[u8] = b"kitsune-proxy/0";
#[allow(dead_code)]
pub(crate) fn gen_tls_configs(
tls: &TlsConfig,
tuning_params: kitsune_p2p_types::config::KitsuneP2pTuningParams,
) -> TransportResult<(Arc<rustls::ServerConfig>, Arc<rustls::ClientConfig>)> {
kitsune_p2p_types::tls::gen_tls_configs(ALPN_KITSUNE_PROXY_0, tls, tuning_params)
.map_err(TransportError::other)
}