@cryptotaxi247 / kubo / commits / 5047c02d9

fix: apply agent-version-suffix to libp2p identify

Closes #9456

Marcin Rataj committed Dec 5, 2022 at 23:54 UTC 5047c02d9a017a2e647d5b6934d38cff3ba0ee12
3 files changed +26 -13
core/node/groups.go
+3 -1
@@ -26,7 +26,6 @@ import (
26 var logger = log.Logger("core:constructor")
27
28 var BaseLibP2P = fx.Options(
29 - fx.Provide(libp2p.UserAgent),
29 fx.Provide(libp2p.PNet),
30 fx.Provide(libp2p.ConnectionManager),
31 fx.Provide(libp2p.Host),
@@ -134,6 +133,9 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
133 opts := fx.Options(
134 BaseLibP2P,
135
136 + // identify's AgentVersion (incl. optional agent-version-suffix)
137 + fx.Provide(libp2p.UserAgent()),
138 +
139 // Services (resource management)
140 fx.Provide(libp2p.ResourceManager(cfg.Swarm)),
141 fx.Provide(libp2p.AddrFilters(cfg.Swarm.AddrFilters)),
core/node/libp2p/libp2p.go
+4 -2
@@ -25,8 +25,6 @@ type Libp2pOpts struct {
25 Opts []libp2p.Option `group:"libp2p"`
26 }
27
28 -var UserAgent = simpleOpt(libp2p.UserAgent(version.GetUserAgentVersion()))
29 -
28 func ConnectionManager(low, high int, grace time.Duration) func() (opts Libp2pOpts, err error) {
29 return func() (opts Libp2pOpts, err error) {
30 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
44 return ps.AddPrivKey(id, sk)
45 }
46
47 +func UserAgent() func() (opts Libp2pOpts, err error) {
48 + return simpleOpt(libp2p.UserAgent(version.GetUserAgentVersion()))
49 +}
50 +
51 func simpleOpt(opt libp2p.Option) func() (opts Libp2pOpts, err error) {
52 return func() (opts Libp2pOpts, err error) {
53 opts.Opts = append(opts.Opts, opt)
test/sharness/t0026-id.sh
+19 -10
@@ -32,16 +32,6 @@ 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 -
35 test_expect_success "checking ProtocolVersion" '
36 echo "ipfs/0.1.0" > expected-protocol-version &&
37 ipfs id -f "<pver>\n" > actual-protocol-version &&
@@ -61,4 +51,23 @@ test_expect_success "checking and converting ID of a random peer while offline"
51 test_cmp expected-id actual-id
52 '
53
54 +# agent-version-suffix (local, offline)
55 +test_launch_ipfs_daemon --agent-version-suffix=test-suffix
56 +test_expect_success "checking AgentVersion with suffix (local)" '
57 + test_id_compute_agent test-suffix > expected-agent-version &&
58 + ipfs id -f "<aver>\n" > actual-agent-version &&
59 + test_cmp expected-agent-version actual-agent-version
60 +'
61 +
62 +# agent-version-suffix (over libp2p identify protocol)
63 +iptb testbed create -type localipfs -count 2 -init
64 +startup_cluster 2 --agent-version-suffix=test-suffix-identify
65 +test_expect_success "checking AgentVersion with suffix (fetched via libp2p identify protocol)" '
66 + ipfsi 0 id -f "<aver>\n" > expected-identify-agent-version &&
67 + ipfsi 1 id "$(ipfsi 0 config Identity.PeerID)" -f "<aver>\n" > actual-libp2p-identify-agent-version &&
68 + test_cmp expected-identify-agent-version actual-libp2p-identify-agent-version
69 +'
70 +test_kill_ipfs_daemon
71 +
72 +
73 test_done