MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / HTTPBindAddresses

Function HTTPBindAddresses

src/httpserver.cpp:278–314  ·  view source on GitHub ↗

Bind HTTP server to specified addresses */

Source from the content-addressed store, hash-verified

276
277/** Bind HTTP server to specified addresses */
278static bool HTTPBindAddresses(struct evhttp* http)
279{
280 int defaultPort = GetArg("-rpcport", BaseParams().RPCPort());
281 int nBound = 0;
282 std::vector<std::pair<std::string, uint16_t> > endpoints;
283
284 // Determine what addresses to bind to
285 if (!mapArgs.count("-rpcallowip")) { // Default to loopback if not allowing external IPs
286 endpoints.push_back(std::make_pair("::1", defaultPort));
287 endpoints.push_back(std::make_pair("127.0.0.1", defaultPort));
288 if (mapArgs.count("-rpcbind")) {
289 LogPrintf("WARNING: option -rpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect\n");
290 }
291 } else if (mapArgs.count("-rpcbind")) { // Specific bind address
292 const std::vector<std::string>& vbind = mapMultiArgs["-rpcbind"];
293 for (std::vector<std::string>::const_iterator i = vbind.begin(); i != vbind.end(); ++i) {
294 int port = defaultPort;
295 std::string host;
296 SplitHostPort(*i, port, host);
297 endpoints.push_back(std::make_pair(host, port));
298 }
299 } else { // No specific bind address specified, bind to any
300 endpoints.push_back(std::make_pair("::", defaultPort));
301 endpoints.push_back(std::make_pair("0.0.0.0", defaultPort));
302 }
303
304 // Bind addresses
305 for (std::vector<std::pair<std::string, uint16_t> >::iterator i = endpoints.begin(); i != endpoints.end(); ++i) {
306 LogPrint("http", "Binding RPC on address %s port %i\n", i->first, i->second);
307 if (evhttp_bind_socket(http, i->first.empty() ? NULL : i->first.c_str(), i->second) == 0) {
308 nBound += 1;
309 } else {
310 LogPrintf("Binding RPC on address %s port %i failed.\n", i->first, i->second);
311 }
312 }
313 return nBound > 0;
314}
315
316/** Simple wrapper to set thread name and run work queue */
317static void HTTPWorkQueueRun(WorkQueue<HTTPClosure>* queue)

Callers 1

InitHTTPServerFunction · 0.85

Calls 8

GetArgFunction · 0.85
SplitHostPortFunction · 0.85
RPCPortMethod · 0.80
countMethod · 0.80
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected