Skip to content

Commit 7190f1b

Browse files
committed
Add IPv6 dual-stack support to HTTP and WebSocket servers
Enable hived webserver and cli_wallet websocket servers to listen on IPv6 endpoints with dual-stack (accepting both IPv4 and IPv6 clients). - Add tcp_pre_bind_handler to set v6_only(false) on websocketpp acceptors when listening on IPv6 addresses, enabling dual-stack - Update fc submodule: fix websocket_server::listen() to use proper asio endpoint conversion (was crashing on IPv6), add pre-bind handler for cli_wallet websocket servers, centralize fc<->asio conversion helpers to eliminate duplication across 4 files
1 parent 815c9fa commit 7190f1b

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

libraries/plugins/webserver/webserver_plugin.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,17 @@ void webserver_plugin_impl<websocket_server_type>::start_webserver()
379379
{
380380
ilog( "start listening for http requests on ${endpoint}", ( "endpoint", boost::lexical_cast<fc::string>( *http_endpoint ) ) );
381381
}
382+
if (ws_endpoint->address().is_v6())
383+
{
384+
ws_server.set_tcp_pre_bind_handler(
385+
[](websocketpp::lib::shared_ptr<boost::asio::ip::tcp::acceptor> acceptor)
386+
-> websocketpp::lib::error_code {
387+
boost::system::error_code ec;
388+
acceptor->set_option(boost::asio::ip::v6_only(false), ec);
389+
return ec;
390+
});
391+
}
392+
382393
ilog( "start listening for ws requests on ${endpoint}", ( "endpoint", boost::lexical_cast<fc::string>( *ws_endpoint ) ) );
383394
ws_server.listen( *ws_endpoint );
384395
update_ws_endpoint();
@@ -429,6 +440,17 @@ void webserver_plugin_impl<websocket_server_type>::start_webserver()
429440
if( tls )
430441
tls->set_tls_handlers( http_server );
431442

443+
if (http_endpoint->address().is_v6())
444+
{
445+
http_server.set_tcp_pre_bind_handler(
446+
[](websocketpp::lib::shared_ptr<boost::asio::ip::tcp::acceptor> acceptor)
447+
-> websocketpp::lib::error_code {
448+
boost::system::error_code ec;
449+
acceptor->set_option(boost::asio::ip::v6_only(false), ec);
450+
return ec;
451+
});
452+
}
453+
432454
ilog( "start listening for ${type} requests on ${endpoint}",
433455
("type", tls ? "https" : "http")( "endpoint", boost::lexical_cast<fc::string>( *http_endpoint ) ) );
434456
http_server.listen( *http_endpoint );

0 commit comments

Comments
 (0)