Commit graph

670 commits

Author SHA1 Message Date
Doyle
abb8dfc48e Merge commit 'c4f75fe' into MergeUpstream3 2020-05-28 15:29:00 +10:00
Doyle
b71ce522c1 Merge commit '6c7d928' into MergeUpstream3 2020-05-28 15:02:40 +10:00
Doyle
4e8786574e Merge commit '328e9db' into MergeUpstream3 2020-05-28 14:50:12 +10:00
Doyle
bda1e6c97b Merge commit '2eee9bcdf8aa33c3fd8cee0685ee16a0131c5b59' into MergeUpstream3 2020-05-28 11:49:14 +10:00
Doyle
7345e62532 Merge commit '092a57df996be75e3a45e9dc69d15138093f503b' into MergeUpstream3 2020-05-28 11:48:41 +10:00
Doyle
00545b4920 Merge commit '5e384f2' into MergeUpstream3 2020-05-27 15:45:13 +10:00
Doyle
95c9200099 Fix m_mime_tipe -> m_mime_type 2020-05-27 15:04:04 +10:00
Doyle
6fa5d0c5e3 Merge commit '8039fd4' into MergeUpstream3 2020-05-27 14:55:53 +10:00
Doyle
fd233c28f9 Merge commit 'f1ca98a7efa4a9a113881b38fe587ba1d231a2f7' into MergeUpstream3 2020-05-27 14:42:34 +10:00
Doyle
4cc48ed813 Merge commit 'fe73607' into MergeUpstream3 2020-05-27 14:38:37 +10:00
Doyle
2114180485 Merge commit 'df98432' into MergeUpstream3 2020-05-26 15:34:36 +10:00
Doyle
f0df6cfb82 Remove math_helper.h and dependers 2020-05-26 15:19:12 +10:00
Doyle
2e42202e94 Merge commit 'dcff02e4c3b1214143b19685361c3c6cffa62be7' into MergeUpstream3 2020-05-26 15:15:25 +10:00
Doyle
804b811ef9 Merge commit '42d84ad' into MergeUpstream3 2020-05-25 14:12:26 +10:00
Doyle
72085b20d7 Merge commit 'bb2bcf35216b819778fe09cee328e7acc2f680cf' into MergeUpstream3 2020-05-25 13:49:06 +10:00
Doyle
d799af317d Merge commit '441ed9f2fef6a43708c115191c51ca16930ce95b' into MergeUpstream3 2020-05-25 10:36:27 +10:00
Doyle
aa8c5bc4ce Merge commit 'fcb4c72bb56e2de1b034636c1ea88d23a5fb8c4b' into MergeUpstream3 2020-05-22 15:05:43 +10:00
Doyle
e7b5e3ea81 Merge commit 'a74a82c8b2e520e487b65124a08af848a14b27b7' into MergeUpstream3 2020-05-22 14:05:20 +10:00
Doyle
170c01c7eb Merge commit '15b9b4e' into MergeUpstream3 2020-05-22 14:02:42 +10:00
Doyle
5822115e4e Adjust the prior commit here (epee: abstract_tcp_server2: resolve CID 203919 (DC.WEAK_CRYPTO))
Adjustment requested by Jagerman, -
It reinitializes std::random_device on each pass through the function, and that can block, and on
top of that doesn't give randomization at all (you might as well just use the random device results
directly rather than using a mt19937 for one single random value generation).

This code needs to be fixed to initialize the RNG from the random device *once*, by moving the
19937+seed construction into a function and then, in the code in the commit, doing:

    static std::mt19937 rng = get_seeded_mt19937();

so that the seeding happens just *once* and then the random values are retrieved repeatedly from the
RNG.

It's also slightly wrong in how it pulls a random value using `rng() % 50`: that produces a
*slightly* biased value (because the range of produced values is not a multiple of 50).  It should
do this instead, to be correct:

    int ms = std::uniform_int_distribution<>{250, 299}(rng);

