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
- func Dial(network, address string, b []byte) (net.Conn, error)
- func DialTCP(network string, laddr, raddr *net.TCPAddr, b []byte) (*net.TCPConn, error)
- func DialTimeout(network, address string, timeout time.Duration, b []byte) (net.Conn, error)
- func Listen(network, address string) (net.Listener, error)
- func ListenContext(ctx context.Context, network, address string) (net.Listener, error)
- func ListenTCP(network string, laddr *net.TCPAddr) (*net.TCPListener, error)
- func SetTFODialer(fd uintptr) error
- func SetTFOListener(fd uintptr) error
- type Dialer
- type ListenConfig
- type PlatformUnsupportedError
Constants ¶
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 DialTCP ¶
DialTCP is like net.DialTCP but enables TFO whenever possible.
func DialTimeout ¶
DialTimeout is like net.DialTimeout but enables TFO whenever possible.
func Listen ¶
Listen is like net.Listen but enables TFO whenever possible.
func ListenContext ¶
ListenContext is like net.ListenContext but enables TFO whenever possible.
func ListenTCP ¶
ListenTCP is like net.ListenTCP but enables TFO whenever possible.
func SetTFODialer ¶
func SetTFOListener ¶
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 ¶
Dial is like net.Dialer.Dial 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 ¶
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) Error() string
func (PlatformUnsupportedError) Is ¶
func (PlatformUnsupportedError) Is(target error) bool