From 8d820432ff50d192f1d51584332be06d236f6449 Mon Sep 17 00:00:00 2001 From: James Brechtel Date: Wed, 10 Jun 2026 10:44:20 -0400 Subject: [PATCH] fix: use correct signal-cli default port 8080 and robust connectivity check - Change default noise-signal-cli-address to port 8080 (signal-cli's --http default) - Replace getVersion (not a valid JSON-RPC method) with noisePing probe - noise-rpc-check now returns t on any valid JSON-RPC response - Update README to reflect correct default port --- README.org | 4 ++-- noise-rpc.el | 37 +++++++++++++++++++++++++++++++++---- noise.el | 10 ++++++---- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/README.org b/README.org index 6e326f8..569907f 100644 --- a/README.org +++ b/README.org @@ -14,7 +14,7 @@ The project assumes a working installation of signal-cli and interfaces with tha For SQLite access we use this library - https://github.com/pekingduck/emacs-sqlite3-api -We communicate with signal-cli via JSON-RPC over HTTP on localhost port 9128 by default but this can be configured by specifying =noise-signal-cli-address= +We communicate with signal-cli via JSON-RPC over HTTP on localhost port 8080 by default but this can be configured by specifying =noise-signal-cli-address= ** User Experience @@ -61,7 +61,7 @@ Below are recipes for several popular Emacs package managers. :protocol https) :config ;; Optional: set a custom signal-cli address - ;; (setq noise-signal-cli-address "http://localhost:9128") + ;; (setq noise-signal-cli-address "http://localhost:8080") ;; Start Noise automatically (noise-mode 1)) diff --git a/noise-rpc.el b/noise-rpc.el index 03816cc..9814f6e 100644 --- a/noise-rpc.el +++ b/noise-rpc.el @@ -83,10 +83,39 @@ Signals `noise-rpc-error` on JSON-RPC error or malformed response." (defun noise-rpc-check () "Check connectivity to signal-cli. -Returns the version string on success. -Signals `noise-rpc-error` on failure." - (let ((result (noise-rpc-call "getVersion"))) - (gethash "version" result))) +Returns t if the daemon responds (even with an error indicating a valid JSON-RPC endpoint). +Signals `noise-rpc-error` on connection failure or timeout." + ;; signal-cli daemon doesn't have a dedicated ping/version RPC method. + ;; We send a request for a purposefully invalid method. If we get back + ;; a valid JSON-RPC error response, the daemon is running and reachable. + ;; If we get a connection error, the daemon is not running. + (let* ((url-request-method "POST") + (url-request-extra-headers + '(("Content-Type" . "application/json"))) + (url-request-data "{\"jsonrpc\":\"2.0\",\"method\":\"noisePing\",\"id\":0}") + (url (concat noise-signal-cli-address "/api/v1/rpc")) + (url-show-status nil) + (buf (condition-case nil + (url-retrieve-synchronously url t) + (error (signal 'noise-rpc-error + (list (format "Could not connect to signal-cli at %s. Is signal-cli daemon running?" + noise-signal-cli-address))))))) + (if (not buf) + (signal 'noise-rpc-error (list (format "No response from signal-cli at %s" noise-signal-cli-address))) + (unwind-protect + (with-current-buffer buf + (goto-char (point-min)) + (re-search-forward "\n\n" nil t) + (let* ((body (buffer-substring (point) (point-max))) + (parsed (condition-case nil + (json-parse-string body) + (error (signal 'noise-rpc-error + (list "signal-cli returned invalid JSON response")))))) + ;; Any valid JSON-RPC response means the daemon is alive + (if (or (gethash "result" parsed) (gethash "error" parsed)) + t + (signal 'noise-rpc-error (list "Invalid JSON-RPC response from signal-cli"))))) + (kill-buffer buf))))) (provide 'noise-rpc) ;;; noise-rpc.el ends here diff --git a/noise.el b/noise.el index c66e0eb..3024dab 100644 --- a/noise.el +++ b/noise.el @@ -19,9 +19,10 @@ :group 'comm :prefix "noise-") -(defcustom noise-signal-cli-address "http://localhost:9128" +(defcustom noise-signal-cli-address "http://localhost:8080" "Base URL of the signal-cli JSON-RPC daemon. -Format: http://HOST:PORT" +Format: http://HOST:PORT +The default port is 8080, matching signal-cli's `--http` default." :type 'string :group 'noise) @@ -30,8 +31,9 @@ Format: http://HOST:PORT" "Check connectivity to the signal-cli JSON-RPC daemon." (interactive) (condition-case err - (let ((version (noise-rpc-check))) - (message "signal-cli connected (version %s)" version)) + (progn + (noise-rpc-check) + (message "signal-cli connected at %s" noise-signal-cli-address)) (noise-rpc-error (message "Error: %s" (cdr err)))))