Commit Graph

90 Commits

Author SHA1 Message Date
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.
2022-10-13 16:29:13 -03:00
Jeff 68148e098f
* add mockable network functions
* add unit tests with ability to pretend to be different network setups
2022-07-20 13:36:03 -04:00
Jeff 98b3860655
set source ip on service nodes for outbound link to not use all interfaces 2022-05-27 13:26:30 -04:00
Jeff a61e9636b2
state machine fix for link layer
if a pending inbound session did not complete a handshake after an unclean close from a previous session the
remote udp endpoint would remain stuck mapped as authed and thus any further attempts from the remote would
be silently dropped as it entered a stuck state in the state machine. this was happening as a small part
of the state machine was hidden in the implementation details of iwp, but instead should be in the super type
as it is logic exclusively outside the details which every dialect would have regardless of its details.

this commit will unmap the udp endpoint every time it needs to in the link layer state machine, independat of
the implementation details of the diact.
2022-05-20 10:18:37 -04:00
Jeff 8960ca08f3
propagate link layer message priority to link layer so it can order retransmissions with that in mind 2022-05-02 15:27:07 -04:00
Jason Rhinelander 9113a6b36b Triggered pumping
This redoes how/when we pump so that we should only be calling the
idempotent PumpLL() when we actually have (or may have) something to
pump.
2021-11-15 13:35:57 -04:00
Jeff Becker 9d0dffe086
only permit 1 pending session per udp endpoint 2021-06-22 09:26:03 -04:00
Jason Rhinelander 181953b4a6 Replace ::Hash nested structs with std::hash specializations 2021-03-10 11:19:52 -04:00
Thomas Winget 7caa87862e standardize include format and pragma once
All #ifndef guards on headers have been removed, I think,
in favor of #pragma once

Headers are now included as `#include "filename"` if the included file
resides in the same directory as the file including it, or any
subdirectory therein.  Otherwise they are included as
`#include <project/top/dir/relative/path/filename>`

The above does not include system/os headers.
2021-03-09 19:01:41 -05:00
Jason Rhinelander f8486604c4 Export UDP file descriptor (for android) 2021-03-04 16:51:18 -04:00
Jason Rhinelander 6e05dc693f Remove unused arguments (and ants) 2021-03-04 16:51:18 -04:00
Jason Rhinelander e198bfd3e1 Remove unused variable 2021-03-04 16:51:18 -04:00
Jason Rhinelander ccc7b5c9e9 Merge Logic functions into EventLoop
loop->call(...) is similar to the old logic->Call(...), but is smart
about the current thread: if called from within the event loop it simply
runs the argument directly, otherwise it queues it.

Similarly most of the other event loop calls are also now thread-aware:
for example, `call_later(...)` can queue the job directly when called if
in the event loop rather than having to double-queue through the even
loop (once to call, then inside the call to initiate the time).
2021-03-04 16:51:18 -04:00
Jason Rhinelander 5b555ee5aa Replace libuv with uvw & related refactoring
- removes all the llarp_ev_* functions, replacing with methods/classes/functions in the llarp
  namespace.
- banish ev/ev.h to the void
- Passes various things by const lvalue ref, especially shared_ptr's that don't need to be copied
  (to avoid an atomic refcount increment/decrement).
- Add a llarp::UDPHandle abstract class for UDP handling
- Removes the UDP tick handler; code that needs tick can just do a separate handler on the event
  loop outside the UDP socket.
- Adds an "OwnedBuffer" which owns its own memory but is implicitly convertible to a llarp_buffer_t.
  This is mostly needed to take over ownership of buffers from uvw without copying them as,
  currently, uvw does its own allocation (pending some open upstream issues/PRs).
- Logic:
  - add `make_caller`/`call_forever`/`call_every` utility functions to abstract Call wrapping and
    dependent timed tasks.
  - Add inLogicThread() so that code can tell its inside the logic thread (typically for
    debugging assertions).
  - get rid of janky integer returns and dealing with cancellations on call_later: the other methods
    added here and the event loop code remove the need for them.
