Commit Graph

149 Commits

Author SHA1 Message Date
Jason Rhinelander b66f653708 Less verbose logging at `info` level
Downgrades a bunch of not-useful-at-info-level debug messages from info
-> debug.  This makes `info` a more useful value for a client that wants
messages about startup/shutdown but not random non-serious connection
related messages.
2020-03-29 15:21:20 -03:00
Jason Rhinelander 716d73d196 All sends use dontwait; add send failure callbacks
We really don't *ever* want send to block, no matter how it is called,
since the send is always in the proxy thread.  This makes the actual
send call always non-blocking, and adds callbacks that we can invoke on
send failures: either on queue full errors (which might be recoverable),
or both full queue and hard failures (which are generally not
recoverable).  These callbacks are both optional: they have to be passed
in using `send_option::queue_full` (if you just want queue full
notifies) or `send_option::queue_failure` (if you want queue full
notifies *and* other send exceptions).
2020-03-29 15:21:20 -03:00
Jason Rhinelander 8e1b2dffa5 Catch connect failures
socket.connect() can throw, e.g. if given an invalid connection address;
catch this, log the error, and return a failure condition.
2020-03-29 14:40:21 -03:00
Jason Rhinelander 2493e2abd4 Remove empty file
All the batch implementation code is in jobs.cpp, this file wasn't meant
to be committed originally.
2020-03-29 12:29:38 -03:00
Jason Rhinelander bcca8dd34e Catch errors on internal msgs; support non-blocking sends
When we try to route an internal message ("BYE", "NOT_A_SERVICE_NODE",
etc.) back to the remote from the proxy thread we can end up trying to
send to a disconnected remote, which raises an exception, but this isn't
caught in proxy code: fix this by catching and ignoring it.

