diff --git a/core/node/groups.go b/core/node/groups.go index cc0134b6446..7bc4e894cf2 100644 --- a/core/node/groups.go +++ b/core/node/groups.go @@ -26,7 +26,6 @@ import ( var logger = log.Logger("core:constructor") var BaseLibP2P = fx.Options( - fx.Provide(libp2p.UserAgent), fx.Provide(libp2p.PNet), fx.Provide(libp2p.ConnectionManager), fx.Provide(libp2p.Host), @@ -134,6 +133,9 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option { opts := fx.Options( BaseLibP2P, + // identify's AgentVersion (incl. optional agent-version-suffix) + fx.Provide(libp2p.UserAgent()), + // Services (resource management) fx.Provide(libp2p.ResourceManager(cfg.Swarm)), fx.Provide(libp2p.AddrFilters(cfg.Swarm.AddrFilters)), diff --git a/core/node/libp2p/libp2p.go b/core/node/libp2p/libp2p.go index b3619715221..e6977b061e8 100644 --- a/core/node/libp2p/libp2p.go +++ b/core/node/libp2p/libp2p.go @@ -25,8 +25,6 @@ type Libp2pOpts struct { Opts []libp2p.Option `group:"libp2p"` } -var UserAgent = simpleOpt(libp2p.UserAgent(version.GetUserAgentVersion())) - func ConnectionManager(low, high int, grace time.Duration) func() (opts Libp2pOpts, err error) { return func() (opts Libp2pOpts, err error) { cm, err := connmgr.NewConnManager(low, high, connmgr.WithGracePeriod(grace)) @@ -46,6 +44,10 @@ func PstoreAddSelfKeys(id peer.ID, sk crypto.PrivKey, ps peerstore.Peerstore) er return ps.AddPrivKey(id, sk) } +func UserAgent() func() (opts Libp2pOpts, err error) { + return simpleOpt(libp2p.UserAgent(version.GetUserAgentVersion())) +} + func simpleOpt(opt libp2p.Option) func() (opts Libp2pOpts, err error) { return func() (opts Libp2pOpts, err error) { opts.Opts = append(opts.Opts, opt) diff --git a/test/sharness/t0026-id.sh b/test/sharness/t0026-id.sh index e8ae7a60cd8..5d6d3db094a 100755 --- a/test/sharness/t0026-id.sh +++ b/test/sharness/t0026-id.sh @@ -32,16 +32,6 @@ test_expect_success "checking AgentVersion" ' test_cmp expected-agent-version actual-agent-version ' -test_launch_ipfs_daemon_without_network --agent-version-suffix=test-suffix - -test_expect_success "checking AgentVersion with suffix (daemon running)" ' - test_id_compute_agent test-suffix > expected-agent-version && - ipfs id -f "\n" > actual-agent-version && - test_cmp expected-agent-version actual-agent-version -' - -test_kill_ipfs_daemon - test_expect_success "checking ProtocolVersion" ' echo "ipfs/0.1.0" > expected-protocol-version && ipfs id -f "\n" > actual-protocol-version && @@ -61,4 +51,23 @@ test_expect_success "checking and converting ID of a random peer while offline" test_cmp expected-id actual-id ' +# agent-version-suffix (local, offline) +test_launch_ipfs_daemon --agent-version-suffix=test-suffix +test_expect_success "checking AgentVersion with suffix (local)" ' + test_id_compute_agent test-suffix > expected-agent-version && + ipfs id -f "\n" > actual-agent-version && + test_cmp expected-agent-version actual-agent-version +' + +# agent-version-suffix (over libp2p identify protocol) +iptb testbed create -type localipfs -count 2 -init +startup_cluster 2 --agent-version-suffix=test-suffix-identify +test_expect_success "checking AgentVersion with suffix (fetched via libp2p identify protocol)" ' + ipfsi 0 id -f "\n" > expected-identify-agent-version && + ipfsi 1 id "$(ipfsi 0 config Identity.PeerID)" -f "\n" > actual-libp2p-identify-agent-version && + test_cmp expected-identify-agent-version actual-libp2p-identify-agent-version +' +test_kill_ipfs_daemon + + test_done