libp2p_core/
lib.rs

1// Copyright 2017-2018 Parity Technologies (UK) Ltd.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a
4// copy of this software and associated documentation files (the "Software"),
5// to deal in the Software without restriction, including without limitation
6// the rights to use, copy, modify, merge, publish, distribute, sublicense,
7// and/or sell copies of the Software, and to permit persons to whom the
8// Software is furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19// DEALINGS IN THE SOFTWARE.
20
21//! Transports, upgrades, multiplexing and node handling of *libp2p*.
22//!
23//! The main concepts of libp2p-core are:
24//!
25//! - The [`Transport`] trait defines how to reach a remote node or listen for incoming remote
26//!   connections. See the [`transport`] module.
27//! - The [`StreamMuxer`] trait is implemented on structs that hold a connection to a remote and can
28//!   subdivide this connection into multiple substreams. See the [`muxing`] module.
29//! - The [`UpgradeInfo`], [`InboundUpgrade`] and [`OutboundUpgrade`] traits define how to upgrade
30//!   each individual substream to use a protocol. See the `upgrade` module.
31
32#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
33
34mod proto {
35    #![allow(unreachable_pub)]
36    include!("generated/mod.rs");
37    pub use self::{
38        envelope_proto::*,
39        peer_record_proto::{mod_PeerRecord::*, PeerRecord},
40    };
41}
42
43/// Multi-address re-export.
44pub use multiaddr;
45pub type Negotiated<T> = multistream_select::Negotiated<T>;
46
47pub mod connection;
48pub mod either;
49pub mod muxing;
50pub mod peer_record;
51pub mod signed_envelope;
52pub mod transport;
53pub mod upgrade;
54
55pub use connection::{ConnectedPoint, Endpoint};
56pub use libp2p_identity::PeerId;
57pub use multiaddr::Multiaddr;
58pub use multihash;
59pub use muxing::StreamMuxer;
60pub use peer_record::PeerRecord;
61pub use signed_envelope::SignedEnvelope;
62pub use transport::Transport;
63pub use upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
64
65#[derive(Debug, thiserror::Error)]
66#[error(transparent)]
67pub struct DecodeError(quick_protobuf::Error);
68
69pub mod util {
70    use std::convert::Infallible;
71
72    /// A safe version of [`std::intrinsics::unreachable`].
73    #[inline(always)]
74    pub fn unreachable(x: Infallible) -> ! {
75        match x {}
76    }
77}