Simplify handling of upgrade information. (#761)

This commit is contained in:
Toralf Wittner
2018-12-11 15:13:10 +01:00
committed by GitHub
parent 2dce4294a0
commit a152e18821
25 changed files with 346 additions and 377 deletions

View File

@ -26,7 +26,7 @@
//! The `Stream` component is used to poll the underlying transport, and the `Sink` component is
//! used to send messages.
use bytes::{Bytes, BytesMut};
use bytes::BytesMut;
use futures::{future, sink, stream, Sink, Stream};
use libp2p_core::{InboundUpgrade, Multiaddr, OutboundUpgrade, PeerId, UpgradeInfo};
use multihash::Multihash;
@ -136,12 +136,12 @@ impl Into<protobuf_structs::dht::Message_Peer> for KadPeer {
pub struct KademliaProtocolConfig;
impl UpgradeInfo for KademliaProtocolConfig {
type NamesIter = iter::Once<(Bytes, ())>;
type UpgradeId = ();
type Info = &'static [u8];
type InfoIter = iter::Once<Self::Info>;
#[inline]
fn protocol_names(&self) -> Self::NamesIter {
iter::once(("/ipfs/kad/1.0.0".into(), ()))
fn protocol_info(&self) -> Self::InfoIter {
iter::once(b"/ipfs/kad/1.0.0")
}
}
@ -154,7 +154,7 @@ where
type Error = IoError;
#[inline]
fn upgrade_inbound(self, incoming: C, _: ()) -> Self::Future {
fn upgrade_inbound(self, incoming: C, _: Self::Info) -> Self::Future {
future::ok(
Framed::new(incoming, codec::UviBytes::default())
.from_err::<IoError>()
@ -180,7 +180,7 @@ where
type Error = IoError;
#[inline]
fn upgrade_outbound(self, incoming: C, _: ()) -> Self::Future {
fn upgrade_outbound(self, incoming: C, _: Self::Info) -> Self::Future {
future::ok(
Framed::new(incoming, codec::UviBytes::default())
.from_err::<IoError>()