Restores context MD passed to GetInfo to mgmt (is it valuable data?)

This commit is contained in:
riccardom
2026-06-16 18:55:08 +02:00
parent 9758145517
commit d1229ed84c
6 changed files with 30 additions and 15 deletions
+7 -5
View File
@@ -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
+1 -1
View File
@@ -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)
}
+13 -4
View File
@@ -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