@cryptotaxi247 / kubo / commits / 94bd2981b

feat(cli): add daemon option --agent-version-suffix (#8419)

* feat(cli): add daemon option --agent-version-suffix * fix sharness test when commit is empty (release) (cherry picked from commit 3a84352f1811b22a17530ddb6a2da4f13fbfeef5)

Lucas Molas committed Sep 21, 2021 at 15:31 UTC 94bd2981b920cd2104ef79a96e55ad8471e27e9a
7 files changed +48 -8
cmd/ipfs/daemon.go
+7
@@ -67,6 +67,7 @@ const (
67 enablePubSubKwd = "enable-pubsub-experiment"
68 enableIPNSPubSubKwd = "enable-namesys-pubsub"
69 enableMultiplexKwd = "enable-mplex-experiment"
70 + agentVersionSuffix = "agent-version-suffix"
71 // apiAddrKwd = "address-api"
72 // swarmAddrKwd = "address-swarm"
73 )
@@ -180,6 +181,7 @@ Headers.
181 cmds.BoolOption(enablePubSubKwd, "Instantiate the ipfs daemon with the experimental pubsub feature enabled."),
182 cmds.BoolOption(enableIPNSPubSubKwd, "Enable IPNS record distribution through pubsub; enables pubsub."),
183 cmds.BoolOption(enableMultiplexKwd, "DEPRECATED"),
184 + cmds.StringOption(agentVersionSuffix, "Optional suffix to the AgentVersion presented by `ipfs id` and also advertised through BitSwap."),
185
186 // TODO: add way to override addresses. tricky part: updating the config if also --init.
187 // cmds.StringOption(apiAddrKwd, "Address for the daemon rpc API (overrides config)"),
@@ -410,6 +412,11 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
412 return fmt.Errorf("unrecognized routing option: %s", routingOption)
413 }
414
415 + agentVersionSuffixString, _ := req.Options[agentVersionSuffix].(string)
416 + if agentVersionSuffixString != "" {
417 + version.SetUserAgentSuffix(agentVersionSuffixString)
418 + }
419 +
420 node, err := core.NewNode(req.Context, ncfg)
421 if err != nil {
422 log.Error("error from node construction: ", err)
core/commands/id.go
+1 -1
@@ -223,6 +223,6 @@ func printSelf(keyEnc ke.KeyEncoder, node *core.IpfsNode) (interface{}, error) {
223 sort.Strings(info.Protocols)
224 }
225 info.ProtocolVersion = identify.LibP2PVersion
226 - info.AgentVersion = version.UserAgent
226 + info.AgentVersion = version.GetUserAgentVersion()
227 return info, nil
228 }
core/corehttp/gateway.go
+1 -1
@@ -104,7 +104,7 @@ func VersionOption() ServeOption {
104 return func(_ *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
105 mux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
106 fmt.Fprintf(w, "Commit: %s\n", version.CurrentCommit)
107 - fmt.Fprintf(w, "Client Version: %s\n", version.UserAgent)
107 + fmt.Fprintf(w, "Client Version: %s\n", version.GetUserAgentVersion())
108 fmt.Fprintf(w, "Protocol Version: %s\n", id.LibP2PVersion)
109 })
110 return mux, nil
core/corehttp/gateway_test.go
+1 -1
@@ -732,7 +732,7 @@ func TestVersion(t *testing.T) {
732 t.Fatalf("response doesn't contain commit:\n%s", s)
733 }
734
735 - if !strings.Contains(s, "Client Version: "+version.UserAgent) {
735 + if !strings.Contains(s, "Client Version: "+version.GetUserAgentVersion()) {
736 t.Fatalf("response doesn't contain client version:\n%s", s)
737 }
738
core/node/libp2p/libp2p.go
+1 -2
@@ -25,8 +25,7 @@ type Libp2pOpts struct {
25 }
26
27 // Misc options
28 -
29 -var UserAgent = simpleOpt(libp2p.UserAgent(version.UserAgent))
28 +var UserAgent = simpleOpt(libp2p.UserAgent(version.GetUserAgentVersion()))
29
30 func ConnectionManager(low, high int, grace time.Duration) func() (opts Libp2pOpts, err error) {
31 return func() (opts Libp2pOpts, err error) {
test/sharness/t0026-id.sh
+20 -1
@@ -7,6 +7,8 @@ test_description="Test to make sure our identity information looks sane"
7 test_init_ipfs
8
9 test_id_compute_agent() {
10 + local AGENT_SUFFIX
11 + AGENT_SUFFIX=$1
12 AGENT_VERSION="$(ipfs version --number)" || return 1
13 AGENT_COMMIT="$(ipfs version --number --commit)" || return 1
14 if test "$AGENT_COMMIT" = "$AGENT_VERSION"; then
@@ -14,7 +16,14 @@ test_id_compute_agent() {
16 else
17 AGENT_COMMIT="${AGENT_COMMIT##$AGENT_VERSION-}"
18 fi
17 - echo "go-ipfs/$AGENT_VERSION/$AGENT_COMMIT"
19 + AGENT_VERSION="go-ipfs/$AGENT_VERSION/$AGENT_COMMIT"
20 + if test -n "$AGENT_SUFFIX"; then
21 + if test -n "$AGENT_COMMIT"; then
22 + AGENT_VERSION="$AGENT_VERSION/"
23 + fi
24 + AGENT_VERSION="$AGENT_VERSION$AGENT_SUFFIX"
25 + fi
26 + echo "$AGENT_VERSION"
27 }
28
29 test_expect_success "checking AgentVersion" '
@@ -23,6 +32,16 @@ test_expect_success "checking AgentVersion" '
32 test_cmp expected-agent-version actual-agent-version
33 '
34
35 +test_launch_ipfs_daemon_without_network --agent-version-suffix=test-suffix
36 +
37 +test_expect_success "checking AgentVersion with suffix (daemon running)" '
38 + test_id_compute_agent test-suffix > expected-agent-version &&
39 + ipfs id -f "<aver>\n" > actual-agent-version &&
40 + test_cmp expected-agent-version actual-agent-version
41 +'
42 +
43 +test_kill_ipfs_daemon
44 +
45 test_expect_success "checking ProtocolVersion" '
46 echo "ipfs/0.1.0" > expected-protocol-version &&
47 ipfs id -f "<pver>\n" > actual-protocol-version &&
version.go
+17 -2
@@ -8,7 +8,22 @@ const CurrentVersionNumber = "0.10.0-rc1"
8
9 const ApiVersion = "/go-ipfs/" + CurrentVersionNumber + "/"
10
11 -// UserAgent is the libp2p user agent used by go-ipfs.
11 +// GetUserAgentVersion is the libp2p user agent used by go-ipfs.
12 //
13 // Note: This will end in `/` when no commit is available. This is expected.
14 -var UserAgent = "go-ipfs/" + CurrentVersionNumber + "/" + CurrentCommit
14 +func GetUserAgentVersion() string {
15 + userAgent := "go-ipfs/" + CurrentVersionNumber + "/" + CurrentCommit
16 + if userAgentSuffix != "" {
17 + if CurrentCommit != "" {
18 + userAgent += "/"
19 + }
20 + userAgent += userAgentSuffix
21 + }
22 + return userAgent
23 +}
24 +
25 +var userAgentSuffix string
26 +
27 +func SetUserAgentSuffix(suffix string) {
28 + userAgentSuffix = suffix
29 +}