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

implement uacomment config parameter which can add comments to user agent as per BIP-0014 #6462

Merged
merged 2 commits into from Aug 5, 2015

Conversation

prusnak
Copy link
Contributor

@prusnak prusnak commented Jul 22, 2015

User can add the following into theirs bitcoin.conf:

uacomment=Prague
uacomment=BeagleBone

which will result in the following user agent:

/Satoshi:0.11.99(Prague; BeagleBone)/

@jgarzik
Copy link
Contributor

jgarzik commented Jul 23, 2015

Concept ACK. Needs some sort of size limiting.

@@ -99,11 +100,20 @@ std::string FormatSubVersion(const std::string& name, int nClientVersion, const
std::ostringstream ss;
ss << "/";
ss << name << ":" << FormatVersion(nClientVersion);
if (!comments.empty())

const std::string key = "-uacomment";
Copy link
Member

Choose a reason for hiding this comment

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

Right now, FormatSubVersion is a pure utility function that doesn't use any global state. I think it should stay that way. E.g. by adding an const std::vector<std::string> &commentList argument. Then pass in this data at the caller side.

Also makes it easier to test this in util_tests.

@laanwj
Copy link
Member

laanwj commented Jul 24, 2015

Concept ACK.

@sipa
Copy link
Member

sipa commented Jul 24, 2015

Concept ACK, agree with @laanwj.

@prusnak
Copy link
Contributor Author

prusnak commented Jul 27, 2015

Updated commit to reflect @laanwj request (to not have FormatSubVersion function dependent on global object).

(Actually, this was my original code, but I changed it, because I did not want to duplicate the logic in two files).

@prusnak
Copy link
Contributor Author

prusnak commented Jul 29, 2015

@jgarzik What is the maximum desired length of user agent string? Or should we just limit the number of comments and their length (e.g. max 5 comments of max 40 characters)?

@sipa
Copy link
Member

sipa commented Jul 29, 2015

Bitcoin Core will reject strings longer than 256 characters for the subser string in "version" messages.

@laanwj laanwj added the P2P label Jul 31, 2015
@laanwj
Copy link
Member

laanwj commented Jul 31, 2015

Tested ACK. Named a few nodes.

  "subversion": "/Satoshi:0.11.99(Inanna)/",
...
  "subversion": "/Satoshi:0.11.99(Ishtar)/",
...
  "subversion": "/Satoshi:0.11.99(Ereshkigal)/",

Names are returned both by getnetworkinfo and the version P2P message, which I verified with bitcoin-submittx:

recv msg_version(nVersion=70002 nServices=1 nTime=Fri Jul 31 15:41:00 2015 addrTo=CAddress(nTime=0 nServices=1 ip=0.0.0.0 port=0) addrFrom=CAddress(nTime=0 nServices=1 ip=0.0.0.0 port=18444) nNonce=0x95FDC41E438E8122 strSubVer=/Satoshi:0.11.99(Ishtar)/ nStartingHeight=0)

It will happily send a subversion longer than 256 bytes, though:

recv msg_version(nVersion=70002 nServices=1 nTime=Fri Jul 31 15:53:46 2015 addrTo=CAddress(nTime=0 nServices=1 ip=0.0.0.0 port=0) addrFrom=CAddress(nTime=0 nServices=1 ip=0.0.0.0 port=18333) nNonce=0x8782C2C672C750F3 strSubVer=/Satoshi:0.11.99(Ishtar; 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef)/ nStartingHeight=5178)

... which, as expected, gets me only connections to old versions. The result is quite interesting. Some nodes send me a REJECT message, which, as it arrives before full version negotiation is seen as misbehavior:

2015-07-31 13:52:46 Misbehaving: 52.1.41.179:18333 (0 -> 1)
2015-07-31 13:52:46 ProcessMessages(reject, 31 bytes) FAILED peer=1

Although not an easy to trigger issue, we should avoid sending a string longer than we accept ourselves.

I share your concern about duplicating code: but you could still define a function that calls FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, mapMultiArgs.count("-uacomment") ? mapMultiArgs["-uacomment"] : std::vector<string>())));

which can add comments to user agent as per BIP-0014
@prusnak
Copy link
Contributor Author

prusnak commented Jul 31, 2015

Easiest logic would be to discard all of the comments if strlen > 256.

@laanwj
Copy link
Member

laanwj commented Jul 31, 2015

It's a workable solution but failing silently is unexpected behavior. I'd prefer to check this in AppInit2 and fail if the subversion string is too long.

@prusnak
Copy link
Contributor Author

prusnak commented Jul 31, 2015

Added check to AppInit2 function. (No more than 4 comments and no longer than 40 characters allowed).

@jonasschnelli
Copy link
Contributor

utACK.

Nit: now you can provide 4string x 40bytes. What if one likes to provide 1x50 bytes?
Would it not make more sense to limit the combined string to 240 (or 255) bytes?

