relay

package module
v0.4.52 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 38 Imported by: 3 modules, 6 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.

README

WebTeleport Relay

go.dev reference License Ask DeepWiki

Documentation

Index

Constants

View Source
const ROOT_INTERNAL = "root.internal"

Variables

View Source
var DefaultLogger *slog.Logger = slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
	Level:     getLogLevel(),
	AddSource: true,
}))
View Source
var DefaultStorage = NewStore()

Functions

func DefaultIndex added in v0.3.4

func DefaultIndex() http.Handler

func IsInternal added in v0.4.37

func IsInternal(r *http.Request) bool

func RoundTripper added in v0.4.12

func RoundTripper(tssn tunnel.Session) http.RoundTripper

Types

type ExpVarStruct added in v0.3.1

type ExpVarStruct struct {
	WebteleportRelayStreamsSpawned   *expvar.Int
	WebteleportRelayStreamsClosed    *expvar.Int
	WebteleportRelaySessionsAccepted *expvar.Int
	WebteleportRelaySessionsClosed   *expvar.Int
}

func NewExpVarStruct added in v0.3.1

func NewExpVarStruct() *ExpVarStruct

type Ingress added in v0.4.47

type Ingress interface {
	// shortcut to dispatcher
	http.Handler

	// apply middleware to dispatcher
	Use(middlewares ...muxr.Middleware)

	// get Session wrapped by http.Transport
	GetRoundTripper(h string) (http.RoundTripper, bool)

	// alias Info
	AliasHandler(w http.ResponseWriter, r *http.Request)

	// record Info
	RecordsHandler(w http.ResponseWriter, r *http.Request)

	// subscribe to incoming stream of edge.Edge
	edge.Subscriber
}

storage exposed as HTTP server

func NewIngress added in v0.4.47

func NewIngress() Ingress

type IngressHandler added in v0.4.47

type IngressHandler struct {
	*muxr.Router
	// contains filtered or unexported fields
}

func NewIngressHandler added in v0.4.47

func NewIngressHandler(storage Storage) *IngressHandler

func (*IngressHandler) AliasHandler added in v0.4.50

func (i *IngressHandler) AliasHandler(w http.ResponseWriter, r *http.Request)

func (*IngressHandler) Dispatch added in v0.4.47

func (i *IngressHandler) Dispatch(r *http.Request) http.Handler

func (*IngressHandler) GetRoundTripper added in v0.4.47

func (i *IngressHandler) GetRoundTripper(h string) (http.RoundTripper, bool)

func (*IngressHandler) RecordsHandler added in v0.4.47

func (i *IngressHandler) RecordsHandler(w http.ResponseWriter, r *http.Request)

func (*IngressHandler) ServeHTTP added in v0.4.47

func (i *IngressHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*IngressHandler) Subscribe added in v0.4.47

func (i *IngressHandler) Subscribe(upgrader edge.Upgrader)

func (*IngressHandler) Use added in v0.4.47

func (i *IngressHandler) Use(middlewares ...muxr.Middleware)

type MetricsTransport added in v0.4.51

type MetricsTransport struct {
	Transport http.RoundTripper
	Stats     *TransportStats
}

MetricsTransport wraps http.Transport to collect various HTTP metrics

func NewMetricsTransport added in v0.4.51

func NewMetricsTransport(wrapped http.RoundTripper) *MetricsTransport

NewMetricsTransport creates a new transport that collects HTTP metrics

func (*MetricsTransport) MarshalJSON added in v0.4.51

func (t *MetricsTransport) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface

func (*MetricsTransport) MarshalJSONIndent added in v0.4.51

func (t *MetricsTransport) MarshalJSONIndent(prefix, indent string) ([]byte, error)

MarshalJSONIndent returns an indented JSON representation

func (*MetricsTransport) RoundTrip added in v0.4.51

