net

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package net is based on [go-conntrack](https://github.com/mwitkow/go-conntrack)

Package net is based on [go-conntrack](https://github.com/mwitkow/go-conntrack)

Index

Constants

View Source
const (
	// LConnWrite means io.Copy writing to lconn
	LConnWrite = iota
	// RConnWrite means io.Copy writing to rconn
	RConnWrite
)

Variables

This section is empty.

Functions

func CopyCloseIO

func CopyCloseIO(lconn, rconn io.ReadWriteCloser) (lconnWritten, rconnWritten int64, err error)

CopyCloseIO establishes a full-duplex link between 2 ReadWriteClosers

func GenericTLSWrap added in v0.5.36

func GenericTLSWrap(conn net.Conn, cfg *tls.Config, tFunc TLSWrapperFunc) (*tls.Conn, error)

GenericTLSWrap takes a TCP connection, a tls config, and an upgrade function and returns the new connection

func HTTP2ALPNTLSWrap added in v0.5.36

func HTTP2ALPNTLSWrap(conn net.Conn, cfg *tls.Config, tFunc TLSWrapperFunc) (*tls.Conn, error)

HTTP2ALPNTLSWrap returns a TLS connection that has been negotiated with `h2` ALPN tFunc must be either tls.Client or tls.Server. See https://golang.org/pkg/crypto/tls/ for proper usage of the tls.Config with either of these options

NOTE: The ALPN is a requirement of the spec for HTTP/2 capability discovery While technically the golang implementation will allow us not to perform ALPN, this breaks the http/2 spec. The goal here is to follow the RFC to the letter as documented in http://httpwg.org/specs/rfc7540.html#starting

func NewListener

func NewListener(inner net.Listener, optFuncs ...ListenerOpt) (net.Listener, error)

NewListener returns the given listener wrapped in connection tracking listener.

func NewTCPListener

func NewTCPListener(inner *net.TCPListener, optFuncs ...ListenerOpt) net.Listener

NewTCPListener returns the given listener wrapped in connection tracking listener.

Types

type ConnPool added in v0.5.36

type ConnPool interface {
	// Insert returns a no error false case only when we try to insert
	// beyond our max connections limit
	Insert(ConnPoolObject) (bool, error)
	Get() ConnPoolContext
}

ConnPool is a fast concurrency safe connection pool structure

func NewConnPool added in v0.5.36

func NewConnPool(logger *logrus.Entry, maxConns int64, initialConns []ConnPoolObject) (ConnPool, error)

NewConnPool creates a new ConnPool

type ConnPoolContext added in v0.6.0

type ConnPoolContext interface {
	ConnPoolObject() ConnPoolObject
	// NumberOfUsers can be used in determining value for min heap
	NumberOfUsers() int64
	// Done reports to the ConnPool that you are done using this ConnPoolObject.
	// This should be done after ALL operations against the object are resolved
	Done()
}

ConnPoolContext is what a ConnPool returns from a Get

type ConnPoolObject added in v0.5.36

type ConnPoolObject interface {
	// Close handles any cleanup required for the connection
	// and is called whenever an object has been queued for deletion
	Close() error

	// ShouldDelete indicates whether a ConnPoolObject should be deleted from the pool
	// An example here would be if an http2 connection runs out of streams
	// NOTE: ShouldDelete should resolve quickly, as it has the possibility to deadlock the queue
	ShouldDelete() bool
}

ConnPoolObject represents an object to be handled by the connection pool NOTE: All functions implemented must be concurrency safe!

type ConnPoolObjectCanMux added in v0.6.0

type ConnPoolObjectCanMux interface {
	ConnPoolObject
	Value() <-chan int
}

ConnPoolObjectCanMux is an optimization for connections with muxable connections If used then they will be ordered by load value in a min-heap for extraction order

type CopyDirection

type CopyDirection int

CopyDirection describes the direction of data copying in full-duplex link

type ExtendedAddr added in v0.6.0

type ExtendedAddr interface {
	Data() interface{}
	net.Addr
}

ExtendedAddr allows for a net.Addr which provides extended data beyond String and Network

type FanInListenerFactoryArgs added in v0.6.0

type FanInListenerFactoryArgs struct {
	Factories []FanInListenerFactoryEntry
	Logger    *logrus.Logger
}

FanInListenerFactoryArgs defines how a FanInListenerFactory should be built

type FanInListenerFactoryEntry added in v0.6.0

type FanInListenerFactoryEntry struct {
	// Factory identifies the factory
	Factory ListenerFactory

	// ShouldCleanup determines if the given factory should close if the fan-in
	// factory closes too
	ShouldCleanup bool
}

FanInListenerFactoryEntry is a type defined for inserting factories into a FanInListenerFactory

type ListenerFactory added in v0.6.0

type ListenerFactory interface {
	// Listener returns a net.Listener
	Listener(args *ListenerFromFactoryArgs) (net.Listener, error)

	// Close tears down the factory and all required additions
	Close() error
}

ListenerFactory defines an interface for a factory which can create listeners

func NewFanInListenerFactory added in v0.6.0

func NewFanInListenerFactory(args *FanInListenerFactoryArgs) (ListenerFactory, error)

NewFanInListenerFactory return a new FanInListenerFactory from the args

func NewMultiPortTCPListenerFactory added in v0.6.0

func NewMultiPortTCPListenerFactory(args *MultiPortTCPListenerFactoryArgs) (ListenerFactory, error)

NewMultiPortTCPListenerFactory defines a new listener factory for standard type listeners

func NewSharedPortTLSListenerFactory added in v0.6.0

func NewSharedPortTLSListenerFactory(args *SharedPortTLSListenerFactoryArgs) (ListenerFactory, error)

NewSharedPortTLSListenerFactory creates a new listener factory for shared port TLS

type ListenerFromFactoryArgs added in v0.6.0

type ListenerFromFactoryArgs struct {
	// ID specifies an ID provided in an SNI
	// for now is ignored unless used from a sharedPortTLSListenerFactory instance
	ID string

	// BindHost allows us to wrap the returning Addr to report a hostname:port rather than an ip:port
	// If unspecified will use the IP
	BindHost string
}

ListenerFromFactoryArgs specify how to create a listener from a factory

type ListenerOpt added in v0.5.35

type ListenerOpt func(*listenerOpts)

ListenerOpt wraps listenerOpts in a func as convenience method to provide friendly API to configure connTrackListener

func TrackWithDeadline

func TrackWithDeadline(deadline time.Duration) ListenerOpt

TrackWithDeadline makes sure that SetDeadline is being called for `net.TCPListener` before each `Accept` call

func TrackWithLabels

func TrackWithLabels(labels map[string]string) ListenerOpt

TrackWithLabels sets additional labels of the Listener for use in tracking in monitoring.

func TrackWithName

func TrackWithName(name string) ListenerOpt

TrackWithName sets the name of the Listener for use in tracking and monitoring.

func TrackWithTCPKeepAlive

func TrackWithTCPKeepAlive(keepalive time.Duration) ListenerOpt

TrackWithTCPKeepAlive makes sure that any `net.TCPConn` that get accepted have a keep-alive. This is useful for HTTP servers in order for, for example laptops, to not use up resources on the server while they don't utilise their connection. A value of 0 disables it.

func TrackWithoutMonitoring

func TrackWithoutMonitoring() ListenerOpt

TrackWithoutMonitoring turns *off* Prometheus monitoring for this listener.

type MultiAddr added in v0.6.0

type MultiAddr interface {
	Addrs() []net.Addr
	net.Addr
}

MultiAddr allows for a net.Addr to contain multiple net.Addrs - where the base net.Addr is simply the first in the slice of []net.Addrs

type MultiPortTCPListenerFactoryArgs added in v0.6.0

type MultiPortTCPListenerFactoryArgs struct {
	// BindAddr should be only an IP or HostName. :0 will be appended to any given value
	BindAddr string
	Logger   *logrus.Logger
}

MultiPortTCPListenerFactoryArgs defines how to create a MultiPortTCPListenerFactory

type ServerConnTracker

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

ServerConnTracker is a wrapper around Net.Conn that tracks when connection is opened, closed and the duration of the connection

func (*ServerConnTracker) Close

func (ct *ServerConnTracker) Close() error

Close closes the connection and records metrics

func (*ServerConnTracker) Read

func (ct *ServerConnTracker) Read(b []byte) (n int, err error)

Read delegates to TCPConn's Read

func (*ServerConnTracker) ReadFrom

func (ct *ServerConnTracker) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom delegates to TCPConn's ReadFrom

func (*ServerConnTracker) ReportDataMetrics

func (ct *ServerConnTracker) ReportDataMetrics(sentBytes, rcvdBytes int64)

ReportDataMetrics reports bytes sent and received over the course of the duration of net.Conn

func (*ServerConnTracker) Write

func (ct *ServerConnTracker) Write(b []byte) (n int, err error)

Write delegates to TCPConn's Write

type SharedPortTLSListenerFactoryArgs added in v0.6.0

type SharedPortTLSListenerFactoryArgs struct {
	TLSConfig *tls.Config
	Address   string
	Logger    *logrus.Logger
}

SharedPortTLSListenerFactoryArgs provides the data needed to create a SharedPortTLSListenerFactory

type SharedTLSAddrExtendedData added in v0.6.0

type SharedTLSAddrExtendedData struct {
	ID     string
	CACert []byte
}

SharedTLSAddrExtendedData can be used when wanting to know more about an Addr

type TLSWrapperFunc added in v0.5.36

type TLSWrapperFunc func(conn net.Conn, cfg *tls.Config) *tls.Conn

TLSWrapperFunc represents a TLS Wrapper. This is intended to be either tls.Client or tls.Server see https://golang.org/pkg/crypto/tls/ for info

Jump to

Keyboard shortcuts

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