libp2p_swarm/
listen_opts.rs

1use libp2p_core::Multiaddr;
2
3use crate::ListenerId;
4
5#[derive(Debug)]
6pub struct ListenOpts {
7    id: ListenerId,
8    address: Multiaddr,
9}
10
11impl ListenOpts {
12    pub fn new(address: Multiaddr) -> ListenOpts {
13        ListenOpts {
14            id: ListenerId::next(),
15            address,
16        }
17    }
18
19    /// Get the [`ListenerId`] of this listen attempt
20    pub fn listener_id(&self) -> ListenerId {
21        self.id
22    }
23
24    /// Get the [`Multiaddr`] that is being listened on
25    pub fn address(&self) -> &Multiaddr {
26        &self.address
27    }
28}
29
30impl From<Multiaddr> for ListenOpts {
31    fn from(addr: Multiaddr) -> Self {
32        ListenOpts::new(addr)
33    }
34}