Browse Source

router stub

master
Milo 10 months ago
parent
commit
c9b6e44fc7
1 changed files with 50 additions and 2 deletions
  1. +50
    -2
      router

+ 50
- 2
router View File

@@ -14,6 +14,25 @@
[info sock-in sock-out]
#:transparent)

;; alist : [Listof [Cons IP Route]]
(struct router
[(alist #:mutable)]
#:transparent)

;; -> Router
(define (make-router)
(router '()))

;; Router Route IP -> Void
(define (router-add! rs r src)
(set-router-alist! rs
(cons (cons src r)
(router-alist rs))))

;; Router IP -> (U IP #f)
(define (router-find-best rs src)
#f)

;; Str [Listof Peer-Conn] -> Void
;; --
;; Runs router logic, given a list of peer connections.
@@ -33,9 +52,38 @@
(channel-put mail (list peer msg))
(loop))))))

(define (ip->peer-conn ip)
(findf (λ (p)
(equal? ip (peer-ip (peer-conn-info p))))
peer-conns))

(define router
(make-router))

(define (loop)
(match-define (list peer data) (channel-get mail))
(printf "from ~a:\n~s\n" peer data)
(match-define (list src-peer msg) (channel-get mail))
(printf "====\nfrom ~a:\n~s\n" src-peer msg)
(match msg

[(msg:update src dst r)
(router-add! router r src)]

[(msg:data src dst data)
(define-values [dst-peer resp-msg]
(match (router-find-best router dst)
[#f
(values peer
(msg:no-route src
dst))]
[dst-peer-ip
(values (ip->peer-conn dst-peer-ip)
msg)]))
(printf "----\nwant to send back ~a to ~a\n"
dst-peer
resp-msg)]

[_
(printf "----\nignored\n")])
(loop))

(printf "waiting for messages...\n")


Loading…
Cancel
Save