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