In practice the bias here isn't going to be significant, but there is also no downside to doing it
correctly here.
2020-05-22 12:15:24 +10:00
Doyle
f2ebd811d0 Merge commit 'c6430f9' into MergeUpstream3 2020-05-22 12:04:20 +10:00
Doyle
9742c0d91d Merge commit 'dbe31f63e1c96e0f6ad57643ef57454986b5d336' into MergeUpstream3 2020-05-21 16:13:28 +10:00
Doyle
39d74a0b38 Merge commit '48d8475b6ea77c6cc9670c9c312f3b7684b12a2c' into MergeUpstream3 2020-05-21 13:37:57 +10:00
Doyle
726910a8f3 Merge commit 'e4f11a6' into MergeUpstream3 2020-05-21 12:30:03 +10:00
Doyle
c7cf2935a3 Don't couple the cancelling wallet code with console_handler 2020-05-21 10:21:05 +10:00
Doyle
6a357fa499 Merge commit '23547e6ed6c9f0dc694d55316540000b030bbb06' into MergeUpstream3 2020-05-20 18:14:48 +10:00
Doyle
15fd7f8200 Merge branch 'dev' into MergeUpstream3 2020-05-20 14:59:12 +10:00
Jason Rhinelander
44d6715d56 Make suspend_readline a (usable) no-op when readline not available
This moves all the conditional HAVE_READLINE into once place rather than
scattering it everywhere we want to suspend readline.  (Since the class
does nothing the compiler can trivially optimize it away when we don't
have readline).
2020-05-20 00:48:59 -03:00
Doyle
c6b121e3db Fix I2P/Tor/simplewallet merge 2020-05-20 12:36:54 +10:00
Doyle
f65d67da86 console_handler: Log errors properly, gracefully shut down wallet
- In simplewallet, we don't report invalid/missing commands to the
CLI because we throw and catch errors that are logged silently. Now we
always log the to the user unless it's thrown by something other than
the wallet.

- Add invalid_command exception to distinguish between an error thrown
by the console_handler (i.e. missing/empty command) versus an actual
std::out_of_range thrown by wallet code (previously would have
incorrectly reported "Unknown command ... ", when it was a known command).

- Catch exceptions thrown via commands sent by RPC over the terminal and
shut down the wallet properly.

- In console_handler don't react to cmd_handler failing. Previously, if
a command failed it'd assume invalid command and log or try the next
branch which was detecting application exit.
2020-05-20 12:27:22 +10:00
Doyle
1ea257323d console_handler: Handle exit first before command_handler
Otherwise we throw an exception and never enter the terminate branch
2020-05-20 12:16:30 +10:00
Doyle
22db7c3b3f console_handler: Remove unused template code 2020-05-20 11:25:59 +10:00
Doyle
34ca917511 Merge commit '98af2e954b78dc7607d0236a9db84b2143a33a90' into MergeUpstream3 2020-05-19 11:04:48 +10:00
Doyle
184183f309 Merge branch 'dev' into MergeUpstream2 2020-05-18 12:58:59 +10:00
Doyle
f1f37fd8fc Revert "Bans for RPC connections"
This reverts commit a182df21d0.
2020-05-18 12:06:11 +10:00
Jason Rhinelander
9268420a09 Fix epee spelling: mime_tipe -> mime_type 2020-05-11 18:45:15 -03:00
Jason Rhinelander
69b86efcec Add epee http piecemeal responses
This lets the user provide multiple strings to be sent (concatenated
together) for an epee http response rather than having to repack
everything into a single string.

This also removes a bunch of related unnecessary temporary string
allocations in the epee response generating code.
2020-05-11 18:45:15 -03:00
Jason Rhinelander
0e3f173c7f RPC overhaul
High-level details:

This redesigns the RPC layer to make it much easier to work with,
decouples it from an embedded HTTP server, and gets the vast majority of
the RPC serialization and dispatch code out of a very commonly included
header.

There is unfortunately rather a lot of interconnected code here that
cannot be easily separated out into separate commits.  The full details
of what happens here are as follows:

