diff --git a/Makefile.am b/Makefile.am index 65ba76e1b..c363389a3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -45,7 +45,6 @@ src_libbitcoin_network_la_SOURCES = \ src/channels/channel.cpp \ src/channels/channel_http.cpp \ src/channels/channel_peer.cpp \ - src/channels/channel_rpc.cpp \ src/channels/channel_ws.cpp \ src/config/address.cpp \ src/config/authority.cpp \ @@ -331,6 +330,10 @@ include_bitcoin_network_impl_async_races_HEADERS = \ include/bitcoin/network/impl/async/races/race_unity.ipp \ include/bitcoin/network/impl/async/races/race_volume.ipp +include_bitcoin_network_impl_channelsdir = ${includedir}/bitcoin/network/impl/channels +include_bitcoin_network_impl_channels_HEADERS = \ + include/bitcoin/network/impl/channels/channel_rpc.ipp + include_bitcoin_network_impl_messagesdir = ${includedir}/bitcoin/network/impl/messages include_bitcoin_network_impl_messages_HEADERS = \ include/bitcoin/network/impl/messages/json_body.ipp @@ -340,12 +343,12 @@ include_bitcoin_network_impl_messages_rpc_HEADERS = \ include/bitcoin/network/impl/messages/rpc/broadcaster.ipp \ include/bitcoin/network/impl/messages/rpc/dispatcher.ipp -include_bitcoin_network_interfacedir = ${includedir}/bitcoin/network/interface -include_bitcoin_network_interface_HEADERS = \ - include/bitcoin/network/interface/http.hpp \ - include/bitcoin/network/interface/interface.hpp \ - include/bitcoin/network/interface/peer_broadcast.hpp \ - include/bitcoin/network/interface/peer_dispatch.hpp +include_bitcoin_network_interfacesdir = ${includedir}/bitcoin/network/interfaces +include_bitcoin_network_interfaces_HEADERS = \ + include/bitcoin/network/interfaces/http.hpp \ + include/bitcoin/network/interfaces/interfaces.hpp \ + include/bitcoin/network/interfaces/peer_broadcast.hpp \ + include/bitcoin/network/interfaces/peer_dispatch.hpp include_bitcoin_network_logdir = ${includedir}/bitcoin/network/log include_bitcoin_network_log_HEADERS = \ diff --git a/builds/cmake/CMakeLists.txt b/builds/cmake/CMakeLists.txt index a8a499b45..715e2c6fc 100644 --- a/builds/cmake/CMakeLists.txt +++ b/builds/cmake/CMakeLists.txt @@ -227,7 +227,6 @@ add_library( ${CANONICAL_LIB_NAME} "../../src/channels/channel.cpp" "../../src/channels/channel_http.cpp" "../../src/channels/channel_peer.cpp" - "../../src/channels/channel_rpc.cpp" "../../src/channels/channel_ws.cpp" "../../src/config/address.cpp" "../../src/config/authority.cpp" diff --git a/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.vcxproj b/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.vcxproj index 9740d1580..3d395caff 100644 --- a/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.vcxproj +++ b/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.vcxproj @@ -127,7 +127,6 @@ - $(IntDir)src_config_address.obj @@ -252,10 +251,10 @@ - - - - + + + + @@ -378,6 +377,7 @@ + diff --git a/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.vcxproj.filters b/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.vcxproj.filters index 9e9a46971..742e702ee 100644 --- a/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.vcxproj.filters +++ b/builds/msvc/vs2022/libbitcoin-network/libbitcoin-network.vcxproj.filters @@ -35,15 +35,18 @@ {564EB540-D6B6-425C-0000-0000000000C1} - {564EB540-D6B6-425C-0000-0000000000E1} + {564EB540-D6B6-425C-0000-0000000000F1} - + {564EB540-D6B6-425C-0000-0000000000D1} + + {564EB540-D6B6-425C-0000-0000000000E1} + - {564EB540-D6B6-425C-0000-0000000000F1} + {564EB540-D6B6-425C-0000-000000000002} - + {564EB540-D6B6-425C-0000-000000000006} @@ -53,25 +56,25 @@ {564EB540-D6B6-425C-0000-000000000008} - {564EB540-D6B6-425C-0000-000000000002} + {564EB540-D6B6-425C-0000-000000000003} - {564EB540-D6B6-425C-0000-000000000005} + {564EB540-D6B6-425C-0000-000000000006} - {564EB540-D6B6-425C-0000-000000000003} + {564EB540-D6B6-425C-0000-000000000004} - {564EB540-D6B6-425C-0000-000000000006} + {564EB540-D6B6-425C-0000-000000000007} - {564EB540-D6B6-425C-0000-000000000007} + {564EB540-D6B6-425C-0000-000000000008} - {564EB540-D6B6-425C-0000-000000000004} + {564EB540-D6B6-425C-0000-000000000005} - {564EB540-D6B6-425C-0000-000000000008} + {564EB540-D6B6-425C-0000-000000000009} {564EB540-D6B6-425C-0000-000000000009} @@ -83,7 +86,7 @@ {564EB540-D6B6-425C-0000-0000000000A1} - {564EB540-D6B6-425C-0000-000000000009} + {564EB540-D6B6-425C-0000-000000000010} {564EB540-D6B6-425C-0000-000000000000} @@ -147,9 +150,6 @@ src\channels - - src\channels - src\channels @@ -506,17 +506,17 @@ include\bitcoin\network - - include\bitcoin\network\interface + + include\bitcoin\network\interfaces - - include\bitcoin\network\interface + + include\bitcoin\network\interfaces - - include\bitcoin\network\interface + + include\bitcoin\network\interfaces - - include\bitcoin\network\interface + + include\bitcoin\network\interfaces include\bitcoin\network\log @@ -880,6 +880,9 @@ include\bitcoin\network\impl\async + + include\bitcoin\network\impl\channels + include\bitcoin\network\impl\messages diff --git a/include/bitcoin/network.hpp b/include/bitcoin/network.hpp index cfc6da2eb..1759287bf 100644 --- a/include/bitcoin/network.hpp +++ b/include/bitcoin/network.hpp @@ -50,10 +50,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include diff --git a/include/bitcoin/network/channels/channel_http.hpp b/include/bitcoin/network/channels/channel_http.hpp index b53424b12..f4bfcb910 100644 --- a/include/bitcoin/network/channels/channel_http.hpp +++ b/include/bitcoin/network/channels/channel_http.hpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -77,7 +77,7 @@ class BCT_API channel_http /// Stranded handler invoked from stop(). void stopping(const code& ec) NOEXCEPT override; - /// Read request buffer (not thread safe). + /// Read request buffer (requires strand). virtual http::flat_buffer& request_buffer() NOEXCEPT; /// Dispatch request to subscribers by verb type. diff --git a/include/bitcoin/network/channels/channel_peer.hpp b/include/bitcoin/network/channels/channel_peer.hpp index 98f8b7eec..5db7b06af 100644 --- a/include/bitcoin/network/channels/channel_peer.hpp +++ b/include/bitcoin/network/channels/channel_peer.hpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/bitcoin/network/channels/channel_rpc.hpp b/include/bitcoin/network/channels/channel_rpc.hpp index 6d13e3133..1733d174b 100644 --- a/include/bitcoin/network/channels/channel_rpc.hpp +++ b/include/bitcoin/network/channels/channel_rpc.hpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -30,20 +29,18 @@ namespace libbitcoin { namespace network { -/// Read rpc-request and send rpc-response. -class BCT_API channel_rpc +/// Read rpc-request and send rpc-response, dispatch to Interface. +template +class channel_rpc : public channel { public: typedef std::shared_ptr ptr; - - // TODO: implement in node. - using interface = rpc::interface::http; - using dispatcher = rpc::dispatcher; + using dispatcher = rpc::dispatcher; /// Subscribe to request from client (requires strand). /// Event handler is always invoked on the channel strand. - template + template inline void subscribe(Handler&& handler) NOEXCEPT { BC_ASSERT(stranded()); @@ -62,33 +59,33 @@ class BCT_API channel_rpc /// Serialize and write response to client (requires strand). /// Completion handler is always invoked on the channel strand. - void send(rpc::response_t&& message, size_t size_hint, + inline void send(rpc::response_t&& message, size_t size_hint, result_handler&& handler) NOEXCEPT; /// Resume reading from the socket (requires strand). - void resume() NOEXCEPT override; + inline void resume() NOEXCEPT override; /// Must call after successful message handling if no stop. - virtual void receive() NOEXCEPT; + virtual inline void receive() NOEXCEPT; protected: /// Stranded handler invoked from stop(). - void stopping(const code& ec) NOEXCEPT override; + inline void stopping(const code& ec) NOEXCEPT override; - /// Read request buffer (not thread safe). - virtual http::flat_buffer& request_buffer() NOEXCEPT; + /// Read request buffer (requires strand). + virtual inline http::flat_buffer& request_buffer() NOEXCEPT; - /// Dispatch request to subscribers by requested method. - virtual void dispatch(const rpc::request_cptr& request) NOEXCEPT; + /// Override to dispatch request to subscribers by requested method. + virtual inline void dispatch(const rpc::request_cptr& request) NOEXCEPT; /// Size and assign response_buffer_ (value type is json-rpc::json). - virtual rpc::response_ptr assign_message(rpc::response_t&& message, + virtual inline rpc::response_ptr assign_message(rpc::response_t&& message, size_t size_hint) NOEXCEPT; /// Handlers. - virtual void handle_receive(const code& ec, size_t bytes, + virtual inline void handle_receive(const code& ec, size_t bytes, const rpc::request_cptr& request) NOEXCEPT; - virtual void handle_send(const code& ec, size_t bytes, + virtual inline void handle_send(const code& ec, size_t bytes, const rpc::response_cptr& response, const result_handler& handler) NOEXCEPT; @@ -108,4 +105,12 @@ class BCT_API channel_rpc } // namespace network } // namespace libbitcoin +#define TEMPLATE template +#define CLASS channel_rpc + +#include + +#undef CLASS +#undef TEMPLATE + #endif diff --git a/src/channels/channel_rpc.cpp b/include/bitcoin/network/impl/channels/channel_rpc.ipp similarity index 77% rename from src/channels/channel_rpc.cpp rename to include/bitcoin/network/impl/channels/channel_rpc.ipp index e20e78f34..89d9290d0 100644 --- a/src/channels/channel_rpc.cpp +++ b/include/bitcoin/network/impl/channels/channel_rpc.ipp @@ -16,7 +16,8 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include +#ifndef LIBBITCOIN_NETWORK_CHANNELS_CHANNEL_RPC_IPP +#define LIBBITCOIN_NETWORK_CHANNELS_CHANNEL_RPC_IPP #include #include @@ -27,10 +28,6 @@ namespace libbitcoin { namespace network { -using namespace system; -using namespace network::rpc; -using namespace std::placeholders; - // Shared pointers required in handler parameters so closures control lifetime. BC_PUSH_WARNING(NO_VALUE_OR_CONST_REF_SHARED_PTR) BC_PUSH_WARNING(SMART_PTR_NOT_NEEDED) @@ -40,14 +37,16 @@ BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) // ---------------------------------------------------------------------------- // This should not be called internally, as derived rely on stop() override. -void channel_rpc::stopping(const code& ec) NOEXCEPT +TEMPLATE +inline void CLASS::stopping(const code& ec) NOEXCEPT { BC_ASSERT(stranded()); channel::stopping(ec); dispatcher_.stop(ec); } -void channel_rpc::resume() NOEXCEPT +TEMPLATE +inline void CLASS::resume() NOEXCEPT { BC_ASSERT(stranded()); channel::resume(); @@ -58,7 +57,8 @@ void channel_rpc::resume() NOEXCEPT // ---------------------------------------------------------------------------- // Failure to call after successful message handling causes stalled channel. -void channel_rpc::receive() NOEXCEPT +TEMPLATE +inline void CLASS::receive() NOEXCEPT { BC_ASSERT(stranded()); BC_ASSERT_MSG(!reading_, "already reading"); @@ -67,7 +67,8 @@ void channel_rpc::receive() NOEXCEPT return; reading_ = true; - const auto in = to_shared(); + const auto in = system::to_shared(); + using namespace std::placeholders; // Post handle_read to strand upon stop, error, or buffer full. read(request_buffer(), *in, @@ -75,8 +76,9 @@ void channel_rpc::receive() NOEXCEPT shared_from_base(), _1, _2, in)); } -void channel_rpc::handle_receive(const code& ec, size_t bytes, - const request_cptr& request) NOEXCEPT +TEMPLATE +inline void CLASS::handle_receive(const code& ec, size_t bytes, + const rpc::request_cptr& request) NOEXCEPT { BC_ASSERT(stranded()); @@ -104,13 +106,15 @@ void channel_rpc::handle_receive(const code& ec, size_t bytes, dispatch(request); } -void channel_rpc::dispatch(const request_cptr& request) NOEXCEPT +TEMPLATE +inline void CLASS::dispatch(const rpc::request_cptr& request) NOEXCEPT { if (const auto code = dispatcher_.notify(request->message)) stop(code); } -http::flat_buffer& channel_rpc::request_buffer() NOEXCEPT +TEMPLATE +inline http::flat_buffer& CLASS::request_buffer() NOEXCEPT { return request_buffer_; } @@ -118,11 +122,13 @@ http::flat_buffer& channel_rpc::request_buffer() NOEXCEPT // Send. // ---------------------------------------------------------------------------- -void channel_rpc::send(response_t&& model, size_t size_hint, +TEMPLATE +inline void CLASS::send(rpc::response_t&& model, size_t size_hint, result_handler&& handler) NOEXCEPT { BC_ASSERT(stranded()); + using namespace std::placeholders; const auto out = assign_message(std::move(model), size_hint); count_handler complete = std::bind(&channel_rpc::handle_send, shared_from_base(), _1, _2, out, std::move(handler)); @@ -136,8 +142,9 @@ void channel_rpc::send(response_t&& model, size_t size_hint, write(*out, std::move(complete)); } -void channel_rpc::handle_send(const code& ec, size_t bytes, - const response_cptr& response, const result_handler& handler) NOEXCEPT +TEMPLATE +inline void CLASS::handle_send(const code& ec, size_t bytes, + const rpc::response_cptr& response, const result_handler& handler) NOEXCEPT { if (ec) stop(ec); @@ -147,11 +154,12 @@ void channel_rpc::handle_send(const code& ec, size_t bytes, } // private -response_ptr channel_rpc::assign_message(response_t&& message, +TEMPLATE +inline rpc::response_ptr CLASS::assign_message(rpc::response_t&& message, size_t size_hint) NOEXCEPT { response_buffer_->max_size(size_hint); - const auto ptr = to_shared(); + const auto ptr = system::to_shared(); ptr->message = std::move(message); ptr->buffer = response_buffer_; return ptr; @@ -160,14 +168,16 @@ response_ptr channel_rpc::assign_message(response_t&& message, // log helpers // ---------------------------------------------------------------------------- -void channel_rpc::log_message(const request& LOG_ONLY(request), +TEMPLATE +inline void CLASS::log_message(const rpc::request& LOG_ONLY(request), size_t LOG_ONLY(bytes)) const NOEXCEPT { LOGA("Rpc request: [" << bytes << "] " << request.message.method << "(...)."); } -void channel_rpc::log_message(const response& LOG_ONLY(response), +TEMPLATE +inline void CLASS::log_message(const rpc::response& LOG_ONLY(response), size_t LOG_ONLY(bytes)) const NOEXCEPT { LOG_ONLY(const auto message = response.message.error.has_value() ? @@ -182,3 +192,5 @@ BC_POP_WARNING() } // namespace network } // namespace libbitcoin + +#endif diff --git a/include/bitcoin/network/interface/http.hpp b/include/bitcoin/network/interfaces/http.hpp similarity index 93% rename from include/bitcoin/network/interface/http.hpp rename to include/bitcoin/network/interfaces/http.hpp index b99eec924..c6b15f845 100644 --- a/include/bitcoin/network/interface/http.hpp +++ b/include/bitcoin/network/interfaces/http.hpp @@ -16,13 +16,12 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#ifndef LIBBITCOIN_NETWORK_INTERFACE_HTTP_HPP -#define LIBBITCOIN_NETWORK_INTERFACE_HTTP_HPP +#ifndef LIBBITCOIN_NETWORK_INTERFACES_HTTP_HPP +#define LIBBITCOIN_NETWORK_INTERFACES_HTTP_HPP #include #include #include -#include namespace libbitcoin { namespace network { diff --git a/include/bitcoin/network/interface/interface.hpp b/include/bitcoin/network/interfaces/interfaces.hpp similarity index 82% rename from include/bitcoin/network/interface/interface.hpp rename to include/bitcoin/network/interfaces/interfaces.hpp index 274671ceb..fe9cd4263 100644 --- a/include/bitcoin/network/interface/interface.hpp +++ b/include/bitcoin/network/interfaces/interfaces.hpp @@ -16,12 +16,12 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#ifndef LIBBITCOIN_NETWORK_INTERFACE_HPP -#define LIBBITCOIN_NETWORK_INTERFACE_HPP +#ifndef LIBBITCOIN_NETWORK_INTERFACES_HPP +#define LIBBITCOIN_NETWORK_INTERFACES_HPP -#include -#include -#include +#include +#include +#include namespace libbitcoin { namespace network { diff --git a/include/bitcoin/network/interface/peer_broadcast.hpp b/include/bitcoin/network/interfaces/peer_broadcast.hpp similarity index 96% rename from include/bitcoin/network/interface/peer_broadcast.hpp rename to include/bitcoin/network/interfaces/peer_broadcast.hpp index b243dce96..9b66cd92c 100644 --- a/include/bitcoin/network/interface/peer_broadcast.hpp +++ b/include/bitcoin/network/interfaces/peer_broadcast.hpp @@ -16,13 +16,12 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#ifndef LIBBITCOIN_NETWORK_INTERFACE_PEER_BROADCAST_HPP -#define LIBBITCOIN_NETWORK_INTERFACE_PEER_BROADCAST_HPP +#ifndef LIBBITCOIN_NETWORK_INTERFACES_PEER_BROADCAST_HPP +#define LIBBITCOIN_NETWORK_INTERFACES_PEER_BROADCAST_HPP #include #include #include -#include namespace libbitcoin { namespace network { diff --git a/include/bitcoin/network/interface/peer_dispatch.hpp b/include/bitcoin/network/interfaces/peer_dispatch.hpp similarity index 97% rename from include/bitcoin/network/interface/peer_dispatch.hpp rename to include/bitcoin/network/interfaces/peer_dispatch.hpp index 7d6020c8f..886dfbdfa 100644 --- a/include/bitcoin/network/interface/peer_dispatch.hpp +++ b/include/bitcoin/network/interfaces/peer_dispatch.hpp @@ -16,13 +16,12 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#ifndef LIBBITCOIN_NETWORK_INTERFACE_PEER_HPP -#define LIBBITCOIN_NETWORK_INTERFACE_PEER_HPP +#ifndef LIBBITCOIN_NETWORK_INTERFACES_PEER_DISPATCH_HPP +#define LIBBITCOIN_NETWORK_INTERFACES_PEER_DISPATCH_HPP #include #include #include -#include namespace libbitcoin { namespace network { diff --git a/include/bitcoin/network/protocols/protocol.hpp b/include/bitcoin/network/protocols/protocol.hpp index 6ab332ae1..8f822c9fe 100644 --- a/include/bitcoin/network/protocols/protocol.hpp +++ b/include/bitcoin/network/protocols/protocol.hpp @@ -52,7 +52,7 @@ class BCT_API protocol /// The channel is stopping (called on strand by stop subscription). /// The stopped flag is set before this is invoked by subscriber stop. - /// This must be called only from the channel strand (not thread safe). + /// This must be called only from the channel strand (requires strand). virtual void stopping(const code& ec) NOEXCEPT; private: @@ -142,10 +142,10 @@ class BCT_API protocol /// Asserts that protocol is stopped. virtual ~protocol() NOEXCEPT; - /// Set protocol started state (strand required). + /// Set protocol started state (requires strand). virtual void start() NOEXCEPT; - /// Get protocol started state (strand required). + /// Get protocol started state (requires required). virtual bool started() const NOEXCEPT; /// Channel is stopped or code set. @@ -217,7 +217,7 @@ class BCT_API protocol #define DECLARE_SUBSCRIBE_CHANNEL() \ template \ void subscribe_channel(Method&& method, Args&&... args) NOEXCEPT \ - { channel_->subscribe(BIND_SHARED(method, args)); } + { channel_->template subscribe(BIND_SHARED(method, args)); } #define SEND(message, method, ...) \ send(message, &CLASS::method, __VA_ARGS__) diff --git a/include/bitcoin/network/protocols/protocol_address_in_209.hpp b/include/bitcoin/network/protocols/protocol_address_in_209.hpp index 4fbd1827a..7adba1f99 100644 --- a/include/bitcoin/network/protocols/protocol_address_in_209.hpp +++ b/include/bitcoin/network/protocols/protocol_address_in_209.hpp @@ -41,7 +41,7 @@ class BCT_API protocol_address_in_209 protocol_address_in_209(const session::ptr& session, const channel::ptr& channel) NOEXCEPT; - /// Start protocol (strand required). + /// Start protocol (requires strand). void start() NOEXCEPT override; protected: diff --git a/include/bitcoin/network/protocols/protocol_address_out_209.hpp b/include/bitcoin/network/protocols/protocol_address_out_209.hpp index 38f836acc..52ed02984 100644 --- a/include/bitcoin/network/protocols/protocol_address_out_209.hpp +++ b/include/bitcoin/network/protocols/protocol_address_out_209.hpp @@ -41,7 +41,7 @@ class BCT_API protocol_address_out_209 protocol_address_out_209(const session::ptr& session, const channel::ptr& channel) NOEXCEPT; - /// Start protocol (strand required). + /// Start protocol (requires strand). void start() NOEXCEPT override; protected: diff --git a/include/bitcoin/network/protocols/protocol_alert_311.hpp b/include/bitcoin/network/protocols/protocol_alert_311.hpp index b6e94eb9d..e31bd3aca 100644 --- a/include/bitcoin/network/protocols/protocol_alert_311.hpp +++ b/include/bitcoin/network/protocols/protocol_alert_311.hpp @@ -41,7 +41,7 @@ class BCT_API protocol_alert_311 protocol_alert_311(const session::ptr& session, const channel::ptr& channel) NOEXCEPT; - /// Start protocol (strand required). + /// Start protocol (requires strand). void start() NOEXCEPT override; protected: diff --git a/include/bitcoin/network/protocols/protocol_http.hpp b/include/bitcoin/network/protocols/protocol_http.hpp index 919bd89f1..8e972412a 100644 --- a/include/bitcoin/network/protocols/protocol_http.hpp +++ b/include/bitcoin/network/protocols/protocol_http.hpp @@ -53,8 +53,8 @@ class BCT_API protocol_http protocol_http(const session::ptr& session, const channel::ptr& channel, const options_t& options) NOEXCEPT; - DECLARE_SEND(); - DECLARE_SUBSCRIBE_CHANNEL(); + DECLARE_SEND() + DECLARE_SUBSCRIBE_CHANNEL() /// Message handlers by http method. virtual void handle_receive_get(const code& ec, diff --git a/include/bitcoin/network/protocols/protocol_peer.hpp b/include/bitcoin/network/protocols/protocol_peer.hpp index a4da0d517..9abed509b 100644 --- a/include/bitcoin/network/protocols/protocol_peer.hpp +++ b/include/bitcoin/network/protocols/protocol_peer.hpp @@ -44,14 +44,14 @@ class BCT_API protocol_peer using options_t = channel_t::options_t; protected: - DECLARE_SEND(); - DECLARE_SUBSCRIBE_CHANNEL(); - /// Construct an instance. /// ----------------------------------------------------------------------- protocol_peer(const session::ptr& session, const channel::ptr& channel) NOEXCEPT; + DECLARE_SEND() + DECLARE_SUBSCRIBE_CHANNEL() + /// Properties. /// ----------------------------------------------------------------------- diff --git a/include/bitcoin/network/protocols/protocol_ping_106.hpp b/include/bitcoin/network/protocols/protocol_ping_106.hpp index cb610ee2b..bce07dc1b 100644 --- a/include/bitcoin/network/protocols/protocol_ping_106.hpp +++ b/include/bitcoin/network/protocols/protocol_ping_106.hpp @@ -41,7 +41,7 @@ class BCT_API protocol_ping_106 protocol_ping_106(const session::ptr& session, const channel::ptr& channel) NOEXCEPT; - /// Start protocol (strand required). + /// Start protocol (requires strand). void start() NOEXCEPT override; /// The channel is stopping (called on strand by stop subscription). diff --git a/include/bitcoin/network/protocols/protocol_ping_60001.hpp b/include/bitcoin/network/protocols/protocol_ping_60001.hpp index cd5445063..cb1cda6da 100644 --- a/include/bitcoin/network/protocols/protocol_ping_60001.hpp +++ b/include/bitcoin/network/protocols/protocol_ping_60001.hpp @@ -41,7 +41,7 @@ class BCT_API protocol_ping_60001 protocol_ping_60001(const session::ptr& session, const channel::ptr& channel) NOEXCEPT; - /// Start protocol (strand required). + /// Start protocol (requires strand). void start() NOEXCEPT override; protected: diff --git a/include/bitcoin/network/protocols/protocol_reject_70002.hpp b/include/bitcoin/network/protocols/protocol_reject_70002.hpp index bf2870e08..abab3342f 100644 --- a/include/bitcoin/network/protocols/protocol_reject_70002.hpp +++ b/include/bitcoin/network/protocols/protocol_reject_70002.hpp @@ -41,7 +41,7 @@ class BCT_API protocol_reject_70002 protocol_reject_70002(const session::ptr& session, const channel::ptr& channel) NOEXCEPT; - /// Start protocol (strand required). + /// Start protocol (requires strand). void start() NOEXCEPT override; protected: diff --git a/include/bitcoin/network/protocols/protocol_rpc.hpp b/include/bitcoin/network/protocols/protocol_rpc.hpp index 2a87776bc..f90aea4a1 100644 --- a/include/bitcoin/network/protocols/protocol_rpc.hpp +++ b/include/bitcoin/network/protocols/protocol_rpc.hpp @@ -23,25 +23,34 @@ #include #include #include -#include namespace libbitcoin { namespace network { - -class BCT_API protocol_rpc + +template +class protocol_rpc : public protocol { public: typedef std::shared_ptr ptr; - using channel_t = channel_rpc; + using channel_t = channel_rpc; using options_t = channel_t::options_t; protected: inline protocol_rpc(const session::ptr& session, const channel::ptr& channel, const options_t&) NOEXCEPT - : protocol(session, channel) + : protocol(session, channel), + channel_(std::dynamic_pointer_cast(channel)) { } + + DECLARE_SEND() + DECLARE_SUBSCRIBE_CHANNEL() + +private: + // This is mostly thread safe, and used in a thread safe manner. + // pause/resume/paused/attach not invoked, setters limited to handshake. + const channel_t::ptr channel_; }; } // namespace network diff --git a/include/bitcoin/network/protocols/protocol_seed_209.hpp b/include/bitcoin/network/protocols/protocol_seed_209.hpp index a03a8b69c..264d5579f 100644 --- a/include/bitcoin/network/protocols/protocol_seed_209.hpp +++ b/include/bitcoin/network/protocols/protocol_seed_209.hpp @@ -41,7 +41,7 @@ class BCT_API protocol_seed_209 protocol_seed_209(const session::ptr& session, const channel::ptr& channel) NOEXCEPT; - /// Perform seeding, stops channel on completion (strand required). + /// Perform seeding, stops channel on completion (requires strand). void start() NOEXCEPT override; /// Capture stop subscription to clear timer. diff --git a/include/bitcoin/network/protocols/protocol_version_106.hpp b/include/bitcoin/network/protocols/protocol_version_106.hpp index bb6a04cfe..0474bd058 100644 --- a/include/bitcoin/network/protocols/protocol_version_106.hpp +++ b/include/bitcoin/network/protocols/protocol_version_106.hpp @@ -47,7 +47,7 @@ class BCT_API protocol_version_106 const channel::ptr& channel, uint64_t minimum_services, uint64_t maximum_services) NOEXCEPT; - /// Perform the handshake (strand required), handler invoked on completion. + /// Perform the handshake (requires strand), handler invoked on completion. virtual void shake(result_handler&& handler) NOEXCEPT; /// The channel is stopping (called on strand by stop subscription). diff --git a/include/bitcoin/network/protocols/protocol_version_70002.hpp b/include/bitcoin/network/protocols/protocol_version_70002.hpp index 7fb485a77..3ab24c95d 100644 --- a/include/bitcoin/network/protocols/protocol_version_70002.hpp +++ b/include/bitcoin/network/protocols/protocol_version_70002.hpp @@ -47,7 +47,7 @@ class BCT_API protocol_version_70002 const channel::ptr& channel, uint64_t minimum_services, uint64_t maximum_services, bool relay) NOEXCEPT; - /// Perform the handshake (strand required), handler invoked on completion. + /// Perform the handshake (requires strand), handler invoked on completion. void shake(result_handler&& handle_event) NOEXCEPT override; protected: diff --git a/include/bitcoin/network/protocols/protocol_version_70016.hpp b/include/bitcoin/network/protocols/protocol_version_70016.hpp index 14feebb45..1e7bcb4be 100644 --- a/include/bitcoin/network/protocols/protocol_version_70016.hpp +++ b/include/bitcoin/network/protocols/protocol_version_70016.hpp @@ -47,7 +47,7 @@ class BCT_API protocol_version_70016 const channel::ptr& channel, uint64_t minimum_services, uint64_t maximum_services, bool relay, bool reject) NOEXCEPT; - /// Perform the handshake (strand required), handler invoked on completion. + /// Perform the handshake (requires strand), handler invoked on completion. void shake(result_handler&& handle_event) NOEXCEPT override; protected: diff --git a/include/bitcoin/network/sessions/session.hpp b/include/bitcoin/network/sessions/session.hpp index 42ddfd0db..c64df1809 100644 --- a/include/bitcoin/network/sessions/session.hpp +++ b/include/bitcoin/network/sessions/session.hpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include