diff --git a/core/commands/id.go b/core/commands/id.go index fd59e4a20..d911b23ef 100644 --- a/core/commands/id.go +++ b/core/commands/id.go @@ -8,6 +8,7 @@ import ( "io" "strings" + version "github.com/ipfs/go-ipfs" core "github.com/ipfs/go-ipfs/core" cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv" @@ -189,6 +190,6 @@ func printSelf(node *core.IpfsNode) (interface{}, error) { } } info.ProtocolVersion = identify.LibP2PVersion - info.AgentVersion = identify.ClientVersion + info.AgentVersion = version.UserAgent return info, nil } diff --git a/core/core.go b/core/core.go index 0dba021e3..c8633f975 100644 --- a/core/core.go +++ b/core/core.go @@ -12,10 +12,8 @@ package core import ( "context" "io" - "path" "github.com/ipfs/go-filestore" - version "github.com/ipfs/go-ipfs" "github.com/ipfs/go-ipfs/core/bootstrap" "github.com/ipfs/go-ipfs/core/node" "github.com/ipfs/go-ipfs/core/node/libp2p" @@ -49,15 +47,10 @@ import ( record "github.com/libp2p/go-libp2p-record" "github.com/libp2p/go-libp2p/p2p/discovery" p2pbhost "github.com/libp2p/go-libp2p/p2p/host/basic" - "github.com/libp2p/go-libp2p/p2p/protocol/identify" ) var log = logging.Logger("core") -func init() { - identify.ClientVersion = path.Join("go-ipfs", version.CurrentVersionNumber, version.CurrentCommit) -} - // IpfsNode is IPFS Core module. It represents an IPFS instance. type IpfsNode struct { diff --git a/core/corehttp/gateway.go b/core/corehttp/gateway.go index 24d26739b..e294cd308 100644 --- a/core/corehttp/gateway.go +++ b/core/corehttp/gateway.go @@ -104,7 +104,7 @@ func VersionOption() ServeOption { return func(_ *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) { mux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Commit: %s\n", version.CurrentCommit) - fmt.Fprintf(w, "Client Version: %s\n", id.ClientVersion) + fmt.Fprintf(w, "Client Version: %s\n", version.UserAgent) fmt.Fprintf(w, "Protocol Version: %s\n", id.LibP2PVersion) }) return mux, nil diff --git a/core/corehttp/gateway_test.go b/core/corehttp/gateway_test.go index 0e08ea2ff..c37f9082e 100644 --- a/core/corehttp/gateway_test.go +++ b/core/corehttp/gateway_test.go @@ -608,7 +608,7 @@ func TestVersion(t *testing.T) { t.Fatalf("response doesn't contain commit:\n%s", s) } - if !strings.Contains(s, "Client Version: "+id.ClientVersion) { + if !strings.Contains(s, "Client Version: "+version.UserAgent) { t.Fatalf("response doesn't contain client version:\n%s", s) } diff --git a/core/node/groups.go b/core/node/groups.go index 703c269dd..2c312524f 100644 --- a/core/node/groups.go +++ b/core/node/groups.go @@ -23,6 +23,7 @@ import ( ) var BaseLibP2P = fx.Options( + fx.Provide(libp2p.UserAgent), fx.Provide(libp2p.PNet), fx.Provide(libp2p.ConnectionManager), fx.Provide(libp2p.DefaultTransports), diff --git a/core/node/libp2p/libp2p.go b/core/node/libp2p/libp2p.go index f0c840279..d9b0b5f55 100644 --- a/core/node/libp2p/libp2p.go +++ b/core/node/libp2p/libp2p.go @@ -3,6 +3,8 @@ package libp2p import ( "time" + version "github.com/ipfs/go-ipfs" + logging "github.com/ipfs/go-log" "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p-connmgr" @@ -22,6 +24,8 @@ type Libp2pOpts struct { // Misc options +var UserAgent = simpleOpt(libp2p.UserAgent(version.UserAgent)) + func ConnectionManager(low, high int, grace time.Duration) func() (opts Libp2pOpts, err error) { return func() (opts Libp2pOpts, err error) { cm := connmgr.NewConnManager(low, high, grace) diff --git a/version.go b/version.go index a9abf3dd9..5ad2408d1 100644 --- a/version.go +++ b/version.go @@ -7,3 +7,6 @@ var CurrentCommit string const CurrentVersionNumber = "0.5.0-dev" const ApiVersion = "/go-ipfs/" + CurrentVersionNumber + "/" + +// UserAgent is the libp2p user agent used by go-ipfs. +var UserAgent = ApiVersion + CurrentCommit