/// Construct `QuicP2p` with supplied parameters, ready to be used.
/// If config is not specified it'll call `Config::read_or_construct_default()`
///
/// `bootstrap_nodes`: takes bootstrap nodes from the user.
///
/// In addition to bootstrap nodes provided, optionally use the nodes found
/// in the bootstrap cache file (if such a file exists) or disable this feature.
///
/// # Example
///
/// ```
/// use qp2p::{QuicP2p, Config};
/// use std::net::{IpAddr, Ipv4Addr, SocketAddr};
///
/// let mut config = Config::default();
/// config.local_ip = Some(IpAddr::V4(Ipv4Addr::LOCALHOST));
/// config.local_port = Some(3000);
/// let hcc = &["127.0.0.1:8080".parse().unwrap()];
/// let quic_p2p = QuicP2p::with_config(Some(config), hcc, true).expect("Error initializing QuicP2p");
/// ```
Construct `QuicP2p` with supplied parameters, ready to be used.
If config is not specified it'll call `Config::read_or_construct_default()`

`bootstrap_nodes`: takes bootstrap nodes from the user.

In addition to bootstrap nodes provided, optionally use the nodes found
in the bootstrap cache file (if such a file exists) or disable this feature.
Construct ` QuicP2p ` with supplied parameters ready to be used . If config is not specified it ' ll call ` Config :: read_or_construct_default () ` ` bootstrap_nodes ` : takes bootstrap nodes from the user . In addition to bootstrap nodes provided optionally use the nodes found in the bootstrap cache file ( if such a file exists ) or disable this feature .
pub fn with_config(
        cfg: Option<Config>,
        bootstrap_nodes: &[SocketAddr],
        use_bootstrap_cache: bool,
    ) -> Result<Self> {
        debug!("Config passed in to qp2p: {:?}", cfg);
        let cfg = unwrap_config_or_default(cfg)?;
        debug!(
            "Config decided on after unwrap and IGD in to qp2p: {:?}",
            cfg
        );
        let (port, allow_random_port) = cfg
            .local_port
            .map(|p| (p, false))
            .unwrap_or((DEFAULT_PORT_TO_TRY, true));
        let ip = cfg.local_ip.ok_or(Error::UnspecifiedLocalIp)?;
        let idle_timeout_msec = cfg.idle_timeout_msec.unwrap_or(DEFAULT_IDLE_TIMEOUT_MSEC);
        let keep_alive_interval_msec = cfg
            .keep_alive_interval_msec
            .unwrap_or(DEFAULT_KEEP_ALIVE_INTERVAL_MSEC);
        let (key, cert) = {
            let our_complete_cert =
                SerialisableCertificate::new(vec![MAIDSAFE_DOMAIN.to_string()])?;
            our_complete_cert.obtain_priv_key_and_cert()?
        };
        let custom_dirs = cfg.bootstrap_cache_dir.clone().map(PathBuf::from);
        let mut qp2p_config = cfg.clone();
        let mut bootstrap_cache =
            BootstrapCache::new(cfg.hard_coded_contacts, custom_dirs.as_ref())?;
        trace!("Peers in bootstrap cache: {:?}", bootstrap_cache.peers());
        if !use_bootstrap_cache {
            let bootstrap_cache = bootstrap_cache.peers_mut();
            bootstrap_cache.clear();
        }
        bootstrap_cache.peers_mut().extend(bootstrap_nodes);
        let endpoint_cfg =
            peer_config::new_our_cfg(idle_timeout_msec, keep_alive_interval_msec, cert, key)?;
        let client_cfg = peer_config::new_client_cfg(idle_timeout_msec, keep_alive_interval_msec)?;
        let upnp_lease_duration = cfg
            .upnp_lease_duration
            .unwrap_or(DEFAULT_UPNP_LEASE_DURATION_SEC);
        qp2p_config.local_ip = Some(ip);
        qp2p_config.local_port = Some(port);
        qp2p_config.keep_alive_interval_msec = Some(keep_alive_interval_msec);
        qp2p_config.idle_timeout_msec = Some(idle_timeout_msec);
        qp2p_config.upnp_lease_duration = Some(upnp_lease_duration);
        Ok(Self {
            local_addr: SocketAddr::new(ip, port),
            allow_random_port,
            bootstrap_cache,
            endpoint_cfg,
            client_cfg,
            qp2p_config,
        })
    }
