[net] Remove assert(nMaxInbound > 0) #9008

pull MarcoFalke wants to merge 1 commits into bitcoin:master from MarcoFalke:Mf1610-netAssert changing 1 files +0 −1
  1. MarcoFalke commented at 8:13 PM on October 24, 2016: member

    nMaxInbound might very well be 0 or -1, if the user prefers to keep a small number of maxconnections.

    Note: nMaxInbound of -1 means that the user set maxconnections to 8 or less, but we still want to keep an additional slot for the feeler connection.

    Closes #9007

  2. [net] Remove assert(nMaxInbound > 0)
    nMaxInbound might very well be 0 or -1, if the user prefers to keep
    a small number of maxconnections.
    
    Note: nMaxInbound of -1 means that the user set maxconnections
    to 8 or less, but we still want to keep an additional slot for
    the feeler connection.
    fa1c3c2eb0
  3. MarcoFalke added the label P2P on Oct 24, 2016
  4. MarcoFalke added this to the milestone 0.13.1 on Oct 24, 2016
  5. MarcoFalke added the label Needs backport on Oct 24, 2016
  6. sipa commented at 8:19 PM on October 24, 2016: member

    Isn't there some behaviour we want when the actual value (based on number of connections, not maximum number) <= 0, like cancelling the attempt?

  7. laanwj commented at 5:44 AM on October 25, 2016: member

    Isn't there some behaviour we want when the actual value (based on number of connections, not maximum number) <= 0, like cancelling the attempt?

    I've checked the code below it and I think there is no danger from this value reaching <0. The only thing that actually uses nMaxInBound is:

        if (nInbound >= nMaxInbound)
        {
            if (!AttemptToEvictConnection()) {
                // No connection to evict, disconnect the new connection
                LogPrint("net", "failed to find an eviction candidate - connection dropped (full)\n");
                CloseSocket(hSocket);
                return;
            }
        }
    

    So it will try to evict all connections, just like when nMaxInbound would be 0, which I think makes sense. No need for special-casing.

    utACK https://github.com/bitcoin/bitcoin/pull/9008/commits/fa1c3c2eb0a1853ed0e0662fc2bdbca51e05ccf5

  8. in src/net.cpp:None in fa1c3c2eb0
     969 | @@ -970,7 +970,6 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
     970 |      CAddress addr;
     971 |      int nInbound = 0;
     972 |      int nMaxInbound = nMaxConnections - (nMaxOutbound + nMaxFeeler);
    


    laanwj commented at 5:47 AM on October 25, 2016:

    Maybe it would be wise to cap this to 0 explicitly, as no one will be expecting this to be negative in future maintenance, and they may add something again that crashes if it is.

    int nMaxInbound = std::max(nMaxConnections - (nMaxOutbound + nMaxFeeler), 0);
    

    MarcoFalke commented at 5:46 PM on October 25, 2016:

    I disagree at just blindly capping this at 0. There are only two ways imo:

    • Add a comment which says this may be negative
    • Rework the "-maxconnections" code to not allow negative numbers here

    laanwj commented at 6:07 PM on October 25, 2016:

    I don't think a negative value for something called nMaxOutbound makes sense. There should never be a difference in behavior between no outgoing connections, or negative outgoing connections. But ok, this needs a different solution anyway at a higher level.

  9. laanwj commented at 6:13 AM on October 25, 2016: member

    Theoretically we could stop listening for inbound connections completely if this is <=0, however, whitelisted connections are probably an exception? There are some potential traps there that can create additional unexpected behavior changes. I think this pull is safe and we can do that later.

  10. gmaxwell commented at 8:35 AM on October 25, 2016: contributor

    Theoretically we could stop listening for inbound connections completely if this is <=0, however, whitelisted connections are probably an exception?

    Probably the logic should be changed further in the future, if you set maxconnections to 5 and -listen=1 -connect=gateway.host I would expect you to end up with 5 connections, not 1.

    But ACK getting rid of the assert, good move for now and telling people to set maxconnections to a small number used to be common advice for people concerned with memory and bandwidth (we now use less memory per peer, so less reason)... I also checked that the negative is fine with the current code.

  11. laanwj merged this on Oct 25, 2016
  12. laanwj closed this on Oct 25, 2016

  13. laanwj referenced this in commit f14f07cb94 on Oct 25, 2016
  14. laanwj referenced this in commit 1c5d3fe9e4 on Oct 25, 2016
  15. laanwj referenced this in commit 58d4fa7da3 on Oct 25, 2016
  16. MarcoFalke deleted the branch on Oct 25, 2016
  17. laanwj removed the label Needs backport on Oct 25, 2016
  18. jtimon referenced this in commit c4e42ff5f0 on Feb 2, 2017
  19. sickpig referenced this in commit 6204bdc42f on Apr 13, 2017
  20. sickpig referenced this in commit 0b45a95be8 on Apr 14, 2017
  21. sickpig referenced this in commit 8708ac1bde on Apr 14, 2017
  22. lateminer referenced this in commit 5ef877ba8f on Oct 18, 2018
  23. 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-17 06:15 UTC

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