- Event loop:
  - redo everything with uvw instead of libuv
  - rename EventLoopWakeup::Wakeup to EventLoopWakeup::Trigger to better reflect what it does.
  - add EventLoopRepeater for repeated events, and replace the code that reschedules itself every
    time it is called with a repeater.
  - Split up `EventLoop::run()` into a non-virtual base method and abstract `run_loop()` methods;
    the base method does a couple extra setup/teardown things that don't need to be in the derived class.
  - udp_listen is replaced with ev->udp(...) which returns a new UDPHandle object rather that
    needing gross C-style-but-not-actually-C-compatible structs.
  - Remove unused register_poll_fd_(un)readable
  - Use shared_ptr for EventLoopWakeup rather than returning a raw pointer; uvw lets us not have to
    worry about having the event loop class maintain ownership of it.
  - Add factory EventLoop::create() function to create a default (uvw-based) event loop (previously
    this was one of the llarp_ev_blahblah unnamespaced functions).
  - ev_libuv: this is mostly rewritten; all of the glue code/structs, in particular, are gone as
    they are no longer needed with uvw.
- DNS:
  - Rename DnsHandler to DnsInterceptor to better describe what it does (this is the code that
    intercepts all DNS to the tun IP range for Android).
- endpoint:
  - remove unused "isolated network" code
  - remove distinct (but actually always the same) variables for router/endpoint logic objects
- llarp_buffer_t
  - make constructors type-safe against being called with points to non-size-1 values
- tun packet reading:
  - read all available packets off the device/file descriptor; previously we were reading one packet
    at a time then returning to the event loop to poll again.
  - ReadNextPacket() now returns a 0-size packet if the read would block (so that we can implement
    the previous point).
  - ReadNextPacket() now throws on I/O error
- Miscellaneous code cleanups/simplifications
2021-03-04 16:51:18 -04:00
Thomas Winget 4c630e0437 Large collection of changes to make android work
- Previous android java and jni code updated to work, but with much love
  still needed to make it work nicely, e.g. handling when the VPN is
  turned off.

- DNS handling refactored to allow android to intercept and handle DNS
  requests as we can't set the system DNS to use a high port
  (and apparently Chrome ignores system DNS settings anyway)

- add packet router structure to allow separate handling of specific
  intercepted traffic, e.g. UDP traffic to port 53 gets handled by our
  DNS handler rather than being naively forwarded as exit traffic.

- For now, android lokinet is exit-only and hard-coded to use exit.loki
  as its exit.  The exit will be configurable before release, but
  allowing to not use exit-only mode is more of a challenge.

- some old gitignore remnants which were matching to things we don't
  want them to (and are no longer relevant) removed

