netx

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: Apache-2.0 Imports: 14 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CurrentOpenConns = promauto.NewGauge(
		prometheus.GaugeOpts{
			Name: "netx_current_open_conns",
			Help: "A gauge of currently open netx.Conns with open file pointers.",
		},
	)
)

Metrics for resource accounting in the netx package.

Functions

func ToTCPAddr

func ToTCPAddr(addr net.Addr) *net.TCPAddr

ToTCPAddr is a helper function for extracting the net.TCPAddr type from a net.Addr of various origins. ToTCPAddr returns nil if addr does not contain a *net.TCPAddr.

Types

type Addr

type Addr struct {
	net.Addr
	// contains filtered or unexported fields
}

Addr supports the net.Addr interface and allows mediated access to operations on the parent Conn.

Why is this necessary? The Conn type accessible to application code is a function of the server protocol. In particular, the tls.Conn is created by a TLS Server, regardless of the underlying Listener type. Because a tls.Conn is a struct, not an interface, and because tls.Conn does not provide access to the underlying net.Conn, we still need a way to access the underlying Conn type in order to access and operate on the underlying connection file descriptor.

So, to support all server protocols using the Listener, we "piggyback" on the net.Conn interface supported by tls.Conns. In particular, the LocalAddr and RemoteAddr methods return an Addr type, which includes a parent reference to the associated Conn.

Because the Addr includes references to the parent Conn, all Addrs should be released before calling Conn.Close.

type Conn

type Conn struct {
	net.Conn
	// contains filtered or unexported fields
}

Conn is returned by Listener.Accept and provides mediated access to additional operations on the Conn file descriptor.

func (*Conn) Close

func (mc *Conn) Close() error

Close the underlying net.Conn and dup'd file descriptor. Note: all net.Addr's returned by LocalAddr and RemoteAddr should be released before calling Close.

func (*Conn) EnableBBR

func (mc *Conn) EnableBBR() error

EnableBBR sets the BBR congestion control on the TCP connection, if supported by the kernel. If unsupported, EnableBBR has no effect.

func (*Conn) GetUUID

func (mc *Conn) GetUUID() (string, error)

GetUUID returns the connection's UUID.

func (*Conn) LocalAddr

func (mc *Conn) LocalAddr() net.Addr

LocalAddr returns an Addr supporting the net.Addr interface, which provides access to the parent Conn.

func (*Conn) ReadInfo

func (mc *Conn) ReadInfo() (inetdiag.BBRInfo, tcp.LinuxTCPInfo, error)

ReadInfo reads metadata about the TCP connections. If BBR was not enabled on the underlying connection, then ReadInfo will return an empty BBRInfo struct. If TCP info metrics cannot be read, an error is returned.

func (*Conn) RemoteAddr

func (mc *Conn) RemoteAddr() net.Addr

RemoteAddr returns an Addr supporting the net.Addr interface, which provides access to the parent Conn.

type ConnInfo

type ConnInfo interface {
	GetUUID() (string, error)
	EnableBBR() error
	ReadInfo() (inetdiag.BBRInfo, tcp.LinuxTCPInfo, error)
}

ConnInfo provides operations on a Conn's underlying file descriptor.

func ToConnInfo

func ToConnInfo(conn net.Conn) ConnInfo

ToConnInfo is a helper function for extracting the ConnInfo interface from the net.Conn of various origins. ToConnInfo panics if conn does not contain a type supporting ConnInfo.

type Listener

type Listener struct {
	*net.TCPListener
	// contains filtered or unexported fields
}

Listener is a TCPListener that is suitable for raw TCP servers, HTTP servers, and TLS HTTP servers. The Conn's returned by Listener.Accept mediate access to the underlying Conn file descriptor, allowing callers to perform meta operations on the connection, e.g. GetUUID, EnableBBR, ReadInfo.

func NewListener

func NewListener(l *net.TCPListener) *Listener

NewListener creates a new Listener using the given net.TCPListener.

func (*Listener) Accept

func (ln *Listener) Accept() (net.Conn, error)

Accept a connection, set 3min keepalive, and return a Conn that enables ConnInfo operations on the underlying net.Conn file descriptor.

Directories

Path Synopsis
Package iface provides access to network connection operations via file descriptor.
Package iface provides access to network connection operations via file descriptor.

Jump to

Keyboard shortcuts

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