diff options
author | David Thompson <dthompson2@worcester.edu> | 2016-03-25 16:18:07 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2016-03-25 16:20:35 -0400 |
commit | 5cc3adb20f2fcc091540a1fa035f668e57ea2a83 (patch) | |
tree | 0c5080baa596ed835b01882dd55200c0900c4001 /web | |
parent | f57eeffa5b26c095fc356eccaca25c2611c9db1e (diff) |
client: Add entropy source.
* web/socket/client.scm (<websocket>)[entropy-port]: New field.
(open-entropy-port): New procedure.
(make-websocket): Open entropy port.
(close-websocket): Close entropy port.
Diffstat (limited to 'web')
-rw-r--r-- | web/socket/client.scm | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/web/socket/client.scm b/web/socket/client.scm index 8a96494..5712cd5 100644 --- a/web/socket/client.scm +++ b/web/socket/client.scm @@ -81,10 +81,11 @@ scheme." s)) (define-record-type <websocket> - (%make-websocket uri socket state) + (%make-websocket uri socket entropy-port state) websocket? (uri websocket-uri) (socket websocket-socket) + (entropy-port websocket-entropy-port) (state websocket-state set-websocket-state!)) (define (display-websocket ws port) @@ -142,6 +143,13 @@ remote resource described by URI." (close-websocket ws) (error "websocket handshake failed" (websocket-uri ws)))))) +(define (open-entropy-port) + "Return an open input port to a reliable source of entropy for the +current system." + ;; XXX: This works on GNU/Linux and OS X systems, but this isn't + ;; exactly portable. + (open-input-file "/dev/urandom")) + (define (make-websocket uri-or-string) "Create and establish a new WebSocket connection for the remote resource described by URI-OR-STRING." @@ -149,7 +157,10 @@ resource described by URI-OR-STRING." ((? uri? uri) uri) ((? string? str) (string->uri str))))) (if (websocket-uri? uri) - (let ((ws (%make-websocket uri (make-client-socket uri) 'connecting))) + (let ((ws (%make-websocket uri + (make-client-socket uri) + (open-entropy-port) + 'connecting))) (handshake ws) ws) (error "not a websocket uri" uri)))) @@ -168,6 +179,7 @@ resource described by URI-OR-STRING." (read-frame socket) ; throw it away (loop))))) (close-port socket) + (close-port (websocket-entropy-port ws)) (set-websocket-state! ws 'closed))) (define (websocket-send ws data) |