Commit Graph

4940 Commits (dev)

Author SHA1 Message Date
Jeff Becker 57b77fecb3
fix crash on shutdown
we were calling llarp::Context::HandleSignal from a non mainloop
thread when running as a win32 service. this caused issues with a non
clean destruction.

call our signal handler instead of llarp::Context::HandleSignal
2 years ago
Thomas Winget dceef0b21e
remove dead dns resolver code 2 years ago
Jason Rhinelander 4ad66ac2a5
Remove unused VERSION_STR constant 2 years ago
Jeff Becker 3b6cbec08e
fix typo in filename 2 years ago
majestrate 84834089d1
Update llarp/router/router.cpp
use `fmt::join` for lokinet version string in status

Co-authored-by: Jason Rhinelander <jason@imaginary.ca>
2 years ago
Jason Rhinelander 31c312ad41
Extend windows startup timeout
If wintun fails it seems to take about 15s, so extend the startup
timeout so that it can fail gracefully (and let us clean up before
exiting).

Also refactors the timeouts to chrono constants.
2 years ago
Jason Rhinelander 71bea4f0fc
Add networkReady to stats result 2 years ago
Jason Rhinelander 5c12110e93
Add some more debugging 2 years ago
Jason Rhinelander 64cf268457
Fix crashes in wintun and windivert stopping
Fixes windows shutdown crashes:

- windivert wasn't handling an ERROR_NO_DATA, which it gets when
  finished handling everything after a shutdown.
- wintun ReadPacket still gets invoked after end_session is called, but
  shouldn't be.  This adds an atomic<bool> to early return.
- fixes up some settings we send for windows service manager notify
2 years ago
Jason Rhinelander 879e678771
Remove dead/redundant code
- win32_platform.cpp is dead
- win32_platform.hpp is useless

Style changes from clang-tidy warnings:
- remove `virtual` from some definitions that already have `override`
- remove virtual destructor from NetworkInterface because it already has
  a virtual destructor via the base type (and clang-tiny warns about it)
2 years ago
Jeff Becker 4103908a8d
system layer manager (llarp::sys::service_manager)
the win32 and sd_notify components provided a disjointed set of
similar high level functionality so we consolidate these duplicate
code paths into one that has the same lifecycle regardless of platform
to reduce complexity of this feature.

this new component is responsible for reporting state changes to the
system layer and optionally propagating state change to lokinet
requested by the system layer (used by windows service).
2 years ago
Thomas Winget 7ddad87dbf some useful log statements 2 years ago
majestrate e8055a05ad
Merge pull request #2039 from jagerman/shorter-gossip-times
Shorten gossip times in systemd status line
2 years ago
Jason Rhinelander b6924f3ef1
Replace duration/timestamp formats with functions
We're defining formats for std::chrono types, which feels wrong (because
fmt itself also has these), so just replace them with functions:

short_time_from_now(...) gives a short "in 14m12s" or "5.123s ago" time
span relative to now, given a time point.  Precision gets reduced for
larger deviations from now (e.g. "4h12m ago").

ToString(Duration_t) gives a string such as "-3h22m02.123s" for a
duration.
2 years ago
Jason Rhinelander 67e002c8ee
Fix time_delta<seconds> formatting in milliseconds
The time_delta<T> was using the wrong duration type when formatting, so
was outputting millisecond precision in the systemd status string which
is pointless (and unintended).
2 years ago
Jason Rhinelander 9f10e8003e
Remove useless iterator assignments
A back_inserter doesn't change when you insert onto it.
2 years ago
Jeff Becker 1e5b5ca1f5
proper handling of public ips
in service node mode make sure that when overriding public ip we only
fail when using 2 different public ip.
2 years ago
Jason Rhinelander 1980ca4d59 Fix bootstrap list bad bootstrap skipping
The iterator here to skip an obsolete bootstrap wasn't properly
reassigning the iterator, so "didn't work" (though why it was hanging
for me is entirely non-obvious).

Also refactored it to simplify/clarify it a bit.
2 years ago
Jason Rhinelander a828ef3f6d Remove obsolete junk
This stuff is already set earlier, in Configure.
2 years ago
Jason Rhinelander 9f49e006e4 Debug Router::Configure; initialize logging earlier
- Move logging initialization to early in Configure rather than at the
  end of FromConfig so that we can add debug logging inside
  Configure/FromConfig/etc.

