• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

butlergroup / rust-libp2p / 18605813685

17 Oct 2025 09:59PM UTC coverage: 77.784% (+2.9%) from 74.891%
18605813685

push

github

butlergroup
	modified:   .github/workflows/ci.yml
	modified:   protocols/autonat/src/lib.rs

39259 of 50472 relevant lines covered (77.78%)

35884.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/protocols/request-response/src/handler/protocol.rs
1
// Copyright 2020 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

21
//! The definition of a request/response protocol via inbound
22
//! and outbound substream upgrades. The inbound upgrade
23
//! receives a request and sends a response, whereas the
24
//! outbound upgrade send a request and receives a response.
25

26
use std::convert::Infallible;
27

28
use futures::future::{ready, Ready};
29
use libp2p_core::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
30
use libp2p_swarm::Stream;
31
use smallvec::SmallVec;
32

33
/// The level of support for a particular protocol.
34
#[derive(Debug, Clone)]
35
pub enum ProtocolSupport {
36
    /// The protocol is only supported for inbound requests.
37
    Inbound,
38
    /// The protocol is only supported for outbound requests.
39
    Outbound,
40
    /// The protocol is supported for inbound and outbound requests.
41
    Full,
42
}
43

44
impl ProtocolSupport {
45
    /// Whether inbound requests are supported.
46
    pub fn inbound(&self) -> bool {
245✔
47
        match self {
245✔
48
            ProtocolSupport::Inbound | ProtocolSupport::Full => true,
217✔
49
            ProtocolSupport::Outbound => false,
28✔
50
        }
51
    }
245✔
52

53
    /// Whether outbound requests are supported.
54
    pub fn outbound(&self) -> bool {
245✔
55
        match self {
245✔
56
            ProtocolSupport::Outbound | ProtocolSupport::Full => true,
225✔
57
            ProtocolSupport::Inbound => false,
20✔
58
        }
59
    }
245✔
60
}
61

62
/// Response substream upgrade protocol.
63
///
64
/// Receives a request and sends a response.
65
#[derive(Debug)]
66
pub struct Protocol<P> {
67
    pub(crate) protocols: SmallVec<[P; 2]>,
68
}
69

70
impl<P> UpgradeInfo for Protocol<P>
71
where
72
    P: AsRef<str> + Clone,
73
{
74
    type Info = P;
75
    type InfoIter = smallvec::IntoIter<[Self::Info; 2]>;
76

77
    fn protocol_info(&self) -> Self::InfoIter {
1,752✔
78
        self.protocols.clone().into_iter()
1,752✔
79
    }
1,752✔
80
}
81

82
impl<P> InboundUpgrade<Stream> for Protocol<P>
83
where
84
    P: AsRef<str> + Clone,
85
{
86
    type Output = (Stream, P);
87
    type Error = Infallible;
88
    type Future = Ready<Result<Self::Output, Self::Error>>;
89

90
    fn upgrade_inbound(self, io: Stream, protocol: Self::Info) -> Self::Future {
138✔
91
        ready(Ok((io, protocol)))
138✔
92
    }
138✔
93
}
94

95
impl<P> OutboundUpgrade<Stream> for Protocol<P>
96
where
97
    P: AsRef<str> + Clone,
98
{
99
    type Output = (Stream, P);
100
    type Error = Infallible;
101
    type Future = Ready<Result<Self::Output, Self::Error>>;
102

103
    fn upgrade_outbound(self, io: Stream, protocol: Self::Info) -> Self::Future {
138✔
104
        ready(Ok((io, protocol)))
138✔
105
    }
138✔
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc