branch: externals/crdt commit f224e8ab3926b227a2d690cfa0e6729d4550913a Author: Qiantan Hong <qh...@mit.edu> Commit: Qiantan Hong <qh...@mit.edu>
add doc. add error handler in network filter --- README.org | 19 +++++++++++++++++++ crdt.el | 42 ++++++++++++++++++++++++------------------ 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/README.org b/README.org new file mode 100644 index 0000000..67f8936 --- /dev/null +++ b/README.org @@ -0,0 +1,19 @@ +* Introduction +~crdt.el~ is a real-time collaborative editing environment for Emacs using Conflict-free Replicated Data Types. +* Usage +** Installation +Just `M-x load-file` `crdt.el`, or `M-x eval-buffer` in `crdt.el`, +or `(require 'crdt)`. Or whatever package management tool you use. +** Share a buffer +In that buffer, `M-x crdt-serve-buffer`. Then enter port, optional password +and your display name. +** Connect to a shared buffer +`M-x crdt-connect` +** List active users. +In a CRDT shared buffer (either server or client), `M-x crdt-list-users`. + +In the displayed user list, press `RET` on an entry to goto that user's cursor position. +** Stop sharing. +For server, `M-x crdt-stop-serve-buffer`, or just kill the buffer, + +For client, `M-x crdt-stop-client`, or just kill the buffer. diff --git a/crdt.el b/crdt.el index 4531392..3b874dc 100644 --- a/crdt.el +++ b/crdt.el @@ -709,24 +709,30 @@ to server unless WITHOUT is NIL." (while (setq message (ignore-errors (read (current-buffer)))) ;; (print message) (with-current-buffer (process-get process 'crdt-buffer) - (save-excursion - (widen) - (if (or (not (crdt--server-p)) (process-get process 'authenticated)) - (let ((crdt--inhibit-update t)) - (crdt-process-message message process)) - (cl-block nil - (when (eq (car message) 'hello) - (cl-destructuring-bind (name &optional response) (cdr message) - (when (or (not (process-get process 'password)) ; server password is empty - (and response (string-equal response (process-get process 'challenge)))) - (process-put process 'authenticated t) - (process-put process 'client-name name) - (crdt--greet-client process) - (cl-return)))) - (let ((challenge (crdt--generate-challenge))) - (process-put process 'challenge - (gnutls-hash-mac 'SHA1 (substring (process-get process 'password)) challenge)) - (process-send-string process (format "%S" `(challenge ,challenge)))))))) + (condition-case err + (save-excursion + (widen) + (if (or (not (crdt--server-p)) (process-get process 'authenticated)) + (let ((crdt--inhibit-update t)) + (crdt-process-message message process)) + (cl-block nil + (when (eq (car message) 'hello) + (cl-destructuring-bind (name &optional response) (cdr message) + (when (or (not (process-get process 'password)) ; server password is empty + (and response (string-equal response (process-get process 'challenge)))) + (process-put process 'authenticated t) + (process-put process 'client-name name) + (crdt--greet-client process) + (cl-return)))) + (let ((challenge (crdt--generate-challenge))) + (process-put process 'challenge + (gnutls-hash-mac 'SHA1 (substring (process-get process 'password)) challenge)) + (process-send-string process (format "%S" `(challenge ,challenge))))))) + (error (message "%s error when processing message from %s:%s, disconnecting." err + (process-contact process :host) (process-contact process :service)) + (if (crdt--server-p) + (delete-process process) + (crdt-stop-client))))) (delete-region (point-min) (point)) (goto-char (point-min)))))))) (defun crdt--server-process-sentinel (client message)