libp2p_relay/lib.rs
1// Copyright 2019 Parity Technologies (UK) Ltd.
2// Copyright 2021 Protocol Labs.
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22//! Implementation of libp2p [circuit relay](https://github.com/libp2p/specs/blob/master/relay/README.md) protocol.
23
24#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
25
26mod behaviour;
27mod copy_future;
28mod multiaddr_ext;
29mod priv_client;
30mod protocol;
31
32mod proto {
33 #![allow(unreachable_pub)]
34 include!("generated/mod.rs");
35 pub use self::message_v2::pb::mod_StopMessage::Type as StopMessageType;
36 pub(crate) use self::message_v2::pb::{
37 mod_HopMessage::Type as HopMessageType, HopMessage, Limit, Peer, Reservation, Status,
38 StopMessage,
39 };
40}
41
42pub use behaviour::{rate_limiter::RateLimiter, Behaviour, CircuitId, Config, Event};
43pub use protocol::{HOP_PROTOCOL_NAME, STOP_PROTOCOL_NAME};
44
45/// Types related to the relay protocol inbound.
46pub mod inbound {
47 pub mod hop {
48 #[deprecated(note = "Renamed to `Error`.")]
49 pub type FatalUpgradeError = Error;
50
51 pub use crate::protocol::inbound_hop::Error;
52 }
53}
54
55/// Types related to the relay protocol outbound.
56pub mod outbound {
57 pub mod hop {
58 pub use crate::protocol::outbound_hop::{ConnectError, ProtocolViolation, ReserveError};
59 }
60 pub mod stop {
61 pub use crate::protocol::outbound_stop::{Error, ProtocolViolation};
62 }
63}
64
65/// Everything related to the relay protocol from a client's perspective.
66pub mod client {
67 pub use crate::priv_client::{new, transport::Transport, Behaviour, Connection, Event};
68
69 pub mod transport {
70 pub use crate::priv_client::transport::Error;
71 }
72}
73
74// Check that we can safely cast a `usize` to a `u64`.
75static_assertions::const_assert! {
76 std::mem::size_of::<usize>() <= std::mem::size_of::<u64>()
77}
78
79/// The ID of an outgoing / incoming, relay / destination request.
80// TODO remove this type and it's usage on `TransportToBehaviourMsg::DialReq`
81// when removed from `v2`.
82#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
83pub struct RequestId(u64);
84
85impl RequestId {
86 fn new() -> RequestId {
87 RequestId(rand::random())
88 }
89}