Commit Graph

269 Commits

Author SHA1 Message Date
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
Jason Rhinelander 719a9b0b58 1.1.4 2020-04-30 15:12:50 -03:00
Jason Rhinelander 22559548fc Add checking for a negative int in bt_*_consumer 2020-04-30 15:11:45 -03:00
Jason Rhinelander 7b552007df Add bt_u64 wrapper for forcing a uint64_t on the wire
Currently with bt_value if you give a high-bit uint64_t value it encodes
it on the wire as a 2's complement int64_t value (and then converts it
back during deserialization).  This is not a problem for bt_value, but
forces other code to deal with a bt_value convention and makes it
impossible to actually put a high-bit uint64_t value on the wire.

This adds an explicit bt_u64 wrapper to allow doing just that.  This is
only really needed when the type is a 2^64 modulo arithmetic type
(ideally *all* uint64_t's should be that, but in practice there is a ton
of code that misuses unsigned types as "shouldn't be negative" when that
isn't what unsigned means at all. cf C++ Core Guidelines ES.100-102)
2020-04-30 15:11:14 -03:00
Jason Rhinelander b905a8a4ff Silence spurious warning on optional send failure
When doing an optional send that gets declined (because we aren't
connected) the "sending would block" warning would still be printed, but
shouldn't be.
2020-04-29 14:54:54 -03:00
Jason Rhinelander 08a11bb9ba Add hack to fix compilation on debian sid 2020-04-28 22:52:18 -03:00
Jason Rhinelander 3a0508fdce Fix incoming ConnectionIDs not being storable
ConnectionIDs weren't comparing their routes, which meant that if
external code stored one in a map or set *all* incoming connections on
the same listener would be considered the same connection.

This fixes it by considering route for equality/hashing, and strips
route off internally where we need to map it to a socket.
2020-04-26 12:12:04 -03:00
Jason Rhinelander f4f1506df0 Add remote address into Message object
Can be useful for end point logging.
2020-04-24 18:59:33 -03:00
Jason Rhinelander a812abd422 Fix ""_sv literal being non-constexpr 2020-04-23 21:59:24 -03:00
Jason Rhinelander 730633bbae Provide caller Access in Message
This lets a callback set up something at, say, basic level, but provide
different values for an admin auth remote than a basic auth remote.
2020-04-23 21:52:39 -03:00
Jason Rhinelander 99bbf8dea9 Bump version (not released yet) 2020-04-23 21:51:52 -03:00
Jason Rhinelander 1a65d7f5e5 Bump version to 1.1.2 2020-04-21 16:59:41 -03:00
Jason Rhinelander e7cd2dedc2 Change worker thread names: "w2" -> "lmq-w2" 2020-04-21 16:58:10 -03:00
Jason Rhinelander 6ddf033674 Fix proxy thread stall when workers fill up
When we hit the limit on the number of workers the proxy thread would
stop processing incoming messages, sending it into an infinite loop of
death.  The check was supposed to use `active_workers()` rather than
`workers.size()`, but even that isn't quite right: we want to *always*
pull all incoming messages off and queue them internally since different
categories have their own queue sizes (and so we have to pull it off to
know whether we want to keep it -- if spare category queue room -- or
drop it).
2020-04-21 16:55:40 -03:00
Jason Rhinelander 0ebfef2164 Set thread names on proxy/workers
Makes debugging which threads are using CPU easier.
2020-04-21 12:02:44 -03:00
Jason Rhinelander fc1ea66599 Reduce heartbeat frequency to 15s
3s was excessive especially considering that the default heartbeat
timeout is set to 30s.
2020-04-18 02:58:22 -03:00
Jason Rhinelander 238dfa7f78 Drop idle connections regularly
The check here on "only if we have some idle workers" fails
catastrophically with one worker because that worker is always occupied
when this code gets called because of how the loop works and so
connections don't get expired at all.
2020-04-18 02:55:12 -03:00
Jason Rhinelander 911c66140f Bump version to 1.1.1 2020-04-17 16:19:32 -03:00