diff --git a/Makefile.am b/Makefile.am index 5440051e2..c7a80c23d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -64,6 +64,7 @@ src_libbitcoin_node_la_SOURCES = \ src/protocols/protocol_header_in_70012.cpp \ src/protocols/protocol_header_out_31800.cpp \ src/protocols/protocol_header_out_70012.cpp \ + src/protocols/protocol_html.cpp \ src/protocols/protocol_observer.cpp \ src/protocols/protocol_peer.cpp \ src/protocols/protocol_performer.cpp \ diff --git a/builds/cmake/CMakeLists.txt b/builds/cmake/CMakeLists.txt index 766aa1613..bc188e1e4 100644 --- a/builds/cmake/CMakeLists.txt +++ b/builds/cmake/CMakeLists.txt @@ -276,6 +276,7 @@ add_library( ${CANONICAL_LIB_NAME} "../../src/protocols/protocol_header_in_70012.cpp" "../../src/protocols/protocol_header_out_31800.cpp" "../../src/protocols/protocol_header_out_70012.cpp" + "../../src/protocols/protocol_html.cpp" "../../src/protocols/protocol_observer.cpp" "../../src/protocols/protocol_peer.cpp" "../../src/protocols/protocol_performer.cpp" diff --git a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj index 6ebad56b5..b2a222665 100644 --- a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj +++ b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj @@ -149,6 +149,7 @@ + diff --git a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters index 500acd61a..a5623ca7f 100644 --- a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters +++ b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters @@ -138,6 +138,9 @@ src\protocols + + src\protocols + src\protocols diff --git a/include/bitcoin/node/block_arena.hpp b/include/bitcoin/node/block_arena.hpp index f125f268f..769637d9b 100644 --- a/include/bitcoin/node/block_arena.hpp +++ b/include/bitcoin/node/block_arena.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_NODE_BLOCK_ARENA_HPP #define LIBBITCOIN_NODE_BLOCK_ARENA_HPP -#include #include namespace libbitcoin { diff --git a/include/bitcoin/node/block_memory.hpp b/include/bitcoin/node/block_memory.hpp index fbe511385..2fe6414d8 100644 --- a/include/bitcoin/node/block_memory.hpp +++ b/include/bitcoin/node/block_memory.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_NODE_BLOCK_MEMORY_HPP #include -#include #include #include diff --git a/include/bitcoin/node/channels/channel.hpp b/include/bitcoin/node/channels/channel.hpp index 96a59150b..aa46ffab1 100644 --- a/include/bitcoin/node/channels/channel.hpp +++ b/include/bitcoin/node/channels/channel.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_NODE_CHANNELS_CHANNEL_HPP #include -#include #include #include #include diff --git a/include/bitcoin/node/channels/channel_http.hpp b/include/bitcoin/node/channels/channel_http.hpp index 18e3523aa..f69cb8434 100644 --- a/include/bitcoin/node/channels/channel_http.hpp +++ b/include/bitcoin/node/channels/channel_http.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_NODE_CHANNELS_CHANNEL_HTTP_HPP #include -#include #include #include #include @@ -35,7 +34,7 @@ class BCN_API channel_http { public: typedef std::shared_ptr ptr; - using options_t = network::settings::http_server; + using options_t = network::channel_http::options_t; channel_http(const network::logger& log, const network::socket::ptr& socket, const node::configuration& config, uint64_t identifier=zero, diff --git a/include/bitcoin/node/channels/channel_peer.hpp b/include/bitcoin/node/channels/channel_peer.hpp index 754d55338..fea61640d 100644 --- a/include/bitcoin/node/channels/channel_peer.hpp +++ b/include/bitcoin/node/channels/channel_peer.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_NODE_CHANNELS_CHANNEL_PEER_HPP #include -#include #include #include #include diff --git a/include/bitcoin/node/channels/channel_tcp.hpp b/include/bitcoin/node/channels/channel_tcp.hpp index 8338c7df4..fccf83303 100644 --- a/include/bitcoin/node/channels/channel_tcp.hpp +++ b/include/bitcoin/node/channels/channel_tcp.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_NODE_CHANNELS_CHANNEL_TCP_HPP #include -#include #include #include #include @@ -35,7 +34,7 @@ class BCN_API channel_tcp { public: typedef std::shared_ptr ptr; - using options_t = network::settings::tcp_server; + using options_t = network::channel_tcp::options_t; channel_tcp(const network::logger& log, const network::socket::ptr& socket, const node::configuration& config, uint64_t identifier=zero, diff --git a/include/bitcoin/node/channels/channels.hpp b/include/bitcoin/node/channels/channels.hpp index cd53d5c6c..fc22e756a 100644 --- a/include/bitcoin/node/channels/channels.hpp +++ b/include/bitcoin/node/channels/channels.hpp @@ -23,6 +23,7 @@ #include #include #include +// add channel_websocket to network and derive here #endif diff --git a/include/bitcoin/node/chasers/chaser.hpp b/include/bitcoin/node/chasers/chaser.hpp index 377da7645..6b493cd67 100644 --- a/include/bitcoin/node/chasers/chaser.hpp +++ b/include/bitcoin/node/chasers/chaser.hpp @@ -19,8 +19,6 @@ #ifndef LIBBITCOIN_NODE_CHASERS_CHASER_HPP #define LIBBITCOIN_NODE_CHASERS_CHASER_HPP -#include -#include #include #include diff --git a/include/bitcoin/node/chasers/chaser_block.hpp b/include/bitcoin/node/chasers/chaser_block.hpp index 10bf59b58..35cc8da62 100644 --- a/include/bitcoin/node/chasers/chaser_block.hpp +++ b/include/bitcoin/node/chasers/chaser_block.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_NODE_CHASERS_CHASER_BLOCK_HPP #define LIBBITCOIN_NODE_CHASERS_CHASER_BLOCK_HPP -#include #include #include diff --git a/include/bitcoin/node/chasers/chaser_check.hpp b/include/bitcoin/node/chasers/chaser_check.hpp index 0789edd2e..64c17bff3 100644 --- a/include/bitcoin/node/chasers/chaser_check.hpp +++ b/include/bitcoin/node/chasers/chaser_check.hpp @@ -21,7 +21,6 @@ #include #include -#include #include #include diff --git a/include/bitcoin/node/chasers/chaser_confirm.hpp b/include/bitcoin/node/chasers/chaser_confirm.hpp index 985885a88..e2a25a567 100644 --- a/include/bitcoin/node/chasers/chaser_confirm.hpp +++ b/include/bitcoin/node/chasers/chaser_confirm.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_NODE_CHASERS_CHASER_CONFIRM_HPP #define LIBBITCOIN_NODE_CHASERS_CHASER_CONFIRM_HPP -#include #include #include diff --git a/include/bitcoin/node/chasers/chaser_header.hpp b/include/bitcoin/node/chasers/chaser_header.hpp index 3ac08f2ef..3afa9eb93 100644 --- a/include/bitcoin/node/chasers/chaser_header.hpp +++ b/include/bitcoin/node/chasers/chaser_header.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_NODE_CHASERS_CHASER_HEADER_HPP #define LIBBITCOIN_NODE_CHASERS_CHASER_HEADER_HPP -#include #include #include diff --git a/include/bitcoin/node/chasers/chaser_organize.hpp b/include/bitcoin/node/chasers/chaser_organize.hpp index a5a51cdfd..63f53c9ad 100644 --- a/include/bitcoin/node/chasers/chaser_organize.hpp +++ b/include/bitcoin/node/chasers/chaser_organize.hpp @@ -20,8 +20,6 @@ #define LIBBITCOIN_NODE_CHASERS_CHASER_ORGANIZE_HPP #include -#include -#include #include #include diff --git a/include/bitcoin/node/chasers/chaser_snapshot.hpp b/include/bitcoin/node/chasers/chaser_snapshot.hpp index f409258b2..ec295aa12 100644 --- a/include/bitcoin/node/chasers/chaser_snapshot.hpp +++ b/include/bitcoin/node/chasers/chaser_snapshot.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_NODE_CHASERS_CHASER_SNAPSHOT_HPP #include -#include #include #include diff --git a/include/bitcoin/node/chasers/chaser_storage.hpp b/include/bitcoin/node/chasers/chaser_storage.hpp index 761bfe4b8..77037d6be 100644 --- a/include/bitcoin/node/chasers/chaser_storage.hpp +++ b/include/bitcoin/node/chasers/chaser_storage.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_NODE_CHASERS_CHASER_STORAGE_HPP #define LIBBITCOIN_NODE_CHASERS_CHASER_STORAGE_HPP -#include #include #include diff --git a/include/bitcoin/node/chasers/chaser_transaction.hpp b/include/bitcoin/node/chasers/chaser_transaction.hpp index 0bc19c953..2b2aeb98f 100644 --- a/include/bitcoin/node/chasers/chaser_transaction.hpp +++ b/include/bitcoin/node/chasers/chaser_transaction.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_NODE_CHASERS_CHASER_TRANSACTION_HPP #define LIBBITCOIN_NODE_CHASERS_CHASER_TRANSACTION_HPP -#include #include #include diff --git a/include/bitcoin/node/chasers/chaser_validate.hpp b/include/bitcoin/node/chasers/chaser_validate.hpp index e3a2faf63..5babd4457 100644 --- a/include/bitcoin/node/chasers/chaser_validate.hpp +++ b/include/bitcoin/node/chasers/chaser_validate.hpp @@ -20,8 +20,6 @@ #define LIBBITCOIN_NODE_CHASERS_CHASER_VALIDATE_HPP #include -#include -#include #include #include diff --git a/include/bitcoin/node/configuration.hpp b/include/bitcoin/node/configuration.hpp index e29e1b946..563ef6840 100644 --- a/include/bitcoin/node/configuration.hpp +++ b/include/bitcoin/node/configuration.hpp @@ -19,8 +19,6 @@ #ifndef LIBBITCOIN_NODE_CONFIGURATION_HPP #define LIBBITCOIN_NODE_CONFIGURATION_HPP -#include -#include #include #include @@ -62,6 +60,7 @@ class BCN_API configuration /// Settings. log::settings log; + server::settings server; node::settings node; network::settings network; database::settings database; diff --git a/include/bitcoin/node/full_node.hpp b/include/bitcoin/node/full_node.hpp index 921f66988..fd92c6df3 100644 --- a/include/bitcoin/node/full_node.hpp +++ b/include/bitcoin/node/full_node.hpp @@ -19,8 +19,6 @@ #ifndef LIBBITCOIN_NODE_FULL_NODE_HPP #define LIBBITCOIN_NODE_FULL_NODE_HPP -#include -#include #include #include #include diff --git a/include/bitcoin/node/impl/chasers/chaser_organize.ipp b/include/bitcoin/node/impl/chasers/chaser_organize.ipp index 67f36272d..8b4b96036 100644 --- a/include/bitcoin/node/impl/chasers/chaser_organize.ipp +++ b/include/bitcoin/node/impl/chasers/chaser_organize.ipp @@ -21,8 +21,6 @@ #include #include -#include -#include #include #include diff --git a/include/bitcoin/node/parser.hpp b/include/bitcoin/node/parser.hpp index 8f6e7bf42..d5e41b8da 100644 --- a/include/bitcoin/node/parser.hpp +++ b/include/bitcoin/node/parser.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_NODE_PARSER_HPP #define LIBBITCOIN_NODE_PARSER_HPP -#include #include #include diff --git a/include/bitcoin/node/protocols/protocol.hpp b/include/bitcoin/node/protocols/protocol.hpp index 183d1106c..37b83e6b1 100644 --- a/include/bitcoin/node/protocols/protocol.hpp +++ b/include/bitcoin/node/protocols/protocol.hpp @@ -20,10 +20,11 @@ #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_HPP #include -#include #include #include #include + +// Only session.hpp. #include namespace libbitcoin { @@ -45,15 +46,13 @@ namespace node { class BCN_API protocol { protected: - typedef std::shared_ptr ptr; - DELETE_COPY_MOVE_DESTRUCT(protocol); /// Constructors. /// ----------------------------------------------------------------------- // reinterpret_pointer_cast because channel is abstract. - protocol(const node::session::ptr& session, + protocol(const auto& session, const network::channel::ptr& channel) NOEXCEPT : channel_(std::reinterpret_pointer_cast(channel)), session_(session) diff --git a/include/bitcoin/node/protocols/protocol_bitcoind.hpp b/include/bitcoin/node/protocols/protocol_bitcoind.hpp index 94a3b2a69..e6127cf4a 100644 --- a/include/bitcoin/node/protocols/protocol_bitcoind.hpp +++ b/include/bitcoin/node/protocols/protocol_bitcoind.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_BITCOIND_HPP #include -#include #include #include #include @@ -34,8 +33,6 @@ class BCN_API protocol_bitcoind { public: typedef std::shared_ptr ptr; - using options_t = network::settings::http_server; - using channel_t = node::channel_http; protocol_bitcoind(const auto& session, const network::channel::ptr& channel, diff --git a/include/bitcoin/node/protocols/protocol_block_in_106.hpp b/include/bitcoin/node/protocols/protocol_block_in_106.hpp index 321ef9070..1f5af47dd 100644 --- a/include/bitcoin/node/protocols/protocol_block_in_106.hpp +++ b/include/bitcoin/node/protocols/protocol_block_in_106.hpp @@ -20,9 +20,7 @@ #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_BLOCK_IN_106_HPP #include -#include #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/node/protocols/protocol_block_in_31800.hpp b/include/bitcoin/node/protocols/protocol_block_in_31800.hpp index 2a31b9e69..51814b333 100644 --- a/include/bitcoin/node/protocols/protocol_block_in_31800.hpp +++ b/include/bitcoin/node/protocols/protocol_block_in_31800.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_BLOCK_IN_31800_HPP #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_BLOCK_IN_31800_HPP -#include #include #include #include diff --git a/include/bitcoin/node/protocols/protocol_block_out_106.hpp b/include/bitcoin/node/protocols/protocol_block_out_106.hpp index 5c2bf7371..5877c5822 100644 --- a/include/bitcoin/node/protocols/protocol_block_out_106.hpp +++ b/include/bitcoin/node/protocols/protocol_block_out_106.hpp @@ -19,9 +19,7 @@ #ifndef LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_BLOCK_OUT_106_HPP #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_BLOCK_OUT_106_HPP -#include #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/node/protocols/protocol_block_out_70012.hpp b/include/bitcoin/node/protocols/protocol_block_out_70012.hpp index 7efc706e8..708f8223d 100644 --- a/include/bitcoin/node/protocols/protocol_block_out_70012.hpp +++ b/include/bitcoin/node/protocols/protocol_block_out_70012.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_BLOCK_OUT_70012_HPP #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_BLOCK_OUT_70012_HPP -#include #include #include diff --git a/include/bitcoin/node/protocols/protocol_electrum.hpp b/include/bitcoin/node/protocols/protocol_electrum.hpp index 05621849b..01316e497 100644 --- a/include/bitcoin/node/protocols/protocol_electrum.hpp +++ b/include/bitcoin/node/protocols/protocol_electrum.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_ELECTRUM_HPP #include -#include #include #include #include @@ -34,8 +33,6 @@ class BCN_API protocol_electrum { public: typedef std::shared_ptr ptr; - using options_t = network::settings::tcp_server; - using channel_t = node::channel_tcp; protocol_electrum(const auto& session, const network::channel::ptr& channel, diff --git a/include/bitcoin/node/protocols/protocol_explore.hpp b/include/bitcoin/node/protocols/protocol_explore.hpp index 6659acd61..a0c3f06af 100644 --- a/include/bitcoin/node/protocols/protocol_explore.hpp +++ b/include/bitcoin/node/protocols/protocol_explore.hpp @@ -20,8 +20,6 @@ #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_EXPLORE_HPP #include -#include -#include #include #include @@ -34,8 +32,6 @@ class BCN_API protocol_explore { public: typedef std::shared_ptr ptr; - using options_t = network::settings::html_server; - using channel_t = node::channel_http; protocol_explore(const auto& session, const network::channel::ptr& channel, @@ -54,10 +50,6 @@ class BCN_API protocol_explore protected: void handle_receive_get(const code& ec, const network::http::method::get& request) NOEXCEPT override; - -private: - // This is thread safe. - ////const options_t& options_; }; } // namespace node diff --git a/include/bitcoin/node/protocols/protocol_filter_out_70015.hpp b/include/bitcoin/node/protocols/protocol_filter_out_70015.hpp index 72d8bb506..4a2adbca1 100644 --- a/include/bitcoin/node/protocols/protocol_filter_out_70015.hpp +++ b/include/bitcoin/node/protocols/protocol_filter_out_70015.hpp @@ -20,9 +20,7 @@ #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_CLIENT_FILTER_HPP #include -#include #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/node/protocols/protocol_header_in_31800.hpp b/include/bitcoin/node/protocols/protocol_header_in_31800.hpp index 21a64210e..c8f2da996 100644 --- a/include/bitcoin/node/protocols/protocol_header_in_31800.hpp +++ b/include/bitcoin/node/protocols/protocol_header_in_31800.hpp @@ -19,9 +19,7 @@ #ifndef LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_HEADER_IN_31800_HPP #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_HEADER_IN_31800_HPP -#include #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/node/protocols/protocol_header_in_70012.hpp b/include/bitcoin/node/protocols/protocol_header_in_70012.hpp index 7f081c2dd..e8583a829 100644 --- a/include/bitcoin/node/protocols/protocol_header_in_70012.hpp +++ b/include/bitcoin/node/protocols/protocol_header_in_70012.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_HEADER_IN_70012_HPP #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_HEADER_IN_70012_HPP -#include #include #include diff --git a/include/bitcoin/node/protocols/protocol_header_out_31800.hpp b/include/bitcoin/node/protocols/protocol_header_out_31800.hpp index f985e2a9f..e109dc722 100644 --- a/include/bitcoin/node/protocols/protocol_header_out_31800.hpp +++ b/include/bitcoin/node/protocols/protocol_header_out_31800.hpp @@ -19,9 +19,7 @@ #ifndef LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_HEADER_OUT_31800_HPP #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_HEADER_OUT_31800_HPP -#include #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/node/protocols/protocol_header_out_70012.hpp b/include/bitcoin/node/protocols/protocol_header_out_70012.hpp index eed6ba5c3..b439a58ee 100644 --- a/include/bitcoin/node/protocols/protocol_header_out_70012.hpp +++ b/include/bitcoin/node/protocols/protocol_header_out_70012.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_HEADER_OUT_70012_HPP #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_HEADER_OUT_70012_HPP -#include #include #include diff --git a/include/bitcoin/node/protocols/protocol_html.hpp b/include/bitcoin/node/protocols/protocol_html.hpp index 8ffbb4071..a721309dd 100644 --- a/include/bitcoin/node/protocols/protocol_html.hpp +++ b/include/bitcoin/node/protocols/protocol_html.hpp @@ -19,31 +19,51 @@ #ifndef LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_HTML_HPP #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_HTML_HPP -#include -#include #include #include #include -#include +#include namespace libbitcoin { namespace node { /// Abstract base for HTML protocols, thread safe. class BCN_API protocol_html - : public network::protocol_html, + : public network::protocol_http, public node::protocol { -protected: - typedef std::shared_ptr ptr; +public: + /// http channel, but html settings. + using options_t = server::settings::html_server; + using channel_t = node::channel_http; +protected: protocol_html(const auto& session, const network::channel::ptr& channel, const options_t& options) NOEXCEPT - : network::protocol_html(session, channel, options), + : network::protocol_http(session, channel, options), + options_(options), node::protocol(session, channel) { } + + /// Message handlers by http method. + void handle_receive_get(const code& ec, + const network::http::method::get& request) NOEXCEPT override; + + /// Senders. + void send_file(const network::http::string_request& request, + network::http::file&& file, network::http::mime_type type) NOEXCEPT; + + /// Utilities. + bool is_allowed_origin(const std::string& origin, + size_t version) const NOEXCEPT; + std::filesystem::path to_local_path( + const std::string& target = "/") const NOEXCEPT; + +private: + // This is thread safe. + const options_t& options_; }; } // namespace node diff --git a/include/bitcoin/node/protocols/protocol_http.hpp b/include/bitcoin/node/protocols/protocol_http.hpp index 0ea0492f4..fe3ca2d9a 100644 --- a/include/bitcoin/node/protocols/protocol_http.hpp +++ b/include/bitcoin/node/protocols/protocol_http.hpp @@ -20,10 +20,11 @@ #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_HTTP_HPP #include -#include #include #include #include + + // Only session.hpp. #include namespace libbitcoin { @@ -34,9 +35,11 @@ class BCN_API protocol_http : public network::protocol_http, public node::protocol { -protected: - typedef std::shared_ptr ptr; +public: + // Replace base class channel_t (network::channel_http). + using channel_t = node::channel_http; +protected: protocol_http(const auto& session, const network::channel::ptr& channel, const options_t& options) NOEXCEPT @@ -52,7 +55,7 @@ class BCN_API protocol_http const node::channel_tcp::ptr channel_; // This is thread safe. - const session::ptr session_; + const node::session::ptr session_; }; } // namespace node diff --git a/include/bitcoin/node/protocols/protocol_observer.hpp b/include/bitcoin/node/protocols/protocol_observer.hpp index 77401b248..4ef8bc58b 100644 --- a/include/bitcoin/node/protocols/protocol_observer.hpp +++ b/include/bitcoin/node/protocols/protocol_observer.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_OBSERVER_HPP #include -#include #include #include #include diff --git a/include/bitcoin/node/protocols/protocol_peer.hpp b/include/bitcoin/node/protocols/protocol_peer.hpp index 263c20443..448ab9c45 100644 --- a/include/bitcoin/node/protocols/protocol_peer.hpp +++ b/include/bitcoin/node/protocols/protocol_peer.hpp @@ -20,10 +20,11 @@ #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_PEER_HPP #include -#include #include #include #include + + // Only session.hpp. #include namespace libbitcoin { @@ -122,7 +123,7 @@ class BCN_API protocol_peer const node::channel_peer::ptr channel_; // This is thread safe. - const session::ptr session_; + const node::session::ptr session_; // This is protected by singular subscription. object_key key_{}; diff --git a/include/bitcoin/node/protocols/protocol_performer.hpp b/include/bitcoin/node/protocols/protocol_performer.hpp index 7d54c914f..59a6ac864 100644 --- a/include/bitcoin/node/protocols/protocol_performer.hpp +++ b/include/bitcoin/node/protocols/protocol_performer.hpp @@ -19,9 +19,7 @@ #ifndef LIBBITCOIN_NODE_PROTOCOL_PERFORMER_HPP #define LIBBITCOIN_NODE_PROTOCOL_PERFORMER_HPP -#include #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/node/protocols/protocol_stratum_v1.hpp b/include/bitcoin/node/protocols/protocol_stratum_v1.hpp index b378b7b56..3f3cff5d5 100644 --- a/include/bitcoin/node/protocols/protocol_stratum_v1.hpp +++ b/include/bitcoin/node/protocols/protocol_stratum_v1.hpp @@ -20,8 +20,6 @@ #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_STRATUM_V1_HPP #include -#include -#include #include #include @@ -34,8 +32,6 @@ class BCN_API protocol_stratum_v1 { public: typedef std::shared_ptr ptr; - using options_t = network::settings::tcp_server; - using channel_t = node::channel_tcp; protocol_stratum_v1(const auto& session, const network::channel::ptr& channel, diff --git a/include/bitcoin/node/protocols/protocol_stratum_v2.hpp b/include/bitcoin/node/protocols/protocol_stratum_v2.hpp index eb214bbc9..fdc71358f 100644 --- a/include/bitcoin/node/protocols/protocol_stratum_v2.hpp +++ b/include/bitcoin/node/protocols/protocol_stratum_v2.hpp @@ -20,8 +20,6 @@ #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_STRATUM_V2_HPP #include -#include -#include #include #include @@ -34,8 +32,6 @@ class BCN_API protocol_stratum_v2 { public: typedef std::shared_ptr ptr; - using options_t = network::settings::tcp_server; - using channel_t = node::channel_tcp; protocol_stratum_v2(const auto& session, const network::channel::ptr& channel, diff --git a/include/bitcoin/node/protocols/protocol_tcp.hpp b/include/bitcoin/node/protocols/protocol_tcp.hpp index 5bdcc8b38..5df824894 100644 --- a/include/bitcoin/node/protocols/protocol_tcp.hpp +++ b/include/bitcoin/node/protocols/protocol_tcp.hpp @@ -20,10 +20,11 @@ #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_TCP_HPP #include -#include #include #include #include + + // Only session.hpp. #include namespace libbitcoin { @@ -34,9 +35,11 @@ class BCN_API protocol_tcp : public network::protocol_tcp, public node::protocol { -protected: - typedef std::shared_ptr ptr; +public: + // Replace base class channel_t (network::channel_tcp). + using channel_t = node::channel_tcp; +protected: protocol_tcp(const auto& session, const network::channel::ptr& channel, const options_t& options) NOEXCEPT @@ -52,7 +55,7 @@ class BCN_API protocol_tcp const node::channel_tcp::ptr channel_; // This is thread safe. - const session::ptr session_; + const node::session::ptr session_; }; } // namespace node diff --git a/include/bitcoin/node/protocols/protocol_transaction_in_106.hpp b/include/bitcoin/node/protocols/protocol_transaction_in_106.hpp index 5cc9396bd..15670a56c 100644 --- a/include/bitcoin/node/protocols/protocol_transaction_in_106.hpp +++ b/include/bitcoin/node/protocols/protocol_transaction_in_106.hpp @@ -19,9 +19,7 @@ #ifndef LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_TRANSACTION_IN_106_HPP #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_TRANSACTION_IN_106_HPP -#include #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/node/protocols/protocol_transaction_out_106.hpp b/include/bitcoin/node/protocols/protocol_transaction_out_106.hpp index d3f32cf98..1f8f518df 100644 --- a/include/bitcoin/node/protocols/protocol_transaction_out_106.hpp +++ b/include/bitcoin/node/protocols/protocol_transaction_out_106.hpp @@ -19,9 +19,7 @@ #ifndef LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_TRANSACTION_OUT_106_HPP #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_TRANSACTION_OUT_106_HPP -#include #include -#include #include namespace libbitcoin { diff --git a/include/bitcoin/node/protocols/protocol_web.hpp b/include/bitcoin/node/protocols/protocol_web.hpp index 5e3616a90..57c4da783 100644 --- a/include/bitcoin/node/protocols/protocol_web.hpp +++ b/include/bitcoin/node/protocols/protocol_web.hpp @@ -20,22 +20,19 @@ #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_WEB_HPP #include -#include -#include #include -#include +#include namespace libbitcoin { namespace node { +/// Administrative web site for the node (currently just page server). class BCN_API protocol_web : public node::protocol_html, protected network::tracker { public: typedef std::shared_ptr ptr; - using options_t = network::settings::html_server; - using channel_t = node::channel_http; protocol_web(const auto& session, const network::channel::ptr& channel, @@ -50,14 +47,6 @@ class BCN_API protocol_web { node::protocol_html::start(); } - -////protected: -//// void handle_receive_get(const code& ec, -//// const network::http::method::get& request) NOEXCEPT override; - -private: - // This is thread safe. - ////const options_t& options_; }; } // namespace node diff --git a/include/bitcoin/node/protocols/protocol_websocket.hpp b/include/bitcoin/node/protocols/protocol_websocket.hpp index 5b6085fe9..cfb0825fa 100644 --- a/include/bitcoin/node/protocols/protocol_websocket.hpp +++ b/include/bitcoin/node/protocols/protocol_websocket.hpp @@ -20,8 +20,6 @@ #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_WEBSOCKET_HPP #include -#include -#include #include #include @@ -34,8 +32,6 @@ class BCN_API protocol_websocket { public: typedef std::shared_ptr ptr; - using options_t = network::settings::http_server; - using channel_t = node::channel_http; protocol_websocket(const auto& session, const network::channel::ptr& channel, diff --git a/include/bitcoin/node/protocols/protocols.hpp b/include/bitcoin/node/protocols/protocols.hpp index 9ffd30fff..a78a5b9af 100644 --- a/include/bitcoin/node/protocols/protocols.hpp +++ b/include/bitcoin/node/protocols/protocols.hpp @@ -19,11 +19,12 @@ #ifndef LIBBITCOIN_NODE_PROTOCOLS_PROTOCOLS_HPP #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOLS_HPP -/// node base +/// base #include - -/// peer base +#include +#include #include +#include /// peer #include @@ -40,11 +41,6 @@ #include #include -/// server base -#include -#include -#include - /// server #include #include diff --git a/include/bitcoin/node/sessions/session.hpp b/include/bitcoin/node/sessions/session.hpp index 22f0afa74..5343d544c 100644 --- a/include/bitcoin/node/sessions/session.hpp +++ b/include/bitcoin/node/sessions/session.hpp @@ -19,8 +19,6 @@ #ifndef LIBBITCOIN_NODE_SESSIONS_SESSION_HPP #define LIBBITCOIN_NODE_SESSIONS_SESSION_HPP -#include -#include #include #include diff --git a/include/bitcoin/node/sessions/session_inbound.hpp b/include/bitcoin/node/sessions/session_inbound.hpp index ffd53cdf9..c4f439c3b 100644 --- a/include/bitcoin/node/sessions/session_inbound.hpp +++ b/include/bitcoin/node/sessions/session_inbound.hpp @@ -19,14 +19,13 @@ #ifndef LIBBITCOIN_NODE_SESSIONS_SESSION_INBOUND_HPP #define LIBBITCOIN_NODE_SESSIONS_SESSION_INBOUND_HPP -#include #include #include namespace libbitcoin { namespace node { -class session_inbound +class BCN_API session_inbound : public session_peer { public: diff --git a/include/bitcoin/node/sessions/session_manual.hpp b/include/bitcoin/node/sessions/session_manual.hpp index 28649d3d6..3293e016d 100644 --- a/include/bitcoin/node/sessions/session_manual.hpp +++ b/include/bitcoin/node/sessions/session_manual.hpp @@ -19,14 +19,13 @@ #ifndef LIBBITCOIN_NODE_SESSIONS_SESSION_MANUAL_HPP #define LIBBITCOIN_NODE_SESSIONS_SESSION_MANUAL_HPP -#include #include #include namespace libbitcoin { namespace node { -class session_manual +class BCN_API session_manual : public session_peer { public: diff --git a/include/bitcoin/node/sessions/session_outbound.hpp b/include/bitcoin/node/sessions/session_outbound.hpp index 3f4c331df..a4edad14c 100644 --- a/include/bitcoin/node/sessions/session_outbound.hpp +++ b/include/bitcoin/node/sessions/session_outbound.hpp @@ -19,14 +19,13 @@ #ifndef LIBBITCOIN_NODE_SESSIONS_SESSION_OUTBOUND_HPP #define LIBBITCOIN_NODE_SESSIONS_SESSION_OUTBOUND_HPP -#include #include #include namespace libbitcoin { namespace node { -class session_outbound +class BCN_API session_outbound : public session_peer { public: diff --git a/include/bitcoin/node/sessions/session_peer.hpp b/include/bitcoin/node/sessions/session_peer.hpp index 34e2eace3..bca26304a 100644 --- a/include/bitcoin/node/sessions/session_peer.hpp +++ b/include/bitcoin/node/sessions/session_peer.hpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include #include @@ -38,6 +38,10 @@ class session_peer public node::session { public: + typedef std::shared_ptr> ptr; + using channel_t = node::channel_peer; + + /// Construct an instance. template session_peer(Node& node, Args&&... args) NOEXCEPT : Session(node, std::forward(args)...), @@ -46,38 +50,47 @@ class session_peer } protected: - network::channel::ptr create_channel( - const network::socket::ptr& socket) NOEXCEPT override + using socket_ptr = network::socket::ptr; + using channel_ptr = network::channel::ptr; + + // this-> is required for dependent base access in CRTP. + + channel_ptr create_channel(const socket_ptr& socket) NOEXCEPT override { - // this-> is required for dependent base access in CRTP. - const auto channel = std::make_shared( + BC_ASSERT(this->stranded()); + + const auto channel = std::make_shared( this->get_memory(), this->log, socket, this->config(), this->create_key()); return std::static_pointer_cast(channel); } - void attach_handshake(const network::channel::ptr& channel, + void attach_handshake(const channel_ptr& channel, network::result_handler&& handler) NOEXCEPT override { + BC_ASSERT(channel->stranded()); + BC_ASSERT(channel->paused()); + // Set the current top for version protocol, before handshake. - const auto top = archive().get_top_confirmed(); - const auto peer = std::dynamic_pointer_cast(channel); + const auto top = this->archive().get_top_confirmed(); + const auto peer = std::dynamic_pointer_cast(channel); peer->set_start_height(top); // Attach and execute appropriate version protocol. Session::attach_handshake(channel, std::move(handler)); } - void attach_protocols( - const network::channel::ptr& channel) NOEXCEPT override + void attach_protocols(const channel_ptr& channel) NOEXCEPT override { + BC_ASSERT(channel->stranded()); + BC_ASSERT(channel->paused()); + using namespace system; using namespace network; using namespace messages::peer; using base = session_peer; - // this-> is required for dependent base access in CRTP. const auto self = this->template shared_from_base(); const auto relay = this->config().network.enable_relay; const auto delay = this->config().node.delay_inbound; @@ -100,7 +113,7 @@ class session_peer channel->attach(self)->start(); // Ready to relay blocks or block filters. - const auto blocks_out = !delay || is_recent(); + const auto blocks_out = !delay || this->is_recent(); /////////////////////////////////////////////////////////////////////// // bip152: "Upon receipt of a `sendcmpct` message with the first and @@ -109,7 +122,7 @@ class session_peer // This allows the node to support bip157 without supporting bip152. /////////////////////////////////////////////////////////////////////// - const auto peer = std::dynamic_pointer_cast(channel); + const auto peer = std::dynamic_pointer_cast(channel); // Node must advertise node_client_filters or no out filters. if (node_client_filters && blocks_out && diff --git a/include/bitcoin/node/sessions/session_server.hpp b/include/bitcoin/node/sessions/session_server.hpp index c41d81210..504510e59 100644 --- a/include/bitcoin/node/sessions/session_server.hpp +++ b/include/bitcoin/node/sessions/session_server.hpp @@ -16,8 +16,8 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#ifndef LIBBITCOIN_NODE_SESSION_SERVER_HPP -#define LIBBITCOIN_NODE_SESSION_SERVER_HPP +#ifndef LIBBITCOIN_NODE_SESSIONS_SESSION_SERVER_HPP +#define LIBBITCOIN_NODE_SESSIONS_SESSION_SERVER_HPP #include #include @@ -27,6 +27,8 @@ namespace libbitcoin { namespace node { +class full_node; + // make_shared<> BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) @@ -49,8 +51,8 @@ class session_server using channel_t = typename Protocol::channel_t; /// Construct an instance (network should be started). - template - session_server(Node& node, uint64_t identifier, const options_t& options, + template + session_server(full_node& node, uint64_t identifier, const options_t& options, Args&&... args) NOEXCEPT : session_tcp(node, identifier, options, std::forward(args)...), options_(options), @@ -67,7 +69,7 @@ class session_server /// based on available factors (e.g. a distinct protocol version). channel_ptr create_channel(const socket_ptr& socket) NOEXCEPT override { - BC_ASSERT_MSG(stranded(), "strand"); + BC_ASSERT(stranded()); const auto channel = std::make_shared(log, socket, config(), create_key(), options_); @@ -83,8 +85,8 @@ class session_server void attach_handshake(const channel_ptr& channel, network::result_handler&& handler) NOEXCEPT override { - BC_ASSERT_MSG(channel->stranded(), "channel strand"); - BC_ASSERT_MSG(channel->paused(), "channel not paused for handshake"); + BC_ASSERT(channel->stranded()); + BC_ASSERT(channel->paused()); session_tcp::attach_handshake(channel, std::move(handler)); } @@ -95,8 +97,8 @@ class session_server /// Use std::dynamic_pointer_cast(channel) to obtain channel_t. void attach_protocols(const channel_ptr& channel) NOEXCEPT override { - BC_ASSERT_MSG(channel->stranded(), "channel strand"); - BC_ASSERT_MSG(channel->paused(), "channel not paused for protocols"); + BC_ASSERT(channel->stranded()); + BC_ASSERT(channel->paused()); const auto self = shared_from_base(); channel->attach(self, options_)->start(); diff --git a/include/bitcoin/node/sessions/session_tcp.hpp b/include/bitcoin/node/sessions/session_tcp.hpp index 386fa483a..ea33879af 100644 --- a/include/bitcoin/node/sessions/session_tcp.hpp +++ b/include/bitcoin/node/sessions/session_tcp.hpp @@ -19,7 +19,6 @@ #ifndef LIBBITCOIN_NODE_SESSIONS_SESSION_TCP_HPP #define LIBBITCOIN_NODE_SESSIONS_SESSION_TCP_HPP -#include #include #include @@ -28,7 +27,7 @@ namespace node { class full_node; -class session_tcp +class BCN_API session_tcp : public network::session_tcp, public node::session { @@ -36,12 +35,10 @@ class session_tcp typedef std::shared_ptr ptr; using options_t = network::session_tcp::options_t; + // (network::net&) cast due to full_node forward ref (inheritance hidden). session_tcp(full_node& node, uint64_t identifier, const options_t& options) NOEXCEPT - : network::session_tcp( - (network::net&)node, - identifier, - (const network::settings::tcp_server&)options), + : network::session_tcp((network::net&)node, identifier, options), node::session(node) { } diff --git a/include/bitcoin/node/settings.hpp b/include/bitcoin/node/settings.hpp index 89a2736bf..b49e233a5 100644 --- a/include/bitcoin/node/settings.hpp +++ b/include/bitcoin/node/settings.hpp @@ -20,7 +20,6 @@ #define LIBBITCOIN_NODE_SETTINGS_HPP #include -#include #include namespace libbitcoin { @@ -97,6 +96,62 @@ class BCN_API settings }; } // namespace node + +namespace server { + +/// [server] settings. +class BCN_API settings +{ +public: + /// html (http/s) document server settings (has directory/default). + /// This is for web servers that expose a local file system directory. + struct html_server + : public network::settings::http_server + { + /// Directory to serve. + std::filesystem::path path{}; + + /// Default page for default URL (recommended). + std::string default_{ "index.html" }; + + /// Validated against origins if configured (recommended). + network::config::endpoints origins{}; + + /// Normalized origins. + system::string_list origin_names() const NOEXCEPT; + + /// !path.empty() && http_server::enabled() [hidden, not virtual] + bool enabled() const NOEXCEPT; + }; + + DEFAULT_COPY_MOVE_DESTRUCT(settings); + + settings() NOEXCEPT {}; + settings(system::chain::selection) NOEXCEPT {}; + + /// native admin web interface, isolated (http/s, stateless html) + server::settings::html_server web{ "web" }; + + /// native RESTful block explorer (http/s, stateless html/json) + server::settings::html_server explore{ "explore" }; + + /// native websocket query interface (http/s->tcp/s, json, handshake) + network::settings::webs_server websocket{ "websocket" }; + + /// bitcoind compat interface (http/s, stateless json-rpc-v2) + network::settings::http_server bitcoind{ "bitcoind" }; + + /// electrum compat interface (tcp/s, json-rpc-v2) + network::settings::tcp_server electrum{ "electrum" }; + + /// stratum v1 compat interface (tcp/s, json-rpc-v1, auth handshake) + network::settings::tcp_server stratum_v1{ "stratum_v1" }; + + /// stratum v2 compat interface (tcp[/s], binary, auth/privacy handshake) + network::settings::tcp_server stratum_v2{ "stratum_v2" }; +}; + +} // namespace server } // namespace libbitcoin #endif diff --git a/src/block_memory.cpp b/src/block_memory.cpp index 14241fd6e..4ca8249d6 100644 --- a/src/block_memory.cpp +++ b/src/block_memory.cpp @@ -19,7 +19,6 @@ #include #include -#include namespace libbitcoin { namespace node { diff --git a/src/channels/channel_peer.cpp b/src/channels/channel_peer.cpp index a9ce4913c..2385ca9bd 100644 --- a/src/channels/channel_peer.cpp +++ b/src/channels/channel_peer.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include diff --git a/src/chasers/chaser.cpp b/src/chasers/chaser.cpp index afa5dabad..c13168b81 100644 --- a/src/chasers/chaser.cpp +++ b/src/chasers/chaser.cpp @@ -19,8 +19,6 @@ #include #include -#include -#include #include #include #include diff --git a/src/chasers/chaser_block.cpp b/src/chasers/chaser_block.cpp index e26f57be1..0851a70ae 100644 --- a/src/chasers/chaser_block.cpp +++ b/src/chasers/chaser_block.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include #include diff --git a/src/chasers/chaser_check.cpp b/src/chasers/chaser_check.cpp index fa4697676..c7eedcded 100644 --- a/src/chasers/chaser_check.cpp +++ b/src/chasers/chaser_check.cpp @@ -22,8 +22,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/src/chasers/chaser_confirm.cpp b/src/chasers/chaser_confirm.cpp index 8878afdb2..d08460765 100644 --- a/src/chasers/chaser_confirm.cpp +++ b/src/chasers/chaser_confirm.cpp @@ -19,8 +19,6 @@ #include #include -#include -#include #include #include #include diff --git a/src/chasers/chaser_header.cpp b/src/chasers/chaser_header.cpp index fbfe6fd2c..544d9f9e4 100644 --- a/src/chasers/chaser_header.cpp +++ b/src/chasers/chaser_header.cpp @@ -18,7 +18,6 @@ */ #include -#include #include #include #include diff --git a/src/chasers/chaser_snapshot.cpp b/src/chasers/chaser_snapshot.cpp index e73cf9c8e..bc0b05f86 100644 --- a/src/chasers/chaser_snapshot.cpp +++ b/src/chasers/chaser_snapshot.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #include #include diff --git a/src/chasers/chaser_storage.cpp b/src/chasers/chaser_storage.cpp index 2a8019d9a..88250f8da 100644 --- a/src/chasers/chaser_storage.cpp +++ b/src/chasers/chaser_storage.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include #include diff --git a/src/chasers/chaser_template.cpp b/src/chasers/chaser_template.cpp index 4e681337c..fb47bdd4b 100644 --- a/src/chasers/chaser_template.cpp +++ b/src/chasers/chaser_template.cpp @@ -18,7 +18,6 @@ */ #include -#include #include #include #include diff --git a/src/chasers/chaser_transaction.cpp b/src/chasers/chaser_transaction.cpp index f44cc92d3..0b46dc3d4 100644 --- a/src/chasers/chaser_transaction.cpp +++ b/src/chasers/chaser_transaction.cpp @@ -18,7 +18,6 @@ */ #include -#include #include #include #include diff --git a/src/chasers/chaser_validate.cpp b/src/chasers/chaser_validate.cpp index 3f3099faa..4ac114b4d 100644 --- a/src/chasers/chaser_validate.cpp +++ b/src/chasers/chaser_validate.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include #include diff --git a/src/configuration.cpp b/src/configuration.cpp index 66c2e93e1..853f99c59 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -18,7 +18,6 @@ */ #include -#include namespace libbitcoin { namespace node { diff --git a/src/full_node.cpp b/src/full_node.cpp index e47f9e69e..9077461d6 100644 --- a/src/full_node.cpp +++ b/src/full_node.cpp @@ -19,8 +19,6 @@ #include #include -#include -#include #include #include #include @@ -540,37 +538,37 @@ network::session_outbound::ptr full_node::attach_outbound_session() NOEXCEPT session_web::ptr full_node::attach_web_session() NOEXCEPT { - return net::attach(*this, config_.network.web); + return net::attach(*this, config_.server.web); } session_explore::ptr full_node::attach_explore_session() NOEXCEPT { - return net::attach(*this, config_.network.explore); + return net::attach(*this, config_.server.explore); } session_websocket::ptr full_node::attach_websocket_session() NOEXCEPT { - return net::attach(*this, config_.network.websocket); + return net::attach(*this, config_.server.websocket); } session_bitcoind::ptr full_node::attach_bitcoind_session() NOEXCEPT { - return net::attach(*this, config_.network.bitcoind); + return net::attach(*this, config_.server.bitcoind); } session_electrum::ptr full_node::attach_electrum_session() NOEXCEPT { - return net::attach(*this, config_.network.electrum); + return net::attach(*this, config_.server.electrum); } session_stratum_v1::ptr full_node::attach_stratum_v1_session() NOEXCEPT { - return net::attach(*this, config_.network.stratum_v1); + return net::attach(*this, config_.server.stratum_v1); } session_stratum_v2::ptr full_node::attach_stratum_v2_session() NOEXCEPT { - return net::attach(*this, config_.network.stratum_v2); + return net::attach(*this, config_.server.stratum_v2); } BC_POP_WARNING() diff --git a/src/parser.cpp b/src/parser.cpp index 75c5fe335..a4550502f 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -19,8 +19,6 @@ #include #include -#include -#include #include #define BC_HTTP_SERVER_NAME "libbitcoin/4.0" @@ -94,13 +92,13 @@ parser::parser(system::chain::selection context) NOEXCEPT configured.network.seeds.emplace_back("seed.mainnet.achownodes.xyz", 8333_u16); // admin - configured.network.web.binds.emplace_back(asio::address{}, 8080_u16); - configured.network.explore.binds.emplace_back(asio::address{}, 8180_u16); - configured.network.websocket.binds.emplace_back(asio::address{}, 8280_u16); - configured.network.bitcoind.binds.emplace_back(asio::address{}, 8380_u16); - configured.network.electrum.binds.emplace_back(asio::address{}, 8480_u16); - configured.network.stratum_v1.binds.emplace_back(asio::address{}, 8580_u16); - configured.network.stratum_v2.binds.emplace_back(asio::address{}, 8680_u16); + configured.server.web.binds.emplace_back(asio::address{}, 8080_u16); + configured.server.explore.binds.emplace_back(asio::address{}, 8180_u16); + configured.server.websocket.binds.emplace_back(asio::address{}, 8280_u16); + configured.server.bitcoind.binds.emplace_back(asio::address{}, 8380_u16); + configured.server.electrum.binds.emplace_back(asio::address{}, 8480_u16); + configured.server.stratum_v1.binds.emplace_back(asio::address{}, 8580_u16); + configured.server.stratum_v2.binds.emplace_back(asio::address{}, 8680_u16); // SCALE: LF2.2 @ 850K. @@ -1098,224 +1096,224 @@ options_metadata parser::load_settings() THROWS /* [web] */ ( "web.secure", - value(&configured.network.web.secure), + value(&configured.server.web.secure), "The service requires TLS (not implemented), defaults to 'false'." ) ( "web.bind", - value(&configured.network.web.binds), + value(&configured.server.web.binds), "IP address to bind, multiple allowed, defaults to '0.0.0.0:8080' (all IPv4)." ) ( "web.connections", - value(&configured.network.web.connections), + value(&configured.server.web.connections), "The required maximum number of connections, defaults to '0'." ) ( "web.timeout_seconds", - value(&configured.network.web.timeout_seconds), + value(&configured.server.web.timeout_seconds), "The idle timeout (http keep-alive), defaults to '60'." ) ( "web.server", - value(&configured.network.web.server), + value(&configured.server.web.server), "The server name (http header), defaults to '" BC_HTTP_SERVER_NAME "'." ) ( "web.host", - value(&configured.network.web.hosts), + value(&configured.server.web.hosts), "The host name (http verification), multiple allowed, defaults to empty (disabled)." ) ( "web.origin", - value(&configured.network.web.origins), + value(&configured.server.web.origins), "The allowed origin (http verification), multiple allowed, defaults to empty (disabled)." ) ( "web.path", - value(&configured.network.web.path), + value(&configured.server.web.path), "The required root path of source files to be served, defaults to empty." ) ( "web.default", - value(&configured.network.web.default_), + value(&configured.server.web.default_), "The path of the default source page, defaults to 'index.html'." ) /* [explore] */ ( "explore.secure", - value(&configured.network.explore.secure), + value(&configured.server.explore.secure), "The service requires TLS (not implemented), defaults to 'false'." ) ( "explore.bind", - value(&configured.network.explore.binds), + value(&configured.server.explore.binds), "IP address to bind, multiple allowed, defaults to '0.0.0.0:8080' (all IPv4)." ) ( "explore.connections", - value(&configured.network.explore.connections), + value(&configured.server.explore.connections), "The required maximum number of connections, defaults to '0'." ) ( "explore.timeout_seconds", - value(&configured.network.explore.timeout_seconds), - "The idle timeout (http keep-alive), defaults to '60'." + value(&configured.server.explore.timeout_seconds), + "The idle timeout (http keep-server), defaults to '60'." ) ( "explore.server", - value(&configured.network.explore.server), + value(&configured.server.explore.server), "The server name (http header), defaults to '" BC_HTTP_SERVER_NAME "'." ) ( "explore.host", - value(&configured.network.explore.hosts), + value(&configured.server.explore.hosts), "The host name (http verification), multiple allowed, defaults to empty (disabled)." ) ( "explore.origin", - value(&configured.network.explore.origins), + value(&configured.server.explore.origins), "The allowed origin (http verification), multiple allowed, defaults to empty (disabled)." ) ( "explore.path", - value(&configured.network.explore.path), + value(&configured.server.explore.path), "The required root path of source files to be served, defaults to empty." ) ( "explore.default", - value(&configured.network.explore.default_), + value(&configured.server.explore.default_), "The path of the default source page, defaults to 'index.html'." ) /* [websocket] */ ( "websocket.secure", - value(&configured.network.websocket.secure), + value(&configured.server.websocket.secure), "The service requires TLS (not implemented), defaults to 'false'." ) ( "websocket.bind", - value(&configured.network.websocket.binds), + value(&configured.server.websocket.binds), "IP address to bind, multiple allowed, defaults to '0.0.0.0:8080' (all IPv4)." ) ( "websocket.connections", - value(&configured.network.websocket.connections), + value(&configured.server.websocket.connections), "The required maximum number of connections, defaults to '0'." ) ( "websocket.timeout_seconds", - value(&configured.network.websocket.timeout_seconds), + value(&configured.server.websocket.timeout_seconds), "The idle timeout (http keep-alive), defaults to '60'." ) ( "websocket.server", - value(&configured.network.websocket.server), + value(&configured.server.websocket.server), "The server name (http header), defaults to '" BC_HTTP_SERVER_NAME "'." ) ( "websocket.host", - value(&configured.network.websocket.hosts), + value(&configured.server.websocket.hosts), "The host name (http verification), multiple allowed, defaults to empty (disabled)." ) /* [bitcoind] */ ( "bitcoind.secure", - value(&configured.network.bitcoind.secure), + value(&configured.server.bitcoind.secure), "The service requires TLS (not implemented), defaults to 'false'." ) ( "bitcoind.bind", - value(&configured.network.bitcoind.binds), + value(&configured.server.bitcoind.binds), "IP address to bind, multiple allowed, defaults to '0.0.0.0:8080' (all IPv4)." ) ( "bitcoind.connections", - value(&configured.network.bitcoind.connections), + value(&configured.server.bitcoind.connections), "The required maximum number of connections, defaults to '0'." ) ( "bitcoind.timeout_seconds", - value(&configured.network.bitcoind.timeout_seconds), + value(&configured.server.bitcoind.timeout_seconds), "The idle timeout (http keep-alive), defaults to '60'." ) ( "bitcoind.server", - value(&configured.network.bitcoind.server), + value(&configured.server.bitcoind.server), "The server name (http header), defaults to '" BC_HTTP_SERVER_NAME "'." ) ( "bitcoind.host", - value(&configured.network.bitcoind.hosts), + value(&configured.server.bitcoind.hosts), "The host name (http verification), multiple allowed, defaults to empty (disabled)." ) /* [electrum] */ ( "electrum.secure", - value(&configured.network.electrum.secure), + value(&configured.server.electrum.secure), "The service requires TLS (not implemented), defaults to 'false'." ) ( "electrum.bind", - value(&configured.network.electrum.binds), + value(&configured.server.electrum.binds), "IP address to bind, multiple allowed, defaults to '0.0.0.0:8080' (all IPv4)." ) ( "electrum.connections", - value(&configured.network.electrum.connections), + value(&configured.server.electrum.connections), "The required maximum number of connections, defaults to '0'." ) ( "electrum.timeout_seconds", - value(&configured.network.electrum.timeout_seconds), + value(&configured.server.electrum.timeout_seconds), "The idle timeout (http keep-alive), defaults to '60'." ) /* [stratum_v1] */ ( "stratum_v1.secure", - value(&configured.network.stratum_v1.secure), + value(&configured.server.stratum_v1.secure), "The service requires TLS (not implemented), defaults to 'false'." ) ( "stratum_v1.bind", - value(&configured.network.stratum_v1.binds), + value(&configured.server.stratum_v1.binds), "IP address to bind, multiple allowed, defaults to '0.0.0.0:8080' (all IPv4)." ) ( "stratum_v1.connections", - value(&configured.network.stratum_v1.connections), + value(&configured.server.stratum_v1.connections), "The required maximum number of connections, defaults to '0'." ) ( "stratum_v1.timeout_seconds", - value(&configured.network.stratum_v1.timeout_seconds), + value(&configured.server.stratum_v1.timeout_seconds), "The idle timeout (http keep-alive), defaults to '60'." ) /* [stratum_v2] */ ( "stratum_v2.secure", - value(&configured.network.stratum_v2.secure), + value(&configured.server.stratum_v2.secure), "The service requires TLS (not implemented), defaults to 'false'." ) ( "stratum_v2.bind", - value(&configured.network.stratum_v2.binds), + value(&configured.server.stratum_v2.binds), "IP address to bind, multiple allowed, defaults to '0.0.0.0:8080' (all IPv4)." ) ( "stratum_v2.connections", - value(&configured.network.stratum_v2.connections), + value(&configured.server.stratum_v2.connections), "The required maximum number of connections, defaults to '0'." ) ( "stratum_v2.timeout_seconds", - value(&configured.network.stratum_v2.timeout_seconds), + value(&configured.server.stratum_v2.timeout_seconds), "The idle timeout (http keep-alive), defaults to '60'." ) diff --git a/src/protocols/protocol.cpp b/src/protocols/protocol.cpp index 4aec0c11c..a08af5274 100644 --- a/src/protocols/protocol.cpp +++ b/src/protocols/protocol.cpp @@ -18,7 +18,6 @@ */ #include -#include #include #include diff --git a/src/protocols/protocol_block_in_106.cpp b/src/protocols/protocol_block_in_106.cpp index 6d4481e01..ddb3e4629 100644 --- a/src/protocols/protocol_block_in_106.cpp +++ b/src/protocols/protocol_block_in_106.cpp @@ -19,8 +19,6 @@ #include #include -#include -#include #include // The block protocol is partially obsoleted by the headers protocol. diff --git a/src/protocols/protocol_block_in_31800.cpp b/src/protocols/protocol_block_in_31800.cpp index 1f8ca8750..5a2f1afa6 100644 --- a/src/protocols/protocol_block_in_31800.cpp +++ b/src/protocols/protocol_block_in_31800.cpp @@ -19,8 +19,6 @@ #include #include -#include -#include #include #include diff --git a/src/protocols/protocol_block_out_106.cpp b/src/protocols/protocol_block_out_106.cpp index d49aee8fe..037992047 100644 --- a/src/protocols/protocol_block_out_106.cpp +++ b/src/protocols/protocol_block_out_106.cpp @@ -19,8 +19,6 @@ #include #include -#include -#include #include namespace libbitcoin { diff --git a/src/protocols/protocol_block_out_70012.cpp b/src/protocols/protocol_block_out_70012.cpp index 2d7beb59b..8318e0eef 100644 --- a/src/protocols/protocol_block_out_70012.cpp +++ b/src/protocols/protocol_block_out_70012.cpp @@ -18,8 +18,6 @@ */ #include -#include -#include #include namespace libbitcoin { diff --git a/src/protocols/protocol_explore.cpp b/src/protocols/protocol_explore.cpp index 7d1554fd4..bc1faba65 100644 --- a/src/protocols/protocol_explore.cpp +++ b/src/protocols/protocol_explore.cpp @@ -18,7 +18,6 @@ */ #include -#include #include namespace libbitcoin { @@ -30,11 +29,11 @@ using namespace system; using namespace network::http; using namespace std::placeholders; +BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) + // Handle get method. // ---------------------------------------------------------------------------- - // fields[], request->target(), file.is_open() are undeclared noexcept. -BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) void protocol_explore::handle_receive_get(const code& ec, const method::get& request) NOEXCEPT diff --git a/src/protocols/protocol_filter_out_70015.cpp b/src/protocols/protocol_filter_out_70015.cpp index 1a6f4b826..7783daa5d 100644 --- a/src/protocols/protocol_filter_out_70015.cpp +++ b/src/protocols/protocol_filter_out_70015.cpp @@ -19,7 +19,6 @@ #include #include -#include #include namespace libbitcoin { diff --git a/src/protocols/protocol_header_in_31800.cpp b/src/protocols/protocol_header_in_31800.cpp index fbee52738..f2b0c1cf1 100644 --- a/src/protocols/protocol_header_in_31800.cpp +++ b/src/protocols/protocol_header_in_31800.cpp @@ -18,8 +18,6 @@ */ #include -#include -#include #include namespace libbitcoin { diff --git a/src/protocols/protocol_header_in_70012.cpp b/src/protocols/protocol_header_in_70012.cpp index a97e6bc25..0470c8e84 100644 --- a/src/protocols/protocol_header_in_70012.cpp +++ b/src/protocols/protocol_header_in_70012.cpp @@ -18,7 +18,6 @@ */ #include -#include #include namespace libbitcoin { diff --git a/src/protocols/protocol_header_out_31800.cpp b/src/protocols/protocol_header_out_31800.cpp index 469ca894f..22bcc95fa 100644 --- a/src/protocols/protocol_header_out_31800.cpp +++ b/src/protocols/protocol_header_out_31800.cpp @@ -18,8 +18,6 @@ */ #include -#include -#include #include namespace libbitcoin { diff --git a/src/protocols/protocol_header_out_70012.cpp b/src/protocols/protocol_header_out_70012.cpp index 4d4710640..cb12f8521 100644 --- a/src/protocols/protocol_header_out_70012.cpp +++ b/src/protocols/protocol_header_out_70012.cpp @@ -18,8 +18,6 @@ */ #include -#include -#include #include namespace libbitcoin { diff --git a/src/protocols/protocol_html.cpp b/src/protocols/protocol_html.cpp new file mode 100644 index 000000000..e377aa721 --- /dev/null +++ b/src/protocols/protocol_html.cpp @@ -0,0 +1,127 @@ +/** + * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) + * + * This file is part of libbitcoin. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +#include + +#include + +namespace libbitcoin { +namespace node { + +#define CLASS protocol_html + +using namespace network::http; +using namespace std::placeholders; + +BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) + +// Handle get method. +// ---------------------------------------------------------------------------- +// fields[] are undeclared noexcept. + +void protocol_html::handle_receive_get(const code& ec, + const method::get& request) NOEXCEPT +{ + BC_ASSERT_MSG(stranded(), "strand"); + + if (stopped(ec)) + return; + + // Enforce http origin policy (requires configured hosts). + if (!is_allowed_origin((*request)[field::origin], request->version())) + { + send_forbidden(*request); + return; + } + + // Enforce http host header (if any hosts are configured). + if (!is_allowed_host((*request)[field::host], request->version())) + { + send_bad_host(*request); + return; + } + + // Empty path implies malformed target (terminal). + const auto path = to_local_path(request->target()); + if (path.empty()) + { + send_bad_target(*request); + return; + } + + // Not open implies file not found (non-terminal). + auto file = get_file_body(path); + if (!file.is_open()) + { + send_not_found(*request); + return; + } + + const auto default_type = mime_type::application_octet; + send_file(*request, std::move(file), file_mime_type(path, default_type)); +} + +// Senders. +// ---------------------------------------------------------------------------- + +void protocol_html::send_file(const string_request& request, + file&& file, mime_type type) NOEXCEPT +{ + BC_ASSERT_MSG(stranded(), "strand"); + BC_ASSERT_MSG(file.is_open(), "sending closed file handle"); + + file_response response{ status::ok, request.version() }; + add_common_headers(response, request); + + response.set(field::content_type, from_mime_type(type)); + response.body() = std::move(file); + response.prepare_payload(); + + SEND(std::move(response), handle_complete, _1, error::success); +} + +// Utilities. +// ---------------------------------------------------------------------------- + +bool protocol_html::is_allowed_origin(const std::string& origin, + size_t version) const NOEXCEPT +{ + BC_ASSERT_MSG(stranded(), "strand"); + + // Allow same-origin and no-origin requests. + // Origin header field is not available until http 1.1. + if (origin.empty() || version < version_1_1) + return true; + + return options_.origins.empty() || system::contains(options_.origins, + network::config::to_normal_host(origin, default_port())); +} + +std::filesystem::path protocol_html::to_local_path( + const std::string& target) const NOEXCEPT +{ + BC_ASSERT_MSG(stranded(), "strand"); + + return sanitize_origin(options_.path, + target == "/" ? target + options_.default_ : target); +} + +BC_POP_WARNING() + +} // namespace node +} // namespace libbitcoin diff --git a/src/protocols/protocol_observer.cpp b/src/protocols/protocol_observer.cpp index d7b3a509c..e0c79e8e1 100644 --- a/src/protocols/protocol_observer.cpp +++ b/src/protocols/protocol_observer.cpp @@ -18,7 +18,6 @@ */ #include -#include #include namespace libbitcoin { diff --git a/src/protocols/protocol_peer.cpp b/src/protocols/protocol_peer.cpp index 023c34989..d2d6f5e85 100644 --- a/src/protocols/protocol_peer.cpp +++ b/src/protocols/protocol_peer.cpp @@ -18,7 +18,6 @@ */ #include -#include #include namespace libbitcoin { diff --git a/src/protocols/protocol_performer.cpp b/src/protocols/protocol_performer.cpp index 4aff1f78c..0160f92fa 100644 --- a/src/protocols/protocol_performer.cpp +++ b/src/protocols/protocol_performer.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include diff --git a/src/protocols/protocol_transaction_in_106.cpp b/src/protocols/protocol_transaction_in_106.cpp index b9e0f3f95..c336c7df2 100644 --- a/src/protocols/protocol_transaction_in_106.cpp +++ b/src/protocols/protocol_transaction_in_106.cpp @@ -18,8 +18,6 @@ */ #include -#include -#include #include namespace libbitcoin { diff --git a/src/protocols/protocol_transaction_out_106.cpp b/src/protocols/protocol_transaction_out_106.cpp index 4c1777b88..b34591360 100644 --- a/src/protocols/protocol_transaction_out_106.cpp +++ b/src/protocols/protocol_transaction_out_106.cpp @@ -18,8 +18,6 @@ */ #include -#include -#include #include namespace libbitcoin { diff --git a/src/sessions/session.cpp b/src/sessions/session.cpp index d15848208..9708658f2 100644 --- a/src/sessions/session.cpp +++ b/src/sessions/session.cpp @@ -19,8 +19,6 @@ #include #include -#include -#include #include #include #include diff --git a/src/settings.cpp b/src/settings.cpp index b904a5f51..3202723b6 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -20,7 +20,6 @@ #include #include -#include using namespace bc::system; using namespace bc::network; @@ -130,4 +129,23 @@ network::thread_priority settings::priority_() const NOEXCEPT } } // namespace node + +namespace server { + +system::string_list settings::html_server::origin_names() const NOEXCEPT +{ + // secure changes default port from 80 to 443. + const auto port = secure ? http::default_tls : http::default_http; + return network::config::to_host_names(hosts, port); +} + +// Because session_tcp upcasts html_server to tcp_server settings, this doesn't +// get executed, so presently an empty path allows the service to start. This +// can be hacked away external to the session at startup. +bool settings::html_server::enabled() const NOEXCEPT +{ + return !path.empty() && http_server::enabled(); +} + +} // namespace server } // namespace libbitcoin diff --git a/test/settings.cpp b/test/settings.cpp index 2155cf13a..1d4b3cb62 100644 --- a/test/settings.cpp +++ b/test/settings.cpp @@ -79,4 +79,161 @@ BOOST_AUTO_TEST_CASE(settings__node__default_context__expected) BOOST_REQUIRE(node.priority_() == network::thread_priority::high); } +// [server] +// ---------------------------------------------------------------------------- + +BOOST_AUTO_TEST_CASE(server__html_server__defaults__expected) +{ + const server::settings::html_server instance{}; + + // tcp_server + BOOST_REQUIRE(instance.name.empty()); + BOOST_REQUIRE(!instance.secure); + BOOST_REQUIRE(instance.binds.empty()); + BOOST_REQUIRE_EQUAL(instance.connections, 0u); + BOOST_REQUIRE_EQUAL(instance.timeout_seconds, 60u); + BOOST_REQUIRE(!instance.enabled()); + + // http_server + BOOST_REQUIRE_EQUAL(instance.server, "libbitcoin/4.0"); + BOOST_REQUIRE(instance.hosts.empty()); + BOOST_REQUIRE(instance.host_names().empty()); + + // html_server + BOOST_REQUIRE(instance.path.empty()); + BOOST_REQUIRE_EQUAL(instance.default_, "index.html"); + BOOST_REQUIRE(instance.origins.empty()); + BOOST_REQUIRE(instance.origin_names().empty()); +} + +BOOST_AUTO_TEST_CASE(server__web_server__defaults__expected) +{ + const server::settings instance{}; + const auto server = instance.web; + + // tcp_server + BOOST_REQUIRE_EQUAL(server.name, "web"); + BOOST_REQUIRE(!server.secure); + BOOST_REQUIRE(server.binds.empty()); + BOOST_REQUIRE_EQUAL(server.connections, 0u); + BOOST_REQUIRE_EQUAL(server.timeout_seconds, 60u); + BOOST_REQUIRE(!server.enabled()); + + // http_server + BOOST_REQUIRE_EQUAL(server.server, "libbitcoin/4.0"); + BOOST_REQUIRE(server.hosts.empty()); + BOOST_REQUIRE(server.host_names().empty()); + + // html_server + BOOST_REQUIRE(server.path.empty()); + BOOST_REQUIRE_EQUAL(server.default_, "index.html"); + BOOST_REQUIRE(server.origins.empty()); + BOOST_REQUIRE(server.origin_names().empty()); +} + +BOOST_AUTO_TEST_CASE(server__explore_server__defaults__expected) +{ + const server::settings instance{}; + const auto server = instance.explore; + + // tcp_server + BOOST_REQUIRE_EQUAL(server.name, "explore"); + BOOST_REQUIRE(!server.secure); + BOOST_REQUIRE(server.binds.empty()); + BOOST_REQUIRE_EQUAL(server.connections, 0u); + BOOST_REQUIRE_EQUAL(server.timeout_seconds, 60u); + BOOST_REQUIRE(!server.enabled()); + + // http_server + BOOST_REQUIRE_EQUAL(server.server, "libbitcoin/4.0"); + BOOST_REQUIRE(server.hosts.empty()); + BOOST_REQUIRE(server.host_names().empty()); + + // html_server + BOOST_REQUIRE(server.path.empty()); + BOOST_REQUIRE_EQUAL(server.default_, "index.html"); + BOOST_REQUIRE(server.origins.empty()); + BOOST_REQUIRE(server.origin_names().empty()); +} + +BOOST_AUTO_TEST_CASE(server__websocket_server__defaults__expected) +{ + const server::settings instance{}; + const auto server = instance.websocket; + + // tcp_server + BOOST_REQUIRE_EQUAL(server.name, "websocket"); + BOOST_REQUIRE(!server.secure); + BOOST_REQUIRE(server.binds.empty()); + BOOST_REQUIRE_EQUAL(server.connections, 0u); + BOOST_REQUIRE_EQUAL(server.timeout_seconds, 60u); + BOOST_REQUIRE(!server.enabled()); + + // http_server + BOOST_REQUIRE_EQUAL(server.server, "libbitcoin/4.0"); + BOOST_REQUIRE(server.hosts.empty()); + BOOST_REQUIRE(server.host_names().empty()); +} + +BOOST_AUTO_TEST_CASE(server__bitcoind_server__defaults__expected) +{ + const server::settings instance{}; + const auto server = instance.bitcoind; + + // tcp_server + BOOST_REQUIRE_EQUAL(server.name, "bitcoind"); + BOOST_REQUIRE(!server.secure); + BOOST_REQUIRE(server.binds.empty()); + BOOST_REQUIRE_EQUAL(server.connections, 0u); + BOOST_REQUIRE_EQUAL(server.timeout_seconds, 60u); + BOOST_REQUIRE(!server.enabled()); + + // http_server + BOOST_REQUIRE_EQUAL(server.server, "libbitcoin/4.0"); + BOOST_REQUIRE(server.hosts.empty()); + BOOST_REQUIRE(server.host_names().empty()); +} + +BOOST_AUTO_TEST_CASE(server__electrum_server__defaults__expected) +{ + const server::settings instance{}; + const auto server = instance.electrum; + + // tcp_server + BOOST_REQUIRE_EQUAL(server.name, "electrum"); + BOOST_REQUIRE(!server.secure); + BOOST_REQUIRE(server.binds.empty()); + BOOST_REQUIRE_EQUAL(server.connections, 0u); + BOOST_REQUIRE_EQUAL(server.timeout_seconds, 60u); + BOOST_REQUIRE(!server.enabled()); +} + +BOOST_AUTO_TEST_CASE(server__stratum_v1_server__defaults__expected) +{ + const server::settings instance{}; + const auto server = instance.stratum_v1; + + // tcp_server + BOOST_REQUIRE_EQUAL(server.name, "stratum_v1"); + BOOST_REQUIRE(!server.secure); + BOOST_REQUIRE(server.binds.empty()); + BOOST_REQUIRE_EQUAL(server.connections, 0u); + BOOST_REQUIRE_EQUAL(server.timeout_seconds, 60u); + BOOST_REQUIRE(!server.enabled()); +} + +BOOST_AUTO_TEST_CASE(server__stratum_v2_server__defaults__expected) +{ + const server::settings instance{}; + const auto server = instance.stratum_v2; + + // tcp_server + BOOST_REQUIRE_EQUAL(server.name, "stratum_v2"); + BOOST_REQUIRE(!server.secure); + BOOST_REQUIRE(server.binds.empty()); + BOOST_REQUIRE_EQUAL(server.connections, 0u); + BOOST_REQUIRE_EQUAL(server.timeout_seconds, 60u); + BOOST_REQUIRE(!server.enabled()); +} + BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test.hpp b/test/test.hpp index 5ef430ec5..c0708f120 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -22,7 +22,6 @@ #include #include -#include #include #define TEST_NAME \