libp2p_swarm/
listen_opts.rs

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