- add said debug logging to Configure/FromConfig/etc.
2 years ago
Jason Rhinelander 3131297b00
Fix backwards compatible config option handler
Without this, old config (with now-irrelevant settings) won't work in
newer lokinet, making lokinet fatal error on startup if one of the
no-longer-used options is still present.
2 years ago
majestrate e8a27d1db3
Merge pull request #2032 from tewinget/pinned_node_config_cleanup
clarify strict-connect usage and enforce minimum of 2 nodes
2 years ago
Thomas Winget 3b6953badc clarify strict-connect usage and enforce minimum of 2 nodes 2 years ago
Thomas Winget 1231d4e6c4 add 'networkReady' to endpoint status 2 years ago
Jeff Becker bd5da10885
fixes issue #2029
when read/writing a .loki privkey file we dont rewind a llarp_buffer_t
after use. this is an argument in favor of just removing that type
from the code entirely.

fixes by using 2 distinct locally scoped llarp_buffer_t, one for read,
one for write.
2 years ago
Jason Rhinelander d011f8fb4a
Bump clang-format to 14 2 years ago
Jason Rhinelander 02108f0504
Merge pull request #2021 from tewinget/route-metric-preference
select gateway with lowest metric
2 years ago
majestrate 86c3b2f4ae
Merge pull request #2019 from jagerman/config-reformat
Config setting documentation edits
2 years ago
Thomas Winget 0c0ba29bae use first gateway, not last... 2 years ago
Jason Rhinelander c3a515da49
Config setting documentation edits
Rewords/reformats the documentation of various configuration options.
2 years ago
jeff 011bd2e84f format 2 years ago
Jeff Becker e5b7ea5f2d
dont do queries while down 2 years ago
Jeff Becker 082756c64c
cancel pending queries on down.
after calling Down() any pending queries will not be properly
canceled and results in a crash when we destruct the queries on our side.
2 years ago
Jeff Becker 306d54e285
when running as a client squelch warnings about snode status and make sure we connect out 2 years ago
majestrate 8f532dec89
Merge pull request #2015 from jagerman/oxend-rpc-updates
Oxend RPC updates
2 years ago
jeff 6813dd659c lint 2 years ago
Jason Rhinelander c5e787b8cb Oxend error ping + unfunded tracking
Currently (from a recent PR) we aren't pinging oxend if not active, but
that behaviour ended up being quite wrong because lokinet needs to ping
even when decommissioned or deregistered (when decommissioned we need
the ping to get commissioned again, and if not registered we need the
ping to get past the "lokinet isn't pinging" nag screen to prepare a
registration).

This considerably revises the pinging behaviour:

- We ping oxend *unless* there is a specific error with our connections
  (i.e. we *should* be establishing peer connections but don't have any)
- If we do have such an error, we send a new oxend "error" ping to
  report the error to oxend and get oxend to hold off on sending uptime
  proofs.

Along the way this also changes how we handle the current node state:
instead of just tracking deregistered/decommissioned, we now track three
states:

- LooksRegistered -- which means the SN is known to the network (but not
  necessarily active or fully staked)
- LooksFunded -- which means it is known *and* is fully funded, but not
  necessarily active
- LooksDecommissioned -- which means it is known, funded, and not
  currently active (which implies decommissioned).

The funded (or more precisely, unfunded) state is now tracked in
rc_lookup_handler in a "greenlist" -- i.e. new SNs that are so new (i.e.
"green") that they aren't even fully staked or active yet.
2 years ago
Jason Rhinelander bd869b3b07 Log demotion
Demote a couple spammy messages to trace level.
2 years ago
Jason Rhinelander 0e576ff59e Clean up oxend service node list handling
This aligns service node updating logic a bit closer to what happens in
storage server, and should make it a bit more resilient, hopefully
tracking down the (off-Github) reported issue where lokinet sometimes
doesn't see itself as active.

- Initiate a service node list update in the 30s timer lokinet ping
  timer (in case we miss a block notify for some reason); although this
  is expensive, the next point mitigates it:

- Retrieve the block hash with the SN state update, and feed it back
  into the next get_service_nodes call (as "poll_block_hash") so that
  oxend just sends back a mostly-empty response when the block hasn't
  changed, allowing both oxend and lokinet to skip nearly all of the
  work of a service node list update when the block hasn't changed since
  the last poll.  (This was already partially implemenated--we were
  already looking for "unchanged"--but without a block hash to get from
  and pass back to oxend we'd never actually get an "unchanged" result).

- Tighten up the service node list handling by moving the "unchanged"
  handling into the get_service_nodes response handler: this way the
  HandleNewServiceNodeList function is only handling the list but not
  the logic as to whether there actually is a new list or not.
2 years ago
Jason Rhinelander 36792d4337
Fix multi-field < ordering
Lots and lots of places in the code had broken < operators because they
are returning something like:

    foo < other.foo or bar < other.bar;

but this breaks both the strict weak ordering requirements that are
required for the "Compare" requirement for things like
std::map/set/priority_queue.

For example:

    a = {.foo=1, .bar=3}
    b = {.foo=3, .bar=1}

does not have an ordering over a and b (both `a < b` and `b < a` are
satisfied at the same time).

This needs to be instead something like:

    foo < other.foo or (foo == other.foo and bar < other.bar)

but that's a bit clunkier, and it is easier to use std::tie for tuple's
built-in < comparison which does the right thing:

    std::tie(foo, bar) < std::tie(other.foo, other.bar)

(Initially I noticed this in SockAddr/sockaddr_in6, but upon further
investigation this extends to the major of multi-field `operator<`'s.)

This fixes it by using std::tie (or something similar) everywhere we are
doing multi-field inequalities.
2 years ago
Jason Rhinelander bc071231c8
Add a net::ToString() to help stringify ipaddr_t
Android, in particular, has problems with fmt's built-in variant
handling for this type for some reason.
2 years ago
Jason Rhinelander 768e953522
De-prioritize some windivert logging
We don't really need to log at info level for every
windivert-intercepted incoming and outgoing packet.
2 years ago
Jason Rhinelander 6f31d5108b
Windows fix: iterate over IPv4/IPv6 interfaces separately
If we get back an IPv6 address as the first gateway then we won't have
the expected IPv4 gateway that the route poker needs to operate.

This iterates through them separately so that we treat the IPv4 and IPv6
sides of an address as separate interfaces which should allow the route
poker to find the one it wants (and just skip the IPv6 one).
2 years ago
Jason Rhinelander e398b5bff8
Fix interface enumeration on posix
The last interface wouldn't be considered.
2 years ago
Jason Rhinelander fe0f916a09
DRY private range selection; add missing ranges
DRY a chunk of repeated code for finding a free private range.

Also fix it so that it will consider 10.255.0.1/16 and 192.168.255.1/24
(previously it would only check up to octet 254).
2 years ago
Jason Rhinelander d10c4b9d17
Add more logging around route poking conditions
Log why we aren't doing anything if we aren't going to do anything.
2 years ago
Jason Rhinelander 4bf80833f4
Add InterfaceInfo formatter 2 years ago
Jason Rhinelander bd8dffc730
Merge pull request #1991 from jagerman/lokinet-vpn-cleanups
Lokinet vpn cleanups
2 years ago
Jason Rhinelander 82e2e6fb10
bake in bootstrap fallbacks at build time
also change the defailt/fallback bootstrap file for testnet to be a list
of RCs (albeit of size 1) rather than just an RC dict.
2 years ago
Thomas Winget 82c95a2486
don't ping core if active with too few peers
If running as a service node, we ping core on a regular interval to
inform it we're running and in a good state.  If we're an active
(not decommissioned or deregistered) service node and have too few
peers and thus we're not actually connected to lokinet, we should skip
that ping so core doesn't think we're ok.
2 years ago
Thomas Winget cc1bcf86fa
Fallback bootstrap router build parameter
Adds a fallback bootstrap file path parameter to CMake, specify
-DBOOTSTRAP_SYSTEM_PATH="/path/to/file" to use.

Adds a list of (currently 1) obsolete bootstrap RouterIDs to check
bootstrap RCs against.  Will not use bootstrap RCs if they're on that
list.

Log an error periodically if we appear to be an active service node but
have fewer than a set number (5) known peers.

Bumps oxen-logging version for literal _format.
2 years ago
Jason Rhinelander 20281ccc60
Clean up/simplify SN list handling 2 years ago
Jason Rhinelander ebdb37ac77
Significantly decrease decomm warning frequency
30s is insanely fast for a error level log statement and spams logs
incessantly; reduce it to repeating once every 5 minutes.
2 years ago
Jason Rhinelander 9f258700b7
Lower log level for renewals to debug
Otherwise you see a lot of unnecessary subscription renewals every 30s
in the logs.
2 years ago
Jason Rhinelander c4c5d128c3
Add ring buffer sink to macos build 2 years ago
Thomas Winget eaf30de1fd
omq rpc log subscription
respects whether RPC is enabled, removes the log sink otherwise

bumps oxen-mq and oxen-logging
2 years ago
Jason Rhinelander fae527517d
Try to appease android's crappy toolchain 2 years ago
Jason Rhinelander f641c08e80
llarp/profiling: refactor to use oxenc producer/consumer
No more llarp_buffer_t here!

(I was tracking down a segfault which led me in here and it was easier
to rewrite this to use bt_dict_{consumer,producer} than to decipher all
the cursed llarp_buffer_t and bencode callback nest).
2 years ago
Jason Rhinelander d335527a70
Add binary file slurp/dump utility functions
We have basically this same bit of code in tons of places; consolidate
it into llarp::util::slurp_file/llarp::util::dump_file.

Also renames all the extra junk that crept into llarp/util/fs.hpp out of
there into llarp/util/file.hpp instead.
2 years ago
Jason Rhinelander 66c79b232a
Fix log warning 2 years ago
Jason Rhinelander 71ea4f4fa2
RPC: Relax token/range argument handling
- Accept empty string or `null` for token to mean "no token."
- Accept `null` for range to mean "default range."
- Don't use a default range (::0/0) in lokinet-vpn because this will
  fail if IPv6 ranges aren't supported on the platform (e.g. on
  Windows), and isn't necessary: if we omit it then the rpc code already
  uses ::0/0 or 0.0.0.0/0 by default, as needed.
2 years ago
Jason Rhinelander 1f9779cdcd
Windows compilation fix 2 years ago
Jason Rhinelander 93c01623b0
Format fixes & fix warning in format script
- Don't escape '#' in the greps in format.sh: they warn about a spurious
  `\` in the latest grep.
- reformat
2 years ago
Jason Rhinelander ec91a6db05
ReconfigureDNS fixes, fixes macos exit mode
- ReconfigureDNS wasn't returning the old servers; made it void instead
  (the Apple code can just store a copy of the original upstream
  servers instead).
- Reconfiguring DNS reset the unbound context but didn't replace it, so
  a Down()/Up() would crash.
- Simplify Resolver() destructor to just call Down(), and make it final
  just so that no one tries to inherit from us (so that calling a
  virtual function from the destructor is safe).
- Rename CancelPendingQueries() to Down(); the former cancelled but also
  shut down the object, so the name seemed a bit misleading.
- Rename SetInternalState in Resolver_Base to ResetResolver, so that we
  aren't conflicting with ResetInternalState from Endpoint (which was a
  problem because TunEndpoint inherited from both; it could be resolved
  through the different argument type if we removed the default, but
  that seems gross).
- Make Resolver use a bare unbound context pointer rather than a
  shared_ptr; since Resolver (now) entirely manages it already we don't
  need an extra management layer, and it saves a bunch of `.get()`s.
2 years ago
Jason Rhinelander 2ccc518849
Fix apple dns, part 817 2 years ago
Jeff Becker bd09f7716d
override method 2 years ago
Jeff Becker 13d1301e08
rewire up dns reconfiguration for macos 2 years ago
Jason Rhinelander 52c6cd497f
Apple DNS fix WIP 2 years ago
Jason Rhinelander 2aae56b0e0
Apple DNS configuration fix: don't obliterate trampoline
On Apple, the network extension is outside the tunnel routing, so we
cannot have libunbound talk directly to upstream (it would leak DNS when
exit mode is enabled).  Instead unbound *always* talks to a localhost
port where we have a "dns trampoline" that takes UDP packets and shoves
them through the tunnel.

We were doing that already, but recent changes here were overwriting the
libunbound settings with.

This also moves the upstream DNS configuration part of `Up()` into its
own method.
2 years ago
Jason Rhinelander 4d920bb2e2
Fix macos
We don't have a resolver on macos, so we were running through this loop
with fails == 0 == m_Impls.size() and throwing, crashing the process.

Early return to avoid the failure and fix macos crash.
2 years ago
Jeff Becker b81ae95246
remove hunk of win32 specific code, it is dead in this codepath 2 years ago
Jason Rhinelander 27d58044c7
macos compilation fixes 2 years ago
Jason Rhinelander a82907bc6c
Set various -W flags on apple
Apple supports anything here that Clang supports and should have them
set the same as everywhere else.

Most importantly this gives apple the -Wno-deprecated-declarations flag
which has been driving me nuts on macos.

This also version-gates the -Wno-deprecated-declarations so that it
will turn on again when we bump the version beyond .10.
2 years ago
Jason Rhinelander 291f311259
Fix linked list iteration for windows ip/gateways
We were requiring `->Next` be true, which means we skipped the last (and
often only) entry of the linked lists and so never properly found the
gateway.
2 years ago
Jason Rhinelander 9097435f64
Refactor/fix GetAdaptersAddresses
- We need to pass a flag to get Windows to include gateway info.
- Refactor it to use microsoft's recommended magic default 15000 buffer
  size and repeat in a loop a few times until it works.  Developers,
  developers, developers, developers!
2 years ago
Jason Rhinelander d1e997177d
Add missing != operator to nuint_t 2 years ago
Jason Rhinelander 613459401d
Linux route poker fixes
- don't add routes when not in exit mode
- don't call Up() from rpc code (the RouterPoker itself decides when to
  call Up())
2 years ago
Jason Rhinelander e9554c7c5e
Don't do route poking when disabled
IsEnabled() is a bit broader than just IsServiceNode, so use it instead.
2 years ago
Jason Rhinelander 45b3365002
Simplifications
- a `static` is less verbose and otherwise identical to an empty
  namespace for a single declaration like this.
- operator== on two optionals already does exactly what the `is_equal`
  lambda here is doing.
- formatting
2 years ago
Jason Rhinelander 517911b499
Fix crash on shutdown
For some (wrong) reason this chunk of code was here.  Removed it to stop
a crash on shutdown.
2 years ago
Jeff Becker 0fb639db53
idempotent dns 2 years ago
Jeff Becker 26c1336517
limit route poker 2 years ago
Jeff Becker 61f66ac1ec
fix up win32 route poker a bit 2 years ago
Jason Rhinelander 15144f193c
cleanups/simplifications 2 years ago
Jason Rhinelander 9ddf7413af
Windows DNS fixes
- windivert was being set up *before* DNS is set up, so the DNS port was
  nullopt and thus we couldn't properly identify upstream DNS traffic.
- close() doesn't close a socket on Windows, so the socket-bind-close
  approach to get a free UDP port wasn't actually closing, and thus
  unbound upstream constrained to the given port were completely
  failing.
- The unbound thread was accessing the same shared_ptr instance as the
  outer code, which isn't thread-safe; changed it to copy a weak_ptr
  into the lambda instead.
- Exclude upstream DNS traffic in the filter rather than capturing and
  reinjecting it.
2 years ago
Jason Rhinelander c470349fb3
Log upstream DNS servers when setting it up 2 years ago
Jason Rhinelander ab2177bee9
Restore Apple hax 2 years ago
Jason Rhinelander de4bce1d96
Disable upstream TCP DNS
windivert, in particular, will get filtered by this and it almost
certainly won't work.
2 years ago
Jason Rhinelander bb85ec4595
De-inline vpn/win32.hpp 2 years ago
Jason Rhinelander 2a27698016
Fix backwards from/to in PacketSource_Wrapper
This resulted in DNS responses in Windows having reversed direction when
reinjected, and thus not arriving as expected.
2 years ago
Jason Rhinelander 7a0d4a905e
fix speeling 2 years ago
Jason Rhinelander 07231dd9e1
Fixed crash in DNS resolving
The inner lambda here wasn't keeping the `Query` (`this`) alive, so
`src` wasn't valid anymore.  This changes it to copy the `src`
shared_ptr into the lambda instead of capturing `this`, and fixes it.
2 years ago
Jason Rhinelander d4739d5d47
Fix sockaddr_len initial value 2 years ago
Jason Rhinelander b856b78de3
format 2 years ago
Jason Rhinelander 05ed9d6de0
llarp/dns logging refactor
Convert everything in llarp/dns to new-style logging.
2 years ago
Jason Rhinelander 49223a7853
bind/close to find free UDP port
The current code isn't working and gives a 0 (which then fails unbound
initialization).  This replaces it by doing a socket+bind to find a free
port then immediately closes (but passes the port we got into unbound).
2 years ago
Jason Rhinelander 9921dd6c77
Simplify dll loading via static function pointers
- Replaces RAII handling of DLLs with global function pointers.  (We
  don't unload the dll this way, but that seems unnecessary anyway).
- Simplifies code by just needing to call an init function, but not
  needing to pass around an object holding the function pointers.
- Adds a templated dll loader that takes the dll and a list of
  name/pointer pairs to load the dll and set the pointers in one shot.
2 years ago
Jeff Becker 281fbe57f7
promote log statement 2 years ago
Jason Rhinelander aee618e0d7
Fail if wintun can't retrieve its version 2 years ago
Jason Rhinelander 84ad0ab4d3
Slightly DRY thread-setting code, fix warning
There were warnings from the rc variable being unused; this DRYes it to
use the same code as linux (including the failure check on rc).
2 years ago