Commit graph

53 commits

Author SHA1 Message Date
Calin Culianu
7a909902ce nit 2019-12-01 02:50:00 +02:00
Calin Culianu
f9494aab65 Fixed a bug where nReceived for bitcoind connection was wrong
This stat wasn't being updated properly when reading the http content.
Fixed.
2019-12-01 02:43:59 +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
4bb949487b minor nit 2019-11-26 10:31:01 +02:00
Calin Culianu
9fbbb68c15
Performance optimization: Pre-create some static QStrings we use often
The strings that act as jsonrpc keys are used a lot in the app -- using
eg varmap["error"] is slower than pre-creating a static QString, s_error = "error",
and then referring to it as varmap[s_error].  So we do that and it
should shave a few percentage points of cpu usage during heavy json rpc
use.
2019-11-26 10:05:00 +02:00
Calin Culianu
b823f97397
nits 2019-11-19 12:33:50 +02:00
Calin Culianu
764419c49d
Got rid of the std::variant based Message::Id, went with pure QVariant
It's less code to maintain to do that, plus it works with all compilers
(I had trouble with std::variant on non-Apple-clang).

On top of that the QVariant approach likely is slightly faster as no
conversion needs to be done from our Message::id -> QVariant when it
*is* a QVariant already.

We sacrifice a tiny bit of type safety.  We just have to be sure in the
code to never allow fractional doubles to go out as an id (this is
unlikely to happen anyway in practice).
2019-11-19 12:16:32 +02:00
Calin Culianu
d7e0ba16db
fixup for error parsing integer id: 1000000.. oops. 2019-11-19 10:44:51 +02:00
Calin Culianu
cec5254720
nits + added nErrorReplies statistic to ConnectionBase 2019-11-19 02:13:08 +02:00
Calin Culianu
f4091bb005
Devised a scheme for asynch messaging to bitcoind
And added some test code in Controller to use the scheme.

It's very asynchronous.  Needs some tuning long term to see how it deals
with load and perhaps throttle the requests if we know bitcoind is under
load.

But for right now, for testing, it should work ok.

Also in this commit small nits, plus bugfix to RPC::Message factory
methods (I forgot to populate some instance properties when constructing
the objects).

Additionally, we were registering the qMetaType wrong for RPC::Message
and RPC::Message::Id (this has been fixed).
2019-11-18 14:32:48 +02:00
Calin Culianu
30424dc341
Finally figure out how to use unique_ptr with opaque classes/structs
Forward delcared private classes whose implementation is opaque to
outside code confuse unique_ptr's auto-generated deleter function.
If you specify your own deleter, you can totally use unique_ptr with opaque
types.
2019-11-17 21:28:41 +02:00
Calin Culianu
9e07f32e95
Added more stats 2019-11-17 12:38:36 +02:00
Calin Culianu
04c4d5d5b7
Squashed commit of the following:
commit 326de9f8e9670ace95d6044e4f2d36a697a78ef9
Author: Calin Culianu <calin.culianu@gmail.com>
Date:   Wed Nov 13 11:27:23 2019 +0200

    fix apple compiler check

commit f794b3df1dda0c8b7df3c587688b8182a0de029d
Author: Calin Culianu <calin.culianu@gmail.com>
Date:   Wed Nov 13 11:12:01 2019 +0200

    added guard for msc_ver which doesn't support #warning

commit 04fbc36bbb40cbcc926e504f2109d766d2335113
Author: Calin Culianu <calin.culianu@gmail.com>
Date:   Wed Nov 13 11:06:12 2019 +0200

    Fix for win32-g++ compilation

commit a79b38b13da03ae741d81ca5a1a7978f9c09d961
Author: Calin Culianu <calin.culianu@gmail.com>
Date:   Wed Nov 13 10:49:33 2019 +0200

    Beat project into sunmission to compile on Linux using clang
2019-11-13 11:32:52 +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
3970fd70c8
more C++ nits 2019-11-12 17:25:15 +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
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
8135f3d339
added authFailure signal to the HttpConnection class 2019-11-11 00:33:29 +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
5ad9da1287
JSON RPC: Added support for JSON RPC 1.0
This is enabled with the 'v1' flag to various functions that operate on
the json data and validate it.  Default is jsonrpc 2.0 but v1 flag can
be used to interop with e.g. bitcoind.
2019-11-10 09:17:39 +02:00
Calin Culianu
c768323434
started impl. HttpConnection 2019-11-10 00:27:44 +02:00
Calin Culianu
20f4708aed
nits 2019-11-09 19:06:40 +02:00
Calin Culianu
6508ea1912
Refactored RPC::Connection to be a little bit transport agnostic
This allows it to talk to things like bitcoind. It still wants a tcp
socket as its transport -- but it can at least now be wrapped in HTTP
for bitcoin as well as re-use of the same code for ElectronX style
linefeed based JSON.

Our RPC lib is nowhere near 100% generic and re-usable but it's a good
first step here with this refactor job.
2019-11-09 17:06:40 +02:00
Calin Culianu
9014198aac
nit 2019-11-09 15:57:48 +02:00
Calin Culianu
e7323b854b
Try and return proper id to client on request failure
We were grabbing the message.id too late. We should grab it as soon as
possible for best json rpc error reporting as per the spec.
2019-11-09 14:39:52 +02:00
Calin Culianu
6d6ea91aa9
nits 2019-11-09 13:49:28 +02:00
Calin Culianu
e07f7be562
Added support for "named" (kwargs) params. Eg "params" : { .. }
This should hopefully fully complete our implementation to support
JSON-RPC 2.0 without batching.  We still are missing batching but at
least now we implement the non-batching portion of the spec more
completely.
2019-11-09 13:08:36 +02:00
Calin Culianu
20066bff04
Put the JSON RPC error codes in an enum, and used it 2019-11-09 03:26:21 +02:00
Calin Culianu
065a221977
More JSON RPC 2.0 spec conformance
It turns out server should always ignore notifications it wasn't
expecting and never respond to them.

What I was doing by returning errors was incorrect.

Instead we add to the error tally for unknown notifications and
eventually disconnect the client.

Also added preliminary support for param maps . . .
2019-11-09 02:33:16 +02:00
Calin Culianu
cd643e7323
Made Message::Id type a std::variant
I restricted the possible underlying types it can contain down to
qint64, QString, and nullptr_t. This should make it more type safe since
we don't want it to inadvertently end up holding lists or maps
(previously it was a straight up QVariant).

It has a conversion to QVariant so it should work nicely.
2019-11-09 01:55:48 +02:00
Calin Culianu
e5886820fa nit 2019-11-08 15:49:42 +02:00
Calin Culianu
cf975c555c refactored id check into Message::idIsValid 2019-11-08 15:41:25 +02:00
Calin Culianu
6633326f49 nit 2019-11-08 14:50:03 +02:00
Calin Culianu
b583089d0b comment nit 2019-11-08 14:48:06 +02:00
Calin Culianu
dbd65cc8c5
nits 2019-11-08 14:42:49 +02:00
Calin Culianu
27e2083b86
Got rid of that "Schema" system which was cumbersome and not useful
- It made the code potentially slower
- Made modifying/adding methods too complex
- Wasn't very beneficial.
- Instead, we just verify JSON-RPC 2.0 spec in the core Connection
class, then we pass on the method call to the subclass if it's found in
the methodlist, etc.
2019-11-08 14:14:38 +02:00
Calin Culianu
6e58170d43
Implemented more of JSON-RPC 2.0. Dummy subscribe method, etc
Our implementation is wayyy too complex.  We need to simplify this
massively.  Perhaps do away with the whole "schema" thing...?
2019-11-08 02:49:09 +02:00
Calin Culianu
43b7e915c4
Got rid of more ShuffleUp stuff, added CLI args 2019-11-07 23:55:13 +02:00
Calin Culianu
c2f6e5f3fe Some nits related to json rpc 2019-05-06 17:31:52 +03:00
Calin Culianu
386383d6d4 Made our JSON-RPC 2.0 implementation more closely match the spec
- It's still a little more restrictive than the spec allows -- doesn't
like non-positive-int 'id'
- We not made the shuffle.spec status report back 'notifications' to the
client rather than repeated 'result' messages (as those would be out of
spec). The first response to a 'shuffle.spec' request is either
result="pending", result="accepted", or an error response
- Subsequent shuffle.spec status changes come as a method notification
for "shuffle.spec" with params=["accepted"] or params=["some error
message"]

Overall I think our bare bones JSON-RPC will at least not break now as
interop with other impls.
2019-05-06 14:34:42 +03:00
Calin Culianu
113efda25a Added spec rpc command from clients to us.. still need to do listunspent 2019-05-03 17:28:51 +03:00
Calin Culianu
6e4db7eb67 nits 2019-05-03 10:24:29 +03:00
Calin Culianu
8a7e443b01 Made the TCP server be Json RPC 2019-05-02 23:01:43 +03:00
Calin Culianu
9e9a227469 added error json reply/sending specific signals/slots 2019-05-02 06:59:00 +03: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
463b3d00b9 intermediate commit 2019-04-30 13:18:05 +03:00
Calin Culianu
ae5237bb0f another step... 2019-04-30 10:37:45 +03:00
Calin Culianu
4bd954a390 intermediate commit.. about to refactor exclient more 2019-04-30 10:01:21 +03:00