Skip to content

Commit 3d88927

Browse files
committed
Derive protocol_html from protocol_ws.
1 parent 33a729d commit 3d88927

File tree

8 files changed

+18
-91
lines changed

8 files changed

+18
-91
lines changed

include/bitcoin/node/full_node.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ class BCN_API full_node
164164
/// Attach server sessions (base net doesn't specialize or start these).
165165
virtual session_web::ptr attach_web_session() NOEXCEPT;
166166
virtual session_explore::ptr attach_explore_session() NOEXCEPT;
167-
virtual session_websocket::ptr attach_websocket_session() NOEXCEPT;
168167
virtual session_bitcoind::ptr attach_bitcoind_session() NOEXCEPT;
169168
virtual session_electrum::ptr attach_electrum_session() NOEXCEPT;
170169
virtual session_stratum_v1::ptr attach_stratum_v1_session() NOEXCEPT;
@@ -179,7 +178,6 @@ class BCN_API full_node
179178
private:
180179
void start_web(const code& ec, const result_handler& handler) NOEXCEPT;
181180
void start_explore(const code& ec, const result_handler& handler) NOEXCEPT;
182-
void start_websocket(const code& ec, const result_handler& handler) NOEXCEPT;
183181
void start_bitcoind(const code& ec, const result_handler& handler) NOEXCEPT;
184182
void start_electrum(const code& ec, const result_handler& handler) NOEXCEPT;
185183
void start_stratum_v1(const code& ec, const result_handler& handler) NOEXCEPT;

