Commit graph

953 commits

Author SHA1 Message Date
Jason Rhinelander 41be330e00 Add ifdef'ed proxy requests code 2021-04-19 20:49:48 -03:00
Jason Rhinelander 71d96c8f7a Added onion request contrib test code 2021-04-19 20:35:17 -03:00
Jason Rhinelander e6b8d8efcf Debug message improvements 2021-04-19 19:51:52 -03:00
Jason Rhinelander 8ae2ab867c Fix empty onion request response 2021-04-19 19:50:22 -03:00
Jason Rhinelander ba2ddd4ddd Don't throw and return "std::exception" as an error string 2021-04-19 17:24:57 -03:00
Jason Rhinelander 81ad901115 Optimize get_swarm_by_pk to return a SwarmInfo reference instead of id
The id is available in `.swarm_id`, but more importantly this avoids
needing to go do linear scans when we actually need the swarm.
2021-04-19 16:22:30 -03:00
Jason Rhinelander 2361b293c9 Serialization: replace ghetto string_view with actual std::string_view
The ghetto version was not even remotely similar to a string view, but
was actually a string iterator pair container with no ability to
actually "view" anything.
2021-04-19 16:20:12 -03:00
Jason Rhinelander 60017e7e4d user pubkey tighter restrictions
- Enforce hex rather than accepting any random 66- or 64-character
  string as a pubkey
- Clean up pubkey -> integer code
- The cleanup fixes a bug where pubkey -> integer conversion was
  skipping the first two bytes on testnet (and ended up in UB by reading
  the null + one byte beyond the end of the string for testnet
  addresses).  THIS WILL BREAK EXISTING TESTNET PUBKEY->SWARM VALUES!
  (but it's only testnet, so that's okay).
2021-04-19 16:14:55 -03:00
Jason Rhinelander 2cd3998144 Avoid unnecessary json->string conversion 2021-04-19 14:07:20 -03:00
Jason Rhinelander ad10713c3a Remove gone reqidx param 2021-04-18 21:34:36 -03:00
Jason Rhinelander ffefbc3acd Remove redundant HTTP status
http::status::bad_request is already set at the beginning of this chunk
of code, and having these makes the cases that *don't* have it look
wrong.
2021-04-18 21:10:52 -03:00
Jason Rhinelander 5b57fcc7fa Add FIXME about silent failures
The protocol is currently underdesigned with no failure mechanism at
all, so there's nothing we *can* fix here.  We should fix the protocol,
of course, but that's outside the scope of this PR.
2021-04-18 20:54:29 -03:00
Jason Rhinelander 05bb4cf7ea Avoid potentially confusing bool addition 2021-04-18 20:44:58 -03:00
Jason Rhinelander ba7be1d0f5 Undo converting ReachType to a bool
The enum is more descriptive.
2021-04-18 20:41:01 -03:00
Jason Rhinelander 401afe3942 Switch derived values to std::arrays
These are 32-byte fixed size values, no need to allocate for them.
2021-04-18 20:33:29 -03:00
Jason Rhinelander 2c6b4b9fb8 Add comment about probability value 2021-04-18 20:23:55 -03:00
Jason Rhinelander 60cd3d3059 Add tester/testee sorting hack for pre-HF18 compatibility
SS's current testee/tester sorting is based on (nasty) sorting of a
lower-case hex string representation of the pubkey.

This adds a hack for compatibility up to HF18, then at HF18 switches to
sorting by direct binary pubkey values.
2021-04-18 16:51:33 -03:00
Jason Rhinelander 874e93f89d Replace asio timers with omq repeated timers
omq ones are much simpler and don't require continuous re-establishing,
saving a bunch of code.
2021-04-18 16:48:51 -03:00
Jason Rhinelander 7d9f6d1a8d Skip inactive nodes before warning about missing keys
If we're skipping it we don't care about it being missing.

Without this we get a bunch of warnings whenever an unfilled awaiting
contributions node has not yet submitted proofs or is abandoned (which
is usually the case on testnet, and sometimes on mainnet).
2021-04-18 15:26:57 -03:00
Jason Rhinelander f3a4db9a79 Add proper encrypt/decrypt unit tests 2021-04-18 14:50:40 -03:00
Jason Rhinelander 98f6140c0f Sort unit test source files 2021-04-18 14:50:40 -03:00
Jason Rhinelander 786042ecbb Replace onion_req ping hack with sn.ping endpoint
Sending a bogus sn.onion_req with a "ping" argument was a gross hack
that was needed for a backwards mid-hf update a long time ago; this
finally replaces it to a proper endpoint (starting at HF18).
2021-04-18 14:50:40 -03:00
Jason Rhinelander 31d35ce869 Remove unused variables/capture 2021-04-18 14:50:40 -03:00
Jason Rhinelander de7bf79854 Optimize/cleanup onion request parsing
- Do the json parsing as part of the payload parsing rather than
allocating a string and then making the caller do it (there's no case
where the caller *doesn't* want to do it).

- Modernize code to use structured bindings, allowing both cleaner code
and reduction in the number of moves/copies.
2021-04-18 14:50:40 -03:00
Jason Rhinelander 88de161365 Abstract encryption type API 2021-04-18 14:50:40 -03:00
Jason Rhinelander 16ec9ac0f2 Misc cleanups and optimizations 2021-04-18 14:50:40 -03:00
Jason Rhinelander afac0e7488 Don't squelch exception if x25519 extraction fails 2021-04-18 14:50:40 -03:00
Jason Rhinelander b5e8f07894 Remove static req index counter
Static local vars incur overhead due to needing thread-safe
initialization, and this one in particular is only used in a single
debug message.
2021-04-18 14:50:40 -03:00
Jason Rhinelander 921eb151e6 Fix CBC encryption/decryption 2021-04-18 14:50:40 -03:00
Jason Rhinelander 45978a85db Remove debugging 2021-04-18 14:50:40 -03:00
Jason Rhinelander b01027d478 Lower oxend ping log frequency
Since pings are 30s now, the ping spam is quite prevalent in the logs,
and unnecessary.  (You can always do oxend status to find out when the
last ping was).

This commit changes ping reporting to work as follows:
- the first ping we get after startup or after a failed ping gets logged
  at info level.
- subsequent successful pings get info-logged once/hour, including the
  number of sequential successful pings we've done.
- otherwise the ping success message is a debug log statement.
2021-04-18 14:50:40 -03:00
Jason Rhinelander 545f412a20 Fix sync status when we don't need to bootstrap
syncing_ was being left as false, which broke everything.
2021-04-18 14:50:40 -03:00
Jason Rhinelander f6e0b095bc Replace Monero crypto with libsodium
This replaces the Monero crypto implementation with a backwards
compatible libsodium implementation.  In particular, this replaces the
signature generation's random value with a deterministic value

    H(H(a) || A || M)

(reduced and clamped).  Since this deterministic value is perfectly good
as a "random" value, this avoids needing a RNG for generation, getting
us something closer (though still not) standard Ed25519 sigs.
2021-04-18 14:50:40 -03:00
Jason Rhinelander 2f96647566 Unbreak https cert signing by not storing a reference
An const lvalue reference is not something to be stored lightly, and can
easily break (as it did here).  Fix it by accepting a value instead,
i.e. by making the code conform to the class API and not making the
class API confirm to the caller code.
2021-04-18 14:50:40 -03:00
Jason Rhinelander c7c76b27a8 Inline simple accessor 2021-04-18 14:50:40 -03:00
Jason Rhinelander fe0d423fb3 Remove unused method 2021-04-18 14:50:40 -03:00
Jason Rhinelander 18296be278 Simplify signature encoding
`signature` is contiguous and trivial, by design.
2021-04-18 14:50:40 -03:00
Jason Rhinelander 1f10f726c8 Add trace/debug logging for number of tested nodes
Also remove the early return since the for loop is a no-op when empty
anyway.
2021-04-18 14:50:40 -03:00
Jason Rhinelander eb7636ccec Add heuristic to significantly avoid bootstrap use
The bootstrapping code was added because, long ago, oxend didn't have
ed/x keys and ip addresses after a restart, so on a SN restart it could
take an hour before we had a full view of the network.

This isn't the case anymore: ed/x/ip/etc. fields are persistent, so the
bootstrap code here is really only necessary for a fresh service node.

This commit thus adds a heuristic to only go to the bootstrap node if
our first snode list from oxend is missing data for more than 3% of the
service nodes; otherwise we just trust our local oxend result so that we
should, on an up-to-date service node, almost never need to contact the
bootstraps.

This also tweaks when we update local swarm data when bootstrapping so
that we recognize ourself as being active right away; the change to
pushed block notifications broke this by adding a delay to the next
arriving block (I think the old version didn't have this issue because
it hammered oxend once/second and so there would have only been a 1s
delay after bootstrap until the next rpc request).
2021-04-18 14:50:40 -03:00
Jason Rhinelander 0dabccfa80 Avoid whining about no pings immediately after startup 2021-04-18 14:50:40 -03:00
Jason Rhinelander 89d881a1dc Fewer unnecessary shared_ptrs
Some API improvements:

- When we need to copy a shared_ptr in a function, taking it by
  `const shared_ptr&` forces an extra atomic increment (and then
  decrement at the call site).  Change these to plain `shared_ptr` so
  that the caller can decide whether they want to move (avoiding any
  increment/decrement) or copy.
- When we *don't* need the shared_ptr container at all pass by reference
  to the contained value instead because this pushes the responsibility
  that the pointer not be null back to the caller.
2021-04-18 14:50:40 -03:00
Jason Rhinelander fa3a09949e Use lokinet .snode address for Host header
Rather than sending "Host: service node" or "Host: service-node" we now
send "Host: whatever.snode" or "Host: service-node.snode" if we don't
have the ed25519 key yet.
2021-04-18 14:50:40 -03:00
Jason Rhinelander 26e9413149 Cleanups
- move stuff into oxen namespace
- remove unused constexpr header values
- de-templatize << sn_response_t and move to .cpp
2021-04-18 14:50:40 -03:00
Jason Rhinelander f43c2c77a9 Remove dead code (FailedRequestHandler) 2021-04-18 14:50:40 -03:00
Jason Rhinelander 575a09fc0b Fix oxend ping arguments 2021-04-18 14:50:40 -03:00
Jason Rhinelander 018be6c1b0 Fix logic inversion on is_ip_public 2021-04-18 14:50:40 -03:00
Jason Rhinelander 8e3683df2f Force logging colours on stdout
Typically storage server output goes to systemd, which passes it off to
the journal; journalctl knows how to show (-a) ansi colors, and also
knows how to strip them when you don't provide -a.
2021-04-18 14:50:40 -03:00
Jason Rhinelander ab609ef938 Properly rate limit random testing
It wasn't updating the next test timestamp.
2021-04-18 14:50:40 -03:00
Jason Rhinelander a02fea6542 Fix report json parsing 2021-04-18 14:50:40 -03:00
Jason Rhinelander 9faa9e4b2d Make the default oxend rpc understand /var/lib/oxen
If our home dir is /var/lib/oxen then the default sock should be
/var/lib/oxen/oxend.sock (or /var/lib/oxen/testnet/oxend.sock).
2021-04-18 14:50:40 -03:00