@prusnak
Copy link
Contributor Author

prusnak commented Aug 1, 2015

Reworked check to check total length of all comments altogether. If it is more than 200 characters the error is issued.

@jgarzik
Copy link
Contributor

jgarzik commented Aug 1, 2015

ut ACK

@sipa
Copy link
Member

sipa commented Aug 1, 2015

utACK

Reworked-By: Wladimir J. van der Laan <laanwj@gmail.com>
@laanwj
Copy link
Member

laanwj commented Aug 5, 2015

@prusnak I slightly reworked the last commit:

  • Add a constant MAX_SUBVERSION_LENGTH in net.h and use where appropriate
  • Compute strSubVersion only once, during initialization, and check the size immediately
  • Use stored strSubVersion in PushVersion and GetNetworkInfo
  • Remove translation for the error.

This reduces the amount of code, and cuts down on magic values.
https://github.com/laanwj/bitcoin/tree/2015_08_prusnak_uacomment
Can you please take it over?

@prusnak
Copy link
Contributor Author

prusnak commented Aug 5, 2015

@laanwj Updated PR to your code.

@laanwj laanwj merged commit 7b79cbd into bitcoin:master Aug 5, 2015
laanwj added a commit that referenced this pull request Aug 5, 2015
7b79cbd limit total length of user agent comments (Pavol Rusnak)
557f8ea implement uacomment config parameter which can add comments to user agent as per BIP-0014 (Pavol Rusnak)
@prusnak
Copy link
Contributor Author

prusnak commented Aug 5, 2015

Thanks!

@ABISprotocol
Copy link

I can't help but wonder if this conflicts somehow with #253 and the effort there which seemed to be to not identify or associate users... what might be the long-term effects of this effort which is to associate a bitcoin address with a node? No need to answer me here.

// format user agent, check total size
strSubVersion = FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, mapMultiArgs.count("-uacomment") ? mapMultiArgs["-uacomment"] : std::vector<string>());
if (strSubVersion.size() > MAX_SUBVERSION_LENGTH) {
return InitError(strprintf("Total length of network version string %i exceeds maximum of %i characters. Reduce the number and/or size of uacomments.",
Copy link

Choose a reason for hiding this comment

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

Shouldn't that one be translatable?

Copy link
Member

Choose a reason for hiding this comment

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

No, I'd say. Apart from being a specific technical error (which we don't translate for Googlability, see translation_strings_policy.md) it's an extremely rare condition caused by almost-abuse of the configuration system. No need to waste translator time on that.

@laanwj
Copy link
Member

laanwj commented Aug 6, 2015

@ABISprotocol How is having this option a problem? It's not always a good idea to use it, but many people run essentially public nodes without wallet, and for those there is no need to 'hide in the crowd'.

@ABISprotocol
Copy link

@laanwj Since you asked, my thinking was that there might be ancillary effects on other users, a butterfly effect if you will in the privacy context. Though different functionally (and thus not comparable in the way one might consider it to be), the address reuse problem comes to mind (again, this is perhaps not relevant here because it is addressed in other ways, such as implementing stealth or confidential transactions); but at the core of this, the concern is that when you have an option which encourages or motivates users to associate a node with an address, then that will have privacy implications not only for the user who makes that choice, but for other users in the network as well.

@sipa
Copy link
Member

sipa commented Aug 10, 2015 via email

@maflcko
Copy link
Member

maflcko commented Sep 1, 2015

I might be missing something but how does this implement BIP-0014? Current master happily accepts comments containing any of the "reserved symbols" mentioned in BIP-0014 and silently drops other characters when pushing to the network.
E.g. -:

My local node:

getnetworkinfo
[...]
"subversion": "/Satoshi:0.11.99(node-bob_12);:/:)()/",
[...]

Some remote node:

getpeerinfo
[...]
"subver": "/Satoshi:0.11.99(nodebob_12);:/:)()/",
[...]

zkbot added a commit to zcash/zcash that referenced this pull request Mar 21, 2018
Misc upstream PRs

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#6077
  - Second commit only (first was already applied to 0.11.X and then reverted)
- bitcoin/bitcoin#6284
- bitcoin/bitcoin#6489
- bitcoin/bitcoin#6462
- bitcoin/bitcoin#6647
- bitcoin/bitcoin#6235
- bitcoin/bitcoin#6905
- bitcoin/bitcoin#6780
  - Excluding second commit (QT) and third commit (requires bitcoin/bitcoin#6993)
- bitcoin/bitcoin#6961
  - Excluding QT parts, and a small `src/policy/policy.cpp` change which depends on a bunch of other PRs, which we'll have to remember to come back to.
- bitcoin/bitcoin#7044
- bitcoin/bitcoin#8856
- bitcoin/bitcoin#9002

Part of #2074 and #2132.
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants