Documentation
¶
Index ¶
- Constants
- Variables
- func AccountIDFromContext(ctx context.Context) types.AccountID
- func WithAccountID(ctx context.Context, accountID types.AccountID) context.Context
- type ClientConfig
- type ClientDebugInfo
- type NetBird
- func (n *NetBird) AddPeer(ctx context.Context, accountID types.AccountID, d domain.Domain, ...) error
- func (n *NetBird) ClientCount() int
- func (n *NetBird) DomainCount(accountID types.AccountID) 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, d domain.Domain) error
- func (n *NetBird) RoundTrip(req *http.Request) (*http.Response, error)
- func (n *NetBird) StopAll(ctx context.Context) error
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.
Types ¶
type ClientConfig ¶ added in v0.66.0
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 ¶
ClientCount returns the total number of active clients.
func (*NetBird) DomainCount ¶
DomainCount returns the number of domains registered for the given account. Returns 0 if the account has no client.
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 domain from an account. The client is only stopped when no domains are using it anymore.