mirror of
https://github.com/ipfs/kubo.git
synced 2025-05-17 15:06:47 +08:00
feat: periodic version check and json config (#10438)
Co-authored-by: Lucas Molas <schomatis@gmail.com> Co-authored-by: Marcin Rataj <lidel@lidel.org>
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
package kubo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
_ "expvar"
|
||||
"fmt"
|
||||
"math"
|
||||
"net"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
@ -438,9 +440,11 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
|
||||
return fmt.Errorf("unrecognized routing option: %s", routingOption)
|
||||
}
|
||||
|
||||
agentVersionSuffixString, _ := req.Options[agentVersionSuffix].(string)
|
||||
if agentVersionSuffixString != "" {
|
||||
version.SetUserAgentSuffix(agentVersionSuffixString)
|
||||
// Set optional agent version suffix
|
||||
versionSuffixFromCli, _ := req.Options[agentVersionSuffix].(string)
|
||||
versionSuffix := cfg.Version.AgentSuffix.WithDefault(versionSuffixFromCli)
|
||||
if versionSuffix != "" {
|
||||
version.SetUserAgentSuffix(versionSuffix)
|
||||
}
|
||||
|
||||
node, err := core.NewNode(req.Context, ncfg)
|
||||
@ -610,6 +614,15 @@ take effect.
|
||||
}
|
||||
if len(peers) == 0 {
|
||||
log.Error("failed to bootstrap (no peers found): consider updating Bootstrap or Peering section of your config")
|
||||
} else {
|
||||
// After 1 minute we should have enough peers
|
||||
// to run informed version check
|
||||
startVersionChecker(
|
||||
cctx.Context(),
|
||||
node,
|
||||
cfg.Version.SwarmCheckEnabled.WithDefault(true),
|
||||
cfg.Version.SwarmCheckPercentThreshold.WithDefault(config.DefaultSwarmCheckPercentThreshold),
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -1056,3 +1069,41 @@ func printVersion() {
|
||||
fmt.Printf("System version: %s\n", runtime.GOARCH+"/"+runtime.GOOS)
|
||||
fmt.Printf("Golang version: %s\n", runtime.Version())
|
||||
}
|
||||
|
||||
func startVersionChecker(ctx context.Context, nd *core.IpfsNode, enabled bool, percentThreshold int64) {
|
||||
if !enabled {
|
||||
return
|
||||
}
|
||||
ticker := time.NewTicker(time.Hour)
|
||||
defer ticker.Stop()
|
||||
go func() {
|
||||
for {
|
||||
o, err := commands.DetectNewKuboVersion(nd, percentThreshold)
|
||||
if err != nil {
|
||||
// The version check is best-effort, and may fail in custom
|
||||
// configurations that do not run standard WAN DHT. If it
|
||||
// errors here, no point in spamming logs: og once and exit.
|
||||
log.Errorw("initial version check failed, will not be run again", "error", err)
|
||||
return
|
||||
}
|
||||
if o.UpdateAvailable {
|
||||
newerPercent := fmt.Sprintf("%.0f%%", math.Round(float64(o.WithGreaterVersion)/float64(o.PeersSampled)*100))
|
||||
log.Errorf(`
|
||||
⚠️ A NEW VERSION OF KUBO DETECTED
|
||||
|
||||
This Kubo node is running an outdated version (%s).
|
||||
%s of the sampled Kubo peers are running a higher version.
|
||||
Visit https://github.com/ipfs/kubo/releases or https://dist.ipfs.tech/#kubo and update to version %s or later.`,
|
||||
o.RunningVersion, newerPercent, o.GreatestVersion)
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-nd.Process.Closing():
|
||||
return
|
||||
case <-ticker.C:
|
||||
continue
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
Reference in New Issue
Block a user