forward update msgs

This commit is contained in:
Milo 2020-01-31 23:38:48 -05:00
parent 38be205744
commit a914535c7d
1 changed files with 32 additions and 17 deletions

49
router
View File

@ -105,29 +105,44 @@
(let loop () (let loop ()
(match-define (list src-peer-conn msg) (channel-get mail)) (match-define (list src-peer-conn msg) (channel-get mail))
(printf "====\nfrom ~a:\n~s\n" src-peer-conn msg) (printf "====\nfrom ~a:\n~s\n" src-peer-conn msg)
(match msg
[(msg:update src dst r) ;; [Listof [Cons Peer-Conn Msg]]
(router-add! router (define to-send
r (match msg
(ip->peer src))
(rt-dump router)]
[(msg:data src dst data) [(msg:update src dst r)
(define-values [dst-peer-conn resp-msg] (router-add! router
r
(ip->peer src))
(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)
(match (router-find-best router dst) (match (router-find-best router dst)
[#f [#f
(values src-peer-conn (list (cons src-peer-conn
(msg:no-route src dst))] (msg:no-route (sub1 src)
src)))]
[dst-peer [dst-peer
(values (peer->peer-conn dst-peer) (list (cons (peer->peer-conn dst-peer)
msg)])) msg))])]
(printf "----\nwant to send back to ~a:\n~a\n"
(peer-conn-info dst-peer-conn) [_
resp-msg)] (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))
[_
(printf "----\nignored\n")])
(loop))) (loop)))
;; Str [Listof Peer] -> ;; Str [Listof Peer] ->