Update to bytes v0.5

Except for `multiaddr` which encapsulates its use of bytes v0.4 now.
This commit is contained in:
Toralf Wittner
2019-12-21 15:35:55 +01:00
parent 589fdafdda
commit 2bc8d9590d
25 changed files with 72 additions and 105 deletions

View File

@ -11,12 +11,12 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
bs58 = "0.3.0"
bytes = "0.4"
bytes = "0.5"
cuckoofilter = "0.3.2"
fnv = "1.0"
futures = "0.3.1"
libp2p-core = { version = "0.13.0", path = "../../core" }
libp2p-swarm = { version = "0.3.0", path = "../../swarm" }
protobuf = "2.8"
rand = "0.6"
rand = "0.7"
smallvec = "1.0"

View File

@ -10,8 +10,8 @@ keywords = ["peer-to-peer", "libp2p", "networking"]
categories = ["network-programming", "asynchronous"]
[dependencies]
bytes = "0.4"
futures_codec = "= 0.3.3"
bytes = "0.5"
futures_codec = "0.3.4"
futures = "0.3.1"
libp2p-core = { version = "0.13.0", path = "../../core" }
libp2p-swarm = { version = "0.3.0", path = "../../swarm" }
@ -20,7 +20,7 @@ multiaddr = { package = "parity-multiaddr", version = "0.6.0", path = "../../mis
protobuf = "2.8"
smallvec = "1.0"
wasm-timer = "0.2"
unsigned-varint = { version = "0.2.3", features = ["futures-codec"] }
unsigned-varint = { git = "https://github.com/twittner/unsigned-varint.git", branch = "bytes-0.5", features = ["futures-codec"] }
[dev-dependencies]
async-std = "1.0"

View File

@ -11,10 +11,10 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
arrayvec = "0.5.1"
bytes = "0.4"
bytes = "0.5"
either = "1.5"
fnv = "1.0"
futures_codec = "= 0.3.3"
futures_codec = "0.3.4"
futures = "0.3.1"
log = "0.4"
libp2p-core = { version = "0.13.0", path = "../../core" }
@ -27,7 +27,7 @@ sha2 = "0.8.0"
smallvec = "1.0"
wasm-timer = "0.2"
uint = "0.8"
unsigned-varint = { version = "0.2.3", features = ["futures-codec"] }
unsigned-varint = { git = "https://github.com/twittner/unsigned-varint.git", branch = "bytes-0.5", features = ["futures-codec"] }
void = "1.0"
[dev-dependencies]

View File

@ -58,7 +58,6 @@ pub enum KadConnectionType {
}
impl From<proto::Message_ConnectionType> for KadConnectionType {
#[inline]
fn from(raw: proto::Message_ConnectionType) -> KadConnectionType {
use proto::Message_ConnectionType::{
CAN_CONNECT, CANNOT_CONNECT, CONNECTED, NOT_CONNECTED
@ -73,7 +72,6 @@ impl From<proto::Message_ConnectionType> for KadConnectionType {
}
impl Into<proto::Message_ConnectionType> for KadConnectionType {
#[inline]
fn into(self) -> proto::Message_ConnectionType {
use proto::Message_ConnectionType::{
CAN_CONNECT, CANNOT_CONNECT, CONNECTED, NOT_CONNECTED
@ -181,7 +179,6 @@ where
type Future = future::Ready<Result<Self::Output, io::Error>>;
type Error = io::Error;
#[inline]
fn upgrade_inbound(self, incoming: Negotiated<C>, _: Self::Info) -> Self::Future {
let mut codec = UviBytes::default();
codec.set_max_len(4096);
@ -191,7 +188,9 @@ where
.err_into()
.with::<_, _, fn(_) -> _, _>(|response| {
let proto_struct = resp_msg_to_proto(response);
future::ready(proto_struct.write_to_bytes().map_err(invalid_data))
future::ready(proto_struct.write_to_bytes()
.map(io::Cursor::new)
.map_err(invalid_data))
})
.and_then::<_, fn(_) -> _>(|bytes| {
let request = match protobuf::parse_from_bytes(&bytes) {
@ -212,7 +211,6 @@ where
type Future = future::Ready<Result<Self::Output, io::Error>>;
type Error = io::Error;
#[inline]
fn upgrade_outbound(self, incoming: Negotiated<C>, _: Self::Info) -> Self::Future {
let mut codec = UviBytes::default();
codec.set_max_len(4096);
@ -222,7 +220,9 @@ where
.err_into()
.with::<_, _, fn(_) -> _, _>(|request| {
let proto_struct = req_msg_to_proto(request);
future::ready(proto_struct.write_to_bytes().map_err(invalid_data))
future::ready(proto_struct.write_to_bytes()
.map(io::Cursor::new)
.map_err(invalid_data))
})
.and_then::<_, fn(_) -> _>(|bytes| {
let response = match protobuf::parse_from_bytes(&bytes) {
@ -243,11 +243,11 @@ pub type KadOutStreamSink<S> = KadStreamSink<S, KadRequestMsg, KadResponseMsg>;
pub type KadStreamSink<S, A, B> = stream::AndThen<
sink::With<
stream::ErrInto<Framed<S, UviBytes<Vec<u8>>>, io::Error>,
Vec<u8>,
stream::ErrInto<Framed<S, UviBytes<io::Cursor<Vec<u8>>>>, io::Error>,
io::Cursor<Vec<u8>>,
A,
future::Ready<Result<Vec<u8>, io::Error>>,
fn(A) -> future::Ready<Result<Vec<u8>, io::Error>>,
future::Ready<Result<io::Cursor<Vec<u8>>, io::Error>>,
fn(A) -> future::Ready<Result<io::Cursor<Vec<u8>>, io::Error>>,
>,
future::Ready<Result<B, io::Error>>,
fn(BytesMut) -> future::Ready<Result<B, io::Error>>,

View File

@ -35,7 +35,7 @@ pub struct Key(Bytes);
impl Key {
/// Creates a new key from the bytes of the input.
pub fn new<K: AsRef<[u8]>>(key: &K) -> Self {
Key(Bytes::from(key.as_ref()))
Key(Bytes::copy_from_slice(key.as_ref()))
}
/// Copies the bytes of the key into a new vector.

View File

@ -8,7 +8,7 @@ repository = "https://github.com/libp2p/rust-libp2p"
edition = "2018"
[dependencies]
bytes = "0.4"
bytes = "0.5"
curve25519-dalek = "1"
futures = "0.3.1"
lazy_static = "1.2"

View File

@ -10,15 +10,15 @@ keywords = ["peer-to-peer", "libp2p", "networking"]
categories = ["network-programming", "asynchronous"]
[dependencies]
bytes = "0.4"
bytes = "0.5"
futures = "0.3.1"
libp2p-core = { version = "0.13.0", path = "../../core" }
libp2p-swarm = { version = "0.3.0", path = "../../swarm" }
log = "0.4.1"
multiaddr = { package = "parity-multiaddr", version = "0.6.0", path = "../../misc/multiaddr" }
futures = "0.3.1"
rand = "0.7.2"
wasm-timer = "0.2"
void = "1.0"
wasm-timer = "0.2"
[dev-dependencies]
async-std = "1.0"

View File

@ -10,14 +10,14 @@ keywords = ["peer-to-peer", "libp2p", "networking"]
categories = ["network-programming", "asynchronous"]
[dependencies]
bytes = "0.4.12"
bytes = "0.5"
futures = "0.3.1"
futures_codec = "= 0.3.3"
futures_codec = "0.3.4"
libp2p-core = { version = "0.13.0", path = "../../core" }
log = "0.4.8"
protobuf = "2.8.1"
rw-stream-sink = { version = "0.1.1", path = "../../misc/rw-stream-sink" }
unsigned-varint = { version = "0.2.3", features = ["futures-codec"] }
unsigned-varint = { git = "https://github.com/twittner/unsigned-varint.git", branch = "bytes-0.5", features = ["futures-codec"] }
void = "1.0.2"
[dev-dependencies]

View File

@ -120,7 +120,7 @@ where
let context = HandshakeContext::new(config)?;
trace!("sending exchange to remote");
socket.send(BytesMut::from(context.state.exchange_bytes.clone())).await?;
socket.send(BytesMut::from(&context.state.exchange_bytes[..])).await?;
trace!("receiving the remote's exchange");
let context = match socket.next().await {