roundtrip

package
v0.66.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: BSD-3-Clause, AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvMaxIdleConns          = "NB_PROXY_MAX_IDLE_CONNS"
	EnvMaxIdleConnsPerHost   = "NB_PROXY_MAX_IDLE_CONNS_PER_HOST"
	EnvMaxConnsPerHost       = "NB_PROXY_MAX_CONNS_PER_HOST"
	EnvIdleConnTimeout       = "NB_PROXY_IDLE_CONN_TIMEOUT"
	EnvTLSHandshakeTimeout   = "NB_PROXY_TLS_HANDSHAKE_TIMEOUT"
	EnvExpectContinueTimeout = "NB_PROXY_EXPECT_CONTINUE_TIMEOUT"
	EnvResponseHeaderTimeout = "NB_PROXY_RESPONSE_HEADER_TIMEOUT"
	EnvWriteBufferSize       = "NB_PROXY_WRITE_BUFFER_SIZE"
	EnvReadBufferSize        = "NB_PROXY_READ_BUFFER_SIZE"
	EnvDisableCompression    = "NB_PROXY_DISABLE_COMPRESSION"
	EnvMaxInflight           = "NB_PROXY_MAX_INFLIGHT"
)

Environment variable names for tuning the backend HTTP transport.

Variables

View Source
var (
	// ErrNoAccountID is returned when a request context is missing the account ID.
	ErrNoAccountID = errors.New("no account ID in request context")
	// ErrNoPeerConnection is returned when no embedded client exists for the account.
	ErrNoPeerConnection = errors.New("no peer connection found")
	// ErrClientStartFailed is returned when the embedded client fails to start.
	ErrClientStartFailed = errors.New("client start failed")
	// ErrTooManyInflight is returned when the per-backend in-flight limit is reached.
	ErrTooManyInflight = errors.New("too many in-flight requests")
)

Functions

func AccountIDFromContext

func AccountIDFromContext(ctx context.Context) types.AccountID

AccountIDFromContext retrieves the account ID from the context.

func WithAccountID

func WithAccountID(ctx context.Context, accountID types.AccountID) context.Context

WithAccountID adds the account ID to the context.

Types

type ClientConfig added in v0.66.0

type ClientConfig struct {
	MgmtAddr     string
	WGPort       int
	PreSharedKey string
}

ClientConfig holds configuration for the embedded NetBird client.

type ClientDebugInfo

type ClientDebugInfo struct {
	AccountID   types.AccountID
	DomainCount int
	Domains     domain.List
	HasClient   bool
	CreatedAt   time.Time
}

ClientDebugInfo contains debug information about a client.

type NetBird

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

NetBird provides an http.RoundTripper implementation backed by underlying NetBird connections. Clients are keyed by AccountID, allowing multiple domains to share the same connection.

func NewNetBird

func NewNetBird(proxyID, proxyAddr string, clientCfg ClientConfig, logger *log.Logger, notifier statusNotifier, mgmtClient managementClient) *NetBird

NewNetBird creates a new NetBird transport. Set clientCfg.WGPort to 0 for a random OS-assigned port. A fixed port only works with single-account deployments; multiple accounts will fail to bind the same port.

func (*NetBird) AddPeer

func (n *NetBird) AddPeer(ctx context.Context, accountID types.AccountID, d domain.Domain, authToken, serviceID string) error

AddPeer registers a domain for an account. If the account doesn't have a client yet, one is created by authenticating with the management server using the provided token. Multiple domains can share the same client.

func (*NetBird) ClientCount

func (n *NetBird) ClientCount() int

ClientCount returns the total number of active clients.

func (*NetBird) DomainCount

func (n *NetBird) DomainCount(accountID types.AccountID) int

DomainCount returns the number of domains registered for the given account. Returns 0 if the account has no client.

func (*NetBird) GetClient

func (n *NetBird) GetClient(accountID types.AccountID) (*embed.Client, bool)

GetClient returns the embed.Client for the given account ID.

func (*NetBird) HasClient

func (n *NetBird) HasClient(accountID types.AccountID) bool

HasClient returns true if there is a client for the given account.

func (*NetBird) ListClientsForDebug

func (n *NetBird) ListClientsForDebug() map[types.AccountID]ClientDebugInfo

ListClientsForDebug returns information about all clients for debug purposes.

func (*NetBird) ListClientsForStartup

func (n *NetBird) ListClientsForStartup() map[types.AccountID]*embed.Client

ListClientsForStartup returns all embed.Client instances for health checks.

func (*NetBird) RemovePeer

func (n *NetBird) RemovePeer(ctx context.Context, accountID types.AccountID, d domain.Domain) error

RemovePeer unregisters a domain from an account. The client is only stopped when no domains are using it anymore.

func (*NetBird) RoundTrip

func (n *NetBird) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper. It looks up the client for the account specified in the request context and uses it to dial the backend.

func (*NetBird) StopAll

func (n *NetBird) StopAll(ctx context.Context) error

StopAll stops all clients.

Jump to

Keyboard shortcuts

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