entrypoint

package
v0.28.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 41 Imported by: ? 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 entrypoint implements a public tunnel entry point that accepts external connections and routes them through the tunnel network to internal services behind NAT/firewall.

Protocol dispatch is done by peeking at the first byte of the connection:

relay.Version1 (0x52 'R') → relay protocol  (handleConnect)
dissector.Handshake (0x16) → TLS passthrough (handleTLS)
otherwise                  → HTTP proxy      (handleHTTP)

The entrypoint is constructed by the parent tunnel package via Config and a DialFunc. It operates as a standalone service with its own TCP listener, decoder wrapper, and protocol-specific handling — independent of the parent's relay-handshake path.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(ep *Entrypoint) handler.Handler

NewHandler wraps an Entrypoint as a handler.Handler.

The returned handler's Init is a no-op (the Entrypoint is fully initialized by New()). Handle delegates to ep.Handle.

func NewTCPListener

func NewTCPListener(ln net.Listener, opts ...listener.Option) listener.Listener

NewTCPListener creates a new TCP listener wrapper around a raw net.Listener.

Imports the proxyproto, metrics, admission, and conn-limiter wrappers in the standard TNET listener order (see architecture docs). Options carry the service name, proxy protocol version, and optional admission/ conn-limit config.

Types

type Config

type Config struct {
	// Node is the local tunnel node ID (from tunnelHandler.id).
	Node string
	// Service is the parent handler's service name, used for ingress lookups,
	// logging, and TLS certificate selection.
	Service             string
	Ingress             ingress.Ingress
	SD                  sd.SD
	Logger              logger.Logger
	Recorder            recorder.RecorderObject
	SniffingWebsocket   bool
	WebsocketSampleRate float64
	// ReadTimeout is applied as SetReadDeadline on upstream connections
	// before sniffing HTTP/TLS reads. Also used as
	// http.Transport.ResponseHeaderTimeout. 0 or negative defaults to 15s.
	ReadTimeout time.Duration
	// ProxyProtocol is the PROXY protocol version (1 or 2) for the listener.
	ProxyProtocol int
	// KeepAlive enables HTTP keep-alive for the transport. Disabled by default.
	KeepAlive bool
	// Compression enables HTTP transport-level compression. Disabled by default.
	Compression bool
}

Config carries dependencies from the tunnel handler into the entrypoint.

All fields must be set by the caller before calling New. The DialFunc bridges the package boundary to avoid an import cycle.

type DialContext

type DialContext interface {
	Value(any) any
}

DialContext carries metadata for a dial request. This interface satisfies the context.Context Value() contract, allowing the parent package to pass a real context.Context which is recovered via type assertion in the DialFunc implementation.

type DialFunc

type DialFunc func(ctx DialContext, network, tid string) (conn net.Conn, node, cid string, err error)

DialFunc is the function signature for establishing a tunnel connection. Implemented by the parent package (tunnel) to avoid import cycles.

ctx carries recorder objects and loggers for the tunnel connection. network is always "tcp" for entrypoint connections. tid is the string representation of the target tunnel ID.

type Entrypoint

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

Entrypoint is a public tunnel entry point that accepts external connections and routes them through the tunnel network.

Protocol dispatch is done by peeking at the first byte of the connection:

  • relay.Version1 (0x52 'R') → relay protocol (handleConnect)
  • dissector.Handshake (0x16) → TLS passthrough (handleTLS)
  • otherwise → HTTP proxy (handleHTTP)

For HTTP/TLS paths, the dial flow is:

ep.Dial() → ingress lookup (host → tunnelID) → dialFn()
  → tunnel connection

The relay protocol path handles its own tunnel ID extraction from the relay request frame.

func New

func New(cfg *Config, dialFn DialFunc) *Entrypoint

New creates a new Entrypoint with the given config and dial function.

The config fields are copied into the Entrypoint struct. The dial function is stored as-is — nil functions cause dial failures at runtime, not at construction time.

The HTTP transport is initialized immediately with ep.dial as its DialContext; responses time out after cfg.ReadTimeout (default 15s).

func (*Entrypoint) Handle

func (ep *Entrypoint) Handle(ctx context.Context, conn net.Conn) (err error)

Handle processes an incoming connection on the entrypoint listener.

The first byte is peeked to dispatch protocol handling:

  • relay.Version1 (0x52 'R') → ep.handleConnect (relay protocol)
  • dissector.Handshake (0x16) → ep.handleTLS (TLS passthrough)
  • otherwise → ep.handleHTTP (HTTP forward proxy)

Recording instrumentation (stats, HTTP/TLS metadata) wraps the connection and is finalized in the deferred recorder callback.

Jump to

Keyboard shortcuts

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