net: simplify PONG handler #15613

pull pstratem wants to merge 1 commits into bitcoin:master from pstratem:2019-03-17-net-processing-pong changing 1 files +24 −45
  1. pstratem commented at 4:39 PM on March 17, 2019: contributor

    We treat a buffer size mismatch as a protocol violation. We treat a zero microsecond pong response as spurious (likely the local clock is broken).

  2. pstratem force-pushed on Mar 17, 2019
  3. pstratem renamed this:
    net: Simplify PONG handler, improve readability of the processing logic.
    net: simplify PONG handler and disconnect for protocol violations
    on Mar 17, 2019
  4. practicalswift commented at 5:05 PM on March 17, 2019: contributor

    Is this intended as a pure refactoring or does the change come with any intentional change in behaviour?

    Is the change from nAvail >= sizeof(nonce) to nAvail != sizeof(nonce) intentional?

  5. pstratem commented at 5:13 PM on March 17, 2019: contributor

    @practicalswift the change is intentional, the buffer should exactly match the expected length (yes i know this means we cant extend the pong message in the future)

  6. practicalswift commented at 5:17 PM on March 17, 2019: contributor

    @pstratem Thanks for clarifying! Any other intentional deviations from a pure refactoring? :-)

  7. pstratem force-pushed on Mar 17, 2019
  8. pstratem force-pushed on Mar 17, 2019
  9. pstratem force-pushed on Mar 17, 2019
  10. Simplify PONG handler, improve readability of the processing logic. a3fc70f084
  11. pstratem force-pushed on Mar 17, 2019
  12. pstratem commented at 5:39 PM on March 17, 2019: contributor

    @practicalswift the timing constraint is changed from > to >= as it's measured in microseconds. a ping time of zero seconds is almost certainly in error.

  13. pstratem commented at 5:39 PM on March 17, 2019: contributor

    and obviously the error messages are changed to be more specific

  14. pstratem force-pushed on Mar 17, 2019
  15. pstratem renamed this:
    net: simplify PONG handler and disconnect for protocol violations
    net: simplify PONG handler
    on Mar 17, 2019
  16. fanquake added the label P2P on Mar 17, 2019
  17. in src/net_processing.cpp:2989 in a3fc70f084
    3018 | +            pfrom->nMinPingUsecTime = std::min(pfrom->nMinPingUsecTime.load(), pingUsecTime);
    3019 |          } else {
    3020 | -            // This is most likely a bug in another implementation somewhere; cancel this ping
    3021 | -            bPingFinished = true;
    3022 | -            sProblem = "Short payload";
    3023 | +            LogPrint(BCLog::NET, "pong peer=%d: received pong before ping sent, maybe clock changed?\n", pfrom->GetId());
    


    laanwj commented at 11:05 AM on June 6, 2019:

    maybe "received pong before or at time ping sent"

  18. in src/net_processing.cpp:2962 in a3fc70f084
    2958 | @@ -2959,58 +2959,37 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
    2959 |      }
    2960 |  
    2961 |      if (strCommand == NetMsgType::PONG) {
    2962 | -        int64_t pingUsecEnd = nTimeReceived;
    2963 | +        // We didn't send a ping, there shouldn't be a pong
    


    fqlx commented at 4:10 AM on July 4, 2019:

    Instead of adding a comment here, we could make the LogPrint more informative (which would self comment the code).

  19. in src/net_processing.cpp:2970 in a3fc70f084
    2968 | +
    2969 |          uint64_t nonce = 0;
    2970 |          size_t nAvail = vRecv.in_avail();
    2971 | -        bool bPingFinished = false;
    2972 | -        std::string sProblem;
    2973 | +        if (nAvail != sizeof(nonce)) {
    


    fqlx commented at 4:13 AM on July 4, 2019:

    Is this intentional? sizeof should return 8 (is 8 intentional here) but we might have side effects depending on the OS. Why use sizeof here and not >0 or just nonce?

  20. fqlx changes_requested
  21. fanquake commented at 12:25 PM on August 23, 2019: member

    @pstratem did you want to follow up and address any comments here?

  22. fanquake added the label Waiting for author on Aug 23, 2019
  23. laanwj commented at 12:36 PM on September 30, 2019: member

    Closing, as this has been waiting for author for more than a month. Let me know if you want to reopen this.

  24. laanwj closed this on Sep 30, 2019

  25. laanwj removed the label Waiting for author on Oct 24, 2019
  26. DrahtBot locked this on Dec 16, 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-19 00:14 UTC

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