forward update msgs
This commit is contained in:
parent
38be205744
commit
a914535c7d
35
router
35
router
|
@ -105,29 +105,44 @@
|
|||
(let loop ()
|
||||
(match-define (list src-peer-conn msg) (channel-get mail))
|
||||
(printf "====\nfrom ~a:\n~s\n" src-peer-conn msg)
|
||||
|
||||
;; [Listof [Cons Peer-Conn Msg]]
|
||||
(define to-send
|
||||
(match msg
|
||||
|
||||
[(msg:update src dst r)
|
||||
(router-add! router
|
||||
r
|
||||
(ip->peer src))
|
||||
(rt-dump router)]
|
||||
(rt-dump router)
|
||||
(for/list ([pc (in-list peer-conns)]
|
||||
#:when (not (eq? pc src-peer-conn)))
|
||||
(cons pc msg))]
|
||||
|
||||
[(msg:data src dst data)
|
||||
(define-values [dst-peer-conn resp-msg]
|
||||
(match (router-find-best router dst)
|
||||
[#f
|
||||
(values src-peer-conn
|
||||
(msg:no-route src dst))]
|
||||
(list (cons src-peer-conn
|
||||
(msg:no-route (sub1 src)
|
||||
src)))]
|
||||
[dst-peer
|
||||
(values (peer->peer-conn dst-peer)
|
||||
msg)]))
|
||||
(printf "----\nwant to send back to ~a:\n~a\n"
|
||||
(peer-conn-info dst-peer-conn)
|
||||
resp-msg)]
|
||||
(list (cons (peer->peer-conn dst-peer)
|
||||
msg))])]
|
||||
|
||||
[_
|
||||
(printf "----\nignored\n")])
|
||||
(printf "----\nignored\n")
|
||||
'()]))
|
||||
|
||||
(for ([dst+msg (in-list to-send)])
|
||||
(match-define (cons dst-peer-conn resp-msg) dst+msg)
|
||||
(printf "----\nwant to send to ~a:\n~a\n"
|
||||
(peer-conn-info dst-peer-conn)
|
||||
resp-msg)
|
||||
(define dst-port
|
||||
(peer-conn-sock-out dst-peer-conn))
|
||||
(write-bytes (msg->bytes resp-msg) dst-port)
|
||||
(flush-output dst-port))
|
||||
|
||||
(loop)))
|
||||
|
||||
;; Str [Listof Peer] ->
|
||||
|
|
Loading…
Reference in New Issue