Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transports/tcp: Unify symbol naming #2961

Merged
merged 26 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1091df7
Migrate `libp2p_tcp` to new naming convention
thomaseizinger Sep 30, 2022
75b6601
Rename `GenTcpTransport` struct to just `Transport`
thomaseizinger Sep 30, 2022
eace956
Hide a few types from the docs
thomaseizinger Sep 30, 2022
8e9b56f
Remove `TcpListenStream` and `TcpListenerEvent` from public API
thomaseizinger Sep 30, 2022
cf4b11e
Several doc fixes
thomaseizinger Sep 30, 2022
16d01e7
Merge branch 'master' into 2173-rename-tcp-transport-symbols
thomaseizinger Sep 30, 2022
b447c1d
Update transports/tcp/CHANGELOG.md
thomaseizinger Sep 30, 2022
ec2c952
Update transports/tcp/CHANGELOG.md
thomaseizinger Sep 30, 2022
669b020
Merge branch 'master' into 2173-rename-tcp-transport-symbols
thomaseizinger Sep 30, 2022
2020cac
Merge branch '2173-rename-tcp-transport-symbols' of github.com:libp2p…
thomaseizinger Sep 30, 2022
93ee672
Merge branch 'master' into 2173-rename-tcp-transport-symbols
thomaseizinger Oct 4, 2022
c4424ee
Merge branch 'master' into 2173-rename-tcp-transport-symbols
thomaseizinger Oct 8, 2022
d584aa2
Only have 1 `use` block
thomaseizinger Oct 8, 2022
5d27c49
Move deprecated items to bottom of file
thomaseizinger Oct 8, 2022
796ecec
Fix doc links
thomaseizinger Oct 8, 2022
d215275
Add examples to transport aliases
thomaseizinger Oct 8, 2022
b486eee
Split feature-flag dependent test into two
thomaseizinger Oct 8, 2022
b079313
Use `Default` where possible
thomaseizinger Oct 8, 2022
ad042fb
Fix docs
thomaseizinger Oct 8, 2022
b3736aa
Add docs to `Transport::new`
thomaseizinger Oct 8, 2022
1f7fb05
Fix links to deprecated config alias
thomaseizinger Oct 8, 2022
a05c504
Add docs to `default` function
thomaseizinger Oct 8, 2022
2f7fbf1
Fix doc tests
thomaseizinger Oct 8, 2022
227c4e2
Merge branch 'master' into 2173-rename-tcp-transport-symbols
thomaseizinger Oct 19, 2022
7f1de3b
Bump version accordingly
thomaseizinger Oct 19, 2022
37811c5
Merge branch 'master' into 2173-rename-tcp-transport-symbols
thomaseizinger Oct 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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::plaintext::PlainText2Config;
use libp2p::tcp::GenTcpConfig;
use libp2p::{mplex, tcp};
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/dcutr.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;
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved
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