Commit Graph

336 Commits

Author SHA1 Message Date
Jason Rhinelander 8d3ed4606f Drop const from _id
Makes the TaggedThreadID copyable.
2020-08-10 09:50:21 -03:00
Jason Rhinelander 30faadf01a Add serialization/deserialization of tuples and pairs
On the wire they are just lists, but this lets you put tuples onto and
pull tuples off of the wire.  (Also supports std::pair).

Supports direct serialization (via bt_serialize()/bt_deserialize()),
list/dict consumer deserialization, and conversion from a bt_value or
bt_list via a new bt_tuple() function.
2020-08-03 00:40:49 -03:00
Jason Rhinelander d8d1d8677c Replace visitor class with generic lambda 2020-08-03 00:40:49 -03:00
Jason Rhinelander e5cf174b83 Fix & add tests for send_option::data_parts(...)
data_parts() wasn't currently used anywhere, and was broken: it was
calling bt_deserialize which was just wrong.

This repurposes it to take iterators over strings (or string-like types)
and append those parts as message parts.

Also adds tests for it.
2020-07-20 14:37:01 -03:00
Jason Rhinelander af189a8d72 Wait for tagged workers
The `join()`s could hang if the tagged worker threads aren't ready yet,
so retry sending until they become routable.
2020-07-10 17:54:45 -03:00
Jason Rhinelander d2f852c217 Add test that destruction doesn't throw 2020-07-10 17:54:45 -03:00
Jason Rhinelander ee080e0550 Fix tagged workers not being properly shut down
If the LokiMQ object gets destroyed before having called `start()` then
we'd end up destroying the threads for tagged workers without joining
them.  This listens on the internal worker socket (normally the domain
of the proxy thread) and tells them to QUIT if such a destruction
happens.
2020-07-10 17:54:45 -03:00
Jason Rhinelander 7cd58e4677 Add missing header for BSD pthread naming 2020-07-06 12:04:51 -03:00
Jason Rhinelander 9c54264321 Doc fix - remove "init" and update "start" doc
init() got removed during the tagged threads PR, but the documentation
didn't get updated.  Fixed it.
2020-06-30 18:48:09 -03:00
Jason Rhinelander 932bbb33d7 Allow injecting tasks into lokimq job queue
This allows mixing some outside task into the lokimq job queue for a
category (queued up with native LMQ requests for that category) for use
when there is some external process that is able to generate messages.

For example, the most immediate use for this is to allow an HTTP server
to handle incoming RPC requests and, as soon as they arrive, inject them
into LokiMQ's queue for the "rpc" category so that native LMQ rpc
requests and HTTP rpc requests share the same thread pool and queue.

These injected jobs bypass all of LokiMQ's authentication and response
mechanisms: that's up to the invoked callback itself to manage.

Injected tasks are somewhat similar to batch jobs, but unlike batch jobs
the are queued and prioritized as ordinary external LokiMQ requests.
(Batch jobs, in contrast, have a higher scheduling priority, no queue
limits, and typically a larger available thread pool).
2020-06-30 18:44:11 -03:00
Jason Rhinelander 07b31bd8a1 Take lokimq::address as connect_remote argument
Deprecates the existing connect_remote() that takes remote addr and
pubkey as separate strings, just taking a `address` instead (into which
the caller can set pubkey/curve data as desired).

Also slightly changes how `connect_remote()` works when called with a
string remote but no pubkey: that string is now an augmented
lokimq::address string so that it can use the various formats supported
by `lokimq::address`.

