router uses msg

This commit is contained in:
Milo 2020-01-30 19:51:35 -05:00
parent 64d5a1968b
commit 0af140b70f
1 changed files with 7 additions and 8 deletions

15
router
View File

@ -4,7 +4,8 @@
(require json
"iputil.rkt"
"unix-socket.rkt")
"unix-socket.rkt"
"msg.rkt")
;; info : Peer
;; sock-in : Input-Port
@ -13,10 +14,9 @@
[info sock-in sock-out]
#:transparent)
;; Str [Listof Peer-Conn] -> [-> Void]
;; Str [Listof Peer-Conn] -> Void
;; --
;; runs router logic given peer connections. returns thunk that, when called, aborts the
;; router.
;; Runs router logic, given a list of peer connections.
(define (run-router/conns ans peer-conns)
(define mail
(make-channel))
@ -29,8 +29,8 @@
(let loop ()
(define len (read-bytes-avail! buf sock-in))
(printf "got ~a bytes from ~a...\n" len peer)
(define jsexpr (bytes->jsexpr (subbytes buf 0 len)))
(channel-put mail (list peer jsexpr))
(define msg (bytes->msg (subbytes buf 0 len)))
(channel-put mail (list peer msg))
(loop))))))
(define (loop)
@ -47,8 +47,7 @@
(displayln asn)
(map displayln peers)
(displayln "------------")
(with-handlers ([exn:break:terminate? (λ (e)
(printf "time to die.\n"))])
(with-handlers ([exn:break? (λ (e) (printf "time to die.\n"))])
(run-router/conns
asn
(for/list ([peer (in-list peers)])