ctx

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: 2 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 ctx provides typed context keys and helpers for passing per-request data (session ID, addresses, client ID, hash source) through the handler chain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithClientID

func ContextWithClientID(ctx context.Context, clientID ClientID) context.Context

ContextWithClientID returns a copy of ctx that carries the client ID clientID.

func ContextWithDstAddr added in v0.0.3

func ContextWithDstAddr(ctx context.Context, addr net.Addr) context.Context

ContextWithDstAddr returns a copy of ctx that carries the destination address addr.

func ContextWithHash

func ContextWithHash(ctx context.Context, h *Hash) context.Context

ContextWithHash returns a copy of ctx that carries the hash source h.

func ContextWithLabels added in v0.28.1

func ContextWithLabels(ctx context.Context, labels map[string]string) context.Context

ContextWithLabels returns a new context carrying the given service labels.

func ContextWithPeerCert added in v0.28.1

func ContextWithPeerCert(ctx context.Context, cert *PeerCert) context.Context

ContextWithPeerCert returns a copy of ctx that carries the peer cert.

func ContextWithSid

func ContextWithSid(ctx context.Context, sid Sid) context.Context

ContextWithSid returns a copy of ctx that carries the session ID sid.

func ContextWithSocks5Cmd added in v0.28.1

func ContextWithSocks5Cmd(ctx context.Context, cmd uint8) context.Context

ContextWithSocks5Cmd returns a copy of ctx that carries a SOCKS5 command override. Connectors use this to send a non-CONNECT command (e.g. Tor RESOLVE/RESOLVE_PTR) to the upstream proxy.

func ContextWithSrcAddr added in v0.0.3

func ContextWithSrcAddr(ctx context.Context, addr net.Addr) context.Context

ContextWithSrcAddr returns a copy of ctx that carries the source address addr.

func DstAddrFromContext added in v0.0.3

func DstAddrFromContext(ctx context.Context) net.Addr

DstAddrFromContext returns the destination address stored in ctx, or nil if none is set.

func LabelsFromContext added in v0.28.1

func LabelsFromContext(ctx context.Context) map[string]string

LabelsFromContext returns the service labels stored in the context, or nil.

func Socks5CmdFromContext added in v0.28.1

func Socks5CmdFromContext(ctx context.Context) (uint8, bool)

Socks5CmdFromContext returns the SOCKS5 command override stored in ctx. The bool is false if no override is present.

func SrcAddrFromContext added in v0.0.3

func SrcAddrFromContext(ctx context.Context) net.Addr

SrcAddrFromContext returns the source address stored in ctx, or nil if none is set.

Types

type ClientID

type ClientID string

ClientID is a client identifier used for hash-based load balancing.

func ClientIDFromContext

func ClientIDFromContext(ctx context.Context) ClientID

ClientIDFromContext returns the client ID stored in ctx, or the zero value if none is set.

func (ClientID) String added in v0.0.3

func (c ClientID) String() string

String implements fmt.Stringer.

type Context added in v0.0.3

type Context interface {
	Context() context.Context
}

Context is implemented by connections that carry a context.Context.

type Hash

type Hash struct {
	Source string
}

Hash carries the hash source used by selectors for sticky load balancing.

func HashFromContext

func HashFromContext(ctx context.Context) *Hash

HashFromContext returns the hash source stored in ctx, or nil if none is set.

type PeerCert added in v0.28.1

type PeerCert struct {
	CN          string
	SANs        []string
	Fingerprint string // SHA-256 hex of cert.Raw
}

PeerCert carries the verified mTLS client certificate identity.

func PeerCertFromContext added in v0.28.1

func PeerCertFromContext(ctx context.Context) *PeerCert

PeerCertFromContext returns the peer cert stored in ctx, or nil.

type Sid

type Sid string

Sid is a session identifier carried in the context.

func SidFromContext

func SidFromContext(ctx context.Context) Sid

SidFromContext returns the session ID stored in ctx, or the zero value if none is set.

func (Sid) String added in v0.0.3

func (s Sid) String() string

String implements fmt.Stringer.

Jump to

Keyboard shortcuts

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