From b202d430762c1b5c9925e948f357c66040f95f10 Mon Sep 17 00:00:00 2001 From: kjj2 Date: Mon, 24 Sep 2012 08:39:12 -0500 Subject: [PATCH] Fix: when testnet=1 specified, change default ports to 18332 and 18333 --- src/bitcoinrpc.cpp | 9 +++++++-- src/init.cpp | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 1a3f51ea4..6072b270b 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -40,6 +40,11 @@ const Object emptyobj; void ThreadRPCServer3(void* parg); +static inline unsigned short GetDefaultRPCPort() +{ + return GetBoolArg("-testnet", false) ? 18332 : 8332; +} + Object JSONRPCError(int code, const string& message) { Object error; @@ -760,7 +765,7 @@ void ThreadRPCServer2(void* parg) // Try a dual IPv6/IPv4 socket, falling back to separate IPv4 and IPv6 sockets const bool loopback = !mapArgs.count("-rpcallowip"); asio::ip::address bindAddress = loopback ? asio::ip::address_v6::loopback() : asio::ip::address_v6::any(); - ip::tcp::endpoint endpoint(bindAddress, GetArg("-rpcport", 8332)); + ip::tcp::endpoint endpoint(bindAddress, GetArg("-rpcport", GetDefaultRPCPort())); boost::system::error_code v6_only_error; boost::shared_ptr acceptor(new ip::tcp::acceptor(io_service)); @@ -1055,7 +1060,7 @@ Object CallRPC(const string& strMethod, const Array& params) asio::ssl::stream sslStream(io_service, context); SSLIOStreamDevice d(sslStream, fUseSSL); iostreams::stream< SSLIOStreamDevice > stream(d); - if (!d.connect(GetArg("-rpcconnect", "127.0.0.1"), GetArg("-rpcport", "8332"))) + if (!d.connect(GetArg("-rpcconnect", "127.0.0.1"), GetArg("-rpcport", itostr(GetDefaultRPCPort())))) throw runtime_error("couldn't connect to server"); // HTTP basic authentication diff --git a/src/init.cpp b/src/init.cpp index dc425da64..8910ed071 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -272,7 +272,7 @@ std::string HelpMessage() #endif " -rpcuser= " + _("Username for JSON-RPC connections") + "\n" + " -rpcpassword= " + _("Password for JSON-RPC connections") + "\n" + - " -rpcport= " + _("Listen for JSON-RPC connections on (default: 8332)") + "\n" + + " -rpcport= " + _("Listen for JSON-RPC connections on (default: 8332 or testnet: 18332)") + "\n" + " -rpcallowip= " + _("Allow JSON-RPC connections from specified IP address") + "\n" + " -rpcconnect= " + _("Send commands to node running on (default: 127.0.0.1)") + "\n" + " -blocknotify= " + _("Execute command when the best block changes (%s in cmd is replaced by block hash)") + "\n" +