Pass level 4, 5

This commit is contained in:
xenia 2020-02-13 20:37:25 -05:00
parent d49d02f504
commit 79af76ed19
1 changed files with 18 additions and 8 deletions

26
router
View File

@ -114,6 +114,13 @@
(peer-ip peer)
(update-aspath r asn)))
;; Peer Peer -> Bool
;; Checks if we should send a route update from the given src peer to the dst peer
(define (router-should-update? src-peer dst-peer)
(match (peer-type src-peer)
['cust #t]
[_ (symbol=? 'cust (peer-type dst-peer))]))
;; Int [Listof Peer-Conn] -> Void
;; --
;; Runs router logic, given a list of peer connections.
@ -170,26 +177,29 @@
(ip->peer src))
(rt-dump router)
(for/list ([pc (in-list peer-conns)]
#:when (not (eq? (peer-conn-info pc) src-peer)))
#:when (not (eq? (peer-conn-info pc) src-peer))
#:when (router-should-update? src-peer (peer-conn-info pc)))
(cons pc (router-format-update (peer-conn-info pc) r asn)))]
[(msg:revoke src dst networks)
(for ([net (in-list networks)]) (router-revoke! router net (ip->peer src)))
(rt-dump router)
(for/list ([pc (in-list peer-conns)]
#:when (not (eq? (peer-conn-info pc) src-peer)))
#:when (not (eq? (peer-conn-info pc) src-peer))
#:when (router-should-update? src-peer (peer-conn-info pc)))
(let ([pip (peer-ip (peer-conn-info pc))])
(cons pc (msg:revoke (peer-ip->own-ip pip) pip networks))))]
[(msg:data src dst data)
(match (router-find-best router dst)
[#f
(list (cons (peer->peer-conn src-peer)
(msg:no-route (peer-ip->own-ip src)
src)))]
[dst-peer
[(? peer? dst-peer) #:when (ormap (compose (curry symbol=? 'cust) peer-type)
(list dst-peer src-peer))
(list (cons (peer->peer-conn dst-peer)
msg))])]
msg))]
[_
(list (cons (peer->peer-conn src-peer)
(msg:no-route (peer-ip->own-ip (peer-ip src-peer))
src)))])]
[(msg:dump src dst)
(list (cons (peer->peer-conn src-peer) (router-dump router src dst)))]
[_