Compare commits
2 Commits
f4051f1244
...
7430ae24e0
| Author | SHA1 | Date | |
|---|---|---|---|
| 7430ae24e0 | |||
| d90cfd5bfe |
@@ -131,3 +131,31 @@ Every session begins with a standard ~HELLO~ handshake, allowing the system to a
|
|||||||
:version version
|
:version version
|
||||||
:capabilities '(:auth :swank :org-ast))))
|
:capabilities '(:auth :swank :org-ast))))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
|
||||||
|
** Protocol Reading (read-framed-message)
|
||||||
|
A robust utility to read a framed message from a stream. It enforces the deterministic hex-length boundary.
|
||||||
|
|
||||||
|
#+begin_src lisp :tangle ../src/communication.lisp
|
||||||
|
(defun read-framed-message (stream)
|
||||||
|
"Reads a hex-length prefixed message from the stream securely."
|
||||||
|
(let ((length-buffer (make-string 6)))
|
||||||
|
(handler-case
|
||||||
|
(progn
|
||||||
|
;; 1. Read the 6-char hex length
|
||||||
|
(let ((count (read-sequence length-buffer stream)))
|
||||||
|
(when (< count 6) (return-from read-framed-message :eof))
|
||||||
|
(let ((len (ignore-errors (parse-integer length-buffer :radix 16))))
|
||||||
|
(unless len (error "Invalid protocol header: ~a" length-buffer))
|
||||||
|
|
||||||
|
;; 2. Read exactly LEN bytes
|
||||||
|
(let ((msg-buffer (make-string len)))
|
||||||
|
(read-sequence msg-buffer stream)
|
||||||
|
(let ((*read-eval* nil))
|
||||||
|
(let ((msg (read-from-string msg-buffer)))
|
||||||
|
(validate-communication-protocol-schema msg)
|
||||||
|
msg))))))
|
||||||
|
(error (c)
|
||||||
|
(harness-log "PROTOCOL READ ERROR: ~a" c)
|
||||||
|
:error))))
|
||||||
|
#+end_src
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ The `main` function initializes the environment, loads skills, and starts the he
|
|||||||
|
|
||||||
(initialize-actuators)
|
(initialize-actuators)
|
||||||
(initialize-all-skills)
|
(initialize-all-skills)
|
||||||
|
(start-daemon)
|
||||||
(start-heartbeat)
|
(start-heartbeat)
|
||||||
|
|
||||||
;; Graceful shutdown handler for SBCL
|
;; Graceful shutdown handler for SBCL
|
||||||
|
|||||||
@@ -65,3 +65,25 @@
|
|||||||
:payload (list :action :handshake
|
:payload (list :action :handshake
|
||||||
:version version
|
:version version
|
||||||
:capabilities '(:auth :swank :org-ast))))
|
:capabilities '(:auth :swank :org-ast))))
|
||||||
|
|
||||||
|
(defun read-framed-message (stream)
|
||||||
|
"Reads a hex-length prefixed message from the stream securely."
|
||||||
|
(let ((length-buffer (make-string 6)))
|
||||||
|
(handler-case
|
||||||
|
(progn
|
||||||
|
;; 1. Read the 6-char hex length
|
||||||
|
(let ((count (read-sequence length-buffer stream)))
|
||||||
|
(when (< count 6) (return-from read-framed-message :eof))
|
||||||
|
(let ((len (ignore-errors (parse-integer length-buffer :radix 16))))
|
||||||
|
(unless len (error "Invalid protocol header: ~a" length-buffer))
|
||||||
|
|
||||||
|
;; 2. Read exactly LEN bytes
|
||||||
|
(let ((msg-buffer (make-string len)))
|
||||||
|
(read-sequence msg-buffer stream)
|
||||||
|
(let ((*read-eval* nil))
|
||||||
|
(let ((msg (read-from-string msg-buffer)))
|
||||||
|
(validate-communication-protocol-schema msg)
|
||||||
|
msg))))))
|
||||||
|
(error (c)
|
||||||
|
(harness-log "PROTOCOL READ ERROR: ~a" c)
|
||||||
|
:error))))
|
||||||
|
|||||||
@@ -51,6 +51,7 @@
|
|||||||
|
|
||||||
(initialize-actuators)
|
(initialize-actuators)
|
||||||
(initialize-all-skills)
|
(initialize-all-skills)
|
||||||
|
(start-daemon)
|
||||||
(start-heartbeat)
|
(start-heartbeat)
|
||||||
|
|
||||||
;; Graceful shutdown handler for SBCL
|
;; Graceful shutdown handler for SBCL
|
||||||
|
|||||||
Reference in New Issue
Block a user