Commit Graph

34 Commits

Author SHA1 Message Date
Jason Rhinelander
5115162066 Use libuv's cached current time for time_now()
We are calling time_now() a huge amount, and it is a major consumer of
CPU cycles, but we don't need it: most of the time the current event
loop time is enough.
2021-11-15 18:32:05 -04:00
Jason Rhinelander
031ea7aa37 Get rid of external event loop direct wakeups
If something needs to wake up the event loop it should be using an
async, as we are now with PumpLL(); but we had various code triggering a
wakeup, expecting that PumpLL gets called on every wakeup, which isn't
true anymore.
2021-11-15 13:36:44 -04:00
Jason Rhinelander
104f63543f
Change MaybeGetLoop to a virtual member func
Minor simplification.
2021-04-19 06:58:36 -04:00
Jeff Becker
4446f2fc16
fix and format.
* start moving quic code to use lokinet internals
2021-04-19 06:57:46 -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
895acc45ff EventLoop: add public wakeup() method, and call it from call()
call(), when invoked from the logic thread, wasn't triggering a wakeup
which stalled some traffic (such as client-to-snode packets).

Fix it by triggering a wakeup on `call()`, and expose it because this is
a useful thing to be able to do.
2021-03-04 16:51:18 -04:00
Jason Rhinelander
36edabd9b0 Rename EventLoop::udp to EventLoop::make_udp
Makes it consistent with the make_waker, etc.

Also removes some debugging.
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
Jeff Becker
42ffbcca0a
try coleasing inbound packets from iwp 2021-02-22 08:26:32 -05:00
Jeff
49b9ad7197
tun code refactor (#1495)
* partial tun code refactor

* take out the trash

* move vpn platform code into llarp/vpn/platform.cpp

* fix hive build

* fix win32

* fix memory leak on win32

* reduce cpu use

* make macos compile

* win32 patches:

* use wepoll for zmq
* use all cores on windows iocp read loop

* fix zmq patch for windows

* clean up cmake for win32

* add uninstall before reinstall option to win32 installer

* more ipv6 stuff

* make it compile

* fix up route poker

* remove an unneeded code block in macos wtf

* always use call to system

* fix route poker behavior on macos

* disable ipv6 on windows for now

* cpu perf improvement:

* colease calls to Router::PumpLL to 1 per event loop wakeup

* set up THEN add addresses

* emulate proactor event loop on win32

* remove excessively verbose error message

* fix issue #1499

* exclude uv_poll from win32 so that it can start up

* update logtag to include directory

* create minidump on windows if there was a crash

* make windows happy

* use dmp suffix on minidump files

* typo fix

* address feedback from jason
* use PROJECT_SOURCE_DIR instead of CMAKE_SOURCE_DIR
* quote $@ in apply-patches in case path has spaces in it

* address feedback from tom

* remove llarp/ev/pipe
* add comments for clairification
* make event loop queue size constant named
2021-01-11 18:13:22 -05:00
Jeff Becker
e13e886df9
fix up event loop crap so that unit tests pass 2020-07-02 11:10:06 -04:00
Thomas Winget
c2a30692cf Implement upstream DNS using libunbound 2020-06-15 18:32:57 -04:00
Jeff Becker
95e55a2544
consistent spelling and use std::max 2020-06-01 13:31:12 -04:00
Jeff Becker
acecb23eb3
make libuv event loop logic queue size configurable.
remove logic constructor that is no-op.
add constant for default logic queue size
add constant for transit hop queue size
2020-06-01 09:17:44 -04:00
Jeff Becker
f04407f183
use only 1 uv_async_t for event loop wakeups
flush logic calls in there too as this was causing unit tests to hang
2020-05-15 08:36:38 -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
Thomas Winget
71bb0dd520 implement timers using libuv
So far only a bit of the code using timers has been modified to use
the new libuv-based timers.  Also only the non-Windows case has been
implemented.  Seems to be working though, so it's a good time to commit.
2019-12-18 13:11:13 -05:00
Jeff Becker
cdfdfa1068 use thread queue 2019-12-10 11:49:32 -07:00
Jeff Becker
cec36b62b5 make logic and net thread one in the same 2019-12-10 11:49:32 -07:00
Thomas Winget
6acf7bff7e Track and log UV event loop ticks in debug builds 2019-11-29 19:11:14 -04:00
Jeff Becker
56dce90de9
add trace log level for tracking logic thread jobs 2019-11-22 16:23:19 -05:00
Jeff Becker
7ee026fa50
make path builds work again 2019-11-05 11:58:53 -05:00
jeff
788bc0f912 Merge remote-tracking branch 'upstream/dev' into ed25519-signing
also stop using libuv's uv_loop_new as it is deprecated
2019-10-16 07:45:52 -04:00
jeff
3c1d5518d8 fix windows port and make it compile 2019-10-02 09:06:14 -04:00
jeff
14c9ef15ed try calling stuff in logic thread from event loop 2019-09-16 06:21:12 -04:00
Jeff Becker
4bf6882c8a
more async cryptography 2019-09-05 13:39:09 -04:00
Jeff Becker
aea4542edd
more 2019-08-22 07:18:05 -04:00
Michael
2cc180b6a4
Add FindLibUV and migrate 2019-07-13 14:06:34 +01:00
Jeff Becker
53d2034a73
fix up libuv close logic 2019-06-20 14:28:59 -04:00
Michael
26e16d5389
Fix event loop tests post-libuv 2019-06-16 22:44:11 +01:00
Jeff Becker
79cdff20a4
fix tpyos and pass event loop by l value 2019-06-12 09:14:38 -04:00
Jeff Becker
9deafa4cb8
use libuv 2019-06-02 17:17:05 -04:00