Skip to content

Commit

Permalink
Migrate libp2p_tcp to new naming convention
Browse files Browse the repository at this point in the history
See #2217.
See #2173.
  • Loading branch information
thomaseizinger committed Sep 30, 2022
1 parent f6bb846 commit 1091df7
Show file tree
Hide file tree
Showing 19 changed files with 84 additions and 81 deletions.
13 changes: 3 additions & 10 deletions examples/chat-tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
//! ```

use futures::StreamExt;
use libp2p::tcp::GenTcpConfig;
use libp2p::{
core::upgrade,
floodsub::{self, Floodsub, FloodsubEvent},
Expand All @@ -47,15 +46,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 @@ -72,7 +65,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 @@ -46,7 +45,7 @@ use libp2p::{
ping::{self, PingEvent},
pnet::{PnetConfig, PreSharedKey},
swarm::SwarmEvent,
tcp::TcpTransport,
tcp,
yamux::YamuxConfig,
Multiaddr, NetworkBehaviour, PeerId, Swarm, Transport,
};
Expand All @@ -60,7 +59,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::{mplex, tcp};
use libp2p::plaintext::PlainText2Config;
use libp2p::tcp::GenTcpConfig;
use std::pin::Pin;
use std::time::Duration;

Expand Down Expand Up @@ -166,7 +165,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 muxers/mplex/tests/async_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use futures::{channel::oneshot, prelude::*};
use libp2p::core::muxing::StreamMuxerExt;
use libp2p::core::{upgrade, Transport};
use libp2p::tcp::TcpTransport;
use libp2p::tcp;

#[test]
fn async_write() {
Expand All @@ -32,7 +32,7 @@ fn async_write() {
let bg_thread = async_std::task::spawn(async move {
let mplex = libp2p::mplex::MplexConfig::new();

let mut transport = TcpTransport::default()
let mut transport = tcp::async_io::Transport::default()
.and_then(move |c, e| upgrade::apply(c, mplex, e, upgrade::Version::V1))
.boxed();

Expand Down Expand Up @@ -68,7 +68,7 @@ fn async_write() {

async_std::task::block_on(async {
let mplex = libp2p::mplex::MplexConfig::new();
let mut transport = TcpTransport::default()
let mut transport = tcp::async_io::Transport::default()
.and_then(move |c, e| upgrade::apply(c, mplex, e, upgrade::Version::V1));

let mut client = transport.dial(rx.await.unwrap()).unwrap().await.unwrap();
Expand Down
14 changes: 7 additions & 7 deletions muxers/mplex/tests/two_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use futures::{channel::oneshot, prelude::*};
use libp2p::core::muxing::StreamMuxerExt;
use libp2p::core::{upgrade, Transport};
use libp2p::tcp::TcpTransport;
use libp2p::tcp;

#[test]
fn client_to_server_outbound() {
Expand All @@ -32,7 +32,7 @@ fn client_to_server_outbound() {
let bg_thread = async_std::task::spawn(async move {
let mplex = libp2p_mplex::MplexConfig::new();

let mut transport = TcpTransport::default()
let mut transport = tcp::async_io::Transport::default()
.and_then(move |c, e| upgrade::apply(c, mplex, e, upgrade::Version::V1))
.boxed();

Expand Down Expand Up @@ -68,7 +68,7 @@ fn client_to_server_outbound() {

async_std::task::block_on(async {
let mplex = libp2p_mplex::MplexConfig::new();
let mut transport = TcpTransport::default()
let mut transport = tcp::async_io::Transport::default()
.and_then(move |c, e| upgrade::apply(c, mplex, e, upgrade::Version::V1))
.boxed();

Expand All @@ -90,7 +90,7 @@ fn client_to_server_inbound() {
let bg_thread = async_std::task::spawn(async move {
let mplex = libp2p_mplex::MplexConfig::new();

let mut transport = TcpTransport::default()
let mut transport = tcp::async_io::Transport::default()
.and_then(move |c, e| upgrade::apply(c, mplex, e, upgrade::Version::V1))
.boxed();

Expand Down Expand Up @@ -126,7 +126,7 @@ fn client_to_server_inbound() {

async_std::task::block_on(async {
let mplex = libp2p_mplex::MplexConfig::new();
let mut transport = TcpTransport::default()
let mut transport = tcp::async_io::Transport::default()
.and_then(move |c, e| upgrade::apply(c, mplex, e, upgrade::Version::V1))
.boxed();

Expand All @@ -147,7 +147,7 @@ fn protocol_not_match() {
let _bg_thread = async_std::task::spawn(async move {
let mplex = libp2p_mplex::MplexConfig::new();

let mut transport = TcpTransport::default()
let mut transport = tcp::async_io::Transport::default()
.and_then(move |c, e| upgrade::apply(c, mplex, e, upgrade::Version::V1))
.boxed();

Expand Down Expand Up @@ -185,7 +185,7 @@ fn protocol_not_match() {
// Make sure they do not connect when protocols do not match
let mut mplex = libp2p_mplex::MplexConfig::new();
mplex.set_protocol_name(b"/mplextest/1.0.0");
let mut transport = TcpTransport::default()
let mut transport = tcp::async_io::Transport::default()
.and_then(move |c, e| upgrade::apply(c, mplex, e, upgrade::Version::V1))
.boxed();
match transport.dial(rx.await.unwrap()).unwrap().await {
Expand Down
6 changes: 3 additions & 3 deletions protocols/dcutr/examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use libp2p::noise;
use libp2p::ping::{Ping, PingConfig, PingEvent};
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::{identity, NetworkBehaviour, PeerId};
use log::info;
Expand Down Expand Up @@ -91,8 +91,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/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,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 @@ -564,7 +564,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, IdentifyProtocol, 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::{DummyBehaviour, KeepAlive, Swarm, SwarmEvent};
use libp2p::tcp::{GenTcpConfig, TcpTransport};
use libp2p::tcp;
use libp2p::yamux;
use quickcheck::*;
use std::{num::NonZeroU8, time::Duration};
Expand Down Expand Up @@ -244,7 +244,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
4 changes: 2 additions & 2 deletions protocols/relay/examples/relay_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use libp2p::multiaddr::Protocol;
use libp2p::ping::{Ping, PingConfig, PingEvent};
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};
Expand All @@ -46,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 @@ -204,13 +204,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 @@ -264,11 +264,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
Loading

0 comments on commit 1091df7

Please sign in to comment.