-
-
Notifications
You must be signed in to change notification settings - Fork 718
websocketserver: Allow the user to bind to a specific address #1279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,11 +38,13 @@ with this program. If not, see <https://www.gnu.org/licenses/> | |
#define PARAM_FIRSTLOAD "first_load" | ||
#define PARAM_ENABLED "server_enabled" | ||
#define PARAM_PORT "server_port" | ||
#define PARAM_HOST "server_host" | ||
#define PARAM_ALERTS "alerts_enabled" | ||
#define PARAM_AUTHREQUIRED "auth_required" | ||
#define PARAM_PASSWORD "server_password" | ||
|
||
#define CMDLINE_WEBSOCKET_PORT "websocket_port" | ||
#define CMDLINE_WEBSOCKET_HOST "websocket_host" | ||
#define CMDLINE_WEBSOCKET_IPV4_ONLY "websocket_ipv4_only" | ||
#define CMDLINE_WEBSOCKET_PASSWORD "websocket_password" | ||
#define CMDLINE_WEBSOCKET_DEBUG "websocket_debug" | ||
|
@@ -72,6 +74,8 @@ void Config::Load(json config) | |
AuthRequired = config[PARAM_AUTHREQUIRED]; | ||
if (config.contains(PARAM_PASSWORD) && config[PARAM_PASSWORD].is_string()) | ||
ServerPassword = config[PARAM_PASSWORD]; | ||
if (config.contains(PARAM_HOST) && config[PARAM_HOST].is_string()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: Move this and other occurrences above the port override |
||
ServerHost = config[PARAM_HOST]; | ||
|
||
// Set server password and save it to the config before processing overrides, | ||
// so that there is always a true configured password regardless of if | ||
|
@@ -105,6 +109,17 @@ void Config::Load(json config) | |
} | ||
} | ||
|
||
// Process `--websocket_host` override | ||
QString host_argument = Utils::Platform::GetCommandLineArgument(CMDLINE_WEBSOCKET_HOST); | ||
if (host_argument != "") { | ||
blog(LOG_INFO, "[Config::Load] --websocket_host passed. Overriding WebSocket host with: %s", | ||
host_argument.toStdString().c_str()); | ||
ServerHost = host_argument.toStdString(); | ||
HostOverridden = true; | ||
} | ||
|
||
|
||
|
||
// Process `--websocket_ipv4_only` override | ||
if (Utils::Platform::GetCommandLineFlagSet(CMDLINE_WEBSOCKET_IPV4_ONLY)) { | ||
silasary marked this conversation as resolved.
Show resolved
Hide resolved
|
||
blog(LOG_INFO, "[Config::Load] --websocket_ipv4_only passed. Binding only to IPv4 interfaces."); | ||
|
@@ -139,6 +154,8 @@ void Config::Save() | |
config[PARAM_ENABLED] = ServerEnabled.load(); | ||
if (!PortOverridden) | ||
config[PARAM_PORT] = ServerPort.load(); | ||
if (!HostOverridden) | ||
config[PARAM_HOST] = ServerHost; | ||
config[PARAM_ALERTS] = AlertsEnabled.load(); | ||
if (!PasswordOverridden) { | ||
config[PARAM_AUTHREQUIRED] = AuthRequired.load(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,7 +100,10 @@ void WebSocketServer::Start() | |
_server.reset(); | ||
|
||
websocketpp::lib::error_code errorCode; | ||
if (conf->Ipv4Only) { | ||
if (conf->ServerHost != "") { | ||
blog(LOG_INFO, "[WebSocketServer::Start] Locked to %s", conf->ServerHost); | ||
_server.listen(conf->ServerHost, std::to_string(conf->ServerPort), errorCode); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm looking at the websocketpp documentation, and I'm not seeing a matching function for listen(). Do you know which function it's being implicitly cast to? I'm guessing It may be safer in this specific situation to first create an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm using As far as I could tell, InternetProtocol doesn't let you bind to a specific address. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feedback thread is still unresolved. What is the path forward here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The feedback was incorrect. Nothing to change. |
||
} else if (conf->Ipv4Only) { | ||
blog(LOG_INFO, "[WebSocketServer::Start] Locked to IPv4 bindings"); | ||
_server.listen(websocketpp::lib::asio::ip::tcp::v4(), conf->ServerPort, errorCode); | ||
} else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that I would like this to use
address
instead ofhost
.address
would likely be less ambiguous.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used host because that's what websocketpp called it, but agreed, address is a better name.