pub fn with_config ( cfg : Option < Config > , bootstrap_nodes : & [ SocketAddr ] , use_bootstrap_cache : bool , ) -> Result < Self > { debug ! ( " " cfg ) ; let cfg = unwrap_config_or_default ( cfg ) ? ; debug ! ( " " cfg ) ; let ( port , allow_random_port ) = cfg . local_port . map ( | p | ( p , false ) ) . unwrap_or ( ( DEFAULT_PORT_TO_TRY , true ) ) ; let ip = cfg . local_ip . ok_or ( Error :: UnspecifiedLocalIp ) ? ; let idle_timeout_msec = cfg . idle_timeout_msec . unwrap_or ( DEFAULT_IDLE_TIMEOUT_MSEC ) ; let keep_alive_interval_msec = cfg . keep_alive_interval_msec . unwrap_or ( DEFAULT_KEEP_ALIVE_INTERVAL_MSEC ) ; let ( key , cert ) = { let our_complete_cert = SerialisableCertificate :: new ( vec ! [ MAIDSAFE_DOMAIN to_string ( ) ] ) ? ; our_complete_cert . obtain_priv_key_and_cert ( ) ? } ; let custom_dirs = cfg . bootstrap_cache_dir . clone ( ) . map ( PathBuf :: from ) ; let mut qp2p_config = cfg . clone ( ) ; let mut bootstrap_cache = BootstrapCache :: new ( cfg . hard_coded_contacts , custom_dirs . as_ref ( ) ) ? ; trace ! ( " " bootstrap_cache peers ( ) ) ; if ! use_bootstrap_cache { let bootstrap_cache = bootstrap_cache . peers_mut ( ) ; bootstrap_cache . clear ( ) ; } bootstrap_cache . peers_mut ( ) . extend ( bootstrap_nodes ) ; let endpoint_cfg = peer_config :: new_our_cfg ( idle_timeout_msec , keep_alive_interval_msec , cert , key ) ? ; let client_cfg = peer_config :: new_client_cfg ( idle_timeout_msec , keep_alive_interval_msec ) ? ; let upnp_lease_duration = cfg . upnp_lease_duration . unwrap_or ( DEFAULT_UPNP_LEASE_DURATION_SEC ) ; qp2p_config . local_ip = Some ( ip ) ; qp2p_config . local_port = Some ( port ) ; qp2p_config . keep_alive_interval_msec = Some ( keep_alive_interval_msec ) ; qp2p_config . idle_timeout_msec = Some ( idle_timeout_msec ) ; qp2p_config . upnp_lease_duration = Some ( upnp_lease_duration ) ; Ok ( Self { local_addr : SocketAddr :: new ( ip , port ) , allow_random_port , bootstrap_cache , endpoint_cfg , client_cfg , qp2p_config , } ) }
Construct `QuicP2p` with supplied parameters, ready to be used.
Construct ` QuicP2p ` with supplied parameters ready to be used .
cfg
Option<Config>
bootstrap_nodes
&[SocketAddr]
use_bootstrap_cache
bool
example
```
use qp2p::{QuicP2p, Config};
use std::net::{IpAddr, Ipv4Addr, SocketAddr}.

let mut config = Config::default();
config.local_ip = Some(IpAddr::V4(Ipv4Addr::LOCALHOST));
config.local_port = Some(3000);
let hcc = &["127.0.0.1:8080".parse().unwrap()];
let quic_p2p = QuicP2p::with_config(Some(config), hcc, true).expect("Error initializing QuicP2p");
```
` ` ` use qp2p :: { QuicP2p Config } ; use std :: net :: { IpAddr Ipv4Addr SocketAddr } . let mut config = Config :: default () ; config . local_ip = Some ( IpAddr :: V4 ( Ipv4Addr :: LOCALHOST )) ; config . local_port = Some ( 3000 ) ; let hcc = & [ " 127 . 0 . 0 . 1 : 8080 " . parse () . unwrap () ] ; let quic_p2p = QuicP2p :: with_config ( Some ( config ) hcc true ) . expect ( " Error initializing QuicP2p " ) ; ` ` `