func (r *receiver) consumeSegment(s *segment, segSeq seqnum.Value, segLen seqnum.Size) bool {
	if segLen > 0 {
		if !r.rcvNxt.InWindow(segSeq, segLen) {
			return false
		}
		if segSeq.LessThan(r.rcvNxt) {
			diff := segSeq.Size(r.rcvNxt)
			segLen -= diff
			segSeq.UpdateForward(diff)
			s.sequenceNumber.UpdateForward(diff)
			s.data.TrimFront(int(diff))
		}
		r.ep.readyToRead(s)
	} else if segSeq != r.rcvNxt {
		return false
	}
	r.rcvNxt = segSeq.Add(segLen)
	if r.rcvAcc.LessThan(r.rcvNxt) {
		r.rcvAcc = r.rcvNxt
	}
	TrimSACKBlockList(&r.ep.sack, r.rcvNxt)
	if s.flagIsSet(header.TCPFlagFin) {
		r.rcvNxt++
		r.ep.snd.sendAck()
		r.closed = true
		r.ep.readyToRead(nil)
		r.ep.mu.Lock()
		switch r.ep.state {
		case StateEstablished:
			r.ep.state = StateCloseWait
		case StateFinWait1:
			if s.flagIsSet(header.TCPFlagAck) {
				r.ep.state = StateTimeWait
			} else {
				r.ep.state = StateClosing
			}
		case StateFinWait2:
			r.ep.state = StateTimeWait
		}
		r.ep.mu.Unlock()
		first := 0
		if len(r.pendingRcvdSegments) != 0 && r.pendingRcvdSegments[0] == s {
			first = 1
		}
		for i := first; i < len(r.pendingRcvdSegments); i++ {
			r.pendingRcvdSegments[i].decRef()
		}
		r.pendingRcvdSegments = r.pendingRcvdSegments[:first]
		return true
	}
	if s.flagIsSet(header.TCPFlagAck) {
		r.ep.mu.Lock()
		switch r.ep.state {
		case StateFinWait1:
			r.ep.state = StateFinWait2
			r.ep.notifyProtocolGoroutine(notifyClose)
		case StateClosing:
			r.ep.state = StateTimeWait
		case StateLastAck:
			r.ep.transitionToStateCloseLocked()
		}
		r.ep.mu.Unlock()
	}
	return true
}
consumeSegment attempts to consume a segment that was received by r. The
segment may have just been received or may have been received earlier but
wasn't ready to be consumed then.

Returns true if the segment was consumed, false if it cannot be consumed
yet because of a missing segment.
package tcp
import (
	"container/heap"
	"time"
	"github.com/google/netstack/tcpip"
	"github.com/google/netstack/tcpip/header"
	"github.com/google/netstack/tcpip/seqnum"
)
type receiver struct {
	ep *endpoint
	rcvNxt seqnum.Value
	rcvAcc seqnum.Value
	rcvWnd seqnum.Size
	rcvWndScale uint8
	closed bool
	pendingRcvdSegments segmentHeap
	pendingBufUsed      seqnum.Size
	pendingBufSize      seqnum.Size
}
func newReceiver(ep *endpoint, irs seqnum.Value, rcvWnd seqnum.Size, rcvWndScale uint8, pendingBufSize seqnum.Size) *receiver {
	return &receiver{
		ep:             ep,
		rcvNxt:         irs + 1,
		rcvAcc:         irs.Add(rcvWnd + 1),
		rcvWnd:         rcvWnd,
		rcvWndScale:    rcvWndScale,
		pendingBufSize: pendingBufSize,
	}
}
func (r *receiver) acceptable(segSeq seqnum.Value, segLen seqnum.Size) bool {
	rcvWnd := r.rcvNxt.Size(r.rcvAcc)
	if rcvWnd == 0 {
		return segLen == 0 && segSeq == r.rcvNxt
	}
	return segSeq.InWindow(r.rcvNxt, rcvWnd) ||
		seqnum.Overlap(r.rcvNxt, rcvWnd, segSeq, segLen)
}
func (r *receiver) getSendParams() (rcvNxt seqnum.Value, rcvWnd seqnum.Size) {
	receiveBufferAvailable := r.ep.receiveBufferAvailable()
	acc := r.rcvNxt.Add(seqnum.Size(receiveBufferAvailable))
	if r.rcvAcc.LessThan(acc) {
		r.rcvAcc = acc
	}
	r.rcvWnd = r.rcvNxt.Size(r.rcvAcc)
	return r.rcvNxt, r.rcvWnd >> r.rcvWndScale
}
func (r *receiver) nonZeroWindow() {
	if (r.rcvAcc-r.rcvNxt)>>r.rcvWndScale != 0 {
		return
	}
	r.ep.snd.sendAck()
}