MCPcopy Create free account
hub / github.com/ElementsProject/elements / HTTPBindAddresses

Function HTTPBindAddresses

src/httpserver.cpp:298–337  ·  view source on GitHub ↗

Bind HTTP server to specified addresses */

Source from the content-addressed store, hash-verified

296
297/** Bind HTTP server to specified addresses */
298static bool HTTPBindAddresses(struct evhttp* http)
299{
300 uint16_t http_port{static_cast<uint16_t>(gArgs.GetIntArg("-rpcport", BaseParams().RPCPort()))};
301 std::vector<std::pair<std::string, uint16_t>> endpoints;
302
303 // Determine what addresses to bind to
304 if (!(gArgs.IsArgSet("-rpcallowip") && gArgs.IsArgSet("-rpcbind"))) { // Default to loopback if not allowing external IPs
305 endpoints.push_back(std::make_pair("::1", http_port));
306 endpoints.push_back(std::make_pair("127.0.0.1", http_port));
307 if (gArgs.IsArgSet("-rpcallowip")) {
308 LogPrintf("WARNING: option -rpcallowip was specified without -rpcbind; this doesn't usually make sense\n");
309 }
310 if (gArgs.IsArgSet("-rpcbind")) {
311 LogPrintf("WARNING: option -rpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect\n");
312 }
313 } else if (gArgs.IsArgSet("-rpcbind")) { // Specific bind address
314 for (const std::string& strRPCBind : gArgs.GetArgs("-rpcbind")) {
315 uint16_t port{http_port};
316 std::string host;
317 SplitHostPort(strRPCBind, port, host);
318 endpoints.push_back(std::make_pair(host, port));
319 }
320 }
321
322 // Bind addresses
323 for (std::vector<std::pair<std::string, uint16_t> >::iterator i = endpoints.begin(); i != endpoints.end(); ++i) {
324 LogPrint(BCLog::HTTP, "Binding RPC on address %s port %i\n", i->first, i->second);
325 evhttp_bound_socket *bind_handle = evhttp_bind_socket_with_handle(http, i->first.empty() ? nullptr : i->first.c_str(), i->second);
326 if (bind_handle) {
327 CNetAddr addr;
328 if (i->first.empty() || (LookupHost(i->first, addr, false) && addr.IsBindAny())) {
329 LogPrintf("WARNING: the RPC server is not safe to expose to untrusted networks such as the public internet\n");
330 }
331 boundSockets.push_back(bind_handle);
332 } else {
333 LogPrintf("Binding RPC on address %s port %i failed.\n", i->first, i->second);
334 }
335 }
336 return !boundSockets.empty();
337}
338
339/** Simple wrapper to set thread name and run work queue */
340static void HTTPWorkQueueRun(WorkQueue<HTTPClosure>* queue, int worker_num)

Callers 1

InitHTTPServerFunction · 0.85

Calls 11

SplitHostPortFunction · 0.85
LookupHostFunction · 0.85
GetIntArgMethod · 0.80
RPCPortMethod · 0.80
IsArgSetMethod · 0.80
GetArgsMethod · 0.80
IsBindAnyMethod · 0.80
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected