Skip to content

Commit 2b04390

Browse files
jrdclaude
andcommitted
JSON-RPC: add optional directory hole punch to jamulusclient/connect
Mirror the new --connectdirectory option on the RPC side: connect now accepts an optional "directory" param. When given, CClient::Connect hole-punches through that directory (CLM_REQ_SERVER_LIST) before connecting, so an RPC-driven client can reach a server behind a cloud firewall/NAT the same way the GUI directory list does. A non-string directory is rejected with invalid params; the server address is connected to verbatim and need not be listed by the directory. docs/JSON-RPC.md regenerated via tools/generate_json_rpc_docs.py. Relates to jamulussoftware/jamuluswebsite#1122 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 886381c commit 2b04390

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

docs/JSON-RPC.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ Parameters:
139139
| --- | --- | --- |
140140
| params.address | string | Socket address of the server (host:port). |
141141
| params.serverName | string | Optional human readable server name used for display purposes. Defaults to the address. |
142+
| params.directory | string | Optional socket address of a directory to hole-punch through before connecting (host:port). Use for a server behind a cloud firewall/NAT that is registered with that directory; address is connected to verbatim and need not be listed by the directory. Example: anygenre1.jamulus.io:22124 |
142143

143144
Results:
144145

src/clientrpc.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ CClientRpc::CClientRpc ( CClient* pClient, CClientSettings* pSettings, CRpcServe
264264
/// notifications to follow its progress.
265265
/// @param {string} params.address - Socket address of the server (host:port).
266266
/// @param {string} params.serverName - Optional human readable server name used for display purposes. Defaults to the address.
267+
/// @param {string} params.directory - Optional socket address of a directory to hole-punch through before
268+
/// connecting (host:port). Use for a server behind a cloud firewall/NAT that is registered with that
269+
/// directory; address is connected to verbatim and need not be listed by the directory. Example:
270+
/// anygenre1.jamulus.io:22124
267271
/// @result {string} result - "ok" once the connection attempt has been initiated.
268272
pRpcServer->HandleMethod ( "jamulusclient/connect", [=] ( const QJsonObject& params, QJsonObject& response ) {
269273
auto jsonAddress = params["address"];
@@ -273,11 +277,19 @@ CClientRpc::CClientRpc ( CClient* pClient, CClientSettings* pSettings, CRpcServe
273277
return;
274278
}
275279

280+
auto jsonDirectory = params["directory"];
281+
if ( !jsonDirectory.isUndefined() && !jsonDirectory.isNull() && !jsonDirectory.isString() )
282+
{
283+
response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: directory is not a string" );
284+
return;
285+
}
286+
276287
auto jsonServerName = params["serverName"];
277288
const QString strAddress = NetworkUtil::FixAddress ( jsonAddress.toString() );
278289
const QString strServerName = jsonServerName.isString() ? jsonServerName.toString() : strAddress;
290+
const QString strDirectory = jsonDirectory.isString() ? NetworkUtil::FixAddress ( jsonDirectory.toString() ) : QString();
279291

280-
pClient->Connect ( strAddress, strServerName );
292+
pClient->Connect ( strAddress, strServerName, strDirectory );
281293

282294
response["result"] = "ok";
283295
} );

0 commit comments

Comments
 (0)