diff --git a/main.go b/main.go index f205d87..22f0535 100644 --- a/main.go +++ b/main.go @@ -64,9 +64,11 @@ func runNewtMain(ctx context.Context) { logger.Init(nil) cfg, err := newtconfig.Load(newtconfig.Options{ - Args: os.Args[1:], - Version: newtVersion, - Platform: newtPlatform, + Args: os.Args[1:], + Version: newtVersion, + Agent: "newt", + AgentVersion: newtVersion, + Platform: newtPlatform, }) if err != nil { logger.Fatal("Configuration error: %v", err) @@ -196,6 +198,7 @@ func runNewtMain(ctx context.Context) { CurrentVersion: newtVersion, Platform: newtPlatform, TLSConfig: selfUpdateTLS, + Agent: "newt", }); err != nil { if errors.Is(err, updates.ErrAutoUpdateUnsupportedInOfficialContainer) { logger.Debug("checkAndSelfUpdate: auto-update skipped: %v", err) diff --git a/newt/config.go b/newt/config.go index 671c8e7..ca416a1 100644 --- a/newt/config.go +++ b/newt/config.go @@ -5,8 +5,10 @@ import "time" // Config holds all runtime configuration for a Newt instance. type Config struct { // Build info - Version string - Platform string + Version string + Platform string + Agent string + AgentVersion string // Logging LogLevel string diff --git a/newt/handlers.go b/newt/handlers.go index 6fede7a..67c3e69 100644 --- a/newt/handlers.go +++ b/newt/handlers.go @@ -145,10 +145,12 @@ func (n *Newt) registerHandlers(ctx context.Context) { chainId := generateChainId() n.pendingRegisterChainId = chainId n.stopFunc = n.client.SendMessageInterval(topicWGRegister, map[string]interface{}{ - "publicKey": n.publicKey.String(), - "pingResults": pingResults, - "newtVersion": n.config.Version, - "chainId": chainId, + "publicKey": n.publicKey.String(), + "pingResults": pingResults, + "newtVersion": n.config.Version, + "agent": n.config.Agent, + "agentVersion": n.config.AgentVersion, + "chainId": chainId, }, 2*time.Second) logger.Debug("Sent exit node ping results to cloud for selection: pingResults=%+v", pingResults) @@ -894,6 +896,8 @@ func (n *Newt) registerHandlers(ctx context.Context) { if err := n.client.SendMessage(topicWGRegister, map[string]interface{}{ "publicKey": n.publicKey.String(), "newtVersion": n.config.Version, + "agent": n.config.Agent, + "agentVersion": n.config.AgentVersion, "backwardsCompatible": true, "chainId": bcChainId, }); err != nil { diff --git a/newtconfig/newtconfig.go b/newtconfig/newtconfig.go index dc62750..642b769 100644 --- a/newtconfig/newtconfig.go +++ b/newtconfig/newtconfig.go @@ -264,8 +264,10 @@ type Options struct { Args []string // Version and Platform populate the resulting Config's build info and // are printed by --version. - Version string - Platform string + Version string + Agent string + AgentVersion string + Platform string } // Load resolves configuration with priority cli > env > file > default, @@ -285,8 +287,10 @@ func Load(opts Options) (newtpkg.Config, error) { // ---- defaults ---- cfg := newtpkg.Config{ - Version: opts.Version, - Platform: opts.Platform, + Version: opts.Version, + Platform: opts.Platform, + Agent: opts.Agent, + AgentVersion: opts.AgentVersion, DNS: "9.9.9.9", LogLevel: "INFO", diff --git a/updates/selfupdate.go b/updates/selfupdate.go index 8476d0a..bde0646 100644 --- a/updates/selfupdate.go +++ b/updates/selfupdate.go @@ -37,6 +37,9 @@ type SelfUpdateConfig struct { Platform string // TLSConfig is an optional TLS configuration for the HTTP client (may be nil). TLSConfig *tls.Config + + // cli or newt depending on where we are + Agent string } // versionResponse mirrors the JSON returned by POST /api/v1/auth/newt/version @@ -156,6 +159,7 @@ func CheckAndSelfUpdate(cfg SelfUpdateConfig) error { "newtId": cfg.NewtID, "secret": cfg.Secret, "platform": plat, + "agent": cfg.Agent, }) if err != nil { return fmt.Errorf("failed to marshal version request: %w", err) @@ -211,7 +215,7 @@ func CheckAndSelfUpdate(cfg SelfUpdateConfig) error { return nil } - logger.Debug("checkAndSelfUpdate: update available %s → %s", cfg.CurrentVersion, verResp.Data.LatestVersion) + logger.Debug("checkAndSelfUpdate: newt package update available %s → %s", cfg.CurrentVersion, verResp.Data.LatestVersion) // --- Pre-download: verify we can write to the binary's directory --- // Do this before downloading so a permission failure doesn't waste bandwidth. @@ -225,7 +229,7 @@ func CheckAndSelfUpdate(cfg SelfUpdateConfig) error { _ = os.Remove(writeTestFile.Name()) // --- Step 2: Download the new binary --- - logger.Debug("checkAndSelfUpdate: beginning download of new binary") + logger.Debug("checkAndSelfUpdate: beginning download of new binary from %s", verResp.Data.DownloadUrl) dlCtx, dlCancel := context.WithTimeout(context.Background(), 5*time.Minute) defer dlCancel()