protocol.h: Move MESSAGE_START_SIZE into CMessageHeader #8880

pull laanwj wants to merge 3 commits into bitcoin:master from laanwj:2016_10_cosmetic changing 3 files +26 −25
  1. laanwj commented at 11:17 AM on October 4, 2016: member

    This moves all the header sizes together. Also move the enum to the top, and remove a deceptive TODO comment (this is just a dumb data structure describing the protocol and there's nothing to be gained from encapsulation at that level).

    Other commit fixes a silly typo in version.h

  2. version.h: s/shord/short/ in comment f9bd92d235
  3. protocol.h: Move MESSAGE_START_SIZE into CMessageHeader
    Also move the enum to the top, and remove a deceptive TODO
    comment.
    2c09a5209a
  4. laanwj added the label Refactoring on Oct 4, 2016
  5. dcousens approved
  6. dcousens commented at 12:31 PM on October 4, 2016: contributor

    utACK

  7. sipa commented at 12:33 PM on October 4, 2016: member

    utACK

  8. in src/protocol.h:None in 2c09a5209a outdated
      55 | @@ -48,17 +56,6 @@ class CMessageHeader
      56 |          READWRITE(FLATDATA(pchChecksum));
      57 |      }
      58 |  
      59 | -    // TODO: make private (improves encapsulation)
    


    paveljanik commented at 1:23 PM on October 4, 2016:

    Comment removed. Is it OK?


    laanwj commented at 2:16 AM on October 5, 2016:

    See OP

    and remove a deceptive TODO comment (this is just a dumb data structure describing the protocol and there's nothing to be gained from encapsulation at that level).

  9. paveljanik commented at 1:23 PM on October 4, 2016: contributor

    utACK

  10. btcdrak commented at 2:29 PM on October 4, 2016: contributor

    utACK

  11. in src/protocol.h:None in 2c09a5209a outdated
      26 | @@ -29,6 +27,16 @@
      27 |  class CMessageHeader
      28 |  {
      29 |  public:
      30 | +    enum {
      31 | +        MESSAGE_START_SIZE = 4,
    


    theuni commented at 3:22 PM on October 4, 2016:

    nit: could make these constexprs instead while we're at it. No real reason other than cosmetic, though.


    laanwj commented at 3:47 PM on October 4, 2016:

    Huh yes now I look at it again using an enum here is a somewhat of a strange use of the C++ language.


    laanwj commented at 3:52 PM on October 4, 2016:

    Though it looks like we use this kind of constant declaration in many places, and so does leveldb:

    arith_uint256.h:    enum { WIDTH=BITS/32 };
    chain.h:    enum { nMedianTimeSpan=11 };
    leveldb/db/skiplist.h:  enum { kMaxHeight = 12 };
    leveldb/helpers/memenv/memenv.cc:  enum { kBlockSize = 8 * 1024 };
    ...
    

    So I suppose it's somewhat acceptable in some cases?


    theuni commented at 4:37 PM on October 4, 2016:

    @laanwj Looks like several of those are hold-overs from c++03. In the case where there's no actual grouping and we're just using them as constants, I think constexpr's would be fine, but the enum is ofc acceptable as well.

    Nevermind for here, we can discuss in a separate style guide PR.

  12. theuni commented at 3:24 PM on October 4, 2016: member

    utACK 2c09a5209ab00573a2422e1e65c437a6e2f59624

  13. laanwj commented at 4:05 PM on October 4, 2016: member

    Added another commit:

    • protocol.h: Make enums in GetDataMsg concrete values: This concretizes the numbers and adds a comment to make it clear that these numbers are fixed by the protocol, and may avoid people forgetting to claim numbers in the future (e.g. issue #8500).
  14. laanwj force-pushed on Oct 5, 2016
  15. protocol.h: Make enums in GetDataMsg concrete values
    This concretizes the numbers and adds a comment to make it clear that
    these numbers are fixed by the protocol, and may avoid people forgetting
    to claim numbers in the future (e.g. issue #8500).
    
    Also gets rid of a weird unused `MSG_TYPE_MAX` in the middle of the
    enumeration (thanks @paveljanik for noticing).
    1df311118d
  16. in src/protocol.h:None in f5d3f0f216 outdated
     326 |      UNDEFINED = 0,
     327 | -    MSG_TX,
     328 | -    MSG_BLOCK,
     329 | +    MSG_TX = 1,
     330 | +    MSG_BLOCK = 2,
     331 |      MSG_TYPE_MAX = MSG_BLOCK,
    


    paveljanik commented at 10:45 AM on October 5, 2016:

    MSG_TYPE_MAX is not used at all in the sources and looks strange in the middle...


    laanwj commented at 11:24 AM on October 5, 2016:

    HUH. That's a good catch. How could I have missed that one.

  17. laanwj force-pushed on Oct 5, 2016
  18. laanwj commented at 11:33 AM on October 5, 2016: member

    Got rid of the awkward MSG_TYPE_MAX leftover in between the enum values (and squashed). Thanks @paveljanik for noticing.

  19. sipa commented at 11:38 AM on October 5, 2016: member

    The MSG_TYPE_MAX is a leftover from earlier code that got refactored in the segwit PR. It delimited the maximum msg type that could be seen in an inv (as opposed to the next ones, which can only be seen in getdata).

  20. laanwj commented at 12:07 PM on October 5, 2016: member

    The MSG_TYPE_MAX is a leftover from earlier code that got refactored in thesegwit PR.

    OK, in historical context it makes sense, it just looks weird now.

  21. jonasschnelli approved
  22. jonasschnelli commented at 4:40 PM on October 8, 2016: contributor

    utACK 1df311118d79c04df1d41e044b19444cfda015da

  23. paveljanik approved
  24. laanwj merged this on Oct 15, 2016
  25. laanwj closed this on Oct 15, 2016

  26. laanwj referenced this in commit 49c5910372 on Oct 15, 2016
  27. codablock referenced this in commit cda6cee7b5 on Sep 19, 2017
  28. codablock referenced this in commit 0f021e55f6 on Jan 12, 2018
  29. hypo-test referenced this in commit eccda40035 on Nov 25, 2018
  30. andvgal referenced this in commit c4a2078b23 on Jan 6, 2019
  31. zkbot referenced this in commit 1d7ed06174 on Aug 13, 2021
  32. zkbot referenced this in commit 56b5f95897 on Aug 17, 2021
  33. DrahtBot 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-13 15:15 UTC

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