guttle

package module
v0.0.0-...-89102db Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 18 Imported by: 2

Documentation

Index

Constants

View Source
const SO_ORIGINAL_DST = 80

Variables

View Source
var ErrRedialAborted = errors.New("unable to restore the connection, aborting")

ErrRedialAborted is returned by Client.Start when the configured backoff strategy gives up.

Functions

func Join

func Join(local, remote net.Conn, logger log.Logger)

Join copies data between local and remote connections. It reads from one connection and writes to the other. It's a building block for ProxyFunc implementations.

Types

type Backoff

type Backoff interface {
	// Next returns the duration to sleep before retrying reconnections.
	// If the returned value is negative, the retry is aborted.
	NextBackOff() time.Duration

	// Reset is used to signal a reconnection was successful and next
	// call to Next should return desired time duration for 1st reconnection
	// attempt.
	Reset()
}

Backoff defines behavior of staggering reconnection retries.

type Client

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

Client is responsible for connecting to a tunnel server.

func NewClient

func NewClient(opts *ClientOptions) *Client

NewClient create a new Client

func (*Client) Start

func (c *Client) Start() error

Start the client and connects to the server

func (*Client) Stop

func (c *Client) Stop()

Stop signals a running client to disconnect. It returns immediately.

type ClientOptions

type ClientOptions struct {
	// ServerAddr defines the TCP address of the tunnel server to be connected.
	ServerAddr string
	// Dial provides custom transport layer for client server communication.
	Dial func(network, address string) (net.Conn, error)

	//ProxyFunc provides a hook for forwarding a tunneled connection to its destination.
	//If non is given SourceRoutedProxy() is used by default.
	ProxyFunc ProxyFunc

	//ListenAddr optinally lets the Client open a listening socket and forward traffic
	//received on the listener to the tunnel server.
	ListenAddr string

	// Backoff is used to control behavior of staggering reconnection loop.
	//
	// If nil, default backoff policy is used which makes a client to never
	// give up on reconnection.
	//
	// If custom backoff is used, Start() will return ErrRedialAborted set
	// with ClientClosed event when no more reconnection atttemps should
	// be made.
	Backoff Backoff

	//Logger used by this service instance
	Logger log.Logger
}

ClientOptions defines the configuration for the Client

type Header struct {
	DestIP   [4]byte
	DestPort uint16
}

Header contains metadata about tunnel requests.

func (Header) Destination

func (p Header) Destination() string

Destination returns the destination as ip:port

func (Header) DestinationIP

func (p Header) DestinationIP() net.IP

DestinationIP returns the destination ip for a tunnel request.

func (Header) DestinationPort

func (p Header) DestinationPort() int

DestinationPort returns the destination port for a tunnle request.

type ProxyFunc

type ProxyFunc func(remote net.Conn, hdr Header, logger log.Logger)

ProxyFunc is responsible for forwarding a tunneled connection to a local destination and writing the response back.

func NoProxy

func NoProxy() ProxyFunc

NoProxy returns a ProxyFunc that does nothing

func SourceRoutedProxy

func SourceRoutedProxy() ProxyFunc

SourceRoutedProxy returns a ProxyFunc that honors the header information of the proxied request and forwards traffic to the given header information.

func StaticProxy

func StaticProxy(destination string) ProxyFunc

StaticProxy ignores the request header and forwards traffic to a static destination

type Server

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

Server is a tunel Server accepting connections from tunnel clients

func NewServer

func NewServer(opts *ServerOptions) *Server

NewServer creates a new tunnel server

func (*Server) AddClientRoute

func (s *Server) AddClientRoute(cidr string, identifier string) error

AddClientRoute adds a route for specific tunnel client. Local tunnel requests for ips that match the given CIDR are routed to the specified client. If a request is matched by multiple routes a random route is choosen.

func (*Server) AddRoute

func (s *Server) AddRoute(cidr string) error

AddRoute adds a generic route for all client. Incoming request that are matched by the given CIDR are routed to any active client. Generic routes are considered when no client route matched for the given request.

func (*Server) Close

func (s *Server) Close()

Close signals a running server to stop. It returns immediately.

func (*Server) DeleteClientRoute

func (s *Server) DeleteClientRoute(cidr, identifier string) error

DeleteClientRoute deletes a route created with AddClientRoute

func (*Server) DeleteRoute

func (s *Server) DeleteRoute(cidr string) error

DeleteRoute deletes a generic route.

func (*Server) Start

func (s *Server) Start() error

Start starts the tunnel server and blocks until it is stopped

type ServerOptions

type ServerOptions struct {
	//Listener is used for accepting tunnel clients.
	//Default: net.Listen("tcp", ":9090")
	Listener net.Listener

	//HijackAddr specifies a local address the server should
	//accept connections on and forward them to tunnel clients.
	//Default: 127.0.0.1:9191
	HijackAddr string

	//ProxyFunc provides a hook for forwarding a tunneled connection to its destination.
	//If non is given NoProxy() is used by default.
	ProxyFunc ProxyFunc

	//Logger used by this service instance
	Logger log.Logger
}

ServerOptions hold the configration of a tunnel server

type StdlibAdapter

type StdlibAdapter struct {
	Logger log.Logger
}

func (StdlibAdapter) Write

func (a StdlibAdapter) Write(p []byte) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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