Pierre Krieger abe2f2afc1
Merge master into stable-futures (#1271)
* Configurable multistream-select protocol. Add V1Lazy variant. (#1245)

Make the multistream-select protocol (version) configurable
on transport upgrades as well as for individual substreams.

Add a "lazy" variant of multistream-select 1.0 that delays
sending of negotiation protocol frames as much as possible
but is only safe to use under additional assumptions that
go beyond what is required by the multistream-select v1
specification.

* Improve the code readability of the chat example (#1253)

* Add bridged chats (#1252)

* Try fix CI (#1261)

* Print Rust version on CI

* Don't print where not appropriate

* Change caching strategy

* Remove win32 build

* Remove win32 from list

* Update libsecp256k1 dep to 0.3.0 (#1258)

* Update libsecp256k1 dep to 0.3.0

* Sign now cannot fail

* Upgrade url and percent-encoding deps to 2.1.0 (#1267)

* Upgrade percent-encoding dep to 2.1.0

* Upgrade url dep to 2.1.0

* Fix more conflicts

* Revert CIPHERS set to null (#1273)
2019-10-10 11:31:44 +02:00

77 lines
2.9 KiB
Rust

// Copyright 2019 Parity Technologies (UK) Ltd.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
use futures::{prelude::*, channel::oneshot};
use libp2p_core::{transport::Transport, upgrade};
use libp2p_deflate::DeflateConfig;
use libp2p_tcp::TcpConfig;
use quickcheck::QuickCheck;
#[test]
fn deflate() {
fn prop(message: Vec<u8>) -> bool {
run(message);
true
}
QuickCheck::new()
.max_tests(30)
.quickcheck(prop as fn(Vec<u8>) -> bool)
}
#[test]
fn lot_of_data() {
run((0..16*1024*1024).map(|_| rand::random::<u8>()).collect());
}
fn run(message1: Vec<u8>) {
let transport1 = TcpConfig::new()
.and_then(|c, e| upgrade::apply(c, DeflateConfig::default(), e, upgrade::Version::V1));
let transport2 = transport1.clone();
let message2 = message1.clone();
let (l_a_tx, l_a_rx) = oneshot::channel();
async_std::task::spawn(async move {
let mut server = transport1.listen_on("/ip4/127.0.0.1/tcp/0".parse().unwrap()).unwrap();
let server_address = server.next().await.unwrap().unwrap().into_new_address().unwrap();
l_a_tx.send(server_address).unwrap();
let mut connec = server.next().await.unwrap().unwrap().into_upgrade().unwrap().0.await.unwrap();
let mut buf = vec![0; message2.len()];
connec.read_exact(&mut buf).await.unwrap();
assert_eq!(&buf[..], &message2[..]);
connec.write_all(&message2).await.unwrap();
connec.close().await.unwrap();
});
futures::executor::block_on(async move {
let listen_addr = l_a_rx.await.unwrap();
let mut connec = transport2.dial(listen_addr).unwrap().await.unwrap();
connec.write_all(&message1).await.unwrap();
connec.close().await.unwrap();
let mut buf = Vec::new();
connec.read_to_end(&mut buf).await.unwrap();
assert_eq!(&buf[..], &message1[..]);
});
}