Skip to content

Commit bbc6735

Browse files
Extend feature-flags to allow choosing runtime for libp2p-tcp (#1471)
* Extend feature-flags to allow choosing runtime for libp2p-tcp * Added CHANGELOG entry Co-authored-by: Pierre Krieger <[email protected]>
1 parent 82156de commit bbc6735

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
an event.
4141
[PR 1567](https://github.com/libp2p/rust-libp2p/pull/1567)
4242

43+
- `libp2p-tcp`, `libp2p`: Made the `libp2p-tcp/async-std` feature flag
44+
disabled by default, and split the `libp2p/tcp` feature in two:
45+
`tcp-async-std` and `tcp-tokio`. `tcp-async-std` is still enabled by default.
46+
[PR 1471](https://github.com/libp2p/rust-libp2p/pull/1471)
47+
4348
- `libp2p-tcp`: On listeners started with an IPv6 multi-address the socket
4449
option `IPV6_V6ONLY` is set to true. Instead of relying on IPv4-mapped IPv6
4550
address support, two listeners can be started if IPv4 and IPv6 should both

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ default = [
2525
"pnet",
2626
"secio",
2727
"secp256k1",
28-
"tcp",
28+
"tcp-async-std",
2929
"uds",
3030
"wasm-ext",
3131
"websocket",
@@ -44,7 +44,8 @@ ping = ["libp2p-ping"]
4444
plaintext = ["libp2p-plaintext"]
4545
pnet = ["libp2p-pnet"]
4646
secio = ["libp2p-secio"]
47-
tcp = ["libp2p-tcp"]
47+
tcp-async-std = ["libp2p-tcp", "libp2p-tcp/async-std"]
48+
tcp-tokio = ["libp2p-tcp", "libp2p-tcp/tokio"]
4849
uds = ["libp2p-uds"]
4950
wasm-ext = ["libp2p-wasm-ext"]
5051
websocket = ["libp2p-websocket"]

src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
//! Example ([`secio`] + [`yamux`] Protocol Upgrade):
8686
//!
8787
//! ```rust
88-
//! # #[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp", feature = "secio", feature = "yamux"))] {
88+
//! # #[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp-async-std", feature = "secio", feature = "yamux"))] {
8989
//! use libp2p::{Transport, core::upgrade, tcp::TcpConfig, secio::SecioConfig, identity::Keypair, yamux};
9090
//! let tcp = TcpConfig::new();
9191
//! let secio = SecioConfig::new(Keypair::generate_ed25519());
@@ -217,8 +217,8 @@ pub use libp2p_plaintext as plaintext;
217217
pub use libp2p_secio as secio;
218218
#[doc(inline)]
219219
pub use libp2p_swarm as swarm;
220-
#[cfg(feature = "tcp")]
221-
#[cfg_attr(docsrs, doc(cfg(feature = "tcp")))]
220+
#[cfg(any(feature = "tcp-async-std", feature = "tcp-tokio-std"))]
221+
#[cfg_attr(docsrs, doc(cfg(any(feature = "tcp-async-std", feature = "tcp-tokio-std"))))]
222222
#[cfg(not(any(target_os = "emscripten", target_os = "unknown")))]
223223
#[doc(inline)]
224224
pub use libp2p_tcp as tcp;
@@ -266,8 +266,8 @@ pub use self::transport_ext::TransportExt;
266266
///
267267
/// > **Note**: This `Transport` is not suitable for production usage, as its implementation
268268
/// > reserves the right to support additional protocols or remove deprecated protocols.
269-
#[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))]
270-
#[cfg_attr(docsrs, doc(cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))))]
269+
#[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp-async-std", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))]
270+
#[cfg_attr(docsrs, doc(cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp-async-std", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))))]
271271
pub fn build_development_transport(keypair: identity::Keypair)
272272
-> std::io::Result<impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<std::io::Error>> + Send + Sync), Error = impl std::error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone>
273273
{
@@ -280,8 +280,8 @@ pub fn build_development_transport(keypair: identity::Keypair)
280280
/// and mplex or yamux as the multiplexing layer.
281281
///
282282
/// > **Note**: If you ever need to express the type of this `Transport`.
283-
#[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))]
284-
#[cfg_attr(docsrs, doc(cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))))]
283+
#[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp-async-std", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))]
284+
#[cfg_attr(docsrs, doc(cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp-async-std", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))))]
285285
pub fn build_tcp_ws_secio_mplex_yamux(keypair: identity::Keypair)
286286
-> std::io::Result<impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<std::io::Error>> + Send + Sync), Error = impl std::error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone>
287287
{
@@ -306,8 +306,8 @@ pub fn build_tcp_ws_secio_mplex_yamux(keypair: identity::Keypair)
306306
/// and mplex or yamux as the multiplexing layer.
307307
///
308308
/// > **Note**: If you ever need to express the type of this `Transport`.
309-
#[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux", feature = "pnet"))]
310-
#[cfg_attr(docsrs, doc(cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux", feature = "pnet"))))]
309+
#[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp-async-std", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux", feature = "pnet"))]
310+
#[cfg_attr(docsrs, doc(cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp-async-std", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux", feature = "pnet"))))]
311311
pub fn build_tcp_ws_pnet_secio_mplex_yamux(keypair: identity::Keypair, psk: PreSharedKey)
312312
-> std::io::Result<impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<std::io::Error>> + Send + Sync), Error = impl std::error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone>
313313
{

transports/tcp/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,3 @@ libp2p-core = { version = "0.18.0", path = "../../core" }
1919
log = "0.4.1"
2020
socket2 = "0.3.12"
2121
tokio = { version = "0.2", default-features = false, features = ["tcp"], optional = true }
22-
23-
[features]
24-
default = ["async-std"]

0 commit comments

Comments
 (0)