1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use super::*;

/// A Bootstrap that makes it easy to bootstrap a pipeline to use for UDP clients.
pub struct BootstrapUdpClient<W> {
    bootstrap_udp: BootstrapUdp<W>,
}

impl<W: 'static> Default for BootstrapUdpClient<W> {
    fn default() -> Self {
        Self::new()
    }
}

impl<W: 'static> BootstrapUdpClient<W> {
    /// Creates a new BootstrapUdpClient
    pub fn new() -> Self {
        Self {
            bootstrap_udp: BootstrapUdp::new(),
        }
    }

    /// Creates pipeline instances from when calling [BootstrapUdpClient::bind].
    pub fn pipeline(
        &mut self,
        pipeline_factory_fn: PipelineFactoryFn<TaggedBytesMut, W>,
    ) -> &mut Self {
        self.bootstrap_udp.pipeline(pipeline_factory_fn);
        self
    }

    /// Binds local address and port
    pub async fn bind<A: AsyncToSocketAddrs>(&mut self, addr: A) -> Result<SocketAddr, Error> {
        self.bootstrap_udp.bind(addr).await
    }

    /// Connects to the remote peer
    pub async fn connect(
        &mut self,
        addr: SocketAddr,
    ) -> Result<Rc<dyn OutboundPipeline<W>>, Error> {
        self.bootstrap_udp.connect(Some(addr)).await
    }

    /// Stops the client
    pub async fn stop(&self) {
        self.bootstrap_udp.stop().await
    }

    /// Waits for stop of the client
    pub async fn wait_for_stop(&self) {
        self.bootstrap_udp.wait_for_stop().await
    }

    /// Gracefully stop the client
    pub async fn graceful_stop(&self) {
        self.bootstrap_udp.graceful_stop().await
    }
}