Major details:
- All of the RPC code is now in a `cryptonote::rpc` namespace; this
  renames quite a bit to be less verbose: e.g. CORE_RPC_STATUS_OK
  becomes `rpc::STATUS_OK`, and `cryptonote::COMMAND_RPC_SOME_LONG_NAME`
  becomes `rpc::SOME_LONG_NAME` (or just SOME_LONG_NAME for code already
  working in the `rpc` namespace).
- `core_rpc_server` is now completely decoupled from providing any
  request protocol: it is now *just* the core RPC call handler.
- The HTTP RPC interface now lives in a new rpc/http_server.h; this code
  handles listening for HTTP requests and dispatching them to
  core_rpc_server, then sending the results back to the caller.
- There is similarly a rpc/lmq_server.h for LMQ RPC code; more details
  on this (and other LMQ specifics) below.
- RPC implementing code now returns the response object and throws when
  things go wrong which simplifies much of the rpc error handling.  They
  can throw anything; generic exceptions get logged and a generic
  "internal error" message gets returned to the caller, but there is
  also an `rpc_error` class to return an error code and message used by
  some json-rpc commands.
- RPC implementing functions now overload `core_rpc_server::invoke`
  following the pattern:

    RPC_BLAH_BLAH::response core_rpc_server::invoke(RPC_BLAH_BLAH::request&& req, rpc_context context);

  This overloading makes the code vastly simpler: all instantiations are
  now done with a small amount of generic instantiation code in a single
  .cpp rather than needing to go to hell and back with a nest of epee
  macros in a core header.
- each RPC endpoint is now defined by the RPC types themselves,
  including its accessible names and permissions, in
  core_rpc_server_commands_defs.h:
  - every RPC structure now has a static `names()` function that returns
    the names by which the end point is accessible.  (The first one is
    the primary, the others are for deprecated aliases).
  - RPC command wrappers define their permissions and type by inheriting
    from special tag classes:
    - rpc::RPC_COMMAND is a basic, admin-only, JSON command, available
      via JSON RPC.  *All* JSON commands are now available via JSON RPC,
      instead of the previous mix of some being at /foo and others at
      /json_rpc.  (Ones that were previously at /foo are still there for
      backwards compatibility; see `rpc::LEGACY` below).
    - rpc::PUBLIC specifies that the command should be available via a
      restricted RPC connection.
    - rpc::BINARY specifies that the command is not JSON, but rather is
      accessible as /name and takes and returns values in the magic epee
      binary "portable storage" (lol) data format.
    - rpc::LEGACY specifies that the command should be available via the
      non-json-rpc interface at `/name` for backwards compatibility (in
      addition to the JSON-RPC interface).
- some epee serialization got unwrapped and de-templatized so that it
  can be moved into a .cpp file with just declarations in the .h.  (This
  makes a *huge* difference for core_rpc_server_commands_defs.h and for
  every compilation unit that includes it which previously had to
  compile all the serialization code and then throw all by one copy away
  at link time).  This required some new macros so as to not break a ton
  of places that will use the old way putting everything in the headers;
  The RPC code uses this as does a few other places; there are comments
  in contrib/epee/include/serialization/keyvalue_serialization.h as to
  how to use it.
- Detemplatized a bunch of epee/storages code.  Most of it should have
  have been using templates at all (because it can only ever be called
  with one type!), and now it isn't.  This broke some things that didn't
  properly compile because of missing headers or (in one case) a messed
  up circular dependency.
- Significantly simplified a bunch of over-templatized serialization
  code.
- All RPC serialization definitions is now out of
  core_rpc_server_commands_defs.h and into a single .cpp file
  (core_rpc_server_commands_defs.cpp).
- core RPC no longer uses the disgusting
  BEGIN_URI_MAP2/MAP_URI_BLAH_BLAH macros.  This was a terrible design
  that forced slamming tons of code into a common header that didn't
  need to be there.
- epee::struct_init is gone.  It was a horrible hack that instiated
  multiple templates just so the coder could be so lazy and write
  `some_type var;` instead of properly value initializing with
  `some_type var{};`.
- Removed a bunch of useless crap from epee.  In particular, forcing
  extra template instantiations all over the place in order to nest
  return objects inside JSON RPC values is no longer needed, as are a
  bunch of stuff related to the above de-macroization of the code.
- get_all_service_nodes, get_service_nodes, and get_n_service_nodes are
  now combined into a single `get_service_nodes` (with deprecated
  aliases for the others), which eliminates a fair amount of
  duplication.  The biggest obstacle here was getting the requested
  fields reference passed through: this is now done by a new ability to
  stash a context in the serialization object that can be retrieved by a
  sub-serialized type.

LMQ-specifics:

- The LokiMQ instance moves into `cryptonote::core` rather than being
  inside cryptonote_protocol.  Currently the instance is used both for
  qnet and rpc calls (and so needs to be in a common place), but I also
  intend future PRs to use the batching code for job processing
  (replacing the current threaded job queue).
- rpc/lmq_server.h handles the actual LMQ-request-to-core-RPC glue.
  Unlike http_server it isn't technically running the whole LMQ stack
  from here, but the parallel name with http_server seemed appropriate.
- All RPC endpoints are supported by LMQ under the same names as defined
  generically, but prefixed with `rpc.` for public commands and `admin.`
  for restricted ones.
- service node keys are now always available, even when not running in
  `--service-node` mode: this is because we want the x25519 key for
  being able to offer CURVE encryption for lmq RPC end-points, and
  because it doesn't hurt to have them available all the time.  In the
  RPC layer this is now called "get_service_keys" (with
  "get_service_node_key" as an alias) since they aren't strictly only
  for service nodes.  This also means code needs to check
  m_service_node, and not m_service_node_keys, to tell if it is running
  as a service node.  (This is also easier to notice because
  m_service_node_keys got renamed to `m_service_keys`).
- Added block and mempool monitoring LMQ RPC endpoints: `sub.block` and
  `sub.mempool` subscribes the connection for new block and new mempool
  TX notifications.  The latter can notify on just blink txes, or all
  new mempool txes (but only new ones -- txes dumped from a block don't
  trigger it).  The client gets pushed a [`notify.block`, `height`,
  `hash`] or [`notify.tx`, `txhash`, `blob`] message when something
  arrives.

Minor details:
- rpc::version_t is now a {major,minor} pair.  Forcing everyone to pack
  and unpack a uint32_t was gross.
- Changed some macros to constexprs (e.g. CORE_RPC_ERROR_CODE_...).
  (This immediately revealed a couple of bugs in the RPC code that was
  assigning CORE_RPC_ERROR_CODE_... to a string, and it worked because
  the macro allows implicit conversion to a char).
- De-templatizing useless templates in epee (i.e. a bunch of templated
  types that were never invoked with different types) revealed a painful
  circular dependency between epee and non-epee code for tor_address and
  i2p_address.  This crap is now handled in a suitably named
  `net/epee_network_address_hack.cpp` hack because it really isn't
  trivial to extricate this mess.
- Removed `epee/include/serialization/serialize_base.h`.  Amazingly the
  code somehow still all works perfectly with this previously vital
  header removed.
- Removed bitrotted, unused epee "crypted_storage" and
  "gzipped_inmemstorage" code.
- Replaced a bunch of epee::misc_utils::auto_scope_leave_caller with
  LOKI_DEFERs.  The epee version involves quite a bit more instantiation
  and is ugly as sin.  Also made the `loki::defer` class invokable for
  some edge cases that need calling before destruction in particular
  conditions.
