transparent

This commit is contained in:
Milo 2020-01-30 19:47:32 -05:00
parent 1c04209328
commit 8ac13a0c31
2 changed files with 23 additions and 10 deletions

View File

@ -14,6 +14,7 @@
(require rackunit))
(struct peer [ip type]
#:transparent
#:methods gen:custom-write
[(define write-proc
(make-constructor-style-printer
@ -21,6 +22,7 @@
(lambda (x) (list (ip->string (peer-ip x)) (peer-type x)))))])
(struct subnet [ip mask]
#:transparent
#:methods gen:custom-write
[(define write-proc
(make-constructor-style-printer

31
msg.rkt
View File

@ -4,6 +4,9 @@
(require json
"iputil.rkt")
(module+ test
(require rackunit))
;; src, dst : IP
;; data : Any
(struct msg [src dst]
@ -86,13 +89,21 @@
(jsexpr->msg bs)))
(module+ test
(jsexpr->msg
(hash 'src "1.2.3.4"
'dst "1.2.3.7"
'type "update"
'msg (hash 'network "1.2.3.5"
'netmask "255.255.255.128"
'localpref 100
'selfOrigin #t
'ASPath '(1 2)
'origin "UNK"))))
(check-equal? (jsexpr->msg
(hash 'src "1.2.3.4"
'dst "1.2.3.7"
'type "update"
'msg (hash 'network "1.2.3.5"
'netmask "255.255.255.128"
'localpref 100
'selfOrigin #t
'ASPath '(1 2)
'origin "UNK")))
(msg:update
(string->ip "1.2.3.4")
(string->ip "1.2.3.7")
(subnet (string->ip "1.2.3.5") 7)
100
#t
'(1 2)
'UNK)))