func (t *MetricsTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the http.RoundTripper interface

type Record added in v0.3.1

type Record struct {
	Key          string            `json:"key"`
	Session      tunnel.Session    `json:"-"`
	RoundTripper http.RoundTripper `json:"metrics"`
	Header       tags.Tags         `json:"header"`
	Tags         tags.Tags         `json:"tags"`
	Since        time.Time         `json:"since"`
	IP           string            `json:"ip"`
	Path         string            `json:"path"`
}

func (*Record) Matches added in v0.4.12

func (r *Record) Matches(kvs url.Values) (ok bool)

type Relayer added in v0.3.6

type Relayer interface {
	// dispatch to HTTPUpgrader and Storage
	dispatcher.Dispatcher

	// builtin HTTPUpgrader
	edge.HTTPUpgrader

	// edge.Edge consumer
	Ingress
}

edge.Edge multiplexer with builtin HTTPUpgrader

type Storage added in v0.3.4

type Storage interface {
	// allocate new session
	Allocate(r *edge.Edge) (string, error)

	// remove session
	RemoveSession(tssn tunnel.Session)

	// upsert session
	Upsert(k string, r *edge.Edge)

	// get record
	GetRecord(h string) (*Record, bool)

	// get all records
	Records() (all []*Record)

	// scan edge.Edge
	Scan(r *edge.Edge)

	// ping edge.Edge
	Ping(r *edge.Edge)

	// subscribe to incoming stream of edge.Edge
	edge.Subscriber

	// alias
	Alias(k string, v string)

	// unalias
	Unalias(k string)

	// get all aliases
	Aliases() (all map[string]string)

	// lookup record
	LookupRecord(k string) (rec *Record, ok bool)
}

edge.Edge multiplexer

type Store added in v0.4.47

type Store struct {
	OnUpdateFunc func(*Store)
	Logger       *slog.Logger
	Lock         *sync.RWMutex
	PingInterval time.Duration
	Client       *http.Client
	RecordMap    map[string]*Record
	AliasMap     map[string]string
}

func NewStore added in v0.4.47

func NewStore() *Store

func (*Store) Alias added in v0.4.50

func (s *Store) Alias(k string, v string)

func (*Store) Aliases added in v0.4.50

func (s *Store) Aliases() (all map[string]string)

func (*Store) Allocate added in v0.4.47

func (s *Store) Allocate(r *edge.Edge) (key string, err error)

func (*Store) GetRecord added in v0.4.51

func (s *Store) GetRecord(h string) (*Record, bool)

func (*Store) LookupRecord added in v0.4.50

func (s *Store) LookupRecord(k string) (rec *Record, ok bool)

lookup record by key, or alias

func (*Store) Mut added in v0.4.52

func (s *Store) Mut(m func(*Store))

func (*Store) OnUpdate added in v0.4.52

func (s *Store) OnUpdate()

func (*Store) Ping added in v0.4.47

func (s *Store) Ping(r *edge.Edge)

func (*Store) Records added in v0.4.47

func (s *Store) Records() (all []*Record)

func (*Store) RemoveSession added in v0.4.47

func (s *Store) RemoveSession(tssn tunnel.Session)

func (*Store) Scan added in v0.4.47

func (s *Store) Scan(r *edge.Edge)

func (*Store) Subscribe added in v0.4.47

func (s *Store) Subscribe(upgrader edge.Upgrader)

func (*Store) Unalias added in v0.4.50

func (s *Store) Unalias(k string)

func (*Store) Upsert added in v0.4.47

func (s *Store) Upsert(k string, r *edge.Edge)

type TransportStats added in v0.4.51

type TransportStats struct {
	BytesSent            int64         `json:"bytesSent"`
	BytesReceived        int64         `json:"bytesReceived"`
	RequestCount         int64         `json:"requestCount"`
	ResponseCount        int64         `json:"responseCount"`
	FailedRequests       int64         `json:"failedRequests"`
	ActiveRequests       int64         `json:"activeRequests"`
	TotalRequestDuration time.Duration `json:"totalRequestDuration"`
	LastRequestTime      time.Time     `json:"lastRequestTime,omitempty"`
	MaxRequestDuration   time.Duration `json:"maxRequestDuration,omitempty"`
	MinRequestDuration   time.Duration `json:"minRequestDuration,omitempty"`
}

TransportStats contains various transport-level statistics

type VerboseConn added in v0.4.32

type VerboseConn struct {
	net.Conn
}

func (*VerboseConn) Read added in v0.4.32

func (c *VerboseConn) Read(b []byte) (n int, err error)

func (*VerboseConn) Write added in v0.4.32

func (c *VerboseConn) Write(b []byte) (n int, err error)

type WSServer added in v0.3.4

type WSServer struct {
	Ingress
	edge.HTTPUpgrader
}

func DefaultWSServer added in v0.4.48

func DefaultWSServer(host string) *WSServer

func NewWSServer added in v0.3.4

func NewWSServer(host string, ingress Ingress) *WSServer

func (*WSServer) Dispatch added in v0.4.19

func (s *WSServer) Dispatch(r *http.Request) (h http.Handler)

func (*WSServer) IsRootExternal added in v0.4.40

func (s *WSServer) IsRootExternal(r *http.Request) bool

func (*WSServer) IsRootInternal added in v0.4.38

func (s *WSServer) IsRootInternal(r *http.Request) bool

func (*WSServer) IsUpgrade added in v0.3.4

func (s *WSServer) IsUpgrade(r *http.Request) (result bool)

func (*WSServer) RootHandler added in v0.4.38

func (s *WSServer) RootHandler(w http.ResponseWriter, r *http.Request)

rewrite requests targeting example.com/sub/* to sub.example.com/*

func (*WSServer) RootInternalHandler added in v0.4.38

func (s *WSServer) RootInternalHandler(w http.ResponseWriter, r *http.Request)

func (*WSServer) ServeHTTP added in v0.3.4

func (s *WSServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type WTServer added in v0.3.6

type WTServer struct {
	Ingress
	*webtransport.Upgrader
}

func DefaultWTServer added in v0.4.48

func DefaultWTServer(host string) *WTServer

func NewWTServer added in v0.3.6

func NewWTServer(host string, ingress Ingress) *WTServer

func (*WTServer) Dispatch added in v0.4.19

func (s *WTServer) Dispatch(r *http.Request) (h http.Handler)

func (*WTServer) IsRootExternal added in v0.4.40

func (s *WTServer) IsRootExternal(r *http.Request) bool

func (*WTServer) IsRootInternal added in v0.4.38

func (s *WTServer) IsRootInternal(r *http.Request) bool

func (*WTServer) IsUpgrade added in v0.4.16

func (s *WTServer) IsUpgrade(r *http.Request) bool

func (*WTServer) ServeHTTP added in v0.3.6

func (s *WTServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*WTServer) WithAddr added in v0.3.7

func (s *WTServer) WithAddr(a string) *WTServer

func (*WTServer) WithTLSConfig added in v0.3.7

func (s *WTServer) WithTLSConfig(tlsConfig *tls.Config) *WTServer

Directories

Path Synopsis
cmd module

Jump to

Keyboard shortcuts

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