[multistream-select] Fix panic with V1Lazy (regression) and more convenient transport boxing. (#1783)

* [multistream-select] Fix panic with V1Lazy and add integration tests.

Fixes a panic when using the `V1Lazy` negotiation protocol,
a regression introduced in https://github.com/libp2p/rust-libp2p/pull/1484.

Thereby adds integration tests for a transport upgrade with both
`V1` and `V1Lazy` to the `multistream-select` crate to prevent
future regressions.

* Cleanup.

* Update changelog.
This commit is contained in:
Roman Borschel
2020-10-07 11:10:54 +02:00
committed by GitHub
parent 2a5c1832a1
commit 3e31ea9337
13 changed files with 193 additions and 78 deletions

View File

@@ -23,14 +23,13 @@ use log::debug;
use quickcheck::{QuickCheck, TestResult};
use rand::{random, seq::SliceRandom, SeedableRng};
use std::{
io::Error,
pin::Pin,
task::{Context, Poll},
time::Duration,
};
use libp2p_core::{
identity, multiaddr::Protocol, muxing::StreamMuxerBox, transport::MemoryTransport, upgrade,
identity, multiaddr::Protocol, transport::MemoryTransport, upgrade,
Multiaddr, Transport,
};
use libp2p_gossipsub::{
@@ -151,10 +150,7 @@ fn build_node() -> (Multiaddr, Swarm<Gossipsub>) {
.authenticate(PlainText2Config {
local_public_key: public_key.clone(),
})
.multiplex(yamux::Config::default())
.map(|(p, m), _| (p, StreamMuxerBox::new(m)))
.map_err(|e| -> Error { panic!("Failed to create transport: {:?}", e) })
.boxed();
.multiplex(yamux::Config::default());
let peer_id = public_key.clone().into_peer_id();

View File

@@ -38,7 +38,6 @@ use libp2p_core::{
identity,
transport::MemoryTransport,
multiaddr::{Protocol, Multiaddr, multiaddr},
muxing::StreamMuxerBox,
upgrade
};
use libp2p_noise as noise;
@@ -46,7 +45,7 @@ use libp2p_swarm::Swarm;
use libp2p_yamux as yamux;
use quickcheck::*;
use rand::{Rng, random, thread_rng, rngs::StdRng, SeedableRng};
use std::{collections::{HashSet, HashMap}, time::Duration, io, num::NonZeroUsize, u64};
use std::{collections::{HashSet, HashMap}, time::Duration, num::NonZeroUsize, u64};
use multihash::{wrap, Code, Multihash};
type TestSwarm = Swarm<Kademlia<MemoryStore>>;
@@ -62,10 +61,7 @@ fn build_node_with_config(cfg: KademliaConfig) -> (Multiaddr, TestSwarm) {
let transport = MemoryTransport::default()
.upgrade(upgrade::Version::V1)
.authenticate(noise::NoiseConfig::xx(noise_keys).into_authenticated())
.multiplex(yamux::Config::default())
.map(|(p, m), _| (p, StreamMuxerBox::new(m)))
.map_err(|e| -> io::Error { panic!("Failed to create transport: {:?}", e); })
.boxed();
.multiplex(yamux::Config::default());
let local_id = local_public_key.clone().into_peer_id();
let store = MemoryStore::new(local_id.clone());

View File

@@ -25,7 +25,7 @@ use libp2p_core::{
PeerId,
identity,
muxing::StreamMuxerBox,
transport::{Transport, boxed::Boxed},
transport::{self, Transport},
upgrade
};
use libp2p_mplex as mplex;
@@ -196,7 +196,7 @@ fn max_failures() {
fn mk_transport(muxer: MuxerChoice) -> (
PeerId,
Boxed<
transport::Boxed<
(PeerId, StreamMuxerBox),
io::Error
>
@@ -204,8 +204,7 @@ fn mk_transport(muxer: MuxerChoice) -> (
let id_keys = identity::Keypair::generate_ed25519();
let peer_id = id_keys.public().into_peer_id();
let noise_keys = noise::Keypair::<noise::X25519Spec>::new().into_authentic(&id_keys).unwrap();
let transport = TcpConfig::new()
(peer_id, TcpConfig::new()
.nodelay(true)
.upgrade(upgrade::Version::V1)
.authenticate(noise::NoiseConfig::xx(noise_keys).into_authenticated())
@@ -215,11 +214,7 @@ fn mk_transport(muxer: MuxerChoice) -> (
MuxerChoice::Mplex =>
upgrade::EitherUpgrade::B(mplex::MplexConfig::default()),
})
.map(|(peer, muxer), _| (peer, StreamMuxerBox::new(muxer)))
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))
.boxed();
(peer_id, transport)
.boxed())
}
#[derive(Debug, Copy, Clone)]

View File

@@ -26,7 +26,7 @@ use libp2p_core::{
PeerId,
identity,
muxing::StreamMuxerBox,
transport::{Transport, boxed::Boxed},
transport::{self, Transport},
upgrade::{self, read_one, write_one}
};
use libp2p_noise::{NoiseConfig, X25519Spec, Keypair};
@@ -213,19 +213,16 @@ fn ping_protocol_throttled() {
let () = async_std::task::block_on(peer2);
}
fn mk_transport() -> (PeerId, Boxed<(PeerId, StreamMuxerBox), io::Error>) {
fn mk_transport() -> (PeerId, transport::Boxed<(PeerId, StreamMuxerBox), io::Error>) {
let id_keys = identity::Keypair::generate_ed25519();
let peer_id = id_keys.public().into_peer_id();
let noise_keys = Keypair::<X25519Spec>::new().into_authentic(&id_keys).unwrap();
let transport = TcpConfig::new()
(peer_id, TcpConfig::new()
.nodelay(true)
.upgrade(upgrade::Version::V1)
.authenticate(NoiseConfig::xx(noise_keys).into_authenticated())
.multiplex(libp2p_yamux::Config::default())
.map(|(peer, muxer), _| (peer, StreamMuxerBox::new(muxer)))
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))
.boxed();
(peer_id, transport)
.boxed())
}
// Simple Ping-Pong Protocol