diff --git a/src/musikcube/app/overlay/ServerOverlay.cpp b/src/musikcube/app/overlay/ServerOverlay.cpp index ae1d0e099..bc659681c 100644 --- a/src/musikcube/app/overlay/ServerOverlay.cpp +++ b/src/musikcube/app/overlay/ServerOverlay.cpp @@ -58,10 +58,11 @@ static const char* KEY_AUDIO_SERVER_ENABLED = "http_server_enabled"; static const char* KEY_AUDIO_SERVER_PORT = "http_server_port"; static const char* KEY_TRANSCODER_CACHE_COUNT = "transcoder_cache_count"; static const char* KEY_TRANSCODER_SYNCHRONOUS = "transcoder_synchronous"; +static const char* KEY_USE_IPV6 = "use_ipv6"; static const char* KEY_PASSWORD = "password"; #define VERTICAL_PADDING 2 -#define DEFAULT_HEIGHT 17 +#define DEFAULT_HEIGHT 18 #define DEFAULT_WIDTH 45 static void applyLabelOverlayStyle(TextLabel& label) { @@ -166,6 +167,10 @@ void ServerOverlay::InitViews() { this->httpPortLabel->SetText(_TSTR("settings_server_port"), text::AlignRight); this->httpPortInput.reset(new TextInput(TextInput::StyleLine)); + /* ipv6 */ + this->ipv6Cb.reset(new Checkbox()); + this->ipv6Cb->SetText(_TSTR("settings_server_use_ipv6")); + /* transcoder */ this->enableSyncTransCb.reset(new Checkbox()); this->enableSyncTransCb->SetText(_TSTR("settings_server_transcoder_synchronous")); @@ -188,6 +193,7 @@ void ServerOverlay::InitViews() { applyCheckboxOverlayStyle(*this->enableHttpCb); applyLabelOverlayStyle(*this->httpPortLabel); applyInputOverlayStyle(*this->httpPortInput); + applyCheckboxOverlayStyle(*this->ipv6Cb); applyCheckboxOverlayStyle(*this->enableSyncTransCb); applyLabelOverlayStyle(*this->transCacheLabel); applyInputOverlayStyle(*this->transCacheInput); @@ -202,6 +208,7 @@ void ServerOverlay::InitViews() { this->AddWindow(this->enableHttpCb); this->AddWindow(this->httpPortLabel); this->AddWindow(this->httpPortInput); + this->AddWindow(this->ipv6Cb); this->AddWindow(this->enableSyncTransCb); this->AddWindow(this->transCacheLabel); this->AddWindow(this->transCacheInput); @@ -215,6 +222,7 @@ void ServerOverlay::InitViews() { this->wssPortInput->SetFocusOrder(order++); this->enableHttpCb->SetFocusOrder(order++); this->httpPortInput->SetFocusOrder(order++); + this->ipv6Cb->SetFocusOrder(order++); this->enableSyncTransCb->SetFocusOrder(order++); this->transCacheInput->SetFocusOrder(order++); this->pwInput->SetFocusOrder(order++); @@ -246,6 +254,8 @@ void ServerOverlay::Layout() { this->httpPortInput->MoveAndResize(x + 4 + httpPortLabelWidth + 1, y, 8, 1); y += 2; + this->ipv6Cb->MoveAndResize(x, y++, clientWidth, 1); + const int transCcacheLabelWidth = TEXT_WIDTH(transCacheLabel); this->enableSyncTransCb->MoveAndResize(x, y++, clientWidth, 1); this->transCacheLabel->MoveAndResize(x, y, transCcacheLabelWidth, 1); @@ -283,6 +293,7 @@ void ServerOverlay::Load() { this->wssPortInput->SetText(settingIntToString(prefs, KEY_METADATA_SERVER_PORT, 7905)); this->httpPortInput->SetText(settingIntToString(prefs, KEY_AUDIO_SERVER_PORT, 7906)); + this->ipv6Cb->SetChecked(prefs->GetBool(KEY_USE_IPV6, false)); this->transCacheInput->SetText(settingIntToString(prefs, KEY_TRANSCODER_CACHE_COUNT, 50)); this->pwInput->SetText(prefs->GetString(KEY_PASSWORD, "")); } @@ -298,6 +309,7 @@ bool ServerOverlay::Save() { this->prefs->SetBool(KEY_METADATA_SERVER_ENABLED, this->enableWssCb->IsChecked()); this->prefs->SetBool(KEY_AUDIO_SERVER_ENABLED, this->enableHttpCb->IsChecked()); + this->prefs->SetBool(KEY_USE_IPV6, this->ipv6Cb->IsChecked()); this->prefs->SetBool(KEY_TRANSCODER_SYNCHRONOUS, this->enableSyncTransCb->IsChecked()); this->prefs->SetInt(KEY_METADATA_SERVER_PORT, wssPort); this->prefs->SetInt(KEY_AUDIO_SERVER_PORT, httpPort); diff --git a/src/musikcube/app/overlay/ServerOverlay.h b/src/musikcube/app/overlay/ServerOverlay.h index 4b31d6444..a09dde32e 100644 --- a/src/musikcube/app/overlay/ServerOverlay.h +++ b/src/musikcube/app/overlay/ServerOverlay.h @@ -78,6 +78,7 @@ namespace musik { std::shared_ptr titleLabel; std::shared_ptr enableWssCb, enableHttpCb, enableSyncTransCb; + std::shared_ptr ipv6Cb; std::shared_ptr wssPortLabel, httpPortLabel, pwLabel, transCacheLabel; std::shared_ptr wssPortInput, httpPortInput, pwInput, transCacheInput; std::shared_ptr shortcuts; diff --git a/src/musikcube/data/locales/en_US.json b/src/musikcube/data/locales/en_US.json index 83f49fb57..f99f0413b 100644 --- a/src/musikcube/data/locales/en_US.json +++ b/src/musikcube/data/locales/en_US.json @@ -61,6 +61,7 @@ "settings_server_password": "password:", "settings_server_invalid_settings_title": "invalid settings", "settings_server_invalid_settings_message": "invalid or missing settings. please check the values and try again.", + "settings_server_use_ipv6": "use ipv6", "settings_preamp": "preamp / replay gain", "settings_preamp_label": "preamp gain (dB):", diff --git a/src/plugins/server/Constants.h b/src/plugins/server/Constants.h index 8734d5337..48e075d5c 100644 --- a/src/plugins/server/Constants.h +++ b/src/plugins/server/Constants.h @@ -44,6 +44,7 @@ namespace defaults { static const int http_server_port = 7906; static const std::string password = ""; static const int transcoder_cache_count = 50; + static const bool use_ipv6 = false; static const bool transcoder_synchronous = false; static const bool transcoder_synchronous_fallback = false; } @@ -53,6 +54,7 @@ namespace prefs { static const std::string websocket_server_port = "websocket_server_port"; static const std::string http_server_enabled = "http_server_enabled"; static const std::string http_server_port = "http_server_port"; + static const std::string use_ipv6 = "use_ipv6"; static const std::string transcoder_cache_count = "transcoder_cache_count"; static const std::string transcoder_synchronous = "transcoder_synchronous"; static const std::string transcoder_synchronous_fallback = "transcoder_synchronous_fallback"; diff --git a/src/plugins/server/HttpServer.cpp b/src/plugins/server/HttpServer.cpp index 51c628626..f44feacb3 100644 --- a/src/plugins/server/HttpServer.cpp +++ b/src/plugins/server/HttpServer.cpp @@ -279,11 +279,16 @@ bool HttpServer::Start() { if (this->Stop()) { Transcoder::RemoveTempTranscodeFiles(this->context); + MHD_FLAG ipVersion = MHD_NO_FLAG; + if (context.prefs->GetBool(prefs::use_ipv6.c_str(), defaults::use_ipv6)) { + ipVersion = MHD_USE_IPv6; + } + httpServer = MHD_start_daemon( #if MHD_VERSION >= 0x00095300 - MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD, + MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | ipVersion, #else - MHD_USE_SELECT_INTERNALLY, + MHD_USE_SELECT_INTERNALLY | ipVersion, #endif context.prefs->GetInt(prefs::http_server_port.c_str(), defaults::http_server_port), nullptr, diff --git a/src/plugins/server/WebSocketServer.cpp b/src/plugins/server/WebSocketServer.cpp index 1cf5bf279..f93e0f6c0 100644 --- a/src/plugins/server/WebSocketServer.cpp +++ b/src/plugins/server/WebSocketServer.cpp @@ -147,11 +147,19 @@ void WebSocketServer::ThreadProc() { wss->clear_access_channels(websocketpp::log::alevel::none); } + using namespace websocketpp::lib::asio::ip; + + const int port = context.prefs->GetInt( + prefs::websocket_server_port.c_str(), defaults::websocket_server_port); + + const bool ipv6 = context.prefs->GetBool( + prefs::use_ipv6.c_str(), defaults::use_ipv6); + wss->init_asio(); wss->set_message_handler(std::bind(&WebSocketServer::OnMessage, this, wss.get(), ::_1, ::_2)); wss->set_open_handler(std::bind(&WebSocketServer::OnOpen, this, ::_1)); wss->set_close_handler(std::bind(&WebSocketServer::OnClose, this, ::_1)); - wss->listen(context.prefs->GetInt(prefs::websocket_server_port.c_str(), defaults::websocket_server_port)); + wss->listen(ipv6 ? tcp::v6() : tcp::v4(), port); wss->start_accept(); wss->run(); @@ -224,7 +232,7 @@ void WebSocketServer::HandleAuthentication(connection_hdl connection, json& requ this->connections[connection] = true; /* mark as authed */ this->RespondWithOptions( - connection, request, json({ + connection, request, json({ { key::authenticated, true }, { key::environment, getEnvironment(context) } }));