- Moved the systemd code around; it makes much more sense to do the
  systemd started notification as in daemon.cpp as late as possible
  rather than in core (when we can still have startup failures, e.g. if
  the RPC layer can't start).
- Made the systemd short status string available in the get_info RPC
  (and no longer require building with systemd).
- during startup, print (only) the x25519 when not in SN mode, and
  continue to print all three when in SN mode.
- DRYed out some RPC implementation code (such as set_limit)
- Made wallet_rpc stop using a raw m_wallet pointer
2020-05-11 18:44:45 -03:00
Jason Rhinelander
73a341f514 No, epee, it's not ok 2020-05-11 18:44:45 -03:00
Jason Rhinelander
52838aa5b2 "Remove namespace pollution" << ENDL
Removes all "using namespace epee;" and "using namespace std;" from the
code and fixes up the various crappy places where unnamespaced types
were being used.

Also removes the ENDL macro (which was defined to be `std::endl`)
because it is retarded, and because even using std::endl instead of a
plain "\n" is usually a mistake (`<< std::endl` is equivalent to `<<
"\n" << std::flush`, and that explicit flush is rarely desirable).
2020-05-11 18:44:45 -03:00
Jason Rhinelander
51b247bfac daemon & daemonize overhaul
This commit continues the complete replacement of the spaghetti code
mess that was inside daemon/ and daemonize/ which started in #1138, and
looked like a entry level Java programmer threw up inside the code base.
This greatly simplifies it, removing a whole pile of useless abstraction
layers that don't actually abstract anything, and results in
considerably simpler code.  (Many of the changes here were also carried
out in #1138; this commit updates them with the merged result which
amends some things from that PR and goes further in some places).

In detail:

- the `--detach` (and related `--pidfile`) options are gone.  (--detach
  is still handled, but now just prints a fatal error).  Detaching a
  process is an archaic unix mechanism that has no place on a modern
  system.  If you *really* want to do it anyway, `nohup lokid &` will do
  the job.  (The Windows service control code, which is probably seldom
  used, is kept because it seems potentially useful for Windows users).

- Many of the `t_whatever` classes in daemon/* are just deleted (mostly
  done in #1138); each one was a bunch of junk code that wraps 3-4 lines
  but forces an extra layer (not even a generic abstraction, just a
  useless wrapper) for no good reason and made the daemon code painfully
  hard to understand and work with.

- All of the remaining `t_whatever` classes in daemon/* are either
  renamed to `whatever` (because prefixing every class with `t_` is
  moronic).

- Some stupid related code (e.g. epee's command handler returning an
  unsuitable "usage" string that has to be string modified into what we
  want) was replaced with more generic, useful code.

- Replaced boost mutexes/cvs with std ones in epee command handler, and
  deleted some commented out code.

- The `--public-node` option handling was terrible: it was being handled
  in main, but main doesn't know anything about options, so then it
  forced it through the spaghetti objects *beside* the pack of all
  options that got passed along.  Moved it to a more sane location
  (core_rpc_server) and parse it out with some sanity.

- Changed a bunch of std::bind's to lambdas because, at least for small
  lambdas (i.e. with only one-or-two pointers for captures) they will
  generally be more efficient as the values can be stored in
  std::function's without any memory allocations.
2020-05-11 18:44:45 -03:00
Doyle
0bcd895d7a Merge branch 'dev' into MergeUpstream2 2020-05-06 14:06:30 +10:00
Doyle
ee44c01c69
Merge pull request #1119 from Doy-lee/MergeUpstream
Merge upstream changes (~130 commits)
2020-04-24 14:09:22 +10:00
Doyle
e7e622e08b Merge commit '459beb5' into MergeUpstream2 2020-04-20 17:25:53 +10:00
Doyle
ca9ce15103 Merge commit 'c5e9266' into MergeUpstream2 2020-04-20 17:07:14 +10:00
Doyle
1895694e65 Merge commit '9a6006bad89db877ee082c7dfa01da76efd6231a' into MergeUpstream 2020-04-09 15:42:03 +10:00
Doyle
254df85d0a Merge commit '8774384acec8f5020323f11585b5cdeb02ea00b0' into MergeUpstream 2020-04-09 15:38:15 +10:00
Doyle
b3980dff37 s/varialble/variable typos have a development cost as well 2020-04-09 12:20:39 +10:00
Doyle
5646fa628a Ensure serialize_default prefers default rvalues when deserializing 2020-04-09 12:20:39 +10:00
luigi1111
c4f75fe898
Merge pull request #6339
c61abf8 remove empty statements (shopglobal)
2020-04-04 12:47:31 -05:00