tfo

package module
v0.0.0-...-5a5c285 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 7 Imported by: 24

README

tfo-go

tfo-go provides TCP Fast Open support for the net dialer and listener.

go get github.com/sagernet/tfo-go

License

MIT

Documentation

Overview

Package tfo provides TCP Fast Open support for the net dialer and listener.

The dial functions have an additional buffer parameter, which specifies data in SYN. If the buffer is empty, TFO is not used.

This package supports Linux, Windows, macOS, and FreeBSD. On unsupported platforms, ErrPlatformUnsupported is returned.

FreeBSD code is completely untested. Use at your own risk. Feedback is welcome.

Index

Constants

View Source
const TCPFastopenQueueLength = 4096

TCPFastopenQueueLength sets the maximum number of total pending TFO connection requests. ref: https://datatracker.ietf.org/doc/html/rfc7413#section-5.1 We default to 4096 to align with listener's default backlog. Change to a lower value if your application is vulnerable to such attacks.

Variables

This section is empty.

Functions

func Dial

func Dial(network, address string, b []byte) (net.Conn, error)

Dial is like net.Dial but enables TFO whenever possible.

func DialTCP

func DialTCP(network string, laddr, raddr *net.TCPAddr, b []byte) (*net.TCPConn, error)

DialTCP is like net.DialTCP but enables TFO whenever possible.

func DialTimeout

func DialTimeout(network, address string, timeout time.Duration, b []byte) (net.Conn, error)

DialTimeout is like net.DialTimeout but enables TFO whenever possible.

func Listen

func Listen(network, address string) (net.Listener, error)

Listen is like net.Listen but enables TFO whenever possible.

func ListenContext

func ListenContext(ctx context.Context, network, address string) (net.Listener, error)

ListenContext is like net.ListenContext but enables TFO whenever possible.

func ListenTCP

func ListenTCP(network string, laddr *net.TCPAddr) (*net.TCPListener, error)

ListenTCP is like net.ListenTCP but enables TFO whenever possible.

func SetTFODialer

func SetTFODialer(fd uintptr) error

func SetTFOListener

func SetTFOListener(fd uintptr) error

Types

type Dialer

type Dialer struct {
	net.Dialer

	// DisableTFO controls whether TCP Fast Open is disabled when the dial methods are called.
	// TFO is enabled by default.
	// Set to true to disable TFO and it will behave exactly the same as [net.Dialer].
	DisableTFO bool
}

Dialer wraps net.Dialer with an additional option that allows you to disable TFO.

func (*Dialer) Dial

func (d *Dialer) Dial(network, address string, b []byte) (net.Conn, error)

Dial is like net.Dialer.Dial but enables TFO whenever possible, unless [Dialer.DisableTFO] is set to true.

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, network, address string, b []byte) (net.Conn, error)

DialContext is like net.Dialer.DialContext but enables TFO whenever possible, unless [Dialer.DisableTFO] is set to true.

type ListenConfig

type ListenConfig struct {
	net.ListenConfig

	// DisableTFO controls whether TCP Fast Open is disabled when the Listen method is called.
	// TFO is enabled by default.
	// Set to true to disable TFO and it will behave exactly the same as [net.ListenConfig].
	DisableTFO bool
}

ListenConfig wraps net.ListenConfig with an additional option that allows you to disable TFO.

func (*ListenConfig) Listen

func (lc *ListenConfig) Listen(ctx context.Context, network, address string) (net.Listener, error)

Listen is like net.ListenConfig.Listen but enables TFO whenever possible, unless [ListenConfig.DisableTFO] is set to true.

type PlatformUnsupportedError

type PlatformUnsupportedError struct{}

PlatformUnsupportedError is returned when tfo-go does not support TCP Fast Open on the current platform.

var (
	ErrPlatformUnsupported PlatformUnsupportedError
)

func (PlatformUnsupportedError) Error

func (PlatformUnsupportedError) Is

func (PlatformUnsupportedError) Is(target error) bool

Jump to

Keyboard shortcuts

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