- some minor changes to CI configuration
2021-03-02 13:18:22 -05:00
Jeff Becker bb9bd25059
get rid of use of llarp::IpAddress from hotpaths 2021-02-22 10:01:05 -05:00
Jeff a0ed303d7b
try to handle router deregistrations on the network better (#1461)
* don't send messages to de-registered relays but allow traffic to clients

* actively close sessions to de-registered relays
2020-11-10 09:24:58 -05:00
Jeff 60f4d96ba5
proper route poking (#1330)
* route poking:

* remove popen() call, replace with reading /proc/net/route for getting default route
* dynamically poke and unpoke routes on runtime

* swap intros and fix rpc endpoint for version to return what the ui expects

* use std::string::find_first_not_of instead of using a lambda
2020-09-01 17:22:22 -04:00
Stephen Shelton b2a72dd46a
Initial test_peer_stats hive test 2020-07-02 10:16:19 -06:00
Stephen Shelton cb8e5354f5
Add some breadcrumbs about how ILinkLayer's callbacks are used 2020-07-02 10:13:26 -06:00
Jeff Becker f4971a88fd
use lokimq workers instead of llarp:🧵:ThreadPool 2020-07-02 11:07:34 -04:00
Stephen Shelton aee96e53a3
Refactor Addr -> IpAddress/SockAddr 2020-05-06 14:38:44 -06:00
Stephen Shelton 273270916e
The Great Wall of Blame
This commit reflects changes to clang-format rules. Unfortunately,
these rule changes create a massive change to the codebase, which
causes an apparent rewrite of git history.

Git blame's --ignore-rev flag can be used to ignore this commit when
attempting to `git blame` some code.
2020-04-07 12:38:56 -06:00
Jeff Becker 7ba30eec25
squash commits 2020-03-11 16:55:12 -04:00
Jeff Becker d2d109e92c
llarp_time_t is now using std::chrono 2020-02-24 15:25:03 -05:00
Jason Rhinelander b4440094b0 De-abseil, part 2: mutex, locks, (most) time
- 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
2020-02-21 23:22:47 -04:00
Jeff Becker 8b8d636ded
make format 2019-12-22 09:16:28 -05:00
Thomas Winget 55b44cfc13 fix derp nested function call and derp merge error 2019-12-18 13:35:01 -05:00
Thomas Winget 50118c3127 Change ILinkLayer::ScheduleTick to use new timer 2019-12-18 13:11:25 -05:00
Jeff Becker 9be4092a2a
more close changes 2019-12-05 11:31:58 -05:00
Jeff 27b1e36039
Merge pull request #936 from majestrate/dev
last changes before 0.6.0 version bump
2019-12-03 15:58:22 -05:00
Stephen Shelton 521ef9b5bb Handle link transport key in KeyManager 2019-12-03 10:58:53 -07:00
Jeff Becker 01b24c7090
limit connections 2019-12-03 12:49:29 -05:00
Jeff Becker c9f26c4911
call Router::PumpLL after every batch of packets from a link session 2019-11-04 13:49:08 -05:00
jeff 3c1d5518d8 fix windows port and make it compile 2019-10-02 09:06:14 -04:00
jeff ac2a2aed1d gut libutp and finish making things compile and pass tests 2019-09-12 14:19:25 -04:00
Jeff Becker e3bb59707e
more 2019-09-05 17:28:50 -04:00
Jeff Becker 3c0245f8b3
Merge remote-tracking branch 'github/master' into iwp-multi-ack 2019-09-05 13:40:04 -04:00
Jeff Becker 4bf6882c8a
more async cryptography 2019-09-05 13:39:09 -04:00
Jeff Becker 1adae338ce
Merge remote-tracking branch 'origin/master' 2019-09-04 07:58:02 -04:00
Michael edd0ec398f
Move thread stuff to subdirectory 2019-09-03 20:52:28 +01:00
Jeff Becker c01112e4b7
tracy lock contention testing and other fun things 2019-09-03 11:56:56 -04:00
Jeff Becker acf5f78949
update iwp , add NACK 2019-08-23 07:32:52 -04:00
Jeff Becker c1f33bb1ac
initial mempipe implementation 2019-08-07 12:33:29 -04:00
Jeff Becker 822f529be8
add link layer delivery feedback 2019-07-26 12:19:31 -04:00
Jeff Becker ec1910b8ca
remove threadpool.hpp
make link layer not use null lock and null mutex
2019-07-02 15:01:14 -04:00
Michael 491fee206b
Port code to use CryptoManager over passing Crypto pointers 2019-05-28 20:45:08 +01:00
Jeff Becker 64c7ed42fc
make format 2019-05-22 12:20:50 -04:00
Jeff Becker 9c96aecf3f
move llarp::Logic to std::shared_ptr
add sequence numbers to HSD messages

begin work on network isolation code

add more docs
2019-05-22 12:20:03 -04:00
Jeff Becker 73f1d34239
make format and revert stupid alloc changes 2019-05-20 08:19:33 -04:00