From: Christopher Allan Webber Date: Sat, 21 Jan 2017 00:14:18 +0000 (-0600) Subject: why use random numbers for client ids at all X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=163f8efbc75f4e34e5ad8e751ae47190c62e8878;p=8sync.git why use random numbers for client ids at all --- 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)