tcp

package
v2.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	// Peeked are the bytes that have been read from Conn for the
	// purposes of route matching, but have not yet been consumed
	// by Read calls. It set to nil by Read when fully consumed.
	Peeked []byte

	// Conn is the underlying connection.
	// It can be type asserted against *net.TCPConn or other types
	// as needed. It should not be read from directly unless
	// Peeked is nil.
	WriteCloser
}

Conn is a connection proxy that handles Peeked bytes

func (*Conn) Read

func (c *Conn) Read(p []byte) (n int, err error)

Read reads bytes from the connection (using the buffer prior to actually reading)

type Handler

type Handler interface {
	ServeTCP(conn WriteCloser)
}

Handler is the TCP Handlers interface

type HandlerFunc

type HandlerFunc func(conn WriteCloser)

The HandlerFunc type is an adapter to allow the use of ordinary functions as handlers.

func (HandlerFunc) ServeTCP

func (f HandlerFunc) ServeTCP(conn WriteCloser)

ServeTCP serves tcp

type HandlerSwitcher

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

HandlerSwitcher is a TCP handler switcher

func (*HandlerSwitcher) ServeTCP

func (s *HandlerSwitcher) ServeTCP(conn WriteCloser)

ServeTCP forwards the TCP connection to the current active handler

func (*HandlerSwitcher) Switch

func (s *HandlerSwitcher) Switch(handler Handler)

Switch sets the new TCP handler to use for new connections

type Proxy

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

Proxy forwards a TCP request to a TCP service

func NewProxy

func NewProxy(address string, terminationDelay time.Duration) (*Proxy, error)

NewProxy creates a new Proxy

func (*Proxy) ServeTCP

func (p *Proxy) ServeTCP(conn WriteCloser)

ServeTCP forwards the connection to a service

type Router

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

Router is a TCP router

func (*Router) AddCatchAllNoTLS

func (r *Router) AddCatchAllNoTLS(handler Handler)

AddCatchAllNoTLS defines the fallback tcp handler

func (*Router) AddRoute

func (r *Router) AddRoute(sniHost string, target Handler)

AddRoute defines a handler for a given sniHost (* is the only valid option)

func (*Router) AddRouteHTTPTLS

func (r *Router) AddRouteHTTPTLS(sniHost string, config *tls.Config)

AddRouteHTTPTLS defines a handler for a given sniHost and sets the matching tlsConfig

func (*Router) AddRouteTLS

func (r *Router) AddRouteTLS(sniHost string, target Handler, config *tls.Config)

AddRouteTLS defines a handler for a given sniHost and sets the matching tlsConfig

func (*Router) GetConn

func (r *Router) GetConn(conn WriteCloser, peeked string) WriteCloser

GetConn creates a connection proxy with a peeked string

func (*Router) GetHTTPHandler

func (r *Router) GetHTTPHandler() http.Handler

GetHTTPHandler gets the attached http handler

func (*Router) GetHTTPSHandler

func (r *Router) GetHTTPSHandler() http.Handler

GetHTTPSHandler gets the attached https handler

func (*Router) HTTPForwarder

func (r *Router) HTTPForwarder(handler Handler)

HTTPForwarder sets the tcp handler that will forward the connections to an http handler

func (*Router) HTTPHandler

func (r *Router) HTTPHandler(handler http.Handler)

HTTPHandler attaches http handlers on the router

func (*Router) HTTPSForwarder

func (r *Router) HTTPSForwarder(handler Handler)

HTTPSForwarder sets the tcp handler that will forward the TLS connections to an http handler

func (*Router) HTTPSHandler

func (r *Router) HTTPSHandler(handler http.Handler, config *tls.Config)

HTTPSHandler attaches https handlers on the router

func (*Router) ServeTCP

func (r *Router) ServeTCP(conn WriteCloser)

ServeTCP forwards the connection to the right TCP/HTTP handler

type TLSHandler

type TLSHandler struct {
	Next   Handler
	Config *tls.Config
}

TLSHandler handles TLS connections

func (*TLSHandler) ServeTCP

func (t *TLSHandler) ServeTCP(conn WriteCloser)

ServeTCP terminates the TLS connection

type WRRLoadBalancer

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

WRRLoadBalancer is a naive RoundRobin load balancer for TCP services

func NewWRRLoadBalancer

func NewWRRLoadBalancer() *WRRLoadBalancer

NewWRRLoadBalancer creates a new WRRLoadBalancer

func (*WRRLoadBalancer) AddServer

func (b *WRRLoadBalancer) AddServer(serverHandler Handler)

AddServer appends a server to the existing list

func (*WRRLoadBalancer) AddWeightServer

func (b *WRRLoadBalancer) AddWeightServer(serverHandler Handler, weight *int)

AddWeightServer appends a server to the existing list with a weight

func (*WRRLoadBalancer) ServeTCP

func (b *WRRLoadBalancer) ServeTCP(conn WriteCloser)

ServeTCP forwards the connection to the right service

type WriteCloser

type WriteCloser interface {
	net.Conn
	// CloseWrite on a network connection, indicates that the issuer of the call
	// has terminated sending on that connection.
	// It corresponds to sending a FIN packet.
	CloseWrite() error
}

WriteCloser describes a net.Conn with a CloseWrite method.

Jump to

Keyboard shortcuts

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