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

test(p2p/protocol/identify): Fix user agent assertion in Go 1.24 #3177

Merged
merged 3 commits into from
Feb 11, 2025
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
5 changes: 2 additions & 3 deletions p2p/protocol/identify/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/libp2p/go-libp2p/core/protocol"
"github.com/libp2p/go-libp2p/core/record"
"github.com/libp2p/go-libp2p/p2p/host/eventbus"
useragent "github.com/libp2p/go-libp2p/p2p/protocol/identify/internal/user-agent"
"github.com/libp2p/go-libp2p/p2p/protocol/identify/pb"

logging "github.com/ipfs/go-log/v2"
Expand Down Expand Up @@ -54,8 +55,6 @@ const (
connectedPeerMaxAddrs = 500
)

var defaultUserAgent = "github.com/libp2p/go-libp2p"

type identifySnapshot struct {
seq uint64
protocols []protocol.ID
Expand Down Expand Up @@ -188,7 +187,7 @@ func NewIDService(h host.Host, opts ...Option) (*idService, error) {
opt(&cfg)
}

userAgent := defaultUserAgent
userAgent := useragent.DefaultUserAgent()
if cfg.userAgent != "" {
userAgent = cfg.userAgent
}
Expand Down
8 changes: 4 additions & 4 deletions p2p/protocol/identify/id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/libp2p/go-libp2p/p2p/net/swarm"
swarmt "github.com/libp2p/go-libp2p/p2p/net/swarm/testing"
"github.com/libp2p/go-libp2p/p2p/protocol/identify"
useragent "github.com/libp2p/go-libp2p/p2p/protocol/identify/internal/user-agent"
"github.com/libp2p/go-libp2p/p2p/protocol/identify/pb"

mockClock "github.com/benbjohnson/clock"
Expand All @@ -44,9 +45,8 @@ func testKnowsAddrs(t *testing.T, h host.Host, p peer.ID, expected []ma.Multiadd

func testHasAgentVersion(t *testing.T, h host.Host, p peer.ID) {
v, err := h.Peerstore().Get(p, "AgentVersion")
if v.(string) != "github.com/libp2p/go-libp2p" { // this is the default user agent
t.Error("agent version mismatch", err)
}
require.NoError(t, err, "fetching agent version")
require.Equal(t, useragent.DefaultUserAgent(), v, "agent version")
}

func testHasPublicKey(t *testing.T, h host.Host, p peer.ID, shouldBe ic.PubKey) {
Expand Down Expand Up @@ -104,7 +104,7 @@ func emitAddrChangeEvt(t *testing.T, h host.Host) {
}
}

// TestIDServiceWait gives the ID service 1s to finish after dialing
// TestIDService gives the ID service 1s to finish after dialing
// this is because it used to be concurrent. Now, Dial wait till the
// id service is done.
func TestIDService(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package identify
package useragent

import (
"fmt"
"runtime/debug"
)

func DefaultUserAgent() string {
return defaultUserAgent
}

var defaultUserAgent = "github.com/libp2p/go-libp2p"

func init() {
bi, ok := debug.ReadBuildInfo()
if !ok {
Expand Down
Loading