Bind HTTP server to specified addresses */
| 310 | |
| 311 | /** Bind HTTP server to specified addresses */ |
| 312 | static bool HTTPBindAddresses(struct evhttp* http) { |
| 313 | int http_port = SysCfg().GetArg("-rpcport", SysCfg().RPCPort()); |
| 314 | std::vector<std::pair<std::string, uint16_t>> endpoints; |
| 315 | |
| 316 | // Determine what addresses to bind to |
| 317 | if (SysCfg().IsArgCount("-rpcbind")) { |
| 318 | // bind to specific address |
| 319 | for (const std::string& strRPCBind : SysCfg().GetMultiArgs("-rpcbind")) { |
| 320 | int port = http_port; |
| 321 | std::string host; |
| 322 | SplitHostPort(strRPCBind, port, host); |
| 323 | endpoints.push_back(std::make_pair(host, port)); |
| 324 | } |
| 325 | } else { // no set -rpcbind |
| 326 | if (SysCfg().IsArgCount("-rpcallowip")) { |
| 327 | // bind to all ip |
| 328 | endpoints.push_back(std::make_pair("::", http_port)); |
| 329 | endpoints.push_back(std::make_pair("0.0.0.0", http_port)); |
| 330 | } else { |
| 331 | // bind to loopback ip only |
| 332 | endpoints.push_back(std::make_pair("::1", http_port)); |
| 333 | endpoints.push_back(std::make_pair("127.0.0.1", http_port)); |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | // Bind addresses |
| 338 | for (std::vector<std::pair<std::string, uint16_t>>::iterator i = endpoints.begin(); |
| 339 | i != endpoints.end(); ++i) { |
| 340 | LogPrint(BCLog::RPC, "Binding RPC on address %s port %i\n", i->first, i->second); |
| 341 | evhttp_bound_socket* bind_handle = evhttp_bind_accept_socket( |
| 342 | http, i->first.empty() ? nullptr : i->first.c_str(), i->second); |
| 343 | if (bind_handle) { |
| 344 | CNetAddr addr; |
| 345 | boundSockets.push_back(bind_handle); |
| 346 | } else { |
| 347 | LogPrint(BCLog::ERROR, "Binding RPC on address %s port %i failed.\n", i->first, i->second); |
| 348 | } |
| 349 | } |
| 350 | return !boundSockets.empty(); |
| 351 | } |
| 352 | |
| 353 | /** Simple wrapper to set thread name and run work queue */ |
| 354 | static void HTTPWorkQueueRun(WorkQueue<HTTPClosure>* queue) { |
no test coverage detected