Commit graph

35 commits

Author SHA1 Message Date
Bertrand Jacquin d53a3bebee
httpserver: include deque
It seems gcc 9.2.0 requires deque to be included:

  x86_64-pc-linux-gnu-g++ -std=c++11 -DHAVE_CONFIG_H -I. -I../src/config   -I. -I./obj -I/usr/include/db5.1/ -pthread -I/usr/include -I./leveldb/include -I./leveldb/helpers/memenv   -I./secp256k1/include    -pthread -I/usr/include/db5.1 -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS    -march=native -O2 -pipe -fomit-frame-pointer -c -o libdogecoin_server_a-httpserver.o `test -f 'httpserver.cpp' || echo './'`httpserver.cpp
  httpserver.cpp:71:10: error: ‘deque’ in namespace ‘std’ does not name a template type
     71 |     std::deque<std::unique_ptr<WorkItem>> queue;
        |          ^~~~~
  httpserver.cpp:30:1: note: ‘std::deque’ is defined in header ‘<deque>’; did you forget to ‘#include <deque>’?
     29 | #include <event2/keyvalq_struct.h>
    +++ |+#include <deque>
     30 |
  httpserver.cpp: In member function ‘bool WorkQueue<WorkItem>::Enqueue(WorkItem*)’:
  httpserver.cpp:110:13: error: ‘queue’ was not declared in this scope; did you mean ‘Enqueue’?
    110 |         if (queue.size() >= maxDepth) {
        |             ^~~~~
        |             Enqueue
  httpserver.cpp:113:9: error: ‘queue’ was not declared in this scope; did you mean ‘Enqueue’?
    113 |         queue.emplace_back(std::unique_ptr<WorkItem>(item));
        |         ^~~~~
        |         Enqueue
  httpserver.cpp: In member function ‘void WorkQueue<WorkItem>::Run()’:
  httpserver.cpp:125:35: error: ‘queue’ was not declared in this scope; did you mean ‘Enqueue’?
    125 |                 while (running && queue.empty())
        |                                   ^~~~~
        |                                   Enqueue
  httpserver.cpp:129:31: error: ‘queue’ was not declared in this scope; did you mean ‘Enqueue’?
    129 |                 i = std::move(queue.front());
        |                               ^~~~~
        |                               Enqueue
  httpserver.cpp: In member function ‘size_t WorkQueue<WorkItem>::Depth()’:
  httpserver.cpp:154:16: error: ‘queue’ was not declared in this scope; did you mean ‘Enqueue’?
    154 |         return queue.size();
        |                ^~~~~
        |                Enqueue
2020-01-24 20:16:27 +00:00
Ross Nicoll 148a2aca05 Introduce basic Dogecoin branding 2019-03-25 05:36:11 +00:00
Matt Corallo 7b2d96b634 Access WorkQueue::running only within the cs lock.
This removes a "race" between Interrupt() and Run(), though it
should not effect any of our supported platforms.
2017-02-03 13:50:17 -05:00
isle2983 27765b6403 Increment MIT Licence copyright header year on files modified in 2016
Edited via:

$ contrib/devtools/copyright_header.py update .
2016-12-31 11:01:21 -07:00
Matt Corallo 0cf86a6678 Introduce (and use) an IsArgSet accessor method 2016-12-23 21:30:16 -05:00
Matt Corallo 2b5f085ad1 Fix non-const mapMultiArgs[] access after init.
Swap mapMultiArgs for a const-reference to a _mapMultiArgs which is
only accessed in util.cpp
2016-12-23 21:30:15 -05:00
Pieter Wuille 9a0ed08b40
Merge #8109: Do not shadow member variables
ff8d279 Do not shadow member variables (Pavel Janík)
2016-08-26 18:13:22 +02:00
Cory Fields 9e9d644f51 net: fixup nits 2016-08-12 14:22:49 -04:00
Cory Fields 8945384bca net: Have LookupNumeric return a CService directly
Also fix up a few small issues:
- Lookup with "badip:port" now sets the port to 0
- Don't allow assert to have side-effects
2016-08-04 16:41:39 -04:00
Pavel Janík ff8d279a78 Do not shadow member variables 2016-07-31 20:55:09 +02:00
Cory Fields b6c3ff3dae net: Split resolving out of CSubNet 2016-07-31 14:01:43 -04:00
Cory Fields f96c7c4d91 net: Split resolving out of CService 2016-07-31 13:24:07 -04:00
Cory Fields 7e87033447 httpserver: replace boost threads with std
along with mutex/condvar/bind/etc.

httpserver handles its own interruption, so there's no reason not to use std
threading.

While we're at it, may as well kill the BOOST_FOREACH's as well.
2016-07-28 19:08:04 -04:00
Cory Fields d3773ca9ae httpserver: explicitly detach worker threads
When using std::thread in place of boost::thread, letting the threads destruct
results in a std::terminate. According to the docs, the same thing should be
be happening in later boost versions:
http://www.boost.org/doc/libs/1_55_0/doc/html/thread/thread_management.html#thread.thread_management.thread.destructor

I'm unsure why this hasn't blown up already, but explicitly detaching can't
hurt.
2016-07-28 19:07:23 -04:00
Cory Fields 755aa05174 httpserver: use a future rather than relying on boost's try_join_for 2016-07-28 19:07:15 -04:00
Wladimir J. van der Laan f0188f9178 http: use std::move to move HTTPRequest into HTTPWorkItem
Thanks to Cory Fields for the idea.
2016-05-05 08:27:12 +02:00
Wladimir J. van der Laan 37b21372a0 http: Change boost::scoped_ptr to std::unique_ptr in HTTPRequest
No need for boost here.
2016-05-05 08:27:12 +02:00
Wladimir J. van der Laan f97b410fdd http: Add log message when work queue is full
More useful error reporting.
2016-05-05 08:27:12 +02:00
Wladimir J. van der Laan 091d6e0499 http: Do a pending c++11 simplification
Use std::unique_ptr for handling work items.

This makes the code more RAII and, as mentioned in the comment, is what
I planned when I wrote the code in the first place.
2016-05-05 08:27:12 +02:00
Wladimir J. van der Laan 07e4edb056 auto_ptr → unique_ptr
Change the few occurrences of the deprecated `auto_ptr` to c++11 `unique_ptr`.
Silences the deprecation warnings.

Also add a missing `std::` for consistency.
2016-04-28 13:43:32 +02:00
Daniel Cousens a0eaff8a1d move rpc* to rpc/ 2016-01-21 08:36:55 +11:00
Wladimir J. van der Laan 3522f49f5a http: add Boost 1.49 compatibility
`try_join_for` was introduced in Boost 1.50:
http://www.boost.org/doc/libs/1_50_0/doc/html/thread/thread_management.html#thread.thread_management.thread.try_join_for

1.49 has `timed_join`, one can accomplish the same with:
http://www.boost.org/doc/libs/1_49_0/doc/html/thread/thread_management.html#thread.thread_management.thread.timed_join

However, `timed_join` was deprecated in 1.50. So a conditional is
necessary.

This solution was tested in #7031.
2015-11-20 10:14:21 +01:00
Gregory Maxwell aee22bf288 Avoid a compile error on hosts with libevent too old for EVENT_LOG_WARN.
This uses _EVENT_LOG_WARN instead, which appears to be defined in the
 old versions of libevent that I have on some systems.
2015-11-16 09:21:54 +00:00
Wladimir J. van der Laan a264c32e33
http: speed up shutdown
This continues/fixes #6719.

`event_base_loopbreak` was not doing what I expected it to, at least in
libevent 2.0.21.
What I expected was that it sets a timeout, given that no other pending
events it would exit in N seconds. However, what it does was delay the
event loop exit with 10 seconds, even if nothing is pending.

Solve it in a different way: give the event loop thread time to exit
out of itself, and if it doesn't, send loopbreak.

This speeds up the RPC tests a lot, each exit incurred a 10 second
overhead, with this change there should be no shutdown overhead in the
common case and up to two seconds if the event loop is blocking.

As a bonus this breaks dependency on boost::thread_group, as the HTTP
server minds its own offspring.
2015-11-13 11:10:48 +01:00
Wladimir J. van der Laan 41db8c4733 http: Restrict maximum size of request line + headers
Prevent memory exhaustion by sending lots of data.
Also add a test to `httpbasics.py`.

Closes #6425
2015-10-20 14:31:40 +02:00
Wladimir J. van der Laan ec908d5f7a http: Force-exit event loop after predefined time
This makes sure that the event loop eventually terminates, even if an
event (like an open timeout, or a hanging connection) happens to be
holding it up.
2015-09-28 15:06:20 +02:00
Wladimir J. van der Laan de9de2de36 http: Wait for worker threads to exit
Add a WaitExit() call to http's WorkQueue to make it delete the work
queue only when all worker threads stopped.

This fixes a problem that was reproducable by pressing Ctrl-C during
AppInit2:
```
/usr/include/boost/thread/pthread/condition_variable_fwd.hpp:81: boost::condition_variable::~condition_variable(): Assertion `!ret' failed.
/usr/include/boost/thread/pthread/mutex.hpp:108: boost::mutex::~mutex(): Assertion `!posix::pthread_mutex_destroy(&m)' failed.
```

I was assuming that `threadGroup->join_all();` would always have been
called when entering the Shutdown(). However this is not the case in
bitcoind's AppInit2-non-zero-exit case "was left out intentionally
here".
2015-09-28 15:06:20 +02:00
Wladimir J. van der Laan 5e0c221356 Make HTTP server shutdown more graceful
Shutting down the HTTP server currently breaks off all current requests.
This can create a race condition with RPC `stop` command, where the calling
process never receives confirmation.

This change removes the listening sockets on shutdown so that no new
requests can come in, but no longer breaks off requests in progress.

Meant to fix #6717.
2015-09-28 15:06:20 +02:00
Wladimir J. van der Laan 2190ea6c4e rpc: Split option -rpctimeout into -rpcservertimeout and -rpcclienttimeout
The two timeouts for the server and client, are essentially different:

- In the case of the server it should be a lower value to avoid clients
clogging up connection slots

- In the case of the client it should be a high value to accomedate slow
  responses from the server, for example for slow queries or when the
  lock is contended

Split the options into `-rpcservertimeout` and `-rpcclienttimeout` with
respective defaults of 30 and 900.
2015-09-21 17:15:36 +02:00
Wladimir J. van der Laan 8b2d6edaa9 http: Disable libevent debug logging, if not explicitly enabled
Add a option "-debug=libevent" to enable libevent debugging for troubleshooting.
Libevent logging is redirected to our own log.
2015-09-21 13:24:34 +02:00
paveljanik eb3002bb71 [TRIVIAL] Fix typo: exactmath -> exactmatch
... but not yet in trivial tree
2015-09-04 19:22:48 +02:00
Wladimir J. van der Laan 3a174cd400 Fix race condition between starting HTTP server thread and setting EventBase()
Split StartHTTPServer into InitHTTPServer and StartHTTPServer to give
clients a window to register their handlers without race conditions.

Thanks @ajweiss for figuring this out.
2015-09-03 10:59:19 +02:00
Wladimir J. van der Laan 6d2bc22146 Document options for new HTTP/RPC server in --help 2015-09-03 10:59:19 +02:00
Wladimir J. van der Laan be33f3f50b Implement RPCTimerHandler for Qt RPC console
Implement RPCTimerHandler for Qt RPC console, so that `walletpassphrase`
works with GUI and `-server=0`.

Also simplify HTTPEvent-related code by using boost::function directly.
2015-09-03 10:59:19 +02:00
Wladimir J. van der Laan 40b556d374 evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.

- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.

- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral

- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.

- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.

By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.

What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.

Configuration options:

- `-rpcthreads`: repurposed as "number of  work handler threads". Still
defaults to 4.

- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.

- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.

- `-debug=http`: low-level http activity logging
2015-09-03 10:59:18 +02:00