Added the ability to switch between IPV4 and IPV6 in the server plugin.

This commit is contained in:
casey langen 2017-12-21 23:19:37 -08:00
parent 70a8aad86d
commit e2f247669a
6 changed files with 34 additions and 5 deletions

View File

@ -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);

View File

@ -78,6 +78,7 @@ namespace musik {
std::shared_ptr<cursespp::TextLabel> titleLabel;
std::shared_ptr<cursespp::Checkbox> enableWssCb, enableHttpCb, enableSyncTransCb;
std::shared_ptr<cursespp::Checkbox> ipv6Cb;
std::shared_ptr<cursespp::TextLabel> wssPortLabel, httpPortLabel, pwLabel, transCacheLabel;
std::shared_ptr<cursespp::TextInput> wssPortInput, httpPortInput, pwInput, transCacheInput;
std::shared_ptr<cursespp::ShortcutsWindow> shortcuts;

View File

@ -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):",

View File

@ -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";

View File

@ -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,

View File

@ -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) }
}));