litep2p/yamux/mod.rs
1// Copyright (c) 2018-2019 Parity Technologies (UK) Ltd.
2//
3// Licensed under the Apache License, Version 2.0 or MIT license, at your option.
4//
5// A copy of the Apache License, Version 2.0 is included in the software as
6// LICENSE-APACHE and a copy of the MIT license is included in the software
7// as LICENSE-MIT. You may also obtain a copy of the Apache License, Version 2.0
8// at https://www.apache.org/licenses/LICENSE-2.0 and a copy of the MIT license
9// at https://opensource.org/licenses/MIT.
10
11//! This crate implements the [Yamux specification][1].
12//!
13//! It multiplexes independent I/O streams over reliable, ordered connections,
14//! such as TCP/IP.
15//!
16//! The three primary objects, clients of this crate interact with, are:
17//!
18//! - [`Connection`], which wraps the underlying I/O resource, e.g. a socket,
19//! - [`Stream`], which implements [`futures::io::AsyncRead`] and [`futures::io::AsyncWrite`], and
20//! - [`Control`], to asynchronously control the [`Connection`].
21//!
22//! [1]: https://github.com/hashicorp/yamux/blob/master/spec.md
23
24#![forbid(unsafe_code)]
25
26mod control;
27
28pub use yamux::{
29 Config, Connection, ConnectionError, FrameDecodeError, HeaderDecodeError, Mode, Packet, Result,
30 Stream, StreamId,
31};
32
33// Switching to the "poll" based yamux API is a massive breaking change for litep2p.
34// Instead, we rely on the upstream yamux and keep the old controller API.
35pub use crate::yamux::control::{Control, ControlledConnection};
36
37pub const DEFAULT_CREDIT: u32 = 256 * 1024; // as per yamux specification
38
39/// The maximum number of streams we will open without an acknowledgement from the other peer.
40///
41/// This enables a very basic form of backpressure on the creation of streams.
42const MAX_ACK_BACKLOG: usize = 256;