include/bitcoin/node/protocols/protocol_html.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ namespace libbitcoin {
2828
namespace node {
2929

3030
/// Abstract base for HTML protocols, thread safe.
31+
/// To keep inheritance simple this derives from protocol_ws, which in turn
32+
/// derives from protocol_http (as required). So any html server is able to
33+
/// operate as a websocket server.
3134
class BCN_API protocol_html
3235
: public node::protocol,
33-
public network::protocol_http,
36+
public network::protocol_ws,
3437
protected network::tracker<protocol_html>
3538
{
3639
public:
@@ -43,7 +46,7 @@ class BCN_API protocol_html
4346
const network::channel::ptr& channel,
4447
const options_t& options) NOEXCEPT
4548
: node::protocol(session, channel),
46-
network::protocol_http(session, channel, options),
49+
network::protocol_ws(session, channel, options),
4750
options_(options),
4851
network::tracker<protocol_html>(session->log)
4952
{

include/bitcoin/node/sessions/sessions.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ namespace node {
3434
/// Alias server sessions, all derived from node::session.
3535
using session_web = session_server<protocol_web>;
3636
using session_explore = session_server<protocol_explore>;
37-
using session_websocket = session_server<protocol_ws>;
3837
using session_bitcoind = session_server<protocol_bitcoind>;
3938
using session_electrum = session_server<protocol_electrum>;
4039
using session_stratum_v1 = session_server<protocol_stratum_v1>;

include/bitcoin/node/settings.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class BCN_API settings
126126
/// html (http/s) document server settings (has directory/default).
127127
/// This is for web servers that expose a local file system directory.
128128
struct html_server
129-
: public network::settings::http_server
129+
: public network::settings::websocket_server
130130
{
131131
// embedded_pages reference precludes copy.
132132
DELETE_COPY(html_server);
@@ -138,6 +138,9 @@ class BCN_API settings
138138
/// This is a reference to the caller's resource (retained instance).
139139
const embedded_pages& pages;
140140

141+
/// Set false to disable http->websocket http upgrade processing.
142+
bool websocket{ true };
143+
141144
/// Directory to serve.
142145
std::filesystem::path path{};
143146

@@ -163,12 +166,9 @@ class BCN_API settings
163166
/// native admin web interface, isolated (http/s, stateless html)
164167
server::settings::html_server web;
165168

166-
/// native RESTful block explorer (http/s, stateless html/json)
169+
/// native RESTful block explorer (http/s, stateless html/websocket)
167170
server::settings::html_server explore;
168171

169-
/// native websocket query interface (http/s->tcp/s, json, handshake)
170-
network::settings::websocket_server socket{ "socket" };
171-
172172
/// bitcoind compat interface (http/s, stateless json-rpc-v2)
173173
network::settings::http_server bitcoind{ "bitcoind" };
174174

src/full_node.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,6 @@ void full_node::start_explore(const code& ec,
145145
}
146146

147147
attach_explore_session()->start(
148-
std::bind(&full_node::start_websocket, this, _1, handler));
149-
}
150-
151-
void full_node::start_websocket(const code& ec,
152-
const result_handler& handler) NOEXCEPT
153-
{
154-
BC_ASSERT(stranded());
155-
156-
if (ec)
157-
{
158-
handler(ec);
159-
return;
160-
}
161-
162-
attach_websocket_session()->start(
163148
std::bind(&full_node::start_bitcoind, this, _1, handler));
164149
}
165150

@@ -545,11 +530,6 @@ session_explore::ptr full_node::attach_explore_session() NOEXCEPT
545530
return net::attach<session_explore>(*this, config_.server.explore);
546531
}
547532

548-
session_websocket::ptr full_node::attach_websocket_session() NOEXCEPT
549-
{
550-
return net::attach<session_websocket>(*this, config_.server.socket);
551-
}
552-
553533
session_bitcoind::ptr full_node::attach_bitcoind_session() NOEXCEPT
554534
{
555535
return net::attach<session_bitcoind>(*this, config_.server.bitcoind);

src/parser.cpp

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ parser::parser(system::chain::selection context,
8383
// admin
8484
configured.server.web.binds.emplace_back(asio::address{}, 8080_u16);
8585
configured.server.explore.binds.emplace_back(asio::address{}, 8180_u16);
86-
configured.server.socket.binds.emplace_back(asio::address{}, 8280_u16);
8786
configured.server.bitcoind.binds.emplace_back(asio::address{}, 8380_u16);
8887
configured.server.electrum.binds.emplace_back(asio::address{}, 8480_u16);
8988
configured.server.stratum_v1.binds.emplace_back(asio::address{}, 8580_u16);
@@ -865,42 +864,10 @@ options_metadata parser::load_settings() THROWS
865864
value<std::string>(&configured.server.explore.default_),
866865
"The path of the default source page, defaults to 'index.html'."
867866
)
868-
869-
/* [socket] */
870-
////(
871-
//// "socket.secure",
872-
//// value<bool>(&configured.network.socket.secure),
873-
//// "Require transport layer security, defaults to 'false' (not implemented)."
874-
////)
875-
(
876-
"socket.bind",
877-
value<network::config::authorities>(&configured.server.socket.binds),
878-
"IP address to bind, multiple allowed, defaults to '0.0.0.0:8280' (all IPv4)."
879-
)
880867
(
881-
"socket.connections",
882-
value<uint16_t>(&configured.server.socket.connections),
883-
"The required maximum number of connections, defaults to '0'."
884-
)
885-
(
886-
"socket.inactivity_minutes",
887-
value<uint32_t>(&configured.server.socket.inactivity_minutes),
888-
"The idle timeout (http keep-alive), defaults to '10'."
889-
)
890-
(
891-
"socket.expiration_minutes",
892-
value<uint32_t>(&configured.server.socket.expiration_minutes),
893-
"The idle timeout (http keep-alive), defaults to '60'."
894-
)
895-
(
896-
"socket.server",
897-
value<std::string>(&configured.server.socket.server),
898-
"The server name (http header), defaults to '" BC_HTTP_SERVER_NAME "'."
899-
)
900-
(
901-
"socket.host",
902-
value<network::config::endpoints>(&configured.server.socket.hosts),
903-
"The host name (http verification), multiple allowed, defaults to empty (disabled)."
868+
"explore.websocket",
869+
value<bool>(&configured.server.explore.websocket),
870+
"Enable websocket interface, defaults to true."
904871
)
905872

906873
/* [bitcoind] */

src/settings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ bool settings::embedded_pages::enabled() const NOEXCEPT
175175
// settings::html_server
176176
settings::html_server::html_server(const std::string_view& logging_name,
177177
const embedded_pages& embedded) NOEXCEPT
178-
: network::settings::http_server(logging_name),
178+
: network::settings::websocket_server(logging_name),
179179
pages(embedded)
180180
{
181181
}

test/settings.cpp

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ BOOST_AUTO_TEST_CASE(server__html_server__defaults__expected)
112112
BOOST_REQUIRE(instance.pages.ecma().empty());
113113
BOOST_REQUIRE(instance.pages.font().empty());
114114
BOOST_REQUIRE(instance.pages.icon().empty());
115+
BOOST_REQUIRE(instance.websocket);
115116
BOOST_REQUIRE(instance.path.empty());
116117
BOOST_REQUIRE_EQUAL(instance.default_, "index.html");
117118
BOOST_REQUIRE(instance.origins.empty());
@@ -149,6 +150,7 @@ BOOST_AUTO_TEST_CASE(server__web_server__defaults__expected)
149150
BOOST_REQUIRE(server.pages.font().empty());
150151
BOOST_REQUIRE(server.pages.icon().empty());
151152
BOOST_REQUIRE(server.path.empty());
153+
BOOST_REQUIRE(server.websocket);
152154
BOOST_REQUIRE_EQUAL(server.default_, "index.html");
153155
BOOST_REQUIRE(server.origins.empty());
154156
BOOST_REQUIRE(server.origin_names().empty());
@@ -185,35 +187,13 @@ BOOST_AUTO_TEST_CASE(server__explore_server__defaults__expected)
185187
BOOST_REQUIRE(server.pages.font().empty());
186188
BOOST_REQUIRE(server.pages.icon().empty());
187189
BOOST_REQUIRE(server.path.empty());
190+
BOOST_REQUIRE(server.websocket);
188191
BOOST_REQUIRE_EQUAL(server.default_, "index.html");
189192
BOOST_REQUIRE(server.origins.empty());
190193
BOOST_REQUIRE(server.origin_names().empty());
191194
}
192195

193-
BOOST_AUTO_TEST_CASE(server__websocket_server__defaults__expected)
194-
{
195-
const server::settings::embedded_pages web{};
196-
const server::settings::embedded_pages explorer{};
197-
const server::settings instance{ selection::none, explorer, web };
198-
const auto& server = instance.socket;
199-
200-
// tcp_server
201-
BOOST_REQUIRE_EQUAL(server.name, "socket");
202-
BOOST_REQUIRE(!server.secure);
203-
BOOST_REQUIRE(server.binds.empty());
204-
BOOST_REQUIRE_EQUAL(server.connections, 0u);
205-
BOOST_REQUIRE_EQUAL(server.inactivity_minutes, 10u);
206-
BOOST_REQUIRE_EQUAL(server.expiration_minutes, 60u);
207-
BOOST_REQUIRE(!server.enabled());
208-
BOOST_REQUIRE(server.inactivity() == minutes(10));
209-
BOOST_REQUIRE(server.expiration() == minutes(60));
210-
211-
// http_server
212-
BOOST_REQUIRE_EQUAL(server.server, "libbitcoin/4.0");
213-
BOOST_REQUIRE(server.hosts.empty());
214-
BOOST_REQUIRE(server.host_names().empty());
215-
}
216-
196+
// TODO: could add websocket under bitcoind as a custom property.
217197
BOOST_AUTO_TEST_CASE(server__bitcoind_server__defaults__expected)
218198
{
219199
const server::settings::embedded_pages web{};

0 commit comments

Comments
 (0)