(This was meant to be included in the PR that added `address` but
apparently didn't get implemented.)
2020-06-30 13:09:34 -03:00
Jason Rhinelander 8a56b18cc6 More header fixes 2020-06-22 20:02:03 -03:00
Jason Rhinelander 1d56c3d44c Add missing header 2020-06-22 19:10:04 -03:00
Jason Rhinelander 66176d44d7 include fixes from iwyu 2020-06-22 16:23:04 -03:00
Jason Rhinelander 4e89dce5b6 Add "C" to languages
Without this CMAKE_C_COMPILER won't be set when building as a standalone
project, and we need that if we build the bundled libzmq.
2020-06-22 13:32:16 -03:00
Jason Rhinelander 0493f615b9 Remove debugging 2020-06-19 12:28:06 -03:00
Jason Rhinelander d0a73e5e68 Pass compiler through ExternalProject_Add 2020-06-09 17:12:11 -03:00
Jason Rhinelander 278909db77 Resolve race condition in test suite
There can be a spurious failure here if the backdoor_details element
hasn't been added yet, so lock & check it when waiting for the test
conditions.

The weirdest thing about this error is that it can fail but then when
expanding values they expand to *correct* values, i.e. so you get:

FAILED:
  REQUIRE( backdoor_details == all_the_things )
with expansion:
  { "Alaska", "I'm the luckiest man in the world", "Loretta", "because all my
  life are belong to Google", "moustache hatred", "photos", "scallops",
  "snorted when she laughed", "tickled pink" }
  ==
  { "Alaska", "I'm the luckiest man in the world", "Loretta", "because all my
  life are belong to Google", "moustache hatred", "photos", "scallops",
  "snorted when she laughed", "tickled pink" }
2020-06-07 21:28:53 -03:00
Jason Rhinelander 3edcab9344 Fix grammar 2020-06-07 21:28:53 -03:00
Jason Rhinelander ae8dd27cdd Drop tagged thread init function; add synchronization dance
The init function doesn't seem all that useful and makes the interface a
bit more complicated, so drop it.

Also addresses a race condition that can happen with tagged thread
startup when the proxy tries to talk to a tagged thread but the tagged
thread hasn't connected yet (which then aborts the proxy because it
assumes workers are always routable).
2020-06-07 21:28:53 -03:00
Jason Rhinelander 8caab97355 Rename TaggedThread to TaggedThreadID, drop .name attribute
This renames the class to make it clearer what it does, and drops the
.name attribute from it so that it can cheaply be passed around.  This
then means it can be cheaply passed by value (using std::optionals)
rather than by pointer when specifying a thread.
2020-06-07 21:28:53 -03:00
Jason Rhinelander 44b91534c2 Made `log()` callable publicly
This allows use of some free functions within lokimq that can still log
(assuming they have a LokiMQ reference).
2020-06-07 21:28:53 -03:00
Jason Rhinelander 29380922bf Tagged threads for jobs, batches, and timers
This adds to ability to have lokimq manage specific threads to which
jobs (individual, batch jobs, batch completions, or timers) can be
directed to.  This allows dedicating a thread to some slow or
thread-unsafe action where you can dump jobs to the tagged thread as
a method of lockless job queuing.
2020-06-07 21:28:53 -03:00
Jason Rhinelander 6356421488 Remove unused variable 2020-06-07 21:28:53 -03:00
Jason Rhinelander d28e39ffeb README: C++14 -> C++17 2020-05-21 02:54:45 -03:00
Jason Rhinelander 9a103f1bf6 Add macOS build 2020-05-19 22:56:32 -03:00
Jason Rhinelander 211d5211b0 Tweak test timeout
macos sometimes needs more time here
2020-05-19 22:56:12 -03:00
Jason Rhinelander 9a283a148c Move address << operator implementation out of header 2020-05-19 22:55:57 -03:00
Jason Rhinelander 65aa5940be Let color through Ninja (1.9+) 2020-05-19 22:55:57 -03:00
Jason Rhinelander ec9c58ea34 Add Debug ci build, set other builds to Release 2020-05-19 22:55:57 -03:00
Jason Rhinelander af59d58797 Add drone ci builds
Adds CI builds (using drone) for various ubuntu/debian builds on
amd64/arm64/i386/armhf.
2020-05-19 22:55:57 -03:00
Jason Rhinelander e072e68d84 Move -isystem hack inside if-found
This was breaking if we didn't find libzmq (or didn't find recent
enough) because the target didn't exist.
2020-05-19 22:55:57 -03:00
Jason Rhinelander e5a8d09127 Link to sodium publicly
The test suite needs this, in particular.
2020-05-15 01:36:01 -03:00
Jason Rhinelander a24e87d4d0 Fix sodium linking and call sodium_init()
We call libsodium functions which require a sodium_init() call; this is
usually a no-op (zmq will have already called it for us), but in case
zmq is built with tweetnacl instead of sodium we need to call it before
we call it directly in the LokiMQ ctor and the test suite.
2020-05-15 01:33:02 -03:00
Jason Rhinelander 9ac47ec419 Add missing <string> headers for libc++ 2020-05-15 01:32:29 -03:00
Jason Rhinelander d0a07f7c08 Fix test segfault under clang
These (...) lambdas are va_arg which cause corruption under clang on
both linux and macos.  They weren't supposed to be va_args -- switch
them to the intended universal references, which fixes the crash.
2020-05-15 01:27:28 -03:00
Jason Rhinelander 86f5b463e9 Add missing files 2020-05-15 00:28:34 -03:00
Jason Rhinelander 68c1899cda C++17 changes; replace mapbox with std::variant
Various small C++17 code improvements.

