~edwargix/tallyard

07999282a245866e254d03c6a5dbe368f7820d07 — David Florness 5 years ago cb28a52
Keep track of votes
1 files changed, 14 insertions(+), 1 deletions(-)

M server.rkt
M server.rkt => server.rkt +14 -1
@@ 29,12 29,24 @@
(define (candidates req)
  (response/json cands))

(define votes '())

(define (submit-vote bstr)
  (let foo ([i 0])
    (if (> (bytes-ref bstr i) 0)
        (let ([s (bytes->string/utf-8 (subbytes bstr i))])
          (set! votes (cons (string-split s ":") votes))
          (println votes))
        (foo (add1 i)))))

(define (vote req)
  (let* ([data (request-post-data/raw req)]
         [m (bytes->integer (subbytes data 0 (/ keylen 8)) #f)]
         [s (bytes->integer (subbytes data (/ keylen 8) (* 2 (/ keylen 8))) #f)])
    (if (equal? m (modular-expt s e n))
        (response/text "vote submitted")
        (begin
          (submit-vote (subbytes data 0 (/ keylen 8)))
          (response/text "vote submitted"))
        (response/text "invalid signature"))))

(define (sign req)


@@ 56,6 68,7 @@
   [("key") key]
   [else candidates]))

(displayln "starting servlet...")
(serve/servlet dispatcher
               #:port 5598
               #:command-line? #t