Documentation
¶
Index ¶
- Constants
- Variables
- func AccountIDFromContext(ctx context.Context) types.AccountID
- func WithAccountID(ctx context.Context, accountID types.AccountID) context.Context
- func WithSkipTLSVerify(ctx context.Context) context.Context
- type ClientConfig
- type ClientDebugInfo
- type NetBird
- func (n *NetBird) AddPeer(ctx context.Context, accountID types.AccountID, key ServiceKey, ...) error
- func (n *NetBird) ClientCount() int
- func (n *NetBird) GetClient(accountID types.AccountID) (*embed.Client, bool)
- func (n *NetBird) HasClient(accountID types.AccountID) bool
- func (n *NetBird) ListClientsForDebug() map[types.AccountID]ClientDebugInfo
- func (n *NetBird) ListClientsForStartup() map[types.AccountID]*embed.Client
- func (n *NetBird) RemovePeer(ctx context.Context, accountID types.AccountID, key ServiceKey) error
- func (n *NetBird) RoundTrip(req *http.Request) (*http.Response, error)
- func (n *NetBird) ServiceCount(accountID types.AccountID) int
- func (n *NetBird) StopAll(ctx context.Context) error
- type ServiceKey
Constants ¶
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 ¶
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 ¶
AccountIDFromContext retrieves the account ID from the context.
func WithAccountID ¶
WithAccountID adds the account ID to the context.
Types ¶
type ClientConfig ¶ added in v0.66.0
ClientConfig holds configuration for the embedded NetBird client.
type ClientDebugInfo ¶
type ClientDebugInfo struct {
AccountID types.AccountID
ServiceCount int
ServiceKeys []string
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 services 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, key ServiceKey, authToken string, serviceID types.ServiceID) error
AddPeer registers a service 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 services can share the same client.
func (*NetBird) ClientCount ¶
ClientCount returns the total number of active clients.
func (*NetBird) ListClientsForDebug ¶
func (n *NetBird) ListClientsForDebug() map[types.AccountID]ClientDebugInfo
ListClientsForDebug returns information about all clients for debug purposes.
func (*NetBird) ListClientsForStartup ¶
ListClientsForStartup returns all embed.Client instances for health checks.
func (*NetBird) RemovePeer ¶
RemovePeer unregisters a service from an account. The client is only stopped when no services are using it anymore.
func (*NetBird) RoundTrip ¶
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) ServiceCount ¶ added in v0.67.0
ServiceCount returns the number of services registered for the given account. Returns 0 if the account has no client.
type ServiceKey ¶ added in v0.67.0
type ServiceKey string
ServiceKey uniquely identifies a service (HTTP reverse proxy or L4 service) that holds a reference to an embedded NetBird client. Callers should use the DomainServiceKey and L4ServiceKey constructors to avoid namespace collisions.
func DomainServiceKey ¶ added in v0.67.0
func DomainServiceKey(domain string) ServiceKey
DomainServiceKey returns a ServiceKey for an HTTP/TLS domain-based service.
func L4ServiceKey ¶ added in v0.67.0
func L4ServiceKey(id types.ServiceID) ServiceKey
L4ServiceKey returns a ServiceKey for an L4 service (TCP/UDP).