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

pull prusnak wants to merge 2 commits into bitcoin:master from prusnak:master changing 5 files +16 −4
  1. prusnak commented at 11:35 AM on July 22, 2015: contributor

    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)/
    
  2. jgarzik commented at 7:01 PM on July 23, 2015: contributor

    Concept ACK. Needs some sort of size limiting.

  3. in src/clientversion.cpp:None in 634eec1680 outdated
      99 | @@ -99,11 +100,20 @@ std::string FormatSubVersion(const std::string& name, int nClientVersion, const
     100 |      std::ostringstream ss;
     101 |      ss << "/";
     102 |      ss << name << ":" << FormatVersion(nClientVersion);
     103 | -    if (!comments.empty())
     104 | +
     105 | +    const std::string key = "-uacomment";
    


    laanwj commented at 11:30 AM on July 24, 2015:

    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.

  4. laanwj commented at 11:33 AM on July 24, 2015: member

    Concept ACK.

  5. sipa commented at 6:00 PM on July 24, 2015: member

    Concept ACK, agree with @laanwj.

  6. prusnak commented at 11:59 PM on July 27, 2015: contributor

    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).

  7. prusnak commented at 5:11 PM on July 29, 2015: contributor

    @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)?

  8. sipa commented at 5:46 PM on July 29, 2015: member

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

  9. laanwj added the label P2P on Jul 31, 2015
  10. laanwj commented at 2:05 PM on July 31, 2015: member

    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>())));

  11. implement uacomment config parameter
    which can add comments to user agent as per BIP-0014
    557f8eac7a
  12. prusnak commented at 2:20 PM on July 31, 2015: contributor

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

  13. laanwj commented at 3:29 PM on July 31, 2015: member

    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.

  14. prusnak commented at 4:07 PM on July 31, 2015: contributor

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

  15. jonasschnelli commented at 7:46 AM on August 1, 2015: 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?

  16. prusnak commented at 1:34 PM on August 1, 2015: contributor

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

  17. jgarzik commented at 4:59 PM on August 1, 2015: contributor

    ut ACK

  18. sipa commented at 6:47 PM on August 1, 2015: member

    utACK

  19. limit total length of user agent comments
    Reworked-By: Wladimir J. van der Laan <laanwj@gmail.com>
    7b79cbd722
  20. laanwj commented at 7:46 AM on August 5, 2015: member

    @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?

  21. prusnak commented at 10:40 AM on August 5, 2015: contributor

    @laanwj Updated PR to your code.

  22. laanwj merged this on Aug 5, 2015
  23. laanwj closed this on Aug 5, 2015

  24. laanwj referenced this in commit c384800027 on Aug 5, 2015
  25. prusnak commented at 1:51 PM on August 5, 2015: contributor

    Thanks!

  26. ABISprotocol commented at 1:51 AM on August 6, 2015: none

    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.

  27. in src/init.cpp:None in 7b79cbd722
    1017 | @@ -1018,6 +1018,13 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
    1018 |  
    1019 |      RegisterNodeSignals(GetNodeSignals());
    1020 |  
    1021 | +    // format user agent, check total size
    1022 | +    strSubVersion = FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, mapMultiArgs.count("-uacomment") ? mapMultiArgs["-uacomment"] : std::vector<string>());
    1023 | +    if (strSubVersion.size() > MAX_SUBVERSION_LENGTH) {
    1024 | +        return InitError(strprintf("Total length of network version string %i exceeds maximum of %i characters. Reduce the number and/or size of uacomments.",
    


    Diapolo commented at 6:49 AM on August 6, 2015:

    Shouldn't that one be translatable?


    laanwj commented at 9:36 AM on August 6, 2015:

    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.

  28. laanwj commented at 4:31 PM on August 6, 2015: member

    @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'.

  29. ABISprotocol commented at 7:13 PM on August 10, 2015: none

    @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.

  30. sipa commented at 7:20 PM on August 10, 2015: member

    The ability to change what software your node advertizes as is not the same as encouraging to put an address there (which is indeed a bad idea IMHO).

  31. MarcoFalke commented at 10:00 PM on September 1, 2015: member

    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);:/:)()/",
    [...]
    
  32. zkbot referenced this in commit f1aeaec471 on Mar 21, 2018
  33. zkbot referenced this in commit c97906e265 on Apr 13, 2018
  34. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-14 18:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me