Commit Graph

71 Commits

Author SHA1 Message Date
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
Jason Rhinelander 428ef12506 Add missing `inline` to de-templatized hex funcs 2020-03-03 15:06:39 -04:00
Jason Rhinelander 501534b5f4 Use modern cmake thread initialization 2020-03-02 18:51:16 -04:00
Jason Rhinelander 465b398b10 Use string_view instead of taking string type by template
Fixes the case of using a char *
2020-03-02 18:50:43 -04:00
Jason Rhinelander dcb7e4df0b Add a category command helper class
This allows simplifying:

    lmq.add_category("foo", ...);
    lmq.add_command("foo", "a", ...);
    lmq.add_command("foo", "b", ...);
    lmq.add_request_command("foo", "c", ...);

to:

    lmq.add_category("foo", ...)
        .add_command("a", ...)
        .add_command("b", ...)
        .add_request_command("b", ...)
        ;
2020-03-02 15:11:54 -04:00
Jason Rhinelander a43ee15b58 _sv wasn't being defined inline 2020-03-02 15:11:29 -04:00
Jason Rhinelander b3abcfc9ae Add ""_sv literal that works just like C++17 ""sv 2020-03-02 14:24:07 -04:00
Jason Rhinelander f18f86cf96 Allow `optional` and `incoming` to take a bool
This makes it much more convenience to use them with a run-time
condition; this simplifies:

    if (should_be_optional)
        lmq.send(..., send_option::optional{});
    else
        lmq.send(...);

to:

    lmq.send(..., send_option::optional{should_be_optional});
2020-03-02 14:24:07 -04:00
Jason Rhinelander 7be9d71d7f CMake updates: exports, drop static, disable cppzmq tests
- Properly export the lokimq::lokimq target for use as a sub-project
- Drop the lokimq::static target; the library will just be static or
non-static dependending on cmake's BUILD_SHARED_LIBS setting
- Properly disable cppzmq tests (the previous setting resulted in cmake
warnings)
2020-03-02 14:24:07 -04:00
Jason Rhinelander 0493082040 Add default allow to `listen_plain()`
The default on listen_curve() was supposed to go on both.
2020-03-01 23:54:06 -04:00
Jason Rhinelander 1cf02d0c66 Fix invalid access in peer address debug message 2020-03-01 15:21:09 -04:00
Jason Rhinelander 46c9f147ec Better subproject cmake support
- disable cppzmq test building
- add target for main and static library
- don't build tests by default when used as a subproject
2020-03-01 14:28:50 -04:00
Jason Rhinelander 4059f93e8c Add note about not blocking job + minor wording fixes 2020-03-01 14:25:52 -04:00
Jason Rhinelander ddeea78b15
Merge pull request #2 from loki-project/non-sn-comms
Added support for general (non-SN) communications
2020-03-01 13:14:26 -04:00
Jason Rhinelander 077c5f4722 Update various outdated things in the readme 2020-02-29 17:49:15 -04:00
Jason Rhinelander e4f93afafa Fix trace IP address 2020-02-29 16:34:37 -04:00
Jason Rhinelander 922435ca3b Add auth and ConnectionID routing tests 2020-02-29 16:06:55 -04:00
Jason Rhinelander 1ad68b2605 Wrap HI response in try/catch
It's possible that the client has gone away, in which case we can get an
exception raised from an unroutable request.
2020-02-29 16:06:08 -04:00
Jason Rhinelander 3be632e73e Fix auth_level for remote connections
The wrong key was being set here (deserialization expects auth_level).
2020-02-29 16:04:43 -04:00
Jason Rhinelander 09c487f327 Add ability to use random routing ids for outgoing 2020-02-29 16:03:25 -04:00
Jason Rhinelander ece8870896 Move routing prefix into ConnectionID
This allows storing a ConnectionID received in a message callback and
using it later to send another message along the connection without
worrying about a routing id: the ConnectionID will have it if it is
required.  Previously you would have had to store the ConnectionID *and*
the routing prefix, and then specified the route as a
send_option::route{}, which was annoying and cumbersome.
2020-02-29 16:01:47 -04:00
Jason Rhinelander 28e36a3eaf Make AuthLevel stream printable 2020-02-29 15:16:58 -04:00
Jason Rhinelander 2743e576b2 Distinguish between batch jobs and reply jobs
This adds a separate category (and reserve count) for "reply jobs",
which are jobs triggered by receiving a reply to a request, or after a
successful connect or unsuccessful timeout.  Previously these were
scheduled as regular batch jobs; this schedules them as a new "reply
jobs" category with its own reserved threads count.

This also changes the defaults for batch jobs and reply jobs to be based
on the specified general workers count rather than directly on hardware
concurrency, so that if you are on a 16-thread CPU but override general
workers from its default of 16 to 4 and don't change batch workers you
now get reserved batch workers set to 2 rather than 8 which constrains
the typical parallel batch jobs to 4 (i.e. the general worker limit)
rather than exceeding it with the batch job limit.

Similarly for reply jobs, which is now ceil(general/8) by default.
2020-02-28 17:54:00 -04:00
Jason Rhinelander 57f0ca74da Added support for general (non-SN) communications
The existing code was largely set up for SN-to-SN or client-to-SN
communications, where messages can always get to the right place because
we can always send by pubkey.

This doesn't work when we want general communications with a random
remote address.

This commit overhauls the way loki-mq handles communication in a few
important ways:

- Listening instances no longer pass bind addresses into the
constructor; instead they call `listen_curve()` or `listen_plain()`
before invoking `start()`.

- `listen_curve()` is equivalent to the existing bind support: it
listens on a socket and accepts encrypted handshaked connections from
anyone who already knows the server's public key.

- `listen_plain()` is all new: it sets up a plain text listening socket
over which random clients can connect and talk.  End-points aren't
verified, and it isn't encrypted, but if you don't know who you are
talking to then encryption isn't doing anything anyway.

- Connecting to a remote now connections in CURVE encryption or NULL
(plain-text) encryption based on whether you provide a remote_pubkey.
For CURVE, the connection will fail if the pubkey does not match.

- `ConnectionID` objects are now returned when connecting to a remote
address; this object is then passed in to send/request/etc. to direct
the message.  For SN communication, ConnectionID's can be created
implicitly from SN pubkey strings, so the existing interface of
`lmq.send(pubkey, ...)` will still work in most cases.

- A ConnectionID is now passed to the ConnectSuccess and ConnectFailure
callbacks.  This can be used to uniquely identify which connection
succeeded or failed, and can determine whether the remote is a service
node (`.sn()`) and/or the pubkey (`.pubkey()`).  (Obviously the service
node status is only available when the client can do service node
lookups, and the pubkey() is only non-empty for encrypted connections).
2020-02-28 00:16:43 -04:00
Jason Rhinelander e4d371b026 Fixed string_view c++17 compatibility
string_view isn't supposed to be implicitly convertible to std::string
and code would break compiling under c++17 (when our local string_view
is simply a std::string_view typedef).
2020-02-24 22:20:56 -04:00
Jason Rhinelander 3c1a0c4280 Adding missing test file 2020-02-23 23:56:26 -04:00
Jason Rhinelander c589599892 Fix off-by-one `remotes` access 2020-02-23 23:50:47 -04:00
Jason Rhinelander 99f4333b18 Add gcc 5 constexpr workaround 2020-02-23 16:28:22 -04:00
Jason Rhinelander f2ee3d9b41 constexpr string_view fixes
Pre-C++17 char_traits::compare isn't constexpr so we can't constexpr the
find/rfind methods that use it.

begin() etc, however, can be constexpr (and need to be for some of the
other constexpr methods here that use them).
2020-02-22 23:27:21 -04:00