This also changes the code to send these messages in "dontwait" mode so
that if we can't queue the message we get (and ignore) an exception
rather than blocking.
2020-03-29 11:34:55 -03:00
Jason Rhinelander 7f9141a4a9 1.0.3 release 2020-03-27 18:55:16 -03:00
Jason Rhinelander fd19f7b183 Trim logged filenames to lokimq/*
Otherwise this includes the full build path which is gross.
2020-03-27 15:17:34 -03:00
Jason Rhinelander 0639bfa629 Avoid segfault on retried SN connection request
When we fail to send to a SN but can retry (e.g. because we had an
incoming connection which no longer works, but can retry an outgoing
connection) we were recursing, but this was resulting in a double-free
of the request callback (since we'd try to take ownership of the
incoming serialized pointer twice).

Rewrite the code to use a loop with single ownership instead.

This also changes the request callback behaviour to fire a failure
callback immediately if we can't send a request; previously you'd have
to wait for a timeout, but that is pointless if we couldn't get the
request out.
2020-03-27 14:59:11 -03:00
Jason Rhinelander a7c669775f Avoid masking ReplyCallback type with template param 2020-03-27 14:48:35 -03:00
Jason Rhinelander 9fec81856f 1.0.2 version bump 2020-03-24 11:35:31 -03:00
Jason Rhinelander 8b6f6f498c Make request timeout configurable
For example:

    lmq.request(conn, "some.method", callback, lokimq::request_timeout{5s});

will result in the callback being called with a failure if the response
doesn't arrive within 5s.  (If it still arrives, but after the failure
callback, it gets dropped).
2020-03-23 22:30:53 -03:00
Jason Rhinelander 75750001ce Reduce connection check interval and make configurable
The previous 1s default seems on the long side; this reduces it to
250ms.  It also makes it a public member so that it can be configured
(which is mainly needed for the test suite, but might be useful for
lokimq-calling code that needs faster or slower connection cleanups).
2020-03-23 22:29:14 -03:00
Jason Rhinelander b97f3442e7 Rename keep-alive -> keep_alive in internal serialization
This makes it consistent with other internal parameter names.
2020-03-23 22:28:23 -03:00
Jason Rhinelander 48d3f261d3 1.0.1 release
- internal data structure change to help armhf/gcc-6
- various test suite fixes
- various build system improvements
2020-03-21 12:57:45 -03:00
Jason Rhinelander 04e2bf7cf7 Change pending_connects from vector to list
Having this as a vector seems to cause armhf/gcc-6 to segfault.  On
closer inspection there's no good reason this should be a vector in the
first place: it only gets used during new connection handshaking and
isn't in any hot loop, plus the elements are fairly large tuples where
shifting elements is going to be relatively expensive.  Thus switching
it to a list everywhere (rather than just on old gcc arm) seems fine.
2020-03-21 12:56:46 -03:00
Jason Rhinelander 98b1bd6930 Add more locks around assertions
Catch2 isn't currently thread safe, so if we hit one of these assertions
while some other thread is doing things such as logging we might
segfault.
2020-03-21 12:56:13 -03:00
Jason Rhinelander 3a120efb79 Increase test timeouts for arm
These *sometimes* spurious fail because apparently they weren't quite
long enough to pass tests on my Pi 4.
2020-03-21 11:10:07 -03:00
Jason Rhinelander 0a7074c573 Add BUILD_BYPRODUCTS so that ninja build works 2020-03-19 19:54:24 -03:00
Jason Rhinelander a36e53d409 More linking overhaul
- Don't try to use cppzmq, just find libzmq ourselves.
- Allow existing `libzmq` and `sodium` targets to be used to control how
we link to libzmq and/or sodium.
- Use PkgConfig:: targets instead of the older bunch-of-variables
approach (requires cmake >= 3.6).
2020-03-15 01:43:23 -03:00
Jason Rhinelander bc0e6be801 Add sodium dep if embedding static lib when doing a shared build, too 2020-03-14 16:06:58 -03:00
Jason Rhinelander dd088c8ba5 cmake compatibility fix 2020-03-14 15:17:48 -03:00
Jason Rhinelander 3d315ba123 More static build linking fixes
Static linking is a dumpster fire.
2020-03-14 14:34:56 -03:00
Jason Rhinelander dd1a8eeb1d Use the correct variable for shared libs 2020-03-14 02:20:43 -03:00
Jason Rhinelander 1176b946e5 1.0.0 release 2020-03-13 21:08:34 -03:00
Jason Rhinelander ec50ee8cbd Compile libzmq statically if embedding 2020-03-13 21:08:34 -03:00
Jason Rhinelander c4d74a8640 Slightly relax build dep to 4.3
Distros (such as buster) include a patched 4.3.1, which is fine to use.
2020-03-13 19:41:08 -03:00
Jason Rhinelander 036e871cdb 32-bit warning fix 2020-03-13 19:05:12 -03:00
Jason Rhinelander 49f8ef21f1 Install mapbox-variant and cppzmq headers 2020-03-13 19:05:12 -03:00
Jason Rhinelander f7efd7f5c3 Add .gitignore 2020-03-13 17:47:40 -03:00
Jason Rhinelander a4ec2c982b Add and install pkgconfig file 2020-03-13 15:31:43 -03:00
Jason Rhinelander 4db1cd6be7 Fix lib install dir 2020-03-13 15:29:59 -03:00
Jason Rhinelander e1e8b85de6 Rearrange cmakelists.txt more logically 2020-03-13 15:29:30 -03:00
Jason Rhinelander 344fcb80d6 Disable gnu cxx extensions 2020-03-13 15:28:03 -03:00
Jason Rhinelander 4f4862fd0b Explicitly add thread linking 2020-03-13 15:27:29 -03:00
Jason Rhinelander 1f99a70f48 Build shared libraries by default
Static libraries are cursed and like to explode in bad ways.
2020-03-13 14:28:21 -03:00
Jason Rhinelander e17ca30411 Split up into logical headers and compilation units
lokimq.cpp and lokimq.h were getting monolithic; this splits lokimq.cpp
into multiple smaller cpp files by logical purpose for better parallel
compilation ability.  It also splits up the lokimq.h header slightly by
moving the ConnectionID and Message types into their own headers.
2020-03-13 14:28:21 -03:00
Jason Rhinelander 1c80b61335 Add version to cmake, generate version header 2020-03-13 14:28:05 -03:00
Jason Rhinelander 3eb6c482e1 Fix static build
Depend on cppzmq-static when doing a static build.

cppzmq-static itself has a dependency problem with libsodium, so
explicitly set the missing but required libsodium dependency on it.
2020-03-12 17:55:34 -03:00
Jason Rhinelander f4fad9c194 Fix problems on outgoing disconnect
This removes two superfluous erases that occur during connection closing
(the proxy_close_connection just above them already removes the element
from `peers`), and also short-circuits the incoming message loop if our
pollitems becomes stale so that we don't try to use a closed connection.

It also fixes a bug in the outgoing connection index that was
decrementing the wrong connection indices, leading to failures when
trying to send on an existing connection after a disconnect.

Also adds a test case (which fails before the changes in this commit) to
test this.
2020-03-10 13:54:41 -03:00
Jason Rhinelander 512086613a Build shared bundled libzmq when doing a shared build 2020-03-05 20:12:47 -04:00
Jason Rhinelander 75a3d7ff11 Add libsodium dependency
We don't necessarily get this through libzmq
2020-03-05 16:29:59 -04:00
Jason Rhinelander 279a4d3ea1 Set PIC on lokimq 2020-03-05 14:52:28 -04:00
Jason Rhinelander 0ce614ef8b Workarounds for old cmake/gcc 2020-03-05 01:33:02 -04:00
Jason Rhinelander fa7d4a8a42 Silence -Wmismatched-tags warning 2020-03-05 01:19:29 -04:00
Jason Rhinelander 443eca3955 Build a static libzmq if no system one or system one is too old 2020-03-05 01:00:35 -04:00
Jason Rhinelander 882750b700 Don't use consumed data when recursing proxy_send
Fixes "Internal error: Invalid proxy send command; conn_pubkey or
conn_id missing"
2020-03-04 00:13:01 -04:00
Jason Rhinelander 3cb52df837 Fix conn index error
The conn_index entry wasn't being added for outgoing SN connections.
2020-03-03 23:26:14 -04:00
Jason Rhinelander 88f0a10bd8 Fix infinite loop on idle peer expiry 2020-03-03 18:12:13 -04:00
Jason Rhinelander ea5ff7790d Fix destructor when `start()` hasn't been called 2020-03-03 17:28:53 -04:00
Jason Rhinelander 2207198574 Add DESTINATION for lokimq target 2020-03-03 15:25:19 -04:00