Skip to main content

confium_net_noise/
kind.rs

1//! Registry kind for `noise://` URLs.
2
3use confium_net::registry::TransportKind;
4use url::Url;
5
6use confium_net::Listener;
7use confium_net::Result;
8use confium_net::Transport;
9
10use crate::transport::NoiseListener;
11use crate::transport::NoiseTransport;
12use crate::transport::parse_url;
13
14/// Owns the `noise` scheme: Noise_XX over TCP with optional key
15/// provisioning (`key=`) and peer pinning (`pinned=`).
16pub struct NoiseTransportKind;
17
18impl TransportKind for NoiseTransportKind {
19    fn schemes(&self) -> &'static [&'static str] {
20        &["noise"]
21    }
22
23    fn connect(&self, url: &Url) -> Result<Box<dyn Transport>> {
24        let params = parse_url(url)?;
25        NoiseTransport::connect(&params).map(|t| Box::new(t) as Box<dyn Transport>)
26    }
27
28    fn listen(&self, url: &Url) -> Result<Box<dyn Listener>> {
29        let params = parse_url(url)?;
30        NoiseListener::new(params).map(|l| Box::new(l) as Box<dyn Listener>)
31    }
32}