tcp

package
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package tcp contains the implementation of the TCP transport protocol. To use it in the networking stack, this package must be added to the project, and activated on the stack by passing tcp.ProtocolName (or "tcp") as one of the transport protocols when calling stack.New(). Then endpoints can be created by passing tcp.ProtocolNumber as the transport protocol number when calling Stack.NewEndpoint().

Index

Constants

View Source
const (
	// ProtocolName is the string representation of the tcp protocol name.
	ProtocolName = "tcp"

	// ProtocolNumber is the tcp protocol number.
	ProtocolNumber = header.TCPProtocolNumber

	// DefaultBufferSize is the default size of the receive and send buffers.
	DefaultBufferSize = 1 << 20 // 1MB

)
View Source
const (

	// InitialCwnd is the initial congestion window.
	// 初始拥塞窗口大小
	InitialCwnd = 10
)
View Source
const (
	// MaxSACKBlocks is the maximum number of SACK blocks stored
	// at receiver side.
	// MaxSACKBlocks 是接收端存储的最大SACK块数。
	MaxSACKBlocks = 6
)

Variables

View Source
var (
	// SynRcvdCountThreshold is the global maximum number of connections
	// that are allowed to be in SYN-RCVD state before TCP starts using SYN
	// cookies to accept connections.
	//
	// It is an exported variable only for testing, and should not otherwise
	// be used by importers of this package.
	SynRcvdCountThreshold uint64 = 1000
)

Functions

func FindWndScale

func FindWndScale(wnd seqnum.Size) int

FindWndScale determines the window scale to use for the given maximum window size. 因为窗口的大小不能超过序列号范围的一半,即窗口最大2^30, so (2^16)*(2^maxWnsScale) < 2^30,get maxWnsScale = 14

func TrimSACKBlockList

func TrimSACKBlockList(sack *SACKInfo, rcvNxt seqnum.Value)

TrimSACKBlockList updates the sack block list by removing/modifying any block where start is < rcvNxt. tcp的可靠性:TrimSACKBlockList 通过删除/修改 start为 <rcvNxt 的任何块来更新sack块列表。

func UpdateSACKBlocks

func UpdateSACKBlocks(sack *SACKInfo, segStart seqnum.Value, segEnd seqnum.Value, rcvNxt seqnum.Value)

UpdateSACKBlocks updates the list of SACK blocks to include the segment specified by segStart->segEnd. If the segment happens to be an out of order delivery then the first block in the sack.blocks always includes the segment identified by segStart->segEnd. tcp的可靠性:UpdateSACKBlocks 更新SACK块列表以包含 segStart-segEnd 指定的段,只有没有被消费掉的seg才会被用来更新sack。 如果该段恰好是无序传递,那么sack.blocks中的第一个块总是包括由 segStart-segEnd 标识的段。

Types

type AvailableCongestionControlOption

type AvailableCongestionControlOption string

AvailableCongestionControlOption returns the supported congestion control algorithms.

type CongestionControlOption

type CongestionControlOption string

CongestionControlOption sets the current congestion control algorithm.

type Forwarder

type Forwarder struct {
	// contains filtered or unexported fields
}

Forwarder is a connection request forwarder, which allows clients to decide what to do with a connection request, for example: ignore it, send a RST, or attempt to complete the 3-way handshake.

The canonical way of using it is to pass the Forwarder.HandlePacket function to stack.SetTransportProtocolHandler. Forwarder是一个连接请求转发器,它允许客户端决定如何处理连接请求,例如:忽略它,发送RST或尝试完成3次握手。

使用它的规范方法是将Forwarder.HandlePacket函数传递给stack.SetTransportProtocolHandler。

func NewForwarder

func NewForwarder(s *stack.Stack, rcvWnd, maxInFlight int, handler func(*ForwarderRequest)) *Forwarder

NewForwarder allocates and initializes a new forwarder with the given maximum number of in-flight connection attempts. Once the maximum is reached new incoming connection requests will be ignored.

If rcvWnd is set to zero, the default buffer size is used instead.

func (*Forwarder) HandlePacket

HandlePacket handles a packet if it is of interest to the forwarder (i.e., if it's a SYN packet), returning true if it's the case. Otherwise the packet is not handled and false is returned.

This function is expected to be passed as an argument to the stack.SetTransportProtocolHandler function.

type ForwarderRequest

type ForwarderRequest struct {
	// contains filtered or unexported fields
}

ForwarderRequest represents a connection request received by the forwarder and passed to the client. Clients must eventually call Complete() on it, and may optionally create an endpoint to represent it via CreateEndpoint.

func (*ForwarderRequest) Complete

func (r *ForwarderRequest) Complete(sendReset bool)

Complete completes the request, and optionally sends a RST segment back to the sender.

func (*ForwarderRequest) CreateEndpoint

func (r *ForwarderRequest) CreateEndpoint(queue *waiter.Queue) (tcpip.Endpoint, *tcpip.Error)

CreateEndpoint creates a TCP endpoint for the connection request, performing the 3-way handshake in the process.

func (*ForwarderRequest) ID

ID returns the 4-tuple (src address, src port, dst address, dst port) that represents the connection request.

type ReceiveBufferSizeOption

type ReceiveBufferSizeOption struct {
	Min     int
	Default int
	Max     int
}

ReceiveBufferSizeOption allows the default, min and max receive buffer size for TCP endpoints to be queried or configured.

type SACKEnabled

type SACKEnabled bool

SACKEnabled option can be used to enable SACK support in the TCP protocol. See: https://tools.ietf.org/html/rfc2018.

type SACKInfo

type SACKInfo struct {
	// Blocks is the maximum number of SACK blocks we track
	// per endpoint.
	Blocks [MaxSACKBlocks]header.SACKBlock

	// NumBlocks is the number of valid SACK blocks stored in the
	// blocks array above.
	NumBlocks int
}

SACKInfo holds TCP SACK related information for a given endpoint.

+stateify savable

type SendBufferSizeOption

type SendBufferSizeOption struct {
	Min     int
	Default int
	Max     int
}

SendBufferSizeOption allows the default, min and max send buffer sizes for TCP endpoints to be queried or configured.

Directories

Path Synopsis
testing
context
Package context provides a test context for use in tcp tests.
Package context provides a test context for use in tcp tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL