Handle incoming RST

This commit is contained in:
Tony Garnock-Jones 2014-06-21 12:23:23 -04:00
parent 4451795146
commit 0a5abb8fff
1 changed files with 26 additions and 22 deletions

48
tcp.rkt
View File

@ -551,28 +551,32 @@
(define expected (next-expected-seqn s)) (define expected (next-expected-seqn s))
(define is-syn? (set-member? flags 'syn)) (define is-syn? (set-member? flags 'syn))
(define is-fin? (set-member? flags 'fin)) (define is-fin? (set-member? flags 'fin))
(if (and (not expected) ;; no syn yet (cond
(or (not is-syn?) ;; and this isn't it [(set-member? flags 'rst)
(and (not (conn-state-listener-listening? s)) ;; or it is, but no listener... (transition s (quit))]
(not (conn-state-local-peer-seen? s))))) ;; ...and no outbound client [(and (not expected) ;; no syn yet
(reset ackn ;; this is *our* seqn (or (not is-syn?) ;; and this isn't it
(seq+ seqn (+ (if is-syn? 1 0) (if is-fin? 1 0))) (and (not (conn-state-listener-listening? s)) ;; or it is, but no listener...
;; ^^ this is what we should acknowledge... (not (conn-state-local-peer-seen? s))))) ;; ...and no outbound client
s) (reset ackn ;; this is *our* seqn
(sequence-transitions (cond (seq+ seqn (+ (if is-syn? 1 0) (if is-fin? 1 0)))
[(not expected) ;; haven't seen syn yet, but we know this is it ;; ^^ this is what we should acknowledge...
(incorporate-segment data (set-inbound-seqn (seq+ seqn 1) s))] s)]
[(= expected seqn) [else
(incorporate-segment data s)] (sequence-transitions (cond
[else [(not expected) ;; haven't seen syn yet, but we know this is it
(transition s '())]) (incorporate-segment data (set-inbound-seqn (seq+ seqn 1) s))]
deliver-inbound-locally [(= expected seqn)
(check-fin flags) (incorporate-segment data s)]
(discard-acknowledged-outbound (set-member? flags 'ack) ackn) [else
(update-outbound-window window) (transition s '())])
(send-outbound old-ackn) deliver-inbound-locally
bump-activity-time (check-fin flags)
quit-when-done))] (discard-acknowledged-outbound (set-member? flags 'ack) ackn)
(update-outbound-window window)
(send-outbound old-ackn)
bump-activity-time
quit-when-done)])]
[(message (tcp-channel _ _ bs) _ _) [(message (tcp-channel _ _ bs) _ _)
;; (log-info "GOT MORE STUFF TO DELIVER ~v" bs) ;; (log-info "GOT MORE STUFF TO DELIVER ~v" bs)
(sequence-transitions (transition (struct-copy conn-state s (sequence-transitions (transition (struct-copy conn-state s