跳到主要内容

协议操作:报文段到达与超时事件

3.7.2 报文段到达事件​

以下场景描述了由远程主机发来的 RDP 报文段到达所引发事件的处理。这里假定该报文段的目的地是与连接记录关联的本地端口。

If State = CLOSED

  If RST set
    Discard segment
    Return
  Endif

  If ACK or NUL set
     Send <SEQ=SEG.ACK + 1><RST>
     Discard segment
     Return
   else
     Send <SEQ=0><RST><ACK=RCV.CUR><ACK>
     Discard segment
     Return
  Endif

Endif

If State = CLOSE-WAIT
  If RST set
     Set State = CLOSED
     Discard segment
     Cancel TIMWAIT timer
     Deallocate connection record
   else
     Discard segment
  Endif
  Return
Endif

If State = LISTEN

  If RST set
    Discard the segment
    Return
  Endif

  If ACK or NUL set
    Send <SEQ=SEG.ACK + 1><RST>
    Return
  Endif

  If SYN set
    Set RCV.CUR = SEG.SEQ
        RCV.IRS = SEG.SEQ
        SND.MAX = SEG.MAX
        SBUF.MAX = SEG.BMAX
    Send <SEQ=SND.ISS><ACK=RCV.CUR><MAX=RCV.MAX><BUFMAX=RBUF.MAX>
         <ACK><SYN>
    Set State = SYN-RCVD
    Return
  Endif

  If anything else (should never get here)
    Discard segment
    Return
  Endif
Endif

If State = SYN-SENT

  If ACK set
    If RST clear and SEG.ACK != SND.ISS
      Send <SEQ=SEG.ACK + 1><RST>
    Endif
    Discard segment; Return
  Endif

  If RST set
    If ACK set
      Signal "Connection Refused"
      Set State =  CLOSED
      Deallocate connection record
    Endif
    Discard segment
    Return
  Endif

  If SYN set
    Set RCV.CUR = SEG.SEQ
        RCV.IRS = SEG.SEQ
        SND.MAX = SEG.MAX
        RBUF.MAX = SEG.BMAX
    If ACK set
      Set SND.UNA = SEG.ACK
      State = OPEN
      Send <SEQ=SND.NXT><ACK=RCV.CUR><ACK>
     else
      Set State = SYN-RCVD
      Send <SEQ=SND.ISS><ACK=RCV.CUR><MAX=RCV.MAX><BUFMAX=RBUF.MAX>
             <SYN><ACK>
    Endif
    Return
  Endif

  If anything else
    Discard segment
    Return
  Endif
Endif

If State = SYN-RCVD

  If RCV.IRS < SEG.SEQ =< RCV.CUR + (RCV.MAX * 2)
    Segment sequence number acceptable
   else
    Send <SEQ=SND.NXT><ACK=RCV.CUR><ACK>
    Discard segment
    Return
  Endif

  If RST set
    If passive Open
       Set State = LISTEN
    else
       Set State = CLOSED
       Signal "Connection Refused"
       Discard segment
       Deallocate connection record
    Endif
    Return
  Endif

  If SYN set
    Send <SEQ=SEG.ACK + 1><RST>
    Set State = CLOSED
    Signal "Connection Reset"
    Discard segment
    Deallocate connection record
    Return
  Endif

  If EACK set
     Send <SEQ=SEG.ACK + 1><RST>
     Discard segment
     Return
  Endif

  If ACK set
    If SEG.ACK = SND.ISS
       Set State = OPEN
     else
       Send <SEQ=SEG.ACK + 1><RST>
       Discard segment
       Return
    Endif
   else
    Discard segment
    Return
  Endif

  If Data in segment or NUL set
    If the received segment is in sequence
       Copy the data (if any) to user buffers
       Set RCV.CUR=SEG.SEQ
       Send <SEQ=SND.NXT><ACK=RCV.CUR><ACK>
     else
       If out-of-sequence delivery permitted
          Copy the data (if any) to user buffers
       Endif
       Send <SEQ=SND.NXT><ACK=RCV.CUR><ACK><EACK><RCVDSEQNO1>
                 ...<RCVDSEQNOn>
    Endif
  Endif

Endif

If State = OPEN

  If RCV.CUR < SEG.SEQ =< RCV.CUR + (RCV.MAX * 2)
    Segment sequence number acceptable
   else
    Send <SEQ=SND.NXT><ACK=RCV.CUR><ACK>
    Discard segment and return
  Endif

  If RST set
    Set State = CLOSE-WAIT
    Signal "Connection Reset"
    Return
  Endif

  If NUL set
    Set RCV.CUR=SEG.SEQ
    Send <SEQ=SND.NXT><ACK=RCV.CUR><ACK>
    Discard segment
    Return
  Endif

  If SYN set
    Send <SEQ=SEG.ACK + 1><RST>
    Set State = CLOSED
    Signal "Connection Reset"
    Discard segment
    Deallocate connection record
    Return
  Endif

  If ACK set
    If SND.UNA =< SEG.ACK < SND.NXT
      Set SND.UNA = SEG.ACK
      Flush acknowledged segments
    Endif
  Endif

  If EACK set
    Flush acknowledged segments
  Endif

  If Data in segment
   If the received segment is in sequence
     Copy the data to user buffers
     Set RCV.CUR=SEG.SEQ
     Send <SEQ=SND.NXT><ACK=RCV.CUR><ACK>
    else
     If out-of-sequence delivery permitted
        Copy the data to user buffers
     Endif
     Send <SEQ=SND.NXT><ACK=RCV.CUR><ACK><EACK><RCVDSEQNO1>
                 ...<RCVDSEQNOn>
   Endif
  Endif
Endif

3.7.3 超时事件​

定时器到期并向 RDP 发出信号时,就会发生超时事件。可能出现两类超时事件,说明如下:

重传超时

  If timeout on segment at head of retransmission queue
Resend the segment at head of queue
Restart the retransmission timer for the segment
Requeue the segment on retransmission queue
Return
Endif

CLOSE-WAIT 超时

  Set State = CLOSED
Deallocate connection record
Return