Bind HTTP server to specified addresses */
| 295 | |
| 296 | /** Bind HTTP server to specified addresses */ |
| 297 | static bool HTTPBindAddresses(struct evhttp* http) |
| 298 | { |
| 299 | int defaultPort = gArgs.GetArg("-rpcport", BaseParams().RPCPort()); |
| 300 | std::vector<std::pair<std::string, uint16_t> > endpoints; |
| 301 | |
| 302 | // Determine what addresses to bind to |
| 303 | if (!gArgs.IsArgSet("-rpcallowip")) { // Default to loopback if not allowing external IPs |
| 304 | endpoints.push_back(std::make_pair("::1", defaultPort)); |
| 305 | endpoints.push_back(std::make_pair("127.0.0.1", defaultPort)); |
| 306 | if (gArgs.IsArgSet("-rpcbind")) { |
| 307 | LogPrintf("WARNING: option -rpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect\n"); |
| 308 | } |
| 309 | } else if (gArgs.IsArgSet("-rpcbind")) { // Specific bind address |
| 310 | for (const std::string& strRPCBind : gArgs.GetArgs("-rpcbind")) { |
| 311 | int port = defaultPort; |
| 312 | std::string host; |
| 313 | SplitHostPort(strRPCBind, port, host); |
| 314 | endpoints.push_back(std::make_pair(host, port)); |
| 315 | } |
| 316 | } else { // No specific bind address specified, bind to any |
| 317 | endpoints.push_back(std::make_pair("::", defaultPort)); |
| 318 | endpoints.push_back(std::make_pair("0.0.0.0", defaultPort)); |
| 319 | } |
| 320 | |
| 321 | // Bind addresses |
| 322 | for (std::vector<std::pair<std::string, uint16_t> >::iterator i = endpoints.begin(); i != endpoints.end(); ++i) { |
| 323 | LogPrint(BCLog::HTTP, "Binding RPC on address %s port %i\n", i->first, i->second); |
| 324 | evhttp_bound_socket *bind_handle = evhttp_bind_socket_with_handle(http, i->first.empty() ? nullptr : i->first.c_str(), i->second); |
| 325 | if (bind_handle) { |
| 326 | boundSockets.push_back(bind_handle); |
| 327 | } else { |
| 328 | LogPrintf("Binding RPC on address %s port %i failed.\n", i->first, i->second); |
| 329 | } |
| 330 | } |
| 331 | return !boundSockets.empty(); |
| 332 | } |
| 333 | |
| 334 | /** Simple wrapper to set thread name and run work queue */ |
| 335 | static void HTTPWorkQueueRun(WorkQueue<HTTPClosure>* queue) |
no test coverage detected