Skip to content

Commit

Permalink
transports/tcp: Unify symbol naming (#2961)
Browse files Browse the repository at this point in the history
Co-authored-by: Elena Frank <elena.frank@protonmail.com>
  • Loading branch information
thomaseizinger and elenaf9 authored Oct 24, 2022
1 parent fcadc83 commit 4d1b165
Show file tree
Hide file tree
Showing 20 changed files with 199 additions and 117 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@

- Remove deprecated features: `tcp-tokio`, `mdns-tokio`, `dns-tokio`, `tcp-async-io`, `mdns-async-io`, `dns-async-std`.
See [PR 3001].
- Introduce [`libp2p-tls` `v0.1.0`](transports/tls/CHANGELOG.md#010). See [PR 2945].
- Update individual crates.
- Update to [`libp2p-tcp` `v0.38.0`](transports/tcp/CHANGELOG.md#0380).

[PR 3001]: https://github.com/libp2p/rust-libp2p/pull/3001
[PR 2945]: https://github.com/libp2p/rust-libp2p/pull/2945

# 0.49.0

Expand All @@ -66,8 +70,6 @@

See [PR 2962].

- Introduce [`libp2p-tls` `v0.1.0`](transports/tls/CHANGELOG.md#010). See [PR 2945].

- Update individual crates.
- Update to [`libp2p-autonat` `v0.8.0`](protocols/autonat/CHANGELOG.md#0080).
- Update to [`libp2p-core` `v0.37.0`](core/CHANGELOG.md#0370).
Expand Down Expand Up @@ -97,7 +99,6 @@

[PR 2918]: https://github.com/libp2p/rust-libp2p/pull/2918
[PR 2962]: https://github.com/libp2p/rust-libp2p/pull/2962
[PR 2945]: https://github.com/libp2p/rust-libp2p/pull/2945

# 0.48.0

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ smallvec = "1.6.1"
libp2p-deflate = { version = "0.37.0", path = "transports/deflate", optional = true }
libp2p-dns = { version = "0.37.0", path = "transports/dns", optional = true }
libp2p-mdns = { version = "0.41.0", path = "protocols/mdns", optional = true }
libp2p-tcp = { version = "0.37.0", path = "transports/tcp", optional = true }
libp2p-tcp = { version = "0.38.0", path = "transports/tcp", optional = true }
libp2p-websocket = { version = "0.39.0", path = "transports/websocket", optional = true }
libp2p-tls = { version = "0.1.0-alpha", path = "transports/tls", optional = true }

Expand Down
13 changes: 3 additions & 10 deletions examples/chat-tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
//! ```

use futures::StreamExt;
use libp2p::tcp::GenTcpConfig;
use libp2p::{
core::upgrade,
floodsub::{self, Floodsub, FloodsubEvent},
Expand All @@ -39,15 +38,9 @@ use libp2p::{
// `TokioMdns` is available through the `mdns-tokio` feature.
TokioMdns,
},
mplex,
noise,
mplex, noise,
swarm::{SwarmBuilder, SwarmEvent},
// `TokioTcpTransport` is available through the `tcp-tokio` feature.
tcp::TokioTcpTransport,
Multiaddr,
NetworkBehaviour,
PeerId,
Transport,
tcp, Multiaddr, NetworkBehaviour, PeerId, Transport,
};
use std::error::Error;
use tokio::io::{self, AsyncBufReadExt};
Expand All @@ -64,7 +57,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

// Create a tokio-based TCP transport use noise for authenticated
// encryption and Mplex for multiplexing of substreams on a TCP stream.
let transport = TokioTcpTransport::new(GenTcpConfig::default().nodelay(true))
let transport = tcp::tokio::Transport::new(tcp::Config::default().nodelay(true))
.upgrade(upgrade::Version::V1)
.authenticate(
noise::NoiseAuthenticated::xx(&id_keys)
Expand Down
5 changes: 2 additions & 3 deletions examples/ipfs-private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
//! to work, the ipfs node needs to be configured to use gossipsub.
use async_std::io;
use futures::{prelude::*, select};
use libp2p::tcp::GenTcpConfig;
use libp2p::{
core::{
either::EitherTransport, muxing::StreamMuxerBox, transport, transport::upgrade::Version,
Expand All @@ -44,7 +43,7 @@ use libp2p::{
noise, ping,
pnet::{PnetConfig, PreSharedKey},
swarm::SwarmEvent,
tcp::TcpTransport,
tcp,
yamux::YamuxConfig,
Multiaddr, NetworkBehaviour, PeerId, Swarm, Transport,
};
Expand All @@ -58,7 +57,7 @@ pub fn build_transport(
let noise_config = noise::NoiseAuthenticated::xx(&key_pair).unwrap();
let yamux_config = YamuxConfig::default();

let base_transport = TcpTransport::new(GenTcpConfig::default().nodelay(true));
let base_transport = tcp::async_io::Transport::new(tcp::Config::default().nodelay(true));
let maybe_encrypted = match psk {
Some(psk) => EitherTransport::Left(
base_transport.and_then(move |socket, _| PnetConfig::new(psk).handshake(socket)),
Expand Down
5 changes: 2 additions & 3 deletions muxers/mplex/benches/split_send_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ use libp2p::core::muxing::StreamMuxerExt;
use libp2p::core::{
identity, multiaddr::multiaddr, muxing, transport, upgrade, Multiaddr, PeerId, Transport,
};
use libp2p::mplex;
use libp2p::plaintext::PlainText2Config;
use libp2p::tcp::GenTcpConfig;
use libp2p::{mplex, tcp};
use std::pin::Pin;
use std::time::Duration;

Expand Down Expand Up @@ -170,7 +169,7 @@ fn tcp_transport(split_send_size: usize) -> BenchTransport {
let mut mplex = mplex::MplexConfig::default();
mplex.set_split_send_size(split_send_size);

libp2p::tcp::TcpTransport::new(GenTcpConfig::default().nodelay(true))
tcp::async_io::Transport::new(tcp::Config::default().nodelay(true))
.upgrade(upgrade::Version::V1)
.authenticate(PlainText2Config { local_public_key })
.multiplex(mplex)
Expand Down
6 changes: 3 additions & 3 deletions protocols/dcutr/examples/dcutr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use libp2p::identify;
use libp2p::noise;
use libp2p::relay::v2::client::{self, Client};
use libp2p::swarm::{SwarmBuilder, SwarmEvent};
use libp2p::tcp::{GenTcpConfig, TcpTransport};
use libp2p::tcp;
use libp2p::Transport;
use libp2p::{dcutr, ping};
use libp2p::{identity, NetworkBehaviour, PeerId};
Expand Down Expand Up @@ -90,8 +90,8 @@ fn main() -> Result<(), Box<dyn Error>> {

let transport = OrTransport::new(
relay_transport,
block_on(DnsConfig::system(TcpTransport::new(
GenTcpConfig::default().port_reuse(true),
block_on(DnsConfig::system(tcp::async_io::Transport::new(
tcp::Config::default().port_reuse(true),
)))
.unwrap(),
)
Expand Down
4 changes: 2 additions & 2 deletions protocols/identify/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ mod tests {
use futures::pin_mut;
use libp2p::mplex::MplexConfig;
use libp2p::noise;
use libp2p::tcp::{GenTcpConfig, TcpTransport};
use libp2p::tcp;
use libp2p_core::{identity, muxing::StreamMuxerBox, transport, upgrade, PeerId, Transport};
use libp2p_swarm::{Swarm, SwarmEvent};
use std::time::Duration;
Expand All @@ -569,7 +569,7 @@ mod tests {
.into_authentic(&id_keys)
.unwrap();
let pubkey = id_keys.public();
let transport = TcpTransport::new(GenTcpConfig::default().nodelay(true))
let transport = tcp::async_io::Transport::new(tcp::Config::default().nodelay(true))
.upgrade(upgrade::Version::V1)
.authenticate(noise::NoiseConfig::xx(noise_keys).into_authenticated())
.multiplex(MplexConfig::new())
Expand Down
6 changes: 3 additions & 3 deletions protocols/identify/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ pub enum UpgradeError {
mod tests {
use super::*;
use futures::channel::oneshot;
use libp2p::tcp::TcpTransport;
use libp2p::tcp;
use libp2p_core::{
identity,
upgrade::{self, apply_inbound, apply_outbound},
Expand All @@ -308,7 +308,7 @@ mod tests {
let (tx, rx) = oneshot::channel();

let bg_task = async_std::task::spawn(async move {
let mut transport = TcpTransport::default().boxed();
let mut transport = tcp::async_io::Transport::default().boxed();

transport
.listen_on("/ip4/127.0.0.1/tcp/0".parse().unwrap())
Expand Down Expand Up @@ -351,7 +351,7 @@ mod tests {
});

async_std::task::block_on(async move {
let mut transport = TcpTransport::default();
let mut transport = tcp::async_io::Transport::default();

let socket = transport.dial(rx.await.unwrap()).unwrap().await.unwrap();
let info = apply_outbound(socket, Protocol, upgrade::Version::V1)
Expand Down
4 changes: 2 additions & 2 deletions protocols/ping/tests/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use libp2p::mplex;
use libp2p::noise;
use libp2p::ping;
use libp2p::swarm::{Swarm, SwarmEvent};
use libp2p::tcp::{GenTcpConfig, TcpTransport};
use libp2p::tcp;
use libp2p::yamux;
use libp2p::NetworkBehaviour;
use libp2p_swarm::keep_alive;
Expand Down Expand Up @@ -246,7 +246,7 @@ fn mk_transport(muxer: MuxerChoice) -> (PeerId, transport::Boxed<(PeerId, Stream
let peer_id = id_keys.public().to_peer_id();
(
peer_id,
TcpTransport::new(GenTcpConfig::default().nodelay(true))
tcp::async_io::Transport::new(tcp::Config::default().nodelay(true))
.upgrade(upgrade::Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&id_keys).unwrap())
.multiplex(match muxer {
Expand Down
7 changes: 4 additions & 3 deletions protocols/relay/examples/relay_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ use futures::stream::StreamExt;
use libp2p::core::upgrade;
use libp2p::identify;
use libp2p::multiaddr::Protocol;
use libp2p::ping;
use libp2p::relay::v2::relay::{self, Relay};
use libp2p::swarm::{Swarm, SwarmEvent};
use libp2p::tcp::TcpTransport;
use libp2p::tcp;
use libp2p::Transport;
use libp2p::{identity, NetworkBehaviour, PeerId};
use libp2p::{noise, Multiaddr};
use libp2p::{ping, Transport};
use std::error::Error;
use std::net::{Ipv4Addr, Ipv6Addr};

Expand All @@ -45,7 +46,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let local_peer_id = PeerId::from(local_key.public());
println!("Local peer id: {:?}", local_peer_id);

let tcp_transport = TcpTransport::default();
let tcp_transport = tcp::async_io::Transport::default();

let transport = tcp_transport
.upgrade(upgrade::Version::V1)
Expand Down
7 changes: 4 additions & 3 deletions protocols/request-response/tests/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ use futures::{channel::mpsc, prelude::*, AsyncWriteExt};
use libp2p::core::{
identity,
muxing::StreamMuxerBox,
transport::{self, Transport},
transport,
upgrade::{self, read_length_prefixed, write_length_prefixed},
Multiaddr, PeerId,
};
use libp2p::noise::NoiseAuthenticated;
use libp2p::request_response::*;
use libp2p::swarm::{Swarm, SwarmEvent};
use libp2p::tcp::{GenTcpConfig, TcpTransport};
use libp2p::tcp;
use libp2p_core::Transport;
use rand::{self, Rng};
use std::{io, iter};

Expand Down Expand Up @@ -298,7 +299,7 @@ fn mk_transport() -> (PeerId, transport::Boxed<(PeerId, StreamMuxerBox)>) {

(
peer_id,
TcpTransport::new(GenTcpConfig::default().nodelay(true))
tcp::async_io::Transport::new(tcp::Config::default().nodelay(true))
.upgrade(upgrade::Version::V1)
.authenticate(NoiseAuthenticated::xx(&id_keys).unwrap())
.multiplex(libp2p::yamux::YamuxConfig::default())
Expand Down
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ pub async fn development_transport(
keypair: identity::Keypair,
) -> std::io::Result<core::transport::Boxed<(PeerId, core::muxing::StreamMuxerBox)>> {
let transport = {
let dns_tcp = dns::DnsConfig::system(tcp::TcpTransport::new(
tcp::GenTcpConfig::new().nodelay(true),
let dns_tcp = dns::DnsConfig::system(tcp::async_io::Transport::new(
tcp::Config::new().nodelay(true),
))
.await?;
let ws_dns_tcp = websocket::WsConfig::new(
dns::DnsConfig::system(tcp::TcpTransport::new(
tcp::GenTcpConfig::new().nodelay(true),
dns::DnsConfig::system(tcp::async_io::Transport::new(
tcp::Config::new().nodelay(true),
))
.await?,
);
Expand Down Expand Up @@ -243,11 +243,11 @@ pub fn tokio_development_transport(
keypair: identity::Keypair,
) -> std::io::Result<core::transport::Boxed<(PeerId, core::muxing::StreamMuxerBox)>> {
let transport = {
let dns_tcp = dns::TokioDnsConfig::system(tcp::TokioTcpTransport::new(
tcp::GenTcpConfig::new().nodelay(true),
let dns_tcp = dns::TokioDnsConfig::system(tcp::tokio::Transport::new(
tcp::Config::new().nodelay(true),
))?;
let ws_dns_tcp = websocket::WsConfig::new(dns::TokioDnsConfig::system(
tcp::TokioTcpTransport::new(tcp::GenTcpConfig::new().nodelay(true)),
tcp::tokio::Transport::new(tcp::Config::new().nodelay(true)),
)?);
dns_tcp.or_transport(ws_dns_tcp)
};
Expand Down
4 changes: 2 additions & 2 deletions transports/deflate/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use futures::{future, prelude::*};
use libp2p::core::{transport::Transport, upgrade};
use libp2p::deflate::DeflateConfig;
use libp2p::tcp::TcpTransport;
use libp2p::tcp;
use quickcheck::{QuickCheck, TestResult};
use rand::RngCore;

Expand All @@ -46,7 +46,7 @@ fn lot_of_data() {

async fn run(message1: Vec<u8>) {
let new_transport = || {
TcpTransport::default()
tcp::async_io::Transport::default()
.and_then(|conn, endpoint| {
upgrade::apply(
conn,
Expand Down
20 changes: 10 additions & 10 deletions transports/noise/tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use libp2p::noise::{
Keypair, NoiseAuthenticated, NoiseConfig, NoiseError, NoiseOutput, RemoteIdentity, X25519Spec,
X25519,
};
use libp2p::tcp::TcpTransport;
use libp2p::tcp;
use log::info;
use quickcheck::*;
use std::{convert::TryInto, io, net::TcpStream};
Expand All @@ -41,7 +41,7 @@ fn core_upgrade_compat() {
// i.e. if it compiles, the "test" is considered a success.
let id_keys = identity::Keypair::generate_ed25519();
let noise = NoiseAuthenticated::xx(&id_keys).unwrap();
let _ = TcpTransport::default()
let _ = tcp::async_io::Transport::default()
.upgrade(upgrade::Version::V1)
.authenticate(noise);
}
Expand All @@ -60,7 +60,7 @@ fn xx_spec() {
let server_dh = Keypair::<X25519Spec>::new()
.into_authentic(&server_id)
.unwrap();
let server_transport = TcpTransport::default()
let server_transport = tcp::async_io::Transport::default()
.and_then(move |output, endpoint| {
upgrade::apply(
output,
Expand All @@ -75,7 +75,7 @@ fn xx_spec() {
let client_dh = Keypair::<X25519Spec>::new()
.into_authentic(&client_id)
.unwrap();
let client_transport = TcpTransport::default()
let client_transport = tcp::async_io::Transport::default()
.and_then(move |output, endpoint| {
upgrade::apply(
output,
Expand Down Expand Up @@ -107,7 +107,7 @@ fn xx() {
let client_id_public = client_id.public();

let server_dh = Keypair::<X25519>::new().into_authentic(&server_id).unwrap();
let server_transport = TcpTransport::default()
let server_transport = tcp::async_io::Transport::default()
.and_then(move |output, endpoint| {
upgrade::apply(
output,
Expand All @@ -120,7 +120,7 @@ fn xx() {
.boxed();

let client_dh = Keypair::<X25519>::new().into_authentic(&client_id).unwrap();
let client_transport = TcpTransport::default()
let client_transport = tcp::async_io::Transport::default()
.and_then(move |output, endpoint| {
upgrade::apply(
output,
Expand Down Expand Up @@ -152,7 +152,7 @@ fn ix() {
let client_id_public = client_id.public();

let server_dh = Keypair::<X25519>::new().into_authentic(&server_id).unwrap();
let server_transport = TcpTransport::default()
let server_transport = tcp::async_io::Transport::default()
.and_then(move |output, endpoint| {
upgrade::apply(
output,
Expand All @@ -165,7 +165,7 @@ fn ix() {
.boxed();

let client_dh = Keypair::<X25519>::new().into_authentic(&client_id).unwrap();
let client_transport = TcpTransport::default()
let client_transport = tcp::async_io::Transport::default()
.and_then(move |output, endpoint| {
upgrade::apply(
output,
Expand Down Expand Up @@ -198,7 +198,7 @@ fn ik_xx() {

let server_dh = Keypair::<X25519>::new().into_authentic(&server_id).unwrap();
let server_dh_public = server_dh.public_dh_key().clone();
let server_transport = TcpTransport::default()
let server_transport = tcp::async_io::Transport::default()
.and_then(move |output, endpoint| {
if endpoint.is_listener() {
Either::Left(apply_inbound(output, NoiseConfig::ik_listener(server_dh)))
Expand All @@ -215,7 +215,7 @@ fn ik_xx() {

let client_dh = Keypair::<X25519>::new().into_authentic(&client_id).unwrap();
let server_id_public2 = server_id_public.clone();
let client_transport = TcpTransport::default()
let client_transport = tcp::async_io::Transport::default()
.and_then(move |output, endpoint| {
if endpoint.is_dialer() {
Either::Left(apply_outbound(
Expand Down
Loading

0 comments on commit 4d1b165

Please sign in to comment.