Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: expose agent-version-suffix via identify protocol #9457

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/node/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)),
Expand Down
6 changes: 4 additions & 2 deletions core/node/libp2p/libp2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down
29 changes: 19 additions & 10 deletions test/sharness/t0026-id.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<aver>\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 "<pver>\n" > actual-protocol-version &&
Expand All @@ -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 "<aver>\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 "<aver>\n" > expected-identify-agent-version &&
ipfsi 1 id "$(ipfsi 0 config Identity.PeerID)" -f "<aver>\n" > actual-libp2p-identify-agent-version &&
test_cmp expected-identify-agent-version actual-libp2p-identify-agent-version
'
test_kill_ipfs_daemon


test_done