-
Notifications
You must be signed in to change notification settings - Fork 222
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
JSON-RPC: Add option to specify bind address for server #2917
Changes from all commits
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 |
---|---|---|
|
@@ -99,6 +99,7 @@ int main ( int argc, char** argv ) | |
int iNumServerChannels = DEFAULT_USED_NUM_CHANNELS; | ||
quint16 iPortNumber = DEFAULT_PORT_NUMBER; | ||
int iJsonRpcPortNumber = INVALID_PORT; | ||
QString strJsonRpcBindIP = DEFAULT_JSON_RPC_LISTEN_ADDRESS; | ||
quint16 iQosNumber = DEFAULT_QOS_NUMBER; | ||
ELicenceType eLicenceType = LT_NO_LICENCE; | ||
QString strMIDISetup = ""; | ||
|
@@ -209,6 +210,15 @@ int main ( int argc, char** argv ) | |
continue; | ||
} | ||
|
||
// JSON-RPC bind address ------------------------------------------------ | ||
if ( GetStringArgument ( argc, argv, i, "--jsonrpcbindip", "--jsonrpcbindip", strArgument ) ) | ||
{ | ||
strJsonRpcBindIP = QString ( strArgument ); | ||
qInfo() << qUtf8Printable ( QString ( "- JSON-RPC will bind to: %1 if enabled" ).arg ( strJsonRpcBindIP ) ); | ||
CommandLineOptions << "--jsonrpcbindip"; | ||
continue; | ||
} | ||
|
||
// Quality of Service -------------------------------------------------- | ||
if ( GetNumericArgument ( argc, argv, i, "-Q", "--qos", 0, 255, rDbleArgument ) ) | ||
{ | ||
|
@@ -783,6 +793,31 @@ int main ( int argc, char** argv ) | |
strServerBindIP = ""; | ||
} | ||
} | ||
|
||
#ifndef NO_JSON_RPC | ||
// | ||
// strJsonRpcBind address defaults to loopback and should not be empty, but | ||
// in the odd chance that an empty IP is passed, we'll check for it here. | ||
|
||
if ( strJsonRpcBindIP.trimmed().isEmpty() ) | ||
{ | ||
qCritical() << qUtf8Printable ( QString ( "JSON-RPC is enabled but no bind address was provided, exiting." ) ); | ||
exit ( 1 ); | ||
} | ||
|
||
// This means of testing the validity of IP addresses is far from perfect but | ||
// we do it here as an upfront check. The downstream network calls will error | ||
// out on malformed addresses not caught here. | ||
{ | ||
QHostAddress InetAddr; | ||
if ( !InetAddr.setAddress ( strJsonRpcBindIP ) ) | ||
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. We should introduce a method which checks IP validity e.g via Regex 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. You're probably right -- an IP address validation function used through the codebase. I think that is out of scope for this particular PR, however. 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 think using the same methods as for Server Bind IP will be okay for now. |
||
{ | ||
qCritical() << qUtf8Printable ( QString ( "The JSON-RPC address specified is not valid, exiting. " ) ); | ||
exit ( 1 ); | ||
} | ||
} | ||
|
||
#endif | ||
} | ||
|
||
// Application/GUI setup --------------------------------------------------- | ||
|
@@ -880,7 +915,7 @@ int main ( int argc, char** argv ) | |
qWarning() << "- JSON-RPC: This interface is experimental and is subject to breaking changes even on patch versions " | ||
"(not subject to semantic versioning) during the initial phase."; | ||
|
||
pRpcServer = new CRpcServer ( pApp, iJsonRpcPortNumber, strJsonRpcSecret ); | ||
pRpcServer = new CRpcServer ( pApp, strJsonRpcBindIP, iJsonRpcPortNumber, strJsonRpcSecret ); | ||
if ( !pRpcServer->Start() ) | ||
{ | ||
qCritical() << qUtf8Printable ( QString ( "- JSON-RPC: Server failed to start. Exiting." ) ); | ||
|
@@ -1072,6 +1107,7 @@ QString UsageArguments ( char** argv ) | |
" --jsonrpcsecretfile\n" | ||
" path to a single-line file which contains a freely\n" | ||
" chosen secret to authenticate JSON-RPC users.\n" | ||
" --jsonrpcbindip optional network address to bind RPC server. Defaults to 127.0.0.1 (IPv4 only, IPv6 not tested).\n" | ||
" -Q, --qos set the QoS value. Default is 128. Disable with 0\n" | ||
" (see the Jamulus website to enable QoS on Windows)\n" | ||
" -t, --notranslation disable translation (use English language)\n" | ||
|
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 the wording of the "objection" is slightly misleading here.
--serverbindip
was passed with a parameter, otherwiseGetStringArgument
would have failed earlier. SoIt might even be useful to do
if ( !InetAddr.setAddress ( strJsonRpcBindIP ) )
, like for Server Bind IP.I'd also question whether "exiting" is in keeping with the other checks we do... it's a bit hit and miss, I guess. I may even have said do it like this :).
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'll squeeze that improvement into #2958 and rename it to be more generic.
I would have certainly supported that (maybe I did ;)). I think we should fail early for new features, even if we didn't do so previously and don't want to make those existing checks more strict for compatibility reasons for now.