embed

package
v0.67.3 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: BSD-3-Clause Imports: 22 Imported by: 1

Documentation

Overview

Package embed provides a way to embed the NetBird client directly into Go programs without requiring a separate NetBird client installation.

Index

Constants

View Source
const (
	// ExposeProtocolHTTP exposes the service as HTTP.
	ExposeProtocolHTTP = expose.ProtocolHTTP
	// ExposeProtocolHTTPS exposes the service as HTTPS.
	ExposeProtocolHTTPS = expose.ProtocolHTTPS
	// ExposeProtocolTCP exposes the service as TCP.
	ExposeProtocolTCP = expose.ProtocolTCP
	// ExposeProtocolUDP exposes the service as UDP.
	ExposeProtocolUDP = expose.ProtocolUDP
	// ExposeProtocolTLS exposes the service as TLS.
	ExposeProtocolTLS = expose.ProtocolTLS
)
View Source
const (
	// PeerStatusConnected indicates the peer is in connected state.
	PeerStatusConnected = peer.StatusConnected
)

Variables

View Source
var (
	ErrClientAlreadyStarted = errors.New("client already started")
	ErrClientNotStarted     = errors.New("client not started")
	ErrEngineNotStarted     = errors.New("engine not started")
	ErrConfigNotInitialized = errors.New("config not initialized")
)

Functions

This section is empty.

Types

type Client

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

Client manages a netbird embedded client instance.

func New

func New(opts Options) (*Client, error)

New creates a new netbird embedded client.

func (*Client) Dial

func (c *Client) Dial(ctx context.Context, network, address string) (net.Conn, error)

Dial dials a network address in the netbird network. Not applicable if the userspace networking mode is disabled.

func (*Client) DialContext added in v0.60.0

func (c *Client) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext dials a network address in the netbird network with context

func (*Client) Expose added in v0.67.2

func (c *Client) Expose(ctx context.Context, req ExposeRequest) (*ExposeSession, error)

Expose exposes a local service via the NetBird reverse proxy, making it accessible through a public URL. It returns an ExposeSession. Call Wait on the session to keep it alive.

func (*Client) GetConfig added in v0.59.0

func (c *Client) GetConfig() (profilemanager.Config, error)

GetConfig returns a copy of the internal client config.

func (*Client) GetLatestSyncResponse added in v0.63.0

func (c *Client) GetLatestSyncResponse() (*mgmProto.SyncResponse, error)

GetLatestSyncResponse returns the latest sync response from the management server.

func (*Client) ListenTCP

func (c *Client) ListenTCP(address string) (net.Listener, error)

ListenTCP listens on the given address in the netbird network. Not applicable if the userspace networking mode is disabled.

func (*Client) ListenUDP

func (c *Client) ListenUDP(address string) (net.PacketConn, error)

ListenUDP listens on the given address in the netbird network. Not applicable if the userspace networking mode is disabled.

func (*Client) NewHTTPClient

func (c *Client) NewHTTPClient() *http.Client

NewHTTPClient returns a configured http.Client that uses the netbird network for requests. Not applicable if the userspace networking mode is disabled.

func (*Client) SetLogLevel added in v0.63.0

func (c *Client) SetLogLevel(levelStr string) error

SetLogLevel sets the logging level for the client and its components.

func (*Client) Start

func (c *Client) Start(startCtx context.Context) error

Start begins client operation and blocks until the engine has been started successfully or a startup error occurs. Pass a context with a deadline to limit the time spent waiting for the engine to start.

func (*Client) Status added in v0.63.0

func (c *Client) Status() (peer.FullStatus, error)

Status returns the current status of the client.

func (*Client) Stop

func (c *Client) Stop(ctx context.Context) error

Stop gracefully stops the client. Pass a context with a deadline to limit the time spent waiting for the engine to stop.

func (*Client) VerifySSHHostKey added in v0.60.0

func (c *Client) VerifySSHHostKey(peerAddress string, key []byte) error

VerifySSHHostKey verifies an SSH host key against stored peer keys. Returns nil if the key matches, ErrPeerNotFound if peer is not in network, ErrNoStoredKey if peer has no stored key, or an error for verification failures.

type ExposeProtocolType added in v0.67.2

type ExposeProtocolType = expose.ProtocolType

ExposeProtocolType represents the protocol used for exposing a service.

type ExposeRequest added in v0.67.2

type ExposeRequest = expose.Request

ExposeRequest is a request to expose a local service via the NetBird reverse proxy.

type ExposeSession added in v0.67.2

type ExposeSession struct {
	Domain      string
	ServiceName string
	ServiceURL  string
	// contains filtered or unexported fields
}

ExposeSession represents an active expose session. Use Wait to block until the session ends.

func (*ExposeSession) Wait added in v0.67.2

func (s *ExposeSession) Wait(ctx context.Context) error

Wait blocks while keeping the expose session alive. It returns when ctx is cancelled or a keep-alive error occurs, then terminates the session.

type Options

type Options struct {
	// DeviceName is this peer's name in the network
	DeviceName string
	// SetupKey is used for authentication
	SetupKey string
	// JWTToken is used for JWT-based authentication
	JWTToken string
	// PrivateKey is used for direct private key authentication
	PrivateKey string
	// ManagementURL overrides the default management server URL
	ManagementURL string
	// PreSharedKey is the pre-shared key for the WireGuard interface
	PreSharedKey string
	// LogOutput is the output destination for logs (defaults to os.Stderr if nil)
	LogOutput io.Writer
	// LogLevel sets the logging level (defaults to info if empty)
	LogLevel string
	// NoUserspace disables the userspace networking mode. Needs admin/root privileges
	NoUserspace bool
	// ConfigPath is the path to the netbird config file. If empty, the config will be stored in memory and not persisted.
	ConfigPath string
	// StatePath is the path to the netbird state file
	StatePath string
	// DisableClientRoutes disables the client routes
	DisableClientRoutes bool
	// BlockInbound blocks all inbound connections from peers
	BlockInbound bool
	// WireguardPort is the port for the WireGuard interface. Use 0 for a random port.
	WireguardPort *int
	// MTU is the MTU for the WireGuard interface.
	// Valid values are in the range 576..8192 bytes.
	// If non-nil, this value overrides any value stored in the config file.
	// If nil, the existing config MTU (if non-zero) is preserved; otherwise it defaults to 1280.
	// Set to a higher value (e.g. 1400) if carrying QUIC or other protocols that require larger datagrams.
	MTU *uint16
	// DNSLabels defines additional DNS labels configured in the peer.
	DNSLabels []string
}

Options configures a new Client.

type PeerConnStatus added in v0.65.0

type PeerConnStatus = peer.ConnStatus

PeerConnStatus is a peer's connection status.

Jump to

Keyboard shortcuts

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