diff --git a/network-query.rkt b/network-query.rkt index 1042a63..69fa417 100644 --- a/network-query.rkt +++ b/network-query.rkt @@ -86,11 +86,13 @@ ;; A NetworkQueryState is a (network-query-state NetworkRequest ;; Integer Map> ListOf -;; ListOf), representing an in-progress DNS network query. +;; Maybe ListOf), representing an in-progress +;; DNS network query. (struct network-query-state (request timeout known-addresses remaining-addresses + current-name remaining-names) #:transparent) @@ -154,29 +156,34 @@ first-timeout (hash) '() + #f server-names)))) (define (try-next-server w) (match w - [(network-query-state _ #f _ _ _) + [(network-query-state _ #f _ _ _ _) ;; No more timeouts to try, so give up. (on-answer w (empty-complete-answer))] - [(network-query-state req timeout _ '() '()) + [(network-query-state req timeout _ '() _ '()) ;; No more addresses to try with this timeout. Refill the list ;; and bump the timeout and retry. ;; TODO: randomize ordering of servers in list. (Don't forget the initial fill.) (try-next-server (struct-copy network-query-state w [timeout (next-timeout timeout)] [remaining-addresses '()] + [current-name #f] [remaining-names (network-request-server-names req)]))] - [(network-query-state req _ known-addresses '() (cons current-name remaining-names)) + [(network-query-state req _ known-addresses '() _ (cons current-name remaining-names)) (if (hash-has-key? known-addresses current-name) (try-next-server (struct-copy network-query-state w [remaining-addresses (hash-ref known-addresses current-name)] + [current-name current-name] [remaining-names remaining-names])) (let ((subq (ns-question current-name (network-request-question req)))) - (transition (struct-copy network-query-state w [remaining-names remaining-names]) + (transition (struct-copy network-query-state w + [current-name current-name] + [remaining-names remaining-names]) (send-message subq) (subscribe/fresh subscription-id (message-handlers w @@ -190,7 +197,7 @@ ips)] [remaining-addresses ips])) (unsubscribe subscription-id))])))))] - [(network-query-state req timeout _ (cons current-ip remaining-ips) _) + [(network-query-state req timeout _ (cons current-ip remaining-ips) _ _) (define rpc-id (gensym 'network-query/allocate-query-id)) (transition w (send-message `(request ,rpc-id allocate-query-id))