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

better user-agent handling #702

Merged
merged 5 commits into from
Aug 28, 2019
Merged

better user-agent handling #702

merged 5 commits into from
Aug 28, 2019

Conversation

Stebalien
Copy link
Member

This PR improves user-agent handling by:

  1. Deprecating the global variable.
  2. Setting the default using go mod.
  3. Adding an option for overriding the user-agent.

if version == "(devel)" {
ClientVersion = bi.Main.Path
} else {
ClientVersion = fmt.Sprintf("%s@%s", bi.Main.Path, bi.Main.Version)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the path/version of the main module (application), not libp2p itself.

@Stebalien Stebalien force-pushed the feat/user-agent branch 3 times, most recently from 63a4a4c to 009eeba Compare August 13, 2019 01:56
Instead of using a global variable.

This also:

* Adds an option to the identify service to set the user agent.
* Removes the ability to pass an identify service to NewHost as any reasonable
  Identify service already needs to be constructed with an instance of the host.
This should help us improve network stats on who's using libp2p.
Copy link
Contributor

@vyzo vyzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

// ClientVersion is the default user agent.
//
// Deprecated: Set this with the UserAgent option.
var ClientVersion = "github.com/libp2p/go-libp2p"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's just call this go-libp2p.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure but users using go mod will still use their full paths by default. E.g., github.com/libp2p/go-libp2p-examples@v0.1.1.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh ok, nevermind then.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will increase the size of the identify messages by 15 bytes. It's ok but worth noting.

}
version := bi.Main.Version
if version == "(devel)" {
ClientVersion = bi.Main.Path
Copy link
Contributor

@vyzo vyzo Aug 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep the devel designator somewhere in the reported agent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything built manually (i.e., built from a manually checked-out source tree) will have a (devel) version. It doesn't mean it's actually a development version.

To get a proper version, one would have to build with go get github.com/libp2p/go-libp2p-examples@latest (i.e., build with go mod).

Users that care can override this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we suffix with @unknown?

@Stebalien Stebalien requested a review from raulk August 16, 2019 20:46
@Stebalien
Copy link
Member Author

@raulk this:

  1. Changes the default user agent for downstream projects from a static string to 'github.com/foo/bar@VERSION`.
  2. Bumps the minimum go version to 1.12 (which we may implicitly require anyways?).

// ClientVersion is the default user agent.
//
// Deprecated: Set this with the UserAgent option.
var ClientVersion = "github.com/libp2p/go-libp2p"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will increase the size of the identify messages by 15 bytes. It's ok but worth noting.

}
version := bi.Main.Version
if version == "(devel)" {
ClientVersion = bi.Main.Path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we suffix with @unknown?

@@ -47,7 +67,8 @@ const transientTTL = 10 * time.Second
// * Our IPFS Agent Version
// * Our public Listen Addresses
type IDService struct {
Host host.Host
Host host.Host
UserAgent string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping this exported could lead to races if the user modifies the value at runtime. Not a biggie, but just pointing it out.

@@ -31,9 +33,27 @@ const ID = "/ipfs/id/1.0.0"

// LibP2PVersion holds the current protocol version for a client running this code
// TODO(jbenet): fix the versioning mess.
// XXX: Don't change this till 2020. You'll break all go-ipfs versions prior to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make this configurable too. Many projects using libp2p don't care about compatibility with IPFS and their networks are deliberately segregated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #714

Copy link
Member

@raulk raulk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, modulo:

  1. some missing godocs -- fixed in a subsequent commit.
  2. suffix unknown versions with @unknown, to normalise the format of that field.
  3. Make LibP2PVersion configurable and dedup with UserAgent #714 (collateral to this).

Thanks for waiting for my sign off, @Stebalien!

@Stebalien Stebalien merged commit 51950e4 into master Aug 28, 2019
@Stebalien Stebalien deleted the feat/user-agent branch August 28, 2019 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants