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

Function HTTPBindAddresses

src/httpserver.cpp:297–332  ·  view source on GitHub ↗

Bind HTTP server to specified addresses */

Source from the content-addressed store, hash-verified

295
296/** Bind HTTP server to specified addresses */
297static 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 */
335static void HTTPWorkQueueRun(WorkQueue<HTTPClosure>* queue)

Callers 1

InitHTTPServerFunction · 0.85

Calls 9

SplitHostPortFunction · 0.85
RPCPortMethod · 0.80
IsArgSetMethod · 0.80
GetArgsMethod · 0.80
GetArgMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected