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

libbitcoin / libbitcoin-network / 41687157645

03 Nov 2026 05:44PM UTC coverage: 94.038% (-0.09%) from 94.128%
41687157645

push

github

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

Initialize bases before members and complete aggregate initializers.

46 of 49 new or added lines in 26 files covered. (93.88%)

10 existing lines in 1 file now uncovered.

13297 of 14140 relevant lines covered (94.04%)

2620.37 hits per line

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

75.68
/src/protocols/protocol_version_70002.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_version_70002.hpp>
20

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

29
namespace libbitcoin {
30
namespace network {
31

32
#define CLASS protocol_version_70002
33

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

38
protocol_version_70002::protocol_version_70002(const session::ptr& session,
×
39
    const channel::ptr& channel) NOEXCEPT
×
40
  : protocol_version_70002(session, channel,
41
        session->network_settings().enable_relay,
×
42
        session->network_settings().enable_reject)
×
43
{
44
}
×
45

46
protocol_version_70002::protocol_version_70002(const session::ptr& session,
86 ✔
47
    const channel::ptr& channel, bool relay, bool reject) NOEXCEPT
86 ✔
48
  : protocol_version_70001(session, channel, relay),
49
    tracker<protocol_version_70002>(session->log),
50
    reject_(reject)
86 ✔
51
{
52
}
86 ✔
53

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

57
void protocol_version_70002::shake(result_handler&& handle_event) NOEXCEPT
86 ✔
58
{
59
    BC_ASSERT_MSG(stranded(), "protocol_version_70002");
86 ✔
60

61
    if (started())
86 ✔
62
        return;
63

64
    if (reject_)
86 ✔
65
    {
66
        SUBSCRIBE_CHANNEL(reject, handle_receive_reject, _1, _2);
16 ✔
67
    }
68

69
    protocol_version_70001::shake(std::move(handle_event));
86 ✔
70
}
71

72
// Outgoing [(in)sufficient_peer => send_reject].
73
// ----------------------------------------------------------------------------
74
// Reject is the only difference at protocol level 70002.
75

76
static reject rejected(reject::reason_code code,
3 ✔
77
    const std::string& reason={}) NOEXCEPT
78
{
79
    return { version::command, code, reason, {} };
3 ✔
80
}
3 ✔
81

82
void protocol_version_70002::rejection(const code& ec) NOEXCEPT
3 ✔
83
{
84
    BC_ASSERT_MSG(stranded(), "protocol_version_70002");
3 ✔
85

86
    if (!reject_)
3 ✔
87
    {
88
        protocol_version_70001::rejection(ec);
×
89
        return;
×
90
    }
91

92
    using enum reject::reason_code;
93

94
    // Handshake completion may result before completion of this send (okay).
95
    if (ec == error::peer_insufficient)
2 ✔
96
    {
97
        SEND(rejected(obsolete), handle_send, _1);
2 ✔
98
    }
99
    else if (ec == error::peer_unsupported)
1 ✔
100
    {
101
        SEND(rejected(undefined, "services"), handle_send, _1);
2 ✔
102
    }
103
    else if (ec == error::protocol_violation)
1 ✔
104
    {
NEW
105
        SEND(rejected(duplicate), handle_send, _1);
×
106
    }
107
    else if (ec == error::peer_timestamp)
×
108
    {
109
        SEND(rejected(undefined, "timestamp"), handle_send, _1);
2 ✔
110
    }
111

112
    protocol_version_70001::rejection(ec);
3 ✔
113
}
114

115
// Incoming [receive_reject => log].
116
// ----------------------------------------------------------------------------
117

118
bool protocol_version_70002::handle_receive_reject(const code& ec,
20 ✔
119
    const reject::cptr& LOG_ONLY(message)) NOEXCEPT
120
{
121
    BC_ASSERT_MSG(stranded(), "protocol_version_70002");
20 ✔
122

123
    if (stopped(ec))
20 ✔
124
        return false;
125

126
    LOGP("Reject message '" << message->message << "' ("
12 ✔
127
        << static_cast<uint16_t>(message->code) << ") from [" << opposite()
128
        << "] with reason: " << message->reason);
129

130
    return true;
4 ✔
131
}
132

133
} // namespace network
134
} // 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