emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/crdt a8c1874a89 1/3: Instead of opening tuntox buffer,


From: ELPA Syncer
Subject: [elpa] externals/crdt a8c1874a89 1/3: Instead of opening tuntox buffer, use messages
Date: Sat, 19 Nov 2022 02:57:29 -0500 (EST)

branch: externals/crdt
commit a8c1874a89f8ced0e1bd40c422b746e8813bd0bd
Author: Jonathan Ming <jming422@gmail.com>
Commit: Jonathan Ming <jming422@gmail.com>

    Instead of opening tuntox buffer, use messages
    
    The *Tuntox Proxy* buffer is mostly useful to those who know about the
    low-level operation of crdt.el. So, instead of always opening that
    process buffer when it is created, leave the process buffer in the
    background and use process filters to post more user-friendly
    notifications about tuntox connection status to *Messages*.
    
    I'm not that familiar with process filters, but I saw that overriding
    the default filter causes the buffer to no longer get updated by
    default, so I copied the way the crdt-connect tuntox filter writes to
    the process buffer into crdt-new-session as well.
    
    Co-authored-by: Arte Ebrahimi <arteebrahimi@gmail.com>
---
 crdt.el | 74 +++++++++++++++++++++++++++++++++++++++--------------------------
 1 file changed, 45 insertions(+), 29 deletions(-)

diff --git a/crdt.el b/crdt.el
index 1f62745f8c..316e2fa0ae 100644
--- a/crdt.el
+++ b/crdt.el
@@ -2389,10 +2389,23 @@ Each element should be one of
                                 "-C" ,(expand-file-name crdt-tuntox-key-path)
                                 "-f" "/dev/stdin" ; do the filtering for 
safety sake
                                 ,@ (when password-p
-                                     `("-s" ,password))))))
+                                     `("-s" ,password)))
+                              :filter
+                              (lambda (proc string)
+                                (cond
+                                 ((string-match "An UDP connection has been 
established" string) (message "Connected to Tuntox network."))
+                                 ((string-match "Lost connection to server" 
string) (warn "Lost connection to Tuntox network!")))
+                                (when (buffer-live-p (process-buffer proc))
+                                  (with-current-buffer (process-buffer proc)
+                                    (let ((moving (= (point) (process-mark 
proc))))
+                                      (save-excursion
+                                        (goto-char (process-mark proc))
+                                        (insert string)
+                                        (set-marker (process-mark proc) 
(point)))
+                                      (if moving (goto-char (process-mark 
proc))))))))))
+          (message "Connecting to Tuntox network...")
           (when password-p
             (process-put proxy-process 'password password))
-          (display-buffer (process-buffer proxy-process))
           (process-put network-process 'tuntox-process proxy-process)
           (process-send-string proxy-process (format "127.0.0.1:%s\n" port)) ; 
only allow connection to our port
           (process-send-eof proxy-process))
@@ -2578,33 +2591,36 @@ Join with DISPLAY-NAME."
                    (password (or (when (url-filename url)
                                    (cadr (split-string (url-filename url) 
"?pwd=")))
                                  (read-passwd "tuntox password (empty for no 
password): "))))
-               (switch-to-buffer-other-window
-                (process-buffer
-                 (make-process
-                  :name "Tuntox Proxy"
-                  :buffer (generate-new-buffer "*Tuntox Proxy*")
-                  :command
-                  `(,crdt-tuntox-executable
-                    "-i" ,(url-host url)
-                    "-L" ,(format "%s:127.0.0.1:%s" port (url-portspec url))
-                    ,@ (when (> (length password) 0)
-                         `("-s" ,password)))
-                  :filter
-                  (let (initialized)
-                    (lambda (proc string)
-                      (when (buffer-live-p (process-buffer proc))
-                        (with-current-buffer (process-buffer proc)
-                          (let ((moving (= (point) (process-mark proc))))
-                            (save-excursion
-                              (goto-char (process-mark proc))
-                              (insert string)
-                              (set-marker (process-mark proc) (point))
-                              (unless initialized
-                                (when (ignore-errors (search-backward "Friend 
request accepted"))
-                                  (setq initialized t)
-                                  (process-put (start-session :host 
"127.0.0.1" :service port)
-                                               'tuntox-process proc))))
-                            (if moving (goto-char (process-mark proc)))))))))))
+               (message "Connecting to Tuntox network...")
+               (make-process
+                :name "Tuntox Proxy"
+                :buffer (generate-new-buffer "*Tuntox Proxy*")
+                :command
+                `(,crdt-tuntox-executable
+                  "-i" ,(url-host url)
+                  "-L" ,(format "%s:127.0.0.1:%s" port (url-portspec url))
+                  ,@ (when (> (length password) 0)
+                       `("-s" ,password)))
+                :filter
+                (let (initialized)
+                  (lambda (proc string)
+                    (cond
+                     ((string-match "An UDP connection has been established" 
string) (message "Connected to Tuntox network, finding host..."))
+                     ((string-match "Lost connection to server" string) (warn 
"Lost connection to Tuntox network!")))
+                    (when (buffer-live-p (process-buffer proc))
+                      (with-current-buffer (process-buffer proc)
+                        (let ((moving (= (point) (process-mark proc))))
+                          (save-excursion
+                            (goto-char (process-mark proc))
+                            (insert string)
+                            (set-marker (process-mark proc) (point))
+                            (unless initialized
+                              (when (ignore-errors (search-backward "Friend 
request accepted"))
+                                (setq initialized t)
+                                (message "Connected to host over Tuntox.")
+                                (process-put (start-session :host "127.0.0.1" 
:service port)
+                                             'tuntox-process proc))))
+                          (if moving (goto-char (process-mark proc)))))))))
                nil))
             (t (error "Unknown protocol \"%s\"" url-type)))
       (push new-session crdt--session-list)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]