func (e *endpoint) StopWork() {
	e.workMu.Lock()
}
StopWork halts packet processing. Only to be used in tests.
package tcp
import (
	"encoding/binary"
	"fmt"
	"math"
	"strings"
	"sync"
	"sync/atomic"
	"time"
	"github.com/google/netstack/rand"
	"github.com/google/netstack/sleep"
	"github.com/google/netstack/tcpip"
	"github.com/google/netstack/tcpip/buffer"
	"github.com/google/netstack/tcpip/hash/jenkins"
	"github.com/google/netstack/tcpip/header"
	"github.com/google/netstack/tcpip/iptables"
	"github.com/google/netstack/tcpip/seqnum"
	"github.com/google/netstack/tcpip/stack"
	"github.com/google/netstack/tmutex"
	"github.com/google/netstack/waiter"
)
type EndpointState uint32
const (
	StateInitial EndpointState = iota
	StateBound
	StateConnecting  
	StateError
	StateEstablished
	StateSynSent
	StateSynRecv
	StateFinWait1
	StateFinWait2
	StateTimeWait
	StateClose
	StateCloseWait
	StateLastAck
	StateListen
	StateClosing
)
func (s EndpointState) connected() bool {
	switch s {
	case StateEstablished, StateFinWait1, StateFinWait2, StateTimeWait, StateCloseWait, StateLastAck, StateClosing:
		return true
	default:
		return false
	}
}
func (s EndpointState) String() string {
	switch s {
	case StateInitial:
		return "INITIAL"
	case StateBound:
		return "BOUND"
	case StateConnecting:
		return "CONNECTING"
	case StateError:
		return "ERROR"
	case StateEstablished:
		return "ESTABLISHED"
	case StateSynSent:
		return "SYN-SENT"
	case StateSynRecv:
		return "SYN-RCVD"
	case StateFinWait1:
		return "FIN-WAIT1"
	case StateFinWait2:
		return "FIN-WAIT2"
	case StateTimeWait:
		return "TIME-WAIT"
	case StateClose:
		return "CLOSED"
	case StateCloseWait:
		return "CLOSE-WAIT"
	case StateLastAck:
		return "LAST-ACK"
	case StateListen:
		return "LISTEN"
	case StateClosing:
		return "CLOSING"
	default:
		panic("unreachable")
	}
}
const (
	notifyNonZeroReceiveWindow = 1 << iota
	notifyReceiveWindowChanged
	notifyClose
	notifyMTUChanged
	notifyDrain
	notifyReset
	notifyKeepaliveChanged
	notifyMSSChanged
	notifyTickleWorker
)
type SACKInfo struct {
	Blocks [MaxSACKBlocks]header.SACKBlock
	NumBlocks int
}
type rcvBufAutoTuneParams struct {
	measureTime time.Time
	copied int
	prevCopied int
	rtt time.Duration
	rttMeasureSeqNumber seqnum.Value
	rttMeasureTime time.Time
	disabled bool
}
type ReceiveErrors struct {
	tcpip.ReceiveErrors
	SegmentQueueDropped tcpip.StatCounter
	ChecksumErrors tcpip.StatCounter
	ListenOverflowSynDrop tcpip.StatCounter
	ListenOverflowAckDrop tcpip.StatCounter
	ZeroRcvWindowState tcpip.StatCounter
}
type SendErrors struct {
	tcpip.SendErrors
	SegmentSendToNetworkFailed tcpip.StatCounter
	SynSendToNetworkFailed tcpip.StatCounter
	Retransmits tcpip.StatCounter
	FastRetransmit tcpip.StatCounter
	Timeouts tcpip.StatCounter
}
type Stats struct {
	SegmentsReceived tcpip.StatCounter
	SegmentsSent tcpip.StatCounter
	FailedConnectionAttempts tcpip.StatCounter
	ReceiveErrors ReceiveErrors
	ReadErrors tcpip.ReadErrors
	SendErrors SendErrors
	WriteErrors tcpip.WriteErrors
}
func (*Stats) IsEndpointStats() {}
type EndpointInfo struct {
	stack.TransportEndpointInfo
	HardError *tcpip.Error
}
func (*EndpointInfo) IsEndpointInfo() {}
type endpoint struct {
	EndpointInfo
	workMu tmutex.Mutex
	stack       *stack.Stack
	waiterQueue *waiter.Queue
	uniqueID    uint64
	lastErrorMu sync.Mutex
	lastError   *tcpip.Error
	rcvListMu     sync.Mutex
	rcvList       segmentList
	rcvClosed     bool
	rcvBufSize    int
	rcvBufUsed    int
	rcvAutoParams rcvBufAutoTuneParams
	zeroWindow bool
	mu sync.RWMutex
	state EndpointState
	origEndpointState EndpointState
	isPortReserved    bool
	isRegistered      bool
	boundNICID        tcpip.NICID
	route             stack.Route
	ttl               uint8
	v6only            bool
	isConnectNotified bool
	broadcast bool
	effectiveNetProtos []tcpip.NetworkProtocolNumber
	workerRunning bool
	workerCleanup bool
	sendTSOk bool
	recentTS uint32
	tsOffset uint32
	shutdownFlags tcpip.ShutdownFlags
	sackPermitted bool
	sack SACKInfo
	reusePort bool
	bindToDevice tcpip.NICID
	delay uint32
	cork uint32
	scoreboard *SACKScoreboard
	reuseAddr bool
	slowAck uint32
	segmentQueue segmentQueue
	synRcvdCount int
	userMSS uint16
	sndBufMu      sync.Mutex
	sndBufSize    int
	sndBufUsed    int
	sndClosed     bool
	sndBufInQueue seqnum.Size
	sndQueue      segmentList
	sndWaker      sleep.Waker
	sndCloseWaker sleep.Waker
	cc tcpip.CongestionControlOption
	packetTooBigCount int
	sndMTU            int
	newSegmentWaker sleep.Waker
	notificationWaker sleep.Waker
	notifyFlags uint32
	keepalive keepalive
	pendingAccepted sync.WaitGroup
	acceptedChan chan *endpoint
	rcv *receiver
	snd *sender
	drainDone chan struct{}
	undrain chan struct{}
	probe stack.TCPProbeFunc
	connectingAddress tcpip.Address
	amss uint16
	sendTOS uint8
	gso *stack.GSO
	stats Stats
	tcpLingerTimeout time.Duration
	closed bool
}
func (e *endpoint) UniqueID() uint64 {
	return e.uniqueID
}
func calculateAdvertisedMSS(userMSS uint16, r stack.Route) uint16 {
	maxMSS := mssForRoute(&r)
	if userMSS != 0 && userMSS < maxMSS {
		return userMSS
	}
	return maxMSS
}