From 163f8efbc75f4e34e5ad8e751ae47190c62e8878 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Fri, 20 Jan 2017 18:14:18 -0600 Subject: [PATCH] why use random numbers for client ids at all --- 8sync/systems/websocket/server.scm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/8sync/systems/websocket/server.scm b/8sync/systems/websocket/server.scm index 04e961c..97645bb 100644 --- a/8sync/systems/websocket/server.scm +++ b/8sync/systems/websocket/server.scm @@ -59,6 +59,12 @@ string." (define no-op (const #f)) +(define (make-simple-counter) + (let ((count 0)) + (lambda () + (set! count (1+ count)) + count))) + (define-actor () ((ws-send websocket-server-send)) (upgrade-paths #:init-value `(("websocket" . @@ -66,6 +72,8 @@ string." #:allocation #:each-subclass #:accessor .upgrade-paths) + (gen-client-id #:init-thunk make-simple-counter) + ;; active websocket connections (ws-clients #:init-thunk make-hash-table #:accessor .ws-clients) @@ -79,6 +87,9 @@ string." #:init-value no-op #:getter .on-ws-client-disconnect)) +(define (web-server-gen-client-id websocket-server) + ((slot-ref websocket-server 'gen-client-id))) + (define (websocket-client-loop websocket-server client request body) "Serve client connected via CLIENT by performing the HTTP handshake and listening for control and data frames. HANDLER is @@ -97,7 +108,7 @@ called for each complete message that is received." ;; Allows other actors to send things to this specific client ;; @@: We probably could just increment a counter... - (define client-id (big-random-number)) + (define client-id (web-server-gen-client-id websocket-server)) (define (close-down) (close-port client) -- 2.31.1