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
#![deny(clippy::arithmetic_side_effects)]
#![deny(clippy::cast_possible_truncation)]

pub mod behavior;
pub mod codecs;
pub mod config;
pub mod discovery;
pub mod gossipsub;
pub mod heartbeat;
pub mod p2p_service;
pub mod peer_manager;
pub mod peer_report;
pub mod ports;
pub mod request_response;
pub mod service;

pub use gossipsub::config as gossipsub_config;
pub use heartbeat::Config;

pub use libp2p::{
    multiaddr::Protocol,
    Multiaddr,
    PeerId,
};

#[cfg(feature = "test-helpers")]
pub mod network_service {
    pub use crate::p2p_service::*;
}

pub trait TryPeerId {
    /// Tries convert `Self` into `PeerId`.
    fn try_to_peer_id(&self) -> Option<PeerId>;
}

impl TryPeerId for Multiaddr {
    fn try_to_peer_id(&self) -> Option<PeerId> {
        self.iter().last().and_then(|p| match p {
            Protocol::P2p(peer_id) => Some(peer_id),
            _ => None,
        })
    }
}

#[cfg(test)]
fuel_core_trace::enable_tracing!();