router uses msg
This commit is contained in:
parent
64d5a1968b
commit
0af140b70f
15
router
15
router
|
@ -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)])
|
||||
|
|
Loading…
Reference in New Issue