MAJ terminée. Nous sommes passés en version 14.6.2 . Pour consulter les "releases notes" associées c'est ici :

https://about.gitlab.com/releases/2022/01/11/security-release-gitlab-14-6-2-released/
https://about.gitlab.com/releases/2022/01/04/gitlab-14-6-1-released/

Commit c824394e authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

proxy: Factorize global request handler.

* guix-jupyter-container.scm (general-handler, dispatch): Remove.
<top level>: Use 'proxy-request-handler' instead.
* guix-jupyter-kernel.scm (general-handler, dispatch): Remove.
<top level>: Use 'proxy-request-handler' instead.
* guix/jupyter/proxy.scm (proxy-request-handler): New procedure.
parent 0ff99a32
......@@ -143,33 +143,6 @@
;; Handler.
;;
(define (general-handler kernel kind message state)
"Handle MESSAGE, which was sent by KERNEL, a client of ours, on KIND (one
of 'kernel-shell', 'kernel-stdin', etc.) STATE is a <proxy-state> record;
return a <proxy-state> record that reflects the new state."
(if (eq? kernel (proxy-state-client state))
;; Record the socket identity of our client so we can forward shell
;; messages to it. As explained at
;; <http://zguide.zeromq.org/php:chapter3#header-68>, we get to
;; discover the identity of our peer the first time we get a message
;; from it, which is why we record it here.
(let* ((client-id (message-sender message))
(state (set-proxy-state-client-id state client-id))
(handler (dispatch (message-type message))))
(handler kernel kind message state))
;; This message is coming from one of our proxied kernels, so
;; forward it to our client.
(let ((id (proxy-state-client-id state)))
(format/log "forwarding ~s from ~s, socket ~s to ~s~%"
(message-type message) (kernel-pid kernel)
kind (bytevector->base16-string id))
(send-message (proxy-state-client state) message
#:kernel-socket kind
#:recipient id)
state)))
;; Unknown request type, ignore it.
(define (ignore-request kernel kind message state)
state)
......@@ -240,14 +213,6 @@ stripped."
("shutdown_request" . ,shutdown)
("comm_info_request" . ,ignore-request)))
(define (dispatch msg-type)
(let ((res (assoc-ref dispatch-route msg-type)))
(unless res
(display
(string-append "\n(WW) unknown message type: "
msg-type "\n\n")))
(if res res ignore-request)))
;;
;; Run.
;;
......@@ -259,4 +224,6 @@ stripped."
#:context %context))
(state (proxy-state kernel)))
(format/log "started proxy as PID ~a~%" (getpid))
(serve-kernels (list kernel) general-handler state))))
(serve-kernels (list kernel)
(proxy-request-handler dispatch-route)
state))))
......@@ -75,33 +75,6 @@
;; Handlers.
;;
(define (general-handler kernel kind message state)
"Handle MESSAGE, which was sent by KERNEL, a client of ours, on KIND (one
of 'kernel-shell', 'kernel-stdin', etc.) STATE is a <proxy-state> record;
return a <proxy-state> record that reflects the new state."
(if (eq? kernel (proxy-state-client state))
;; Record the socket identity of our client so we can forward shell
;; messages to it. As explained at
;; <http://zguide.zeromq.org/php:chapter3#header-68>, we get to
;; discover the identity of our peer the first time we get a message
;; from it, which is why we record it here.
(let* ((client-id (message-sender message))
(state (set-proxy-state-client-id state client-id))
(handler (dispatch (message-type message))))
(handler kernel kind message state))
;; This message is coming from one of our proxied kernels, so
;; forward it to our client.
(let ((id (proxy-state-client-id state)))
(format/log "forwarding ~s from ~s, socket ~s to ~s~%"
(message-type message) (kernel-pid kernel)
kind (bytevector->base16-string id))
(send-message (proxy-state-client state) message
#:kernel-socket kind
#:recipient id)
state)))
;; Unknown request type, ignore it.
(define (ignore-request kernel kind message state)
state)
......@@ -193,18 +166,6 @@ return a <proxy-state> record that reflects the new state."
("shutdown_request" . ,shutdown)
("comm_info_request" . ,ignore-request)))
(define (dispatch msg-type)
(let ((res (assoc-ref dispatch-route msg-type)))
(unless res
(display
(string-append "\n(WW) unknown message type: "
msg-type "\n\n")))
(if res res ignore-request)))
;;
;; Process exit and signals handler.
;;
;;
;; Run.
;;
......@@ -284,5 +245,5 @@ container."
(state (register-proxied "default" sub-kernel
(proxy-state kernel))))
(serve-kernels (list kernel sub-kernel)
general-handler
(proxy-request-handler dispatch-route)
state)))
......@@ -18,6 +18,7 @@
#:use-module (guix jupyter logging)
#:use-module (jupyter messages)
#:use-module (jupyter kernels)
#:use-module (gcrypt base16)
#:use-module (srfi srfi-9 gnu)
#:use-module (ice-9 vlist)
#:use-module (ice-9 match)
......@@ -34,7 +35,8 @@
proxy-state-proxied-number
increment-execution-count
set-proxy-state-execution-count
terminate-proxied-kernels))
terminate-proxied-kernels
proxy-request-handler))
;;; Commentary:
;;;
......@@ -94,3 +96,37 @@ MESSAGE. Return the new state."
(proxy-state-proxied state))
;; FIXME: We should tell the server loop to "unmonitor" them.
(set-proxy-state-proxied state vlist-null))
(define (proxy-request-handler handlers)
"Return a handler procedure suitable for 'serve-kernels' that forwards
messages from the client to the proxied kernels and vice-versa and return the
updated <proxy-state>. When a client message has one of the types found in
HANDLERS, a list of message type/handler pairs, pass it to that handler."
(lambda (kernel kind message state)
(if (eq? kernel (proxy-state-client state))
;; Record the socket identity of our client so we can forward shell
;; messages to it. As explained at
;; <http://zguide.zeromq.org/php:chapter3#header-68>, we get to
;; discover the identity of our peer the first time we get a message
;; from it, which is why we record it here.
(let* ((client-id (message-sender message))
(state (set-proxy-state-client-id state client-id))
(handler (assoc-ref handlers (message-type message))))
(if handler
(handler kernel kind message state)
(begin
(format/log "unhandled '~a' message from client; ignoring~%"
(message-type message))
state)))
;; This message is coming from one of our proxied kernels, so
;; forward it to our client.
(let ((id (proxy-state-client-id state)))
(format/log "forwarding ~s from ~s, socket ~s to ~s~%"
(message-type message) (kernel-pid kernel)
kind (bytevector->base16-string id))
(send-message (proxy-state-client state) message
#:kernel-socket kind
#:recipient id)
state))))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment