They are fairly useless under stdlibc++ because it doesn't have the
required annotations on stl mutexes and locks, so we just get tons of
useless warnings.
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).
Howard Hinnart's date.h is the library that was accepted as C++20
date/calendar support, so this is essentially a backport of C++20 date
time support.
(It does support timezone support, but requires more of the library and
that seems like overkill for what we need; this just prints UTC
timestamps instead, which need only a header-only include).
This was being used to get at gcc/clang's __builtin_expect, but we don't
really need that: we can just avoid the check entirely when not in debug
mode which should be even faster.
fromEnv here wasn't usefully templatized (the base template basically
couldn't be used for anything except a string anyway), so just replaced
it with the overloads we need and moved the implementations out of the
header.
Adds a TrimWhiteSpace instead of using abseil's.
Adds Catch2 tests for it, and also converts the existing str tests to
catch (which look much, much nicer than the gtest ones).
The comparison done here was really weird: by comparing lengths *before*
contents "zz" would sort before "aaa". It wasn't invalid for the
specific purpose being used here (looking for true/false values), but
would be highly broken if someone tried to use it elsewhere.
Also renamed it because it really is just a `<` implementation, not a
full cmp implementation.
These aren't needed: CMake already knows how to follow #includes and
rebuild when headers change as long as the headers are included
*somewhere*. The extra .cpp files here just require building a bunch of
.cpp files with just header content that we just end up throw away
during linking (since the same things will also be compiled in whatever
other compilation units include the same headers).
- util::Mutex is now a std::shared_timed_mutex, which is capable of
exclusive and shared locks.
- util::Lock is still present as a std::lock_guard<util::Mutex>.
- the locking annotations are preserved, but updated to the latest
supported by clang rather than using abseil's older/deprecated ones.
- ACQUIRE_LOCK macro is gone since we don't pass mutexes by pointer into
locks anymore (WTF abseil).
- ReleasableLock is gone. Instead there are now some llarp::util helper
methods to obtain unique and/or shared locks:
- `auto lock = util::unique_lock(mutex);` gets an RAII-but-also
unlockable object (std::unique_lock<T>, with T inferred from
`mutex`).
- `auto lock = util::shared_lock(mutex);` gets an RAII shared (i.e.
"reader") lock of the mutex.
- `auto lock = util::unique_locks(mutex1, mutex2, mutex3);` can be
used to atomically lock multiple mutexes at once (returning a
tuple of the locks).
This are templated on the mutex which makes them a bit more flexible
than using a concrete type: they can be used for any type of lockable
mutex, not only util::Mutex. (Some of the code here uses them for
getting locks around a std::mutex). Until C++17, using the RAII types
is painfully verbose:
```C++
// pre-C++17 - needing to figure out the mutex type here is annoying:
std::unique_lock<util::Mutex> lock(mutex);
// pre-C++17 and even more verbose (but at least the type isn't needed):
std::unique_lock<decltype(mutex)> lock(mutex);
// our compromise:
auto lock = util::unique_lock(mutex);
// C++17:
std::unique_lock lock(mutex);
```
All of these functions will also warn (under gcc or clang) if you
discard the return value. You can also do fancy things like
`auto l = util::unique_lock(mutex, std::adopt_lock)` (which lets a
lock take over an already-locked mutex).
- metrics code is gone, which also removes a big pile of code that was
only used by metrics:
- llarp::util::Scheduler
- llarp:🧵:TimerQueue
- llarp::util::Stopwatch
Step 1 of removing abseil from lokinet.
For the most part this is a drop-in replacement, but there are also a
few changes here to the JSONRPC layer that were needed to work around
current gcc 10 dev snapshot:
- JSONRPC returns a json now instead of an optional<json>. It doesn't
make any sense to have a json rpc call that just closes the connection
with returning anything. Invoked functions can return a null (default
constructed) result now if they don't have anything to return (such a
null value won't be added as "result").
Our current abseil won't build with gcc 10 (its `optional`
implementation appears broken), and spews warnings under slightly older
compilers; updating to the latest stable 2019 branch fixes both issues.
It seems `__BYTE_ORDER`/`__LITTLE_ENDIAN`/`__BIG_ENDIAN` aren't defined
on macOS, so `if __BYTE_ORDER == __BIG_ENDIAN` was true which made macOS
take the big endian path *twice* (which cancelled out the big endian
conversion).
This makes util/endian.hpp define __LITTLE_ENDIAN__ or __BIG_ENDIAN__
everywhere, and errors if it can't be set.
This makes PrivateKey store both the key followed by the hash. For
PrivateKeys based on SecretKeys this just means the second half of the
SHA-512 of the seed, and makes a PrivateKey constructed from a SecretKey
give an identical signature to signing directly with sodium.
For derived keys we use a ShortHash of the root key's signing hash
concatenated with the publicly known hash value, so that our derived key
signing hash will be different from the root signing hash and also
different for different derivation parameters.
This also changed one of the asserts in crypto_noop, but upon closer
inspection the copying of the secret key into the signature seems really
wrong, so just changed them to fill with 0s.
The reason things weren't working here is because libsodium does
something completely unintuitive and called the seed the "secret key"
when it isn't, it's the seed.
This adds a new PrivateKey class (alongside the existing SecretKey and
PubKey) that holds just a private key value but no seed -- which we need
to do because there is no way we can get a seed after calculating a
derived keypair.
With these changes, we now generate exactly the same keys and subkeys as
Tor (and a new test case uses values generated in Tor to verify this).
This is incomplete -- the subkey signing code is still not implemented;
it has to be adapted to create a signature from a PrivateKey rather than
a SecretKey which will probably requiring working around/reimplementing
some of what libsodium does for creating a signature since it expects
"secret keys" i.e. the seed.