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