Skip to content

Commit 5032c6f

Browse files
Extend feature-flags to allow choosing runtime for libp2p-tcp
1 parent bd5e81f commit 5032c6f

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

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;
@@ -268,8 +268,8 @@ use std::{error, io, time::Duration};
268268
///
269269
/// > **Note**: This `Transport` is not suitable for production usage, as its implementation
270270
/// > reserves the right to support additional protocols or remove deprecated protocols.
271-
#[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))]
272-
#[cfg_attr(docsrs, doc(cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))))]
271+
#[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp-async-std", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))]
272+
#[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"))))]
273273
pub fn build_development_transport(keypair: identity::Keypair)
274274
-> io::Result<impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<io::Error>> + Send + Sync), Error = impl error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone>
275275
{
@@ -282,8 +282,8 @@ pub fn build_development_transport(keypair: identity::Keypair)
282282
/// and mplex or yamux as the multiplexing layer.
283283
///
284284
/// > **Note**: If you ever need to express the type of this `Transport`.
285-
#[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))]
286-
#[cfg_attr(docsrs, doc(cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))))]
285+
#[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp-async-std", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))]
286+
#[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"))))]
287287
pub fn build_tcp_ws_secio_mplex_yamux(keypair: identity::Keypair)
288288
-> io::Result<impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<io::Error>> + Send + Sync), Error = impl error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone>
289289
{
@@ -308,8 +308,8 @@ pub fn build_tcp_ws_secio_mplex_yamux(keypair: identity::Keypair)
308308
/// and mplex or yamux as the multiplexing layer.
309309
///
310310
/// > **Note**: If you ever need to express the type of this `Transport`.
311-
#[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux", feature = "pnet"))]
312-
#[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"))))]
311+
#[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp-async-std", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux", feature = "pnet"))]
312+
#[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"))))]
313313
pub fn build_tcp_ws_pnet_secio_mplex_yamux(keypair: identity::Keypair, psk: PreSharedKey)
314314
-> io::Result<impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<io::Error>> + Send + Sync), Error = impl error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone>
315315
{

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)