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

libbitcoin / libbitcoin-network / 34430316768

10 Sep 2026 02:39AM UTC coverage: 16.131% (+0.009%) from 16.122%
34430316768

push

github

web-flow
Merge pull request #883 from evoskuil/master

Fix socket monitor, raises min win to win10.

7 of 45 new or added lines in 5 files covered. (15.56%)

4 existing lines in 4 files now uncovered.

8729 of 54113 relevant lines covered (16.13%)

124.0 hits per line

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

64.15
/src/protocols/protocol.cpp
1
/**
2
 * Copyright (c) 2011-2026 libbitcoin developers
3
 *
4
 * This file is part of libbitcoin.
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Affero General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Affero General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
#include <bitcoin/network/protocols/protocol.hpp>
20

21
#include <bitcoin/network/channels/channels.hpp>
22
#include <bitcoin/network/config/config.hpp>
23
#include <bitcoin/network/define.hpp>
24
#include <bitcoin/network/log/log.hpp>
25
#include <bitcoin/network/messages/messages.hpp>
26
#include <bitcoin/network/net/net.hpp>
27
#include <bitcoin/network/sessions/sessions.hpp>
28

29
namespace libbitcoin {
30
namespace network {
31

32
#define CLASS protocol
33

34
using namespace system;
35
using namespace messages::peer;
36
using namespace std::placeholders;
37

38
// Protocols invoke channel stop for application layer protocol violations.
39
// Channels invoke channel stop for channel timouts and communcation failures.
40
protocol::protocol(const session::ptr& session,
13 ✔
41
    const channel::ptr& channel) NOEXCEPT
13 ✔
42
  : channel_(channel),
43
    session_(session),
44
    reporter(session->log)
13 ✔
45
{
46
}
13 ✔
47

48
protocol::~protocol() NOEXCEPT
13 ✔
49
{
50
    BC_ASSERT_MSG(stopped(), "protocol destruct before channel stop");
13 ✔
51
    if (!stopped()) { LOGF("~protocol is not stopped."); }
13 ✔
52
}
13 ✔
53

54
// Start/Stop.
55
// ----------------------------------------------------------------------------
56

57
void protocol::start() NOEXCEPT
13 ✔
58
{
59
    BC_ASSERT(stranded());
13 ✔
60
    started_ = true;
13 ✔
61
}
13 ✔
62

63
bool protocol::started() const NOEXCEPT
19 ✔
64
{
65
    BC_ASSERT(stranded());
19 ✔
66
    return started_;
19 ✔
67
}
68

69
// Utility to test for failure code or stopped.
70
// Any failure code from a send or receive handler implies channel::proxy stop.
71
// So this should be used to test entry into those handlers. Other handlers,
72
// such as timers, should use stopped() and independently evaluate the code.
73
bool protocol::stopped(const code& ec) const NOEXCEPT
68 ✔
74
{
75
    return channel_->stopped() || ec;
68 ✔
76
}
77

78
// Called from stop subscription instead of stop (which would be a cycle).
79
void protocol::stopping(const code&) NOEXCEPT
×
80
{
81
    BC_ASSERT(stranded());
×
82
}
×
83

84
// Stop the channel::proxy, which results protocol stop handler invocation.
85
// The stop handler invokes stopping(ec), for protocol cleanup operations.
86
void protocol::stop(const code& ec) NOEXCEPT
×
87
{
88
    channel_->stop(ec);
×
89
}
×
90

91
// Suspend reads from the socket until resume.
92
void protocol::pause() NOEXCEPT
1 ✔
93
{
94
    BC_ASSERT(stranded());
1 ✔
95
    channel_->pause();
1 ✔
96
}
1 ✔
97

98
// Arms the next read (session resumes channel following pause).
99
void protocol::read_next() NOEXCEPT
×
100
{
101
    BC_ASSERT(stranded());
×
102
    channel_->resume();
×
103
}
×
104

UNCOV
105
void protocol::monitor(bool value) NOEXCEPT
×
106
{
107
    BC_ASSERT(stranded());
×
108
    channel_->monitor(value);
×
109
}
×
110

111
// Zero if timer expired.
112
size_t protocol::remaining() const NOEXCEPT
×
113
{
114
    BC_ASSERT(stranded());
×
115
    return channel_->remaining();
×
116
}
117

118
// Properties.
119
// ----------------------------------------------------------------------------
120
// The public properties may be accessed outside the strand, except during
121
// handshake protocol operation. Thread safety requires that setters are never
122
// invoked outside of the handshake protocol (start handler).
123

124
bool protocol::stranded() const NOEXCEPT
119 ✔
125
{
126
    return channel_->stranded();
119 ✔
127
}
128

129
config::endpoint protocol::opposite() const NOEXCEPT
4 ✔
130
{
131
    BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
132
    return { channel_->endpoint() };
4 ✔
133
    BC_POP_WARNING()
134
}
135

136
const config::address& protocol::outbound() const NOEXCEPT
2 ✔
137
{
138
    return channel_->address();
2 ✔
139
}
140

141
uint64_t protocol::nonce() const NOEXCEPT
2 ✔
142
{
143
    return channel_->nonce();
2 ✔
144
}
145

146
const network::settings& protocol::network_settings() const NOEXCEPT
6 ✔
147
{
148
    return session_->network_settings();
6 ✔
149
}
150

151
uint64_t protocol::identifier() const NOEXCEPT
×
152
{
153
    return channel_->identifier();
×
154
}
155

156
// Send.
157
// ----------------------------------------------------------------------------
158
// Send (and receive) completion handlers are invoked on the channel strand.
159

160
// Send and receive failures are logged by the proxy, so there is no need to
161
// log here. This can be used as a no-op handler for sends. Some protocols may
162
// create custom handlers to perform operations upon send completion.
163
void protocol::handle_send(const code&) NOEXCEPT
1 ✔
164
{
165
    BC_ASSERT(stranded());
1 ✔
166
}
1 ✔
167

168
} // namespace network
169
} // namespace libbitcoin
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc