mirror of
https://github.com/netbirdio/netbird.git
synced 2026-08-29 11:01:29 +02:00
Restores context MD passed to GetInfo to mgmt (is it valuable data?)
This commit is contained in:
@@ -205,7 +205,7 @@ func runInForegroundMode(ctx context.Context, cmd *cobra.Command, activeProf *pr
|
||||
connectClient := internal.NewConnectClient(ctx, r)
|
||||
SetupDebugHandler(ctx, config, r, connectClient, "")
|
||||
|
||||
return connectClient.Run(config, nil, util.FindFirstLogPath(logFiles))
|
||||
return connectClient.Run(config, nil, nil, util.FindFirstLogPath(logFiles))
|
||||
}
|
||||
|
||||
func runInDaemonMode(ctx context.Context, cmd *cobra.Command, pm *profilemanager.ProfileManager, activeProf *profilemanager.Profile, profileSwitched bool) error {
|
||||
|
||||
@@ -272,7 +272,7 @@ func (c *Client) Start(startCtx context.Context) error {
|
||||
run := make(chan struct{})
|
||||
clientErr := make(chan error, 1)
|
||||
go func() {
|
||||
if err := client.Run(c.config, run, ""); err != nil {
|
||||
if err := client.Run(c.config, nil, run, ""); err != nil {
|
||||
clientErr <- err
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
gstatus "google.golang.org/grpc/status"
|
||||
|
||||
"github.com/netbirdio/netbird/client/iface/wgaddr"
|
||||
@@ -85,12 +86,13 @@ func (c *ConnectClient) SetUpdateManager(um *updater.Manager) {
|
||||
c.updateManager = um
|
||||
}
|
||||
|
||||
// Run with main logic.
|
||||
func (c *ConnectClient) Run(config *profilemanager.Config, runningChan chan struct{}, logPath string) error {
|
||||
// Run with main logic. md carries optional gRPC metadata (e.g. the UI
|
||||
// user-agent) to forward to the management/signal services; nil when none.
|
||||
func (c *ConnectClient) Run(config *profilemanager.Config, md metadata.MD, runningChan chan struct{}, logPath string) error {
|
||||
if androidRunOverride != nil {
|
||||
return androidRunOverride(c, config, runningChan, logPath)
|
||||
}
|
||||
return c.sup.start(config, MobileDependency{}, runningChan, logPath)
|
||||
return c.sup.start(config, md, MobileDependency{}, runningChan, logPath)
|
||||
}
|
||||
|
||||
// RunOnAndroid with main logic on mobile system
|
||||
@@ -114,7 +116,7 @@ func (c *ConnectClient) RunOnAndroid(
|
||||
StateFilePath: stateFilePath,
|
||||
TempDir: cacheDir,
|
||||
}
|
||||
return c.sup.start(config, mobileDependency, nil, "")
|
||||
return c.sup.start(config, nil, mobileDependency, nil, "")
|
||||
}
|
||||
|
||||
func (c *ConnectClient) RunOniOS(
|
||||
@@ -133,7 +135,7 @@ func (c *ConnectClient) RunOniOS(
|
||||
DnsManager: dnsManager,
|
||||
StateFilePath: stateFilePath,
|
||||
}
|
||||
return c.sup.start(config, mobileDependency, nil, "")
|
||||
return c.sup.start(config, nil, mobileDependency, nil, "")
|
||||
}
|
||||
|
||||
// run executes a single client run. runCtx is owned by the supervisor: cancelling
|
||||
|
||||
@@ -30,5 +30,5 @@ func (c *ConnectClient) runOnAndroidEmbed(
|
||||
HostDNSAddresses: dnsAddresses,
|
||||
DnsReadyListener: dnsReadyListener,
|
||||
}
|
||||
return c.sup.start(config, mobileDependency, runningChan, logPath)
|
||||
return c.sup.start(config, nil, mobileDependency, runningChan, logPath)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"google.golang.org/grpc/metadata"
|
||||
|
||||
"github.com/netbirdio/netbird/client/internal/profilemanager"
|
||||
)
|
||||
|
||||
@@ -33,6 +35,7 @@ const (
|
||||
type lifecycleCmd struct {
|
||||
op lifecycleOp
|
||||
config *profilemanager.Config
|
||||
md metadata.MD
|
||||
mobileDep MobileDependency
|
||||
runningChan chan struct{}
|
||||
logPath string
|
||||
@@ -108,6 +111,12 @@ func (s *supervisor) handleStart(cmd lifecycleCmd) {
|
||||
}
|
||||
|
||||
runCtx, cancel := context.WithCancel(s.ctx)
|
||||
if cmd.md != nil {
|
||||
// Carry caller-supplied gRPC metadata (e.g. UI user-agent) into the run
|
||||
// context so the engine's management/signal calls forward it. The cancel
|
||||
// still drives runCtx (metadata wrapping preserves cancellation).
|
||||
runCtx = metadata.NewOutgoingContext(runCtx, cmd.md)
|
||||
}
|
||||
s.runCancel = cancel
|
||||
s.curStart = &cmd
|
||||
|
||||
@@ -163,8 +172,8 @@ func (s *supervisor) shutdown() {
|
||||
// startAsync enqueues a start without blocking. If done is non-nil it receives
|
||||
// the run's end result (or errAlreadyRunning on rejection, or the context error
|
||||
// on shutdown).
|
||||
func (s *supervisor) startAsync(config *profilemanager.Config, mobileDep MobileDependency, runningChan chan struct{}, logPath string, done chan error) {
|
||||
cmd := lifecycleCmd{op: opStart, config: config, mobileDep: mobileDep, runningChan: runningChan, logPath: logPath, done: done}
|
||||
func (s *supervisor) startAsync(config *profilemanager.Config, md metadata.MD, mobileDep MobileDependency, runningChan chan struct{}, logPath string, done chan error) {
|
||||
cmd := lifecycleCmd{op: opStart, config: config, md: md, mobileDep: mobileDep, runningChan: runningChan, logPath: logPath, done: done}
|
||||
select {
|
||||
case s.cmdCh <- cmd:
|
||||
case <-s.ctx.Done():
|
||||
@@ -174,9 +183,9 @@ func (s *supervisor) startAsync(config *profilemanager.Config, mobileDep MobileD
|
||||
|
||||
// start enqueues a start and blocks until the run terminates, preserving the
|
||||
// blocking contract of the legacy Run entry points.
|
||||
func (s *supervisor) start(config *profilemanager.Config, mobileDep MobileDependency, runningChan chan struct{}, logPath string) error {
|
||||
func (s *supervisor) start(config *profilemanager.Config, md metadata.MD, mobileDep MobileDependency, runningChan chan struct{}, logPath string) error {
|
||||
done := make(chan error, 1)
|
||||
s.startAsync(config, mobileDep, runningChan, logPath, done)
|
||||
s.startAsync(config, md, mobileDep, runningChan, logPath, done)
|
||||
select {
|
||||
case err := <-done:
|
||||
return err
|
||||
|
||||
@@ -285,8 +285,12 @@ func (s *Server) connectWithRetryRuns(ctx context.Context, client *internal.Conn
|
||||
}
|
||||
}()
|
||||
|
||||
// Forward any gRPC metadata the RPC caller attached (e.g. the UI
|
||||
// user-agent in Up); nil for boot/MDM paths that have no incoming call.
|
||||
md, _ := metadata.FromOutgoingContext(ctx)
|
||||
|
||||
runOperation := func() error {
|
||||
err := s.connectOnce(client, profileConfig, runningChan)
|
||||
err := s.connectOnce(client, profileConfig, md, runningChan)
|
||||
if err != nil {
|
||||
log.Debugf("will retry the connection in the background")
|
||||
return err
|
||||
@@ -1737,9 +1741,9 @@ func (s *Server) GetFeatures(ctx context.Context, msg *proto.GetFeaturesRequest)
|
||||
// connectOnce performs a single client run (Run blocks, retrying its own
|
||||
// internal backoff, until the run ends). The outer connectWithRetryRuns
|
||||
// backoff re-invokes it only when a run returns an error.
|
||||
func (s *Server) connectOnce(client *internal.ConnectClient, config *profilemanager.Config, runningChan chan struct{}) error {
|
||||
func (s *Server) connectOnce(client *internal.ConnectClient, config *profilemanager.Config, md metadata.MD, runningChan chan struct{}) error {
|
||||
log.Tracef("running client connection")
|
||||
if err := client.Run(config, runningChan, s.logFile); err != nil {
|
||||
if err := client.Run(config, md, runningChan, s.logFile); err != nil {
|
||||
log.Debugf("run client connection exited with error: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user