Add agent and agent version

This commit is contained in:
Owen
2026-09-15 11:08:47 -04:00
parent 4df8d541ae
commit 656102eb35
5 changed files with 32 additions and 15 deletions
+6 -3
View File
@@ -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)
+4 -2
View File
@@ -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
+8 -4
View File
@@ -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 {
+8 -4
View File
@@ -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",
+6 -2
View File
@@ -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()