Skip to content

Commit 595c7d2

Browse files
authored
Merge pull request #721 from evoskuil/master
Replace invalid use of std::function<...>{} with noop handler.
2 parents 93efceb + 6c8be51 commit 595c7d2

File tree

9 files changed

+54
-38
lines changed

9 files changed

+54
-38
lines changed

include/bitcoin/network/channels/channel_rpc.hpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,7 @@ class channel_rpc
5858
{
5959
}
6060

61-
/// Senders, rpc version and identity added to responses (requires strand).
62-
inline void send_code(const code& ec) NOEXCEPT;
63-
inline void send_error(rpc::result_t&& error) NOEXCEPT;
64-
inline void send_result(rpc::value_t&& result, size_t size_hint) NOEXCEPT;
65-
66-
/// Senders with completion handlers (requires strand).
61+
/// Senders (requires strand).
6762
inline void send_code(const code& ec, result_handler&& handler) NOEXCEPT;
6863
inline void send_error(rpc::result_t&& error,
6964
result_handler&& handler) NOEXCEPT;
@@ -104,9 +99,6 @@ class channel_rpc
10499
const rpc::response_cptr& response,
105100
const result_handler& handler) NOEXCEPT;
106101

107-
/// Default noop completion handler.
108-
virtual inline void complete(const code&) NOEXCEPT {};
109-
110102
private:
111103
// These are protected by strand.
112104
rpc::version version_;

