diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2017-07-15 13:16:56 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2017-07-15 13:26:49 -0700 |
commit | c5904e871479514b2e2e18b4fdbbe468c4e5ec8e (patch) | |
tree | 3951c04875361305a281e6dd66b8f622fac6ca4e /src/bitcoin-cli.cpp | |
parent | 10b22e3141a603ec891d2cfc7100c29c7409aabe (diff) | |
parent | 5c643241e5d98992c0d5487b65e9c7b6d8005d1a (diff) | |
download | bitcoin-c5904e871479514b2e2e18b4fdbbe468c4e5ec8e.tar.xz |
Merge #10812: [utils] Allow bitcoin-cli's -rpcconnect option to be used with square brackets
5c643241e [utils] allow square brackets for ipv6 addresses in bitcoin-cli (John Newbery)
fe4fabaf1 [refactor] move SplitHostPort() into utilstrencodings (John Newbery)
Pull request description:
bitcoin-cli's `-rpcconnect` can accept ipv6 addresses (as long as the libevent version is new enough), but fails to parse ipv6 with square brackets. This PR makes `bitcoin-cli` parse ipv6 in square brackets correctly.
`bitcoin-cli -rpcconnect=[::1] <command>`
should now be equivalent to
`bitcoin-cli -rpcconnect=::1 <command>`
This is useful so the `bitcoin-cli` option can now be in the same format as the `bitcoind` option.
Doesn't include tests. I have a branch that fully tests `bitcoin-cli`, but that's queued behind several intermediate PRs.
- first commit moves `SplitHostPort()` from libbitcoin_common into libbitcoin_util
- second commit adds proper ipv6 parsing to bitcoin-cli
Tree-SHA512: 249d409f10360c989474283341f458cc97364a56a7d004ae6d5f13d8bffe3a51b5dc2484d42218848e2d42cd9c0b13a1b92e94ea19b209f7e91c875c208d8409
Diffstat (limited to 'src/bitcoin-cli.cpp')
-rw-r--r-- | src/bitcoin-cli.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 885b787b4d..92f6a21ebb 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -10,6 +10,7 @@ #include "chainparamsbase.h" #include "clientversion.h" #include "fs.h" +#include "utilstrencodings.h" #include "rpc/client.h" #include "rpc/protocol.h" #include "util.h" @@ -191,8 +192,14 @@ static void http_error_cb(enum evhttp_request_error err, void *ctx) UniValue CallRPC(const std::string& strMethod, const UniValue& params) { - std::string host = GetArg("-rpcconnect", DEFAULT_RPCCONNECT); - int port = GetArg("-rpcport", BaseParams().RPCPort()); + std::string host; + // In preference order, we choose the following for the port: + // 1. -rpcport + // 2. port in -rpcconnect (ie following : in ipv4 or ]: in ipv6) + // 3. default port for chain + int port = BaseParams().RPCPort(); + SplitHostPort(GetArg("-rpcconnect", DEFAULT_RPCCONNECT), port, host); + port = GetArg("-rpcport", port); // Obtain event base raii_event_base base = obtain_event_base(); |