Replace mapbox::variant with std::variant.

Remove the bt_u64 type wrapper; instead we know have `bt_value` which
wraps a variant holding both int64_t and uint64_t, and has contructors
to send signed/unsigned integer types into the appropriate one.
lokimq::get_int checks both as appropriate during extraction.

As a side effect this means we no longer do the uint64_t -> int64_t
conversion on the wire, ever, without needing the wrapper; although this
can break older versions sending large positive integers (i.e. larger
than int64_t max) those weren't actually working completely reliably
with mapbox variant anyway, and the one place using such a value in loki
core (in a checksum) is already fully upgraded across the network
(currently using bt_u64, but always sending a positive value on the
wire).
2020-05-14 20:19:43 -03:00
Jason Rhinelander 1479a030d7 Add it pair versions of {to,from}_{hex,base32z,base64}
Previously you could only generate a string from a string_view, or could
manage the string yourself and pass input iterators plus an output
iterator.

This commit adds an intermediate version that creates a string from a
pair of input iterators.
2020-05-13 14:47:01 -03:00
Stephen Shelton f296b82ba5 Wrap code section in README.md 2020-05-13 13:55:32 -03:00
Jason Rhinelander 1f60abf50e Make from_{hex,base32z,base64} compatible with std::byte
Make the char handling a bit more generic so that std::byte (or other
size-1 types) will work.
2020-05-12 19:38:05 -03:00
Jason Rhinelander de395af872 Add missing initialization of curr 2020-05-12 18:55:56 -03:00
Jason Rhinelander e970f14e55 C++17 class template deduction 2020-05-12 15:59:22 -03:00
Jason Rhinelander 1e38f3b1d1 Remove pre-C++17 workarounds/ifdefs 2020-05-12 15:50:36 -03:00
Jason Rhinelander c9cf833861 Silence c++17 warnings from cppzmq
In C++17 all the recv calls have a [[nodiscard]], so check them as part
of the test (both to silence the warnings and for better test code).
2020-05-12 15:47:22 -03:00
Jason Rhinelander 7b42537801 Require C++17
Removes lokimq::string_view (the type alias is still provided for
backwards compat, but now is always std::string_view).

Bump version (on dev branch) to 1.2.0
2020-05-12 15:33:59 -03:00
Jason Rhinelander 8984dfc4ea Add address parsing/generating class
This class extends the basic ZMQ addresses with addresses that handle
parsing and generating of addresses with embedded curve pubkeys of
various forms, along with a QR-friendly address generator.
2020-05-08 21:42:16 -03:00
Jason Rhinelander be4cbc6641 Add base64 encoder/decoder 2020-05-08 13:57:29 -03:00
Jason Rhinelander 46d007e1ac Add base32z encoder/decoder 2020-05-08 13:34:42 -03:00
Jason Rhinelander 59a41943d4 Add support for setting umask when binding
This is needed to be able to control the permissions of any created ipc
sockets.
2020-05-06 14:52:41 -03:00