include/bitcoin/network/impl/channels/channel_rpc.ipp

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ inline void CLASS::handle_receive(const code& ec, size_t bytes,
107107
identity_ = request->message.id;
108108
version_ = request->message.jsonrpc;
109109

110-
LOGA("Rpc request: [" << bytes << "] "
110+
LOGA("Rpc request: (" << bytes << ") bytes from [" << endpoint() << "] "
111111
<< request->message.method << "(...).");
112112

113113
reading_ = false;
@@ -132,24 +132,6 @@ inline http::flat_buffer& CLASS::request_buffer() NOEXCEPT
132132
// Send.
133133
// ----------------------------------------------------------------------------
134134

135-
TEMPLATE
136-
void CLASS::send_code(const code& ec) NOEXCEPT
137-
{
138-
send_code(ec, std::bind(&CLASS::complete, _1));
139-
}
140-
141-
TEMPLATE
142-
void CLASS::send_error(rpc::result_t&& error) NOEXCEPT
143-
{
144-
send_error(std::move(error), std::bind(&CLASS::complete, _1));
145-
}
146-
147-
TEMPLATE
148-
void CLASS::send_result(rpc::value_t&& result, size_t size_hint) NOEXCEPT
149-
{
150-
send_result(std::move(result), size_hint, std::bind(&CLASS::complete, _1));
151-
}
152-
153135
TEMPLATE
154136
void CLASS::send_code(const code& ec, result_handler&& handler) NOEXCEPT
155137
{
@@ -205,8 +187,8 @@ inline void CLASS::handle_send(const code& ec, size_t bytes,
205187
// Typically a noop, but handshake may pause channel here.
206188
handler(ec);
207189

208-
LOGA("Rpc response: [" << bytes << "], " <<
209-
response->message.error.value_or(rpc::result_t{}).message);
190+
LOGA("Rpc response: (" << bytes << ") bytes to [" << endpoint() << "] "
191+
<< response->message.error.value_or(rpc::result_t{}).message);
210192

211193
// Continue read loop (does not unpause or restart channel).
212194
receive();

include/bitcoin/network/impl/protocols/protocol_rpc.ipp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,30 @@
2525
namespace libbitcoin {
2626
namespace network {
2727

28+
TEMPLATE
29+
inline void CLASS::send_code(const code& ec) NOEXCEPT
30+
{
31+
using namespace std::placeholders;
32+
send_code(ec,std::bind(&CLASS::complete,
33+
shared_from_base<CLASS>(), _1));
34+
}
35+
36+
TEMPLATE
37+
inline void CLASS::send_error(rpc::result_t&& error) NOEXCEPT
38+
{
39+
using namespace std::placeholders;
40+
send_error(std::move(error), std::bind(&CLASS::complete,
41+
shared_from_base<CLASS>(), _1));
42+
}
43+
44+
TEMPLATE
45+
inline void CLASS::send_result(rpc::value_t&& result, size_t size_hint) NOEXCEPT
46+
{
47+
using namespace std::placeholders;
48+
send_result(std::move(result), size_hint, std::bind(&CLASS::complete,
49+
shared_from_base<CLASS>(), _1));
50+
}
51+
2852
TEMPLATE
2953
inline void CLASS::send_code(const code& ec, result_handler&& handler) NOEXCEPT
3054
{

include/bitcoin/network/protocols/protocol_rpc.hpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,22 @@ class protocol_rpc
4848

4949
DECLARE_SUBSCRIBE_CHANNEL()
5050

51-
/// Senders (requires strand).
51+
/// Senders with default completion (requires strand).
52+
virtual inline void send_code(const code& ec) NOEXCEPT;
53+
virtual inline void send_error(rpc::result_t&& error) NOEXCEPT;
54+
virtual inline void send_result(rpc::value_t&& result,
55+
size_t size_hint) NOEXCEPT;
56+
57+
/// Senders, rpc version and identity added to responses (requires strand).
5258
virtual inline void send_code(const code& ec,
53-
result_handler&& handler={}) NOEXCEPT;
59+
result_handler&& handler) NOEXCEPT;
5460
virtual inline void send_error(rpc::result_t&& error,
55-
result_handler&& handler={}) NOEXCEPT;
61+
result_handler&& handler) NOEXCEPT;
5662
virtual inline void send_result(rpc::value_t&& result, size_t size_hint,
57-
result_handler&& handler={}) NOEXCEPT;
63+
result_handler&& handler) NOEXCEPT;
64+
65+
/// Default noop completion handler.
66+
virtual inline void complete(const code&) NOEXCEPT {};
5867

5968
private:
6069
// This is mostly thread safe, and used in a thread safe manner.

src/error.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
281281
{ extra_named, "extra named" },
282282
{ missing_array, "missing array" },
283283
{ missing_object, "missing object" },
284-
{ missing_parameter, "missing optional" }
284+
{ missing_parameter, "missing parameter" }
285285
};
286286

287287
DEFINE_ERROR_T_CATEGORY(error, "network", "network code")

src/sessions/session_manual.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ session_manual::session_manual(net& network, uint64_t identifier) NOEXCEPT
5353
void session_manual::start(result_handler&& handler) NOEXCEPT
5454
{
5555
BC_ASSERT(stranded());
56+
57+
// This applies only to "configured" manual connections (can be added).
58+
if (!network_settings().manual.enabled())
59+
{
60+
LOGN("Not configured for manual peer connections.");
61+
}
62+
5663
session_peer::start(BIND(handle_started, _1, std::move(handler)));
5764
}
5865

src/sessions/session_outbound.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void session_outbound::start(result_handler&& handler) NOEXCEPT
5656

5757
if (!network_settings().outbound.enabled())
5858
{
59-
LOGN("Not configured for outbound connections.");
59+
LOGN("Not configured for outbound peer connections.");
6060
handler(error::success);
6161
unsubscribe_close();
6262
return;

src/settings.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ bool settings::peer_manual::peered(const address_item& item) const NOEXCEPT
210210

211211
bool settings::peer_manual::enabled() const NOEXCEPT
212212
{
213-
return settings::tcp_server::enabled() && !peers.empty();
213+
// connections field is not currently used, and this applies only to
214+
// initial configuration of manual connections, as they can be added.
215+
return /* settings::tcp_server::enabled() && */ !peers.empty();
214216
}
215217

216218
// [network]

test/error.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,7 @@ BOOST_AUTO_TEST_CASE(error_t__code__missing_parameter__true_expected_message)
20342034
const auto ec = code(value);
20352035
BOOST_REQUIRE(ec);
20362036
BOOST_REQUIRE(ec == value);
2037-
BOOST_REQUIRE_EQUAL(ec.message(), "missing optional");
2037+
BOOST_REQUIRE_EQUAL(ec.message(), "missing parameter");
20382038
}
20392039

20402040
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)