cs_mwc_libp2p_swarm/protocols_handler/
dummy.rs

1// Copyright 2018 Parity Technologies (UK) Ltd.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a
4// copy of this software and associated documentation files (the "Software"),
5// to deal in the Software without restriction, including without limitation
6// the rights to use, copy, modify, merge, publish, distribute, sublicense,
7// and/or sell copies of the Software, and to permit persons to whom the
8// Software is furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19// DEALINGS IN THE SOFTWARE.
20
21use crate::NegotiatedSubstream;
22use crate::protocols_handler::{
23    KeepAlive,
24    SubstreamProtocol,
25    ProtocolsHandler,
26    ProtocolsHandlerEvent,
27    ProtocolsHandlerUpgrErr
28};
29use mwc_libp2p_core::{Multiaddr, upgrade::{InboundUpgrade, OutboundUpgrade, DeniedUpgrade}};
30use std::task::{Context, Poll};
31use void::Void;
32
33/// Implementation of `ProtocolsHandler` that doesn't handle anything.
34#[derive(Clone, Debug)]
35pub struct DummyProtocolsHandler {
36    pub keep_alive: KeepAlive,
37}
38
39impl Default for DummyProtocolsHandler {
40    fn default() -> Self {
41        DummyProtocolsHandler {
42            keep_alive: KeepAlive::No
43        }
44    }
45}
46
47impl ProtocolsHandler for DummyProtocolsHandler {
48    type InEvent = Void;
49    type OutEvent = Void;
50    type Error = Void;
51    type InboundProtocol = DeniedUpgrade;
52    type OutboundProtocol = DeniedUpgrade;
53    type OutboundOpenInfo = Void;
54    type InboundOpenInfo = ();
55
56    fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol, Self::InboundOpenInfo> {
57        SubstreamProtocol::new(DeniedUpgrade, ())
58    }
59
60    fn inject_fully_negotiated_inbound(
61        &mut self,
62        _: <Self::InboundProtocol as InboundUpgrade<NegotiatedSubstream>>::Output,
63        _: Self::InboundOpenInfo
64    ) {
65    }
66
67    fn inject_fully_negotiated_outbound(
68        &mut self,
69        _: <Self::OutboundProtocol as OutboundUpgrade<NegotiatedSubstream>>::Output,
70        _: Self::OutboundOpenInfo
71    ) {
72    }
73
74    fn inject_event(&mut self, _: Self::InEvent) {}
75
76    fn inject_address_change(&mut self, _: &Multiaddr) {}
77
78    fn inject_dial_upgrade_error(&mut self, _: Self::OutboundOpenInfo, _: ProtocolsHandlerUpgrErr<<Self::OutboundProtocol as OutboundUpgrade<NegotiatedSubstream>>::Error>) {}
79
80    fn inject_listen_upgrade_error(&mut self, _: Self::InboundOpenInfo, _: ProtocolsHandlerUpgrErr<<Self::InboundProtocol as InboundUpgrade<NegotiatedSubstream>>::Error>) {}
81
82    fn connection_keep_alive(&self) -> KeepAlive {
83        self.keep_alive
84    }
85
86    fn poll(
87        &mut self,
88        _: &mut Context<'_>,
89    ) -> Poll<
90        ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent, Self::Error>,
91    > {
92        Poll::Pending
93    }
94}