Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions include/bitcoin/network/channels/channel_rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,7 @@ class channel_rpc
{
}

/// Senders, rpc version and identity added to responses (requires strand).
inline void send_code(const code& ec) NOEXCEPT;
inline void send_error(rpc::result_t&& error) NOEXCEPT;
inline void send_result(rpc::value_t&& result, size_t size_hint) NOEXCEPT;

/// Senders with completion handlers (requires strand).
/// Senders (requires strand).
inline void send_code(const code& ec, result_handler&& handler) NOEXCEPT;
inline void send_error(rpc::result_t&& error,
result_handler&& handler) NOEXCEPT;
Expand Down Expand Up @@ -104,9 +99,6 @@ class channel_rpc
const rpc::response_cptr& response,
const result_handler& handler) NOEXCEPT;

/// Default noop completion handler.
virtual inline void complete(const code&) NOEXCEPT {};

private:
// These are protected by strand.
rpc::version version_;
Expand Down
24 changes: 3 additions & 21 deletions include/bitcoin/network/impl/channels/channel_rpc.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ inline void CLASS::handle_receive(const code& ec, size_t bytes,
identity_ = request->message.id;
version_ = request->message.jsonrpc;

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

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

TEMPLATE
void CLASS::send_code(const code& ec) NOEXCEPT
{
send_code(ec, std::bind(&CLASS::complete, _1));
}

TEMPLATE
void CLASS::send_error(rpc::result_t&& error) NOEXCEPT
{
send_error(std::move(error), std::bind(&CLASS::complete, _1));
}

TEMPLATE
void CLASS::send_result(rpc::value_t&& result, size_t size_hint) NOEXCEPT
{
send_result(std::move(result), size_hint, std::bind(&CLASS::complete, _1));
}

TEMPLATE
void CLASS::send_code(const code& ec, result_handler&& handler) NOEXCEPT
{
Expand Down Expand Up @@ -205,8 +187,8 @@ inline void CLASS::handle_send(const code& ec, size_t bytes,
// Typically a noop, but handshake may pause channel here.
handler(ec);

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

// Continue read loop (does not unpause or restart channel).
receive();
Expand Down
24 changes: 24 additions & 0 deletions include/bitcoin/network/impl/protocols/protocol_rpc.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@
namespace libbitcoin {
namespace network {

TEMPLATE
inline void CLASS::send_code(const code& ec) NOEXCEPT
{
using namespace std::placeholders;
send_code(ec,std::bind(&CLASS::complete,
shared_from_base<CLASS>(), _1));
}

TEMPLATE
inline void CLASS::send_error(rpc::result_t&& error) NOEXCEPT
{
using namespace std::placeholders;
send_error(std::move(error), std::bind(&CLASS::complete,
shared_from_base<CLASS>(), _1));
}

TEMPLATE
inline void CLASS::send_result(rpc::value_t&& result, size_t size_hint) NOEXCEPT
{
using namespace std::placeholders;
send_result(std::move(result), size_hint, std::bind(&CLASS::complete,
shared_from_base<CLASS>(), _1));
}

TEMPLATE
inline void CLASS::send_code(const code& ec, result_handler&& handler) NOEXCEPT
{
Expand Down
17 changes: 13 additions & 4 deletions include/bitcoin/network/protocols/protocol_rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,22 @@ class protocol_rpc

DECLARE_SUBSCRIBE_CHANNEL()

/// Senders (requires strand).
/// Senders with default completion (requires strand).
virtual inline void send_code(const code& ec) NOEXCEPT;
virtual inline void send_error(rpc::result_t&& error) NOEXCEPT;
virtual inline void send_result(rpc::value_t&& result,
size_t size_hint) NOEXCEPT;

/// Senders, rpc version and identity added to responses (requires strand).
virtual inline void send_code(const code& ec,
result_handler&& handler={}) NOEXCEPT;
result_handler&& handler) NOEXCEPT;
virtual inline void send_error(rpc::result_t&& error,
result_handler&& handler={}) NOEXCEPT;
result_handler&& handler) NOEXCEPT;
virtual inline void send_result(rpc::value_t&& result, size_t size_hint,
result_handler&& handler={}) NOEXCEPT;
result_handler&& handler) NOEXCEPT;

/// Default noop completion handler.
virtual inline void complete(const code&) NOEXCEPT {};

private:
// This is mostly thread safe, and used in a thread safe manner.
Expand Down
2 changes: 1 addition & 1 deletion src/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
{ extra_named, "extra named" },
{ missing_array, "missing array" },
{ missing_object, "missing object" },
{ missing_parameter, "missing optional" }
{ missing_parameter, "missing parameter" }
};

DEFINE_ERROR_T_CATEGORY(error, "network", "network code")
Expand Down
7 changes: 7 additions & 0 deletions src/sessions/session_manual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ session_manual::session_manual(net& network, uint64_t identifier) NOEXCEPT
void session_manual::start(result_handler&& handler) NOEXCEPT
{
BC_ASSERT(stranded());

// This applies only to "configured" manual connections (can be added).
if (!network_settings().manual.enabled())
{
LOGN("Not configured for manual peer connections.");
}

session_peer::start(BIND(handle_started, _1, std::move(handler)));
}

Expand Down
2 changes: 1 addition & 1 deletion src/sessions/session_outbound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void session_outbound::start(result_handler&& handler) NOEXCEPT

if (!network_settings().outbound.enabled())
{
LOGN("Not configured for outbound connections.");
LOGN("Not configured for outbound peer connections.");
handler(error::success);
unsubscribe_close();
return;
Expand Down
4 changes: 3 additions & 1 deletion src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ bool settings::peer_manual::peered(const address_item& item) const NOEXCEPT

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

// [network]
Expand Down
2 changes: 1 addition & 1 deletion test/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2034,7 +2034,7 @@ BOOST_AUTO_TEST_CASE(error_t__code__missing_parameter__true_expected_message)
const auto ec = code(value);
BOOST_REQUIRE(ec);
BOOST_REQUIRE(ec == value);
BOOST_REQUIRE_EQUAL(ec.message(), "missing optional");
BOOST_REQUIRE_EQUAL(ec.message(), "missing parameter");
}

BOOST_AUTO_TEST_SUITE_END()
Loading