Add ProtocolsHandler::InboundOpenInfo. (#1714)

* Add `ProtocolsHandler::InboundOpenInfo`.

* Update swarm/src/protocols_handler/multi.rs

Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>

* Update CHANGELOGs and versions.

Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
This commit is contained in:
Toralf Wittner
2020-08-23 16:57:20 +02:00
committed by GitHub
parent 740a2e0235
commit 0b05b21093
32 changed files with 337 additions and 204 deletions

View File

@ -40,7 +40,7 @@ use std::{
/// Protocol Handler that manages a single long-lived substream with a peer.
pub struct GossipsubHandler {
/// Upgrade configuration for the gossipsub protocol.
listen_protocol: SubstreamProtocol<ProtocolConfig>,
listen_protocol: SubstreamProtocol<ProtocolConfig, ()>,
/// The single long-lived outbound substream.
outbound_substream: Option<OutboundSubstreamState>,
@ -95,7 +95,7 @@ impl GossipsubHandler {
protocol_id,
max_transmit_size,
validation_mode,
)),
), ()),
inbound_substream: None,
outbound_substream: None,
outbound_substream_establishing: false,
@ -112,14 +112,16 @@ impl ProtocolsHandler for GossipsubHandler {
type InboundProtocol = ProtocolConfig;
type OutboundProtocol = ProtocolConfig;
type OutboundOpenInfo = GossipsubRpc;
type InboundOpenInfo = ();
fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol> {
fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol, Self::InboundOpenInfo> {
self.listen_protocol.clone()
}
fn inject_fully_negotiated_inbound(
&mut self,
substream: <Self::InboundProtocol as InboundUpgrade<NegotiatedSubstream>>::Output,
_info: Self::InboundOpenInfo
) {
// new inbound substream. Replace the current one, if it exists.
trace!("New inbound substream request");
@ -184,8 +186,7 @@ impl ProtocolsHandler for GossipsubHandler {
self.send_queue.shrink_to_fit();
self.outbound_substream_establishing = true;
return Poll::Ready(ProtocolsHandlerEvent::OutboundSubstreamRequest {
protocol: self.listen_protocol.clone(),
info: message,
protocol: self.listen_protocol.clone().map_info(|()| message)
});
}