mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-27 08:41:36 +00:00
Wrap multistream-select streams under a Negotiated (#1001)
This commit is contained in:
@ -24,7 +24,7 @@ use crate::protocol::{IdentifyInfo, IdentifySender, IdentifySenderFuture};
|
||||
use futures::prelude::*;
|
||||
use libp2p_core::protocols_handler::{ProtocolsHandler, ProtocolsHandlerSelect, ProtocolsHandlerUpgrErr};
|
||||
use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction, PollParameters};
|
||||
use libp2p_core::{Multiaddr, PeerId, PublicKey, either::EitherOutput};
|
||||
use libp2p_core::{Multiaddr, PeerId, PublicKey, either::EitherOutput, upgrade::Negotiated};
|
||||
use smallvec::SmallVec;
|
||||
use std::{collections::HashMap, collections::VecDeque, io};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
@ -42,9 +42,9 @@ pub struct Identify<TSubstream> {
|
||||
/// For each peer we're connected to, the observed address to send back to it.
|
||||
observed_addresses: HashMap<PeerId, Multiaddr>,
|
||||
/// List of senders to answer, with the observed multiaddr.
|
||||
to_answer: SmallVec<[(PeerId, IdentifySender<TSubstream>, Multiaddr); 4]>,
|
||||
to_answer: SmallVec<[(PeerId, IdentifySender<Negotiated<TSubstream>>, Multiaddr); 4]>,
|
||||
/// List of futures that send back information back to remotes.
|
||||
futures: SmallVec<[(PeerId, IdentifySenderFuture<TSubstream>); 4]>,
|
||||
futures: SmallVec<[(PeerId, IdentifySenderFuture<Negotiated<TSubstream>>); 4]>,
|
||||
/// Events that need to be produced outside when polling..
|
||||
events: VecDeque<NetworkBehaviourAction<EitherOutput<Void, Void>, IdentifyEvent>>,
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ use crate::protocol::{IdentifySender, IdentifyProtocolConfig};
|
||||
use futures::prelude::*;
|
||||
use libp2p_core::{
|
||||
protocols_handler::{KeepAlive, ProtocolsHandler, ProtocolsHandlerEvent, ProtocolsHandlerUpgrErr},
|
||||
upgrade::{DeniedUpgrade, InboundUpgrade, OutboundUpgrade}
|
||||
upgrade::{DeniedUpgrade, InboundUpgrade, OutboundUpgrade, Negotiated}
|
||||
};
|
||||
use smallvec::SmallVec;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
@ -34,7 +34,7 @@ pub struct IdentifyListenHandler<TSubstream> {
|
||||
config: IdentifyProtocolConfig,
|
||||
|
||||
/// List of senders to yield to the user.
|
||||
pending_result: SmallVec<[IdentifySender<TSubstream>; 4]>,
|
||||
pending_result: SmallVec<[IdentifySender<Negotiated<TSubstream>>; 4]>,
|
||||
}
|
||||
|
||||
impl<TSubstream> IdentifyListenHandler<TSubstream> {
|
||||
@ -53,7 +53,7 @@ where
|
||||
TSubstream: AsyncRead + AsyncWrite,
|
||||
{
|
||||
type InEvent = Void;
|
||||
type OutEvent = IdentifySender<TSubstream>;
|
||||
type OutEvent = IdentifySender<Negotiated<TSubstream>>;
|
||||
type Error = Void;
|
||||
type Substream = TSubstream;
|
||||
type InboundProtocol = IdentifyProtocolConfig;
|
||||
|
@ -24,7 +24,7 @@ use futures::{future::{self, FutureResult}, Async, AsyncSink, Future, Poll, Sink
|
||||
use futures::try_ready;
|
||||
use libp2p_core::{
|
||||
Multiaddr, PublicKey,
|
||||
upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}
|
||||
upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo, Negotiated}
|
||||
};
|
||||
use log::{debug, trace};
|
||||
use protobuf::Message as ProtobufMessage;
|
||||
@ -150,11 +150,11 @@ impl<C> InboundUpgrade<C> for IdentifyProtocolConfig
|
||||
where
|
||||
C: AsyncRead + AsyncWrite,
|
||||
{
|
||||
type Output = IdentifySender<C>;
|
||||
type Output = IdentifySender<Negotiated<C>>;
|
||||
type Error = IoError;
|
||||
type Future = FutureResult<Self::Output, IoError>;
|
||||
|
||||
fn upgrade_inbound(self, socket: C, _: Self::Info) -> Self::Future {
|
||||
fn upgrade_inbound(self, socket: Negotiated<C>, _: Self::Info) -> Self::Future {
|
||||
trace!("Upgrading inbound connection");
|
||||
let socket = Framed::new(socket, codec::UviBytes::default());
|
||||
let sender = IdentifySender { inner: socket };
|
||||
@ -168,9 +168,9 @@ where
|
||||
{
|
||||
type Output = RemoteInfo;
|
||||
type Error = IoError;
|
||||
type Future = IdentifyOutboundFuture<C>;
|
||||
type Future = IdentifyOutboundFuture<Negotiated<C>>;
|
||||
|
||||
fn upgrade_outbound(self, socket: C, _: Self::Info) -> Self::Future {
|
||||
fn upgrade_outbound(self, socket: Negotiated<C>, _: Self::Info) -> Self::Future {
|
||||
IdentifyOutboundFuture {
|
||||
inner: Framed::new(socket, codec::UviBytes::<BytesMut>::default()),
|
||||
shutdown: false,
|
||||
|
Reference in New Issue
Block a user