Fix: when testnet=1 specified, change default RPC port to 18332 #1862

pull kjj2 wants to merge 1 commits into bitcoin:master from kjj2:testports changing 2 files +8 −3
  1. kjj2 commented at 3:54 PM on September 24, 2012: none

    Fix: when testnet=1 specified, change default RPC port to 18332

  2. jgarzik commented at 5:15 PM on September 24, 2012: contributor

    ACK

  3. in src/protocol.h:None in 767f9a4e8b outdated
      21 | @@ -21,6 +22,10 @@ static inline unsigned short GetDefaultPort(const bool testnet = fTestNet)
      22 |      return testnet ? 18333 : 8333;
      23 |  }
      24 |  
      25 | +static inline unsigned short GetDefaultRPCPort()
    


    gavinandresen commented at 5:23 PM on September 24, 2012:

    The RPC port has nothing to do with the p2p protocol, so this doesn't belong in protocol.h.

    Should go at the top of bitcoinrpc.cpp, in my humble opinion.


    Diapolo commented at 5:53 PM on September 24, 2012:
  4. in src/init.cpp:None in 767f9a4e8b outdated
     271 | @@ -272,7 +272,7 @@ bool static Bind(const CService &addr, bool fError = true) {
     272 |  #endif
     273 |          "  -rpcuser=<user>        " + _("Username for JSON-RPC connections") + "\n" +
     274 |          "  -rpcpassword=<pw>      " + _("Password for JSON-RPC connections") + "\n" +
     275 | -        "  -rpcport=<port>        " + _("Listen for JSON-RPC connections on <port> (default: 8332)") + "\n" +
     276 | +        "  -rpcport=<port>        " + _("Listen for JSON-RPC connections on <port> (default: 8332 or Testnet: 18332)") + "\n" +
    


    Diapolo commented at 5:52 PM on September 24, 2012:

    testnet should be lowercase

  5. Diapolo commented at 8:17 PM on September 24, 2012: none

    Looking good now :).

  6. gavinandresen commented at 8:24 PM on September 24, 2012: contributor

    Squash them into one commit and it is perfect.

  7. Fix: when testnet=1 specified, change default ports to 18332 and 18333 b202d43076
  8. kjj2 commented at 8:27 PM on September 24, 2012: none

    Done.

  9. in src/bitcoinrpc.cpp:None in b202d43076
    1059 | @@ -1055,7 +1060,7 @@ Object CallRPC(const string& strMethod, const Array& params)
    1060 |      asio::ssl::stream<asio::ip::tcp::socket> sslStream(io_service, context);
    1061 |      SSLIOStreamDevice<asio::ip::tcp> d(sslStream, fUseSSL);
    1062 |      iostreams::stream< SSLIOStreamDevice<asio::ip::tcp> > stream(d);
    1063 | -    if (!d.connect(GetArg("-rpcconnect", "127.0.0.1"), GetArg("-rpcport", "8332")))
    1064 | +    if (!d.connect(GetArg("-rpcconnect", "127.0.0.1"), GetArg("-rpcport", itostr(GetDefaultRPCPort()))))
    


    Diapolo commented at 9:10 PM on September 24, 2012:

    itostr() does strprintf("%d", n), which is for signed integers, so should we better use strprintf("%u", GetDefaultRPCPort()) instead, as we have an unsigned short as port number?


    kjj2 commented at 11:49 PM on September 24, 2012:

    My understanding is that this is well defined. The implicit type conversion is from unsigned short to signed int, which is always safe. (Since the short is unsigned, there is no sign to extend.) The compiler doesn't even blink at this with -Wall, but it does gripe often about the 3 lines in net.h that assign a literal -1 to an unsigned int.


    Diapolo commented at 5:03 AM on September 25, 2012:

    Alright I'm fine with this patch then, but now I'm interested in which lines give you that signed/unsigned warning, as we are always interested in finding and fixing these :).


    kjj2 commented at 5:12 AM on September 25, 2012:

    net.h, lines 219, 353, 388. All three lines have nMessageStart = -1; but nMessageStart is unsigned int from line 167. There are other warnings that pop up when I compile, but net.h seems to be in just about everything, so I see them over and over again when I build. Does your compiler not warn on them? Mine is a bit old.


    laanwj commented at 8:46 AM on September 25, 2012:

    No problem here, it is entirely correct: calling itostr casts the unsigned short to a signed integer (which is larger, so there is never undefined behavior), before feeding it into strprintf as a signed integer (%d).


    Diapolo commented at 9:15 AM on September 25, 2012:

    @kjj2 OT on net.h: AFAIK -1 for an unsigned var means set all bits, which should be correct. I'm not sure if it is intended, but valid ^^. Oh and my compiler doesn't warn there (GCC 4.7.0).


    laanwj commented at 9:42 AM on September 25, 2012:

    You could also use ~0 to specify "set all bits". It's less controversial. Though I think (unsigned) -1 is correct. Overflow when converting from signed to unsigned never results in undefined behavior, don't try it the other way, though...


    sipa commented at 2:11 PM on September 28, 2012:

    Why convert to a string here first?


    kjj2 commented at 2:59 PM on September 28, 2012:

    Because d.connect() takes two strings.


    sipa commented at 3:02 PM on September 28, 2012:

    Oh my - never mind then.

  10. BitcoinPullTester commented at 11:52 PM on September 24, 2012: none

    Automatic sanity-testing: FAILED MERGE, see http://jenkins.bluematt.me/pull-tester/29e6b573cad01877c15ec8755c7a573250a700c3 for test log.

    This pull does not merge cleanly onto current master

  11. BitcoinPullTester commented at 7:20 PM on September 25, 2012: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/b202d430762c1b5c9925e948f357c66040f95f10 for binaries and test log.

  12. Diapolo commented at 8:03 PM on September 25, 2012: none

    ACK

  13. laanwj commented at 8:00 AM on September 26, 2012: member

    ACK

  14. sipa referenced this in commit 842a31ad1b on Sep 28, 2012
  15. sipa merged this on Sep 28, 2012
  16. sipa closed this on Sep 28, 2012

  17. KolbyML referenced this in commit 70c1fd1981 on Dec 5, 2020
  18. 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-19 15:15 UTC

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