Commit graph

29 commits

Author SHA1 Message Date
Calin Culianu
f63eea29f4
Added config options for workqueue and worker_threads
These control the number of jobs that may be enqueued before error, and
the number of concurrent threads to process jobs, respectively.

Also renamed 'misc' subdir to 'doc'

Also added some /stats: show all the configured global Options as they
came in from conf file/CLI. ("Config" subdict in /stats JSON).
2020-01-07 10:36:41 +02:00
Calin Culianu
1462717c85
Added max_buffer and max_history config variables, plus some DoS prot.
The DoS protection added is against unlikely and hard-to-pull-off memory
exhaustion attacks whereby clients fill our receive buffers with data
without sending newlines.  If we detect our receive buffer (default 4MB
buffer size) is starting to fill, we time clients out quickly if no
newline arrives within 5 seconds.
2020-01-06 12:32:16 +02:00
Calin Culianu
752818171e
Added per-IP connection limits plus various other nits and tweaks
Per-IP connection limit defaults to 12, but is configurable from the
config file.

Also added exlusion sets for subnets for this (and any future per-IP
limits).

By default localhost-originating connections are excluded.

Also in this commit:

- Replaced some usages of QMap with QHash for data items where order is
not important -- QHash is faster.
- Made the global 'id' type from IdMixin be IdMixin::Id (type alias for
quint4).  This way code using this data item is cleared/easier to read
and more explicit in what it's doing.
2020-01-06 01:26:50 +02:00
Calin Culianu
4c3f6ca4a0
Properly implemented server.features, added hostname, public_*_port to config
Config variables added:

- hostname
- public_tcp_port
- public_ssl_port

These are used by server.features.  They will also go towards the peer
discovery/peering subsystem when that is implemented.
2020-01-04 22:32:05 +02:00
Calin Culianu
70a7a5a684
Nit 2019-12-30 08:16:38 +02:00
Calin Culianu
f074f84a31
Modified "New Client XXX" log print to be more readable
Also tells you how many extant connections total
2019-12-29 11:04:47 +02:00
Calin Culianu
a831cce8ac
Modified license preamble to say "Bitcoin Cash" instead of "Electron Cash"
The hope is maybe people will adopt this with other wallets...
2019-12-28 23:48:24 +02:00
Calin Culianu
405335c173
Added LICENSE preamble to all top-level source files
GPL v3. YAY!
2019-12-28 23:46:05 +02:00
Calin Culianu
3034cada1c
Added server.features
Also added a mechanism to query peer port, peer address, etc from
AbstractConnection instances.

Added genesisHash() public thread-safe function to Storage.
2019-12-23 11:12:29 +02:00
Calin Culianu
6df916565a
Made app only start listening for client connections after initial sync
Also in this commit various nits and subtle bugs prevented.

Refactored the 'Stats' mechanism to return a generic QVariant rather
than QVariantMap, which is more flexible.

Misc. other nits.
2019-11-27 14:07:09 +02:00
Calin Culianu
4b59e2233a Increased parallelism for the header sync
Set maxcur to 16, spinning up 3 bitcoind threads.

Seems to have brought header synch down from 170s to 71s on my mainnet
node here locally. Not bad!

Also fixed a bug where selecting bitcoind nodes was failing if >2 nodes.
2019-11-19 01:58:30 +02:00
Calin Culianu
7e16244609
Nits: Runtime check that classes deriving from QObjectMixin are ok.
added some asserts, plus -DNDEBUG to release build to disable asserts
for release.
2019-11-17 10:59:50 +02:00
Calin Culianu
3c52e988dd
Fixed the dreaded virtual QObject *qobj() thing we had in this codebase
Finally, after 20 years, I figured out how to do this.  Diamond-patter
multiple inheritence is tricky. Downcasting from a Base to a Derived
must be unambiguous, for one (thus you need virtual when inheriting the
base).

Secondly -- it must all be public all the way down to the concrete
class!

This is subtle.  I suppose the Base cannot see the Derived class
inherits it per C++ rules if not publicly inherited.  TIL.

