layer4

package
v0.0.0-...-0e21b06 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// VarsCtxKey is the key used to store the variables table
	// in a Connection's context.
	VarsCtxKey caddy.CtxKey = "vars"

	// ReplacerCtxKey is the key used to store the replacer.
	ReplacerCtxKey caddy.CtxKey = "replacer"
)

Functions

This section is empty.

Types

type App

type App struct {
	Servers map[string]*Server `json:"servers,omitempty"`
	// contains filtered or unexported fields
}

App is a Caddy app that operates closest to layer 4 of the OSI model.

func (App) CaddyModule

func (App) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*App) Provision

func (a *App) Provision(ctx caddy.Context) error

Provision sets up the app.

func (*App) Start

func (a *App) Start() error

Start starts the app.

func (App) Stop

func (a App) Stop() error

Stop stops the servers and closes all listeners.

type ConnMatcher

type ConnMatcher interface {
	// Match returns true if the given connection matches.
	// It should read from the connection as little as possible:
	// only as much as necessary to determine a match.
	Match(*Connection) (bool, error)
}

ConnMatcher is a type that can match a connection.

type Connection

type Connection struct {
	// The underlying connection.
	net.Conn

	// The context for the connection.
	Context context.Context
	// contains filtered or unexported fields
}

Connection contains information about the connection as it passes through various handlers. It also has the capability of recording and rewinding when necessary.

A Connection can be used as a net.Conn because it embeds a net.Conn; but when wrapping underlying connections, usually you want to be careful to replace the embedded Conn, not this entire Connection value.

Connection structs are NOT safe for concurrent use.

func WrapConnection

func WrapConnection(underlying net.Conn, buf *bytes.Buffer) *Connection

WrapConnection wraps an underlying connection into a layer4 connection that supports recording and rewinding, as well as adding context with a replacer and variable table. This function is intended for use at the start of a connection handler chain where the underlying connection is not yet a layer4 Connection value.

func (Connection) GetVar

func (cx Connection) GetVar(key string) interface{}

GetVar gets a value from the context's variable table with the given key. It returns the value if found, and true if it found a value with that key; false otherwise.

func (*Connection) Read

func (cx *Connection) Read(p []byte) (n int, err error)

Read implements io.Reader in such a way that reads first deplete any associated buffer from the prior recording, and once depleted (or if there isn't one), it continues reading from the underlying connection.

func (Connection) SetVar

func (cx Connection) SetVar(key string, value interface{})

SetVar sets a value in the context's variable table with the given key. It overwrites any previous value with the same key.

func (*Connection) Wrap

func (cx *Connection) Wrap(conn net.Conn) *Connection

Wrap wraps conn in a new Connection based on cx (reusing cx's existing buffer and context). This is useful after a connection is wrapped by a package that does not support our Connection type (for example, `tls.Server()`).

func (*Connection) Write

func (cx *Connection) Write(p []byte) (n int, err error)

type Handler

type Handler interface {
	Handle(*Connection) error
}

Handler is a type that can handle connections.

type HandlerFunc

type HandlerFunc func(*Connection) error

HandlerFunc can turn a function into a Handler type.

func (HandlerFunc) Handle

func (h HandlerFunc) Handle(cx *Connection) error

Handle handles a connection; it implements the Handler interface.

type Handlers

type Handlers []NextHandler

Handlers is a list of connection handlers.

func (Handlers) Compile

func (h Handlers) Compile() Handler

Compile assembles the list of handlers into a single handler chain.

type MatchIP

type MatchIP struct {
	Ranges []string `json:"ranges,omitempty"`
	// contains filtered or unexported fields
}

MatchIP matches requests by remote IP (or CIDR range).

func (MatchIP) CaddyModule

func (MatchIP) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (MatchIP) Match

func (m MatchIP) Match(cx *Connection) (bool, error)

Match returns true if the connection is from one of the designated IP ranges.

func (*MatchIP) Provision

func (m *MatchIP) Provision(ctx caddy.Context) error

Provision parses m's IP ranges, either from IP or CIDR expressions.

type MatcherSet

type MatcherSet []ConnMatcher

MatcherSet is a set of matchers which must all match in order for the request to be matched successfully.

func (MatcherSet) Match

func (mset MatcherSet) Match(cx *Connection) (matched bool, err error)

Match returns true if the connection matches all matchers in mset or if there are no matchers. Any error terminates matching.

type MatcherSets

type MatcherSets []MatcherSet

MatcherSets is a group of matcher sets capable of checking whether a connection matches any of the sets.

func (MatcherSets) AnyMatch

func (mss MatcherSets) AnyMatch(cx *Connection) (matched bool, err error)

AnyMatch returns true if the connection matches any of the matcher sets in mss or if there are no matchers, in which case the request always matches. Any error terminates matching.

func (*MatcherSets) FromInterface

func (mss *MatcherSets) FromInterface(matcherSets interface{}) error

FromInterface fills ms from an interface{} value obtained from LoadModule.

type Middleware

type Middleware func(Handler) Handler

Middleware is a function that wraps a handler.

type NextHandler

type NextHandler interface {
	Handle(*Connection, Handler) error
}

NextHandler is a type that can handle connections as part of a middleware chain.

type RawMatcherSets

type RawMatcherSets []caddy.ModuleMap

RawMatcherSets is a group of matcher sets in their raw JSON form.

type Route

type Route struct {
	MatcherSetsRaw []caddy.ModuleMap `json:"match,omitempty" caddy:"namespace=layer4.matchers"`
	HandlersRaw    []json.RawMessage `json:"handle,omitempty" caddy:"namespace=layer4.handlers inline_key=handler"`
	// contains filtered or unexported fields
}

Route represents a collection of handlers that are gated by matching and other kinds of logic.

func (*Route) Provision

func (r *Route) Provision(ctx caddy.Context) error

Provision sets up a route.

type RouteList

type RouteList []*Route

RouteList is a list of connection routes that can create a middleware chain.

func (RouteList) Compile

func (routes RouteList) Compile(next Handler, logger *zap.Logger) Handler

Compile prepares a middleware chain from the route list. This should only be done once: after all the routes have been provisioned, and before the server loop begins.

func (RouteList) Provision

func (routes RouteList) Provision(ctx caddy.Context) error

Provision sets up all the routes.

type Server

type Server struct {
	Listen []string  `json:"listen,omitempty"`
	Routes RouteList `json:"routes,omitempty"`
	// contains filtered or unexported fields
}

Server represents a Caddy layer4 server.

func (*Server) Provision

func (s *Server) Provision(ctx caddy.Context, logger *zap.Logger) error

Provision sets up the server.

Jump to

Keyboard shortcuts

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