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
#[allow(unused_imports)]
use super::*;

use crate::SwarmBuilder;
use libp2p_core::Transport;
use libp2p_swarm::Swarm;

pub struct BuildPhase<T, B> {
    pub(crate) behaviour: B,
    pub(crate) transport: T,
    pub(crate) swarm_config: libp2p_swarm::Config,
}

const CONNECTION_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(10);

impl<Provider, T: AuthenticatedMultiplexedTransport, B: libp2p_swarm::NetworkBehaviour>
    SwarmBuilder<Provider, BuildPhase<T, B>>
{
    pub fn build(self) -> Swarm<B> {
        Swarm::new(
            libp2p_core::transport::timeout::TransportTimeout::new(
                self.phase.transport,
                CONNECTION_TIMEOUT,
            )
            .boxed(),
            self.phase.behaviour,
            self.keypair.public().to_peer_id(),
            self.phase.swarm_config,
        )
    }
}