Upgrade to libp2p 0.15 (#4732)

* Fixes for libp2p 0.15

* More work

* Update libp2p

* Update to libp2p 0.15
This commit is contained in:
Pierre Krieger
2020-01-27 18:27:36 +01:00
committed by Gavin Wood
parent ed3da9f903
commit 5c8743510e
16 changed files with 332 additions and 237 deletions
@@ -18,7 +18,7 @@ use super::upgrade::{RegisteredProtocol, RegisteredProtocolEvent, RegisteredProt
use bytes::BytesMut;
use futures::prelude::*;
use futures_timer::Delay;
use libp2p::core::{ConnectedPoint, PeerId, Endpoint};
use libp2p::core::{ConnectedPoint, Negotiated, PeerId, Endpoint};
use libp2p::core::upgrade::{InboundUpgrade, OutboundUpgrade};
use libp2p::swarm::{
ProtocolsHandler, ProtocolsHandlerEvent,
@@ -159,7 +159,7 @@ enum ProtocolState<TSubstream> {
/// Waiting for the behaviour to tell the handler whether it is enabled or disabled.
Init {
/// List of substreams opened by the remote but that haven't been processed yet.
substreams: SmallVec<[RegisteredProtocolSubstream<TSubstream>; 6]>,
substreams: SmallVec<[RegisteredProtocolSubstream<Negotiated<TSubstream>>; 6]>,
/// Deadline after which the initialization is abnormally long.
init_deadline: Delay,
},
@@ -175,9 +175,9 @@ enum ProtocolState<TSubstream> {
/// If we are in this state, we have sent a `CustomProtocolOpen` message to the outside.
Normal {
/// The substreams where bidirectional communications happen.
substreams: SmallVec<[RegisteredProtocolSubstream<TSubstream>; 4]>,
substreams: SmallVec<[RegisteredProtocolSubstream<Negotiated<TSubstream>>; 4]>,
/// Contains substreams which are being shut down.
shutdown: SmallVec<[RegisteredProtocolSubstream<TSubstream>; 4]>,
shutdown: SmallVec<[RegisteredProtocolSubstream<Negotiated<TSubstream>>; 4]>,
},
/// We are disabled. Contains substreams that are being closed.
@@ -185,7 +185,7 @@ enum ProtocolState<TSubstream> {
/// outside or we have never sent any `CustomProtocolOpen` in the first place.
Disabled {
/// List of substreams to shut down.
shutdown: SmallVec<[RegisteredProtocolSubstream<TSubstream>; 6]>,
shutdown: SmallVec<[RegisteredProtocolSubstream<Negotiated<TSubstream>>; 6]>,
/// If true, we should reactivate the handler after all the substreams in `shutdown` have
/// been closed.
@@ -466,7 +466,7 @@ where
/// Called by `inject_fully_negotiated_inbound` and `inject_fully_negotiated_outbound`.
fn inject_fully_negotiated(
&mut self,
mut substream: RegisteredProtocolSubstream<TSubstream>
mut substream: RegisteredProtocolSubstream<Negotiated<TSubstream>>
) {
self.state = match mem::replace(&mut self.state, ProtocolState::Poisoned) {
ProtocolState::Poisoned => {
@@ -538,14 +538,14 @@ where TSubstream: AsyncRead + AsyncWrite + Unpin {
fn inject_fully_negotiated_inbound(
&mut self,
proto: <Self::InboundProtocol as InboundUpgrade<TSubstream>>::Output
proto: <Self::InboundProtocol as InboundUpgrade<Negotiated<TSubstream>>>::Output
) {
self.inject_fully_negotiated(proto);
}
fn inject_fully_negotiated_outbound(
&mut self,
proto: <Self::OutboundProtocol as OutboundUpgrade<TSubstream>>::Output,
proto: <Self::OutboundProtocol as OutboundUpgrade<Negotiated<TSubstream>>>::Output,
_: Self::OutboundOpenInfo
) {
self.inject_fully_negotiated(proto);
@@ -621,7 +621,7 @@ where
/// Given a list of substreams, tries to shut them down. The substreams that have been successfully
/// shut down are removed from the list.
fn shutdown_list<TSubstream>
(list: &mut SmallVec<impl smallvec::Array<Item = RegisteredProtocolSubstream<TSubstream>>>,
(list: &mut SmallVec<impl smallvec::Array<Item = RegisteredProtocolSubstream<Negotiated<TSubstream>>>>,
cx: &mut Context)
where TSubstream: AsyncRead + AsyncWrite + Unpin {
'outer: for n in (0..list.len()).rev() {
@@ -18,7 +18,7 @@ use crate::config::ProtocolId;
use bytes::BytesMut;
use futures::prelude::*;
use futures_codec::Framed;
use libp2p::core::{Negotiated, Endpoint, UpgradeInfo, InboundUpgrade, OutboundUpgrade, upgrade::ProtocolName};
use libp2p::core::{Endpoint, UpgradeInfo, InboundUpgrade, OutboundUpgrade, upgrade::ProtocolName};
use std::{collections::VecDeque, io, pin::Pin, vec::IntoIter as VecIntoIter};
use std::task::{Context, Poll};
use unsigned_varint::codec::UviBytes;
@@ -82,7 +82,7 @@ pub struct RegisteredProtocolSubstream<TSubstream> {
/// If true, we should call `poll_complete` on the inner sink.
requires_poll_flush: bool,
/// The underlying substream.
inner: stream::Fuse<Framed<Negotiated<TSubstream>, UviBytes<BytesMut>>>,
inner: stream::Fuse<Framed<TSubstream, UviBytes<BytesMut>>>,
/// Version of the protocol that was negotiated.
protocol_version: u8,
/// If true, we have sent a "remote is clogged" event recently and shouldn't send another one
@@ -250,7 +250,7 @@ where TSubstream: AsyncRead + AsyncWrite + Unpin,
fn upgrade_inbound(
self,
socket: Negotiated<TSubstream>,
socket: TSubstream,
info: Self::Info,
) -> Self::Future {
let framed = {
@@ -280,7 +280,7 @@ where TSubstream: AsyncRead + AsyncWrite + Unpin,
fn upgrade_outbound(
self,
socket: Negotiated<TSubstream>,
socket: TSubstream,
info: Self::Info,
) -> Self::Future {
let framed = Framed::new(socket, UviBytes::default());