https://en.cppreference.com/w/cpp/language/dynamic_cast#Explanation
2019-11-17 10:31:40 +02:00
Calin Culianu
ca9db3fc8d
Refactored stats stuff into a mixin class, StatsMixin
This makes it so that subobjects that return stats get the "statsSafe()"
function for free (which does a Util::LambdaOnObject).
2019-11-17 00:18:44 +02:00
Calin Culianu
dc8d95ee69
Refactoring; made all AbstractConnection inherit TimersByNameMixin
Also wrote a virtual methd 'getStats()' for AbstractConnection which
puts some basic stats into a QVariantMap for the /stats endpoint.

Subclasses can call the base implementation and add their own stats to
the returned map.

Also in this commit: misc refactoring and nits
2019-11-16 22:28:27 +02:00
Calin Culianu
ec046c818d
Added more temp. /stats for bitcoind instances 2019-11-13 01:23:20 +02:00
Calin Culianu
7d1ee5d6de
Finally got to the bottom of the "didn't call on_finished" bug
Basically it's not called on app exit. We made it so it's not so crucial
it be called for cleanup.

Also added some preliminary stats to the http /stats endpoint for the
BitcoinD instances.
2019-11-13 00:57:20 +02:00
Calin Culianu
a34585da1b
Added BitcoinD classes.. lord help me.
Also "upgraded" the universal ID we use for all objects to use quint64
(unsigned) rather than signed, and the "NO_ID" is 0.
2019-11-12 22:14:04 +02:00
Calin Culianu
277b0a212f
AbstractConnection: Socket now sets ReadBufferSize
This is to prevent memory exhaustion attacks from peers and enforce the
MAX_BUFFER we already defined for the clss.

Also added the EXPECT macro for clang's __builtin_expect for some branch
prediction to make some unlikely checks we make not be terribly costly
on the processor.
2019-11-12 00:31:38 +02:00
Calin Culianu
0d0f41c2f5
Changed the way timestamps are printed in the log 2019-11-11 11:55:10 +02:00
Calin Culianu
71961b28f5
Ensure nagling is disbaled on sockets, disable keepalive
This is done in AbstractConnection and pretty much should affect all
sockets that pass through that class.
2019-11-11 01:14:40 +02:00
Calin Culianu
b2b2509f25
Got HttpConnection working and talking to bitcoind
It works!  I still haven't figured out how to provoke the dreaded
"Workdepth exceeded" error .. but we pretty much drop the connection
anyway on anything too unexpected from bitcoind.

When the bitcoind manager class is written it will back off and try
again if too many disconnects happen.

For now though, the code we have is fast and works well against
bitcoind.
2019-11-11 00:22:31 +02:00
Calin Culianu
4ef96a9ae5
more nits 2019-11-09 14:17:32 +02:00
Calin Culianu
faeb64207f Finally.. finished refactoring out the RPC bits.
Now we can re-use the RPC method<->result code in the TcpServer side
which will face wallets.  Phew!  Took me long enough!

It's a minimal JSON-RPC protocol impl.. but it'll do.

The 1 nice bit is the Schema spec I came up with which more-or-less
works well enough as a first-pass validatior.

Further passes are needed in interested client code, but the initial
pass validation can be done in a thread so as to not waste the main
thread's time validating json or dict key presence/absense. Yay.
2019-04-30 19:21:47 +03:00
Calin Culianu
5e4aa2d9f9 renamed boilerplate_disconnect to disconnect 2019-04-30 17:09:07 +03:00
Calin Culianu
06d7dc5ea7 added more diagnostic print msgs to tract disconnections and socket lifecycle, etc 2019-04-30 13:43:34 +03:00
Calin Culianu
463b3d00b9 intermediate commit 2019-04-30 13:18:05 +03:00
Calin Culianu
4bd954a390 intermediate commit.. about to refactor exclient more 2019-04-30 10:01:21 +03:00
Calin Culianu
c28b9221e3 renamed AbstractClient -> AbstractConnection 2019-04-29 20:52:40 +03:00
Renamed from AbstractClient.cpp (Browse further)