front

package
v0.2.0-dev.5 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package front shares one TCP port between services by the SNI of the first ClientHello. It reads the hello without answering, picks a route by the exact name (the default route for anything it does not know) and hands the connection, with the bytes already read put back in front, to the route's net.Listener. It sends nothing itself and keeps no per-source limits: behind a relay, a bridge or CGNAT many clients share an address.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Front

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

Front is the listener of a shared port.

func New

func New(ln net.Listener, log *slog.Logger) *Front

New starts the front on ln, which the caller bound; Close closes it. A nil log discards.

func (*Front) Close

func (f *Front) Close() error

Close stops accepting, closes the connections that have no route yet and ends every route's Accept. Connections already handed over are the engines'.

func (*Front) Listener

func (f *Front) Listener(id string) net.Listener

Listener returns the listener of route id, nil if there is no such route. Closing it ends one engine's Accept; the route stays, and Listener gives the next engine a new one.

func (*Front) SetDown

func (f *Front) SetDown(id string, down bool)

SetDown says whether the service of route id is not running (it failed, or never started). Its names then go to the default route at once, as a stranger's do, instead of waiting for an Accept that will not come. A route that is up but does not Accept in time (an engine restarting) sends the connection to the default route too, after routeWait. The default route itself has nowhere to fall back to.

func (*Front) SetRoutes

func (f *Front) SetRoutes(routes []Route, def string)

SetRoutes replaces the routes. def is the id of the default route. A route whose id stays keeps its queue, so connections waiting for it, and its listener, are not disturbed; a route that is gone has its listeners closed.

func (*Front) Stats

func (f *Front) Stats() Stats

Stats returns the counters.

type NameCount

type NameCount struct {
	Name  string
	Count uint64
}

NameCount is an SNI name and how many connections came with it.

type Route

type Route struct {
	ID    string   // the inbound's id
	Names []string // exact SNI names, lower case, no trailing dot, ASCII; a name another route holds already is ignored
	// KeepAlive is set on a connection when this route is chosen, so each service keeps the keepalive it has when it
	// listens alone. nil leaves what the listener set.
	KeepAlive *net.KeepAliveConfig
}

Route is one service on the port.

type Stats

type Stats struct {
	Accepted      uint64
	Delivered     map[string]uint64 // by route id: handed to the route's Accept
	NoSNI         uint64
	UnknownName   uint64
	NotTLS        uint64
	BadHello      uint64
	HelloTooLarge uint64
	Timeouts      uint64 // closed: no complete hello in time
	Evicted       uint64 // closed: more than maxPending unfinished, this was the oldest
	RouteDown     uint64 // went to the default route: the route's service is not running (SetDown), or did not Accept in time
	Refused       uint64 // closed: nobody Accepted it in time (the default route too), or the route went away
	NoRoute       uint64 // closed: nowhere to send it
	Panics        uint64
	// Unknown is the most frequent names no route holds, most frequent first. A name that came in after the list was
	// full takes over the least frequent entry and its count, so counts may be too high after churn.
	Unknown []NameCount
}

Stats counts since New. The Default* fields say why a connection went to the default route; they count even when there is none, and then NoRoute counts too.

Directories

Path Synopsis
Package fronttest puts a real front on loopback in front of an engine under test: the engine's tests then show what reaches it through the shared port, not what a stand-in would.
Package fronttest puts a real front on loopback in front of an engine under test: the engine's tests then show what reaches it through the shared port, not what a stand-in would.

Jump to

Keyboard shortcuts

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