1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/llarp/ev/libuv.hpp
Jeff 871c3e3281
changeset for windows port
* wintun vpn platform for windows
* bundle config snippets into nsis installer for exit node, keyfile persisting, reduced hops mode.
* use wintun for vpn platform
* isolate all windows platform specific code into their own compilation units and libraries
* split up internal libraries into more specific components
* rename liblokinet.a target to liblokinet-amalgum.a to elimiate ambiguity with liblokinet.so
* DNS platform for win32
* rename llarp/ev/ev_libuv.{c,h}pp to llarp/ev/libuv.{c,h}pp as the old name was idiotic
* split up net platform into win32 and posix specific compilation units
* rename lokinet_init.c to easter_eggs.cpp as that is what they are for and it does not need to be a c compilation target
* add cmake option STRIP_SYMBOLS for seperating out debug symbols for windows builds
* intercept dns traffic on all interfaces on windows using windivert and feed it into lokinet
2022-09-08 14:24:59 -04:00

103 lines
2.1 KiB
C++

#pragma once
#include "ev.hpp"
#include "udp_handle.hpp"
#include <llarp/util/thread/queue.hpp>
#include <llarp/util/meta/memfn.hpp>
#include <uvw/loop.h>
#include <uvw/async.h>
#include <uvw/poll.h>
#include <uvw/udp.h>
#include <functional>
#include <map>
#include <vector>
namespace llarp::uv
{
class UVWakeup;
class UVRepeater;
class Loop : public llarp::EventLoop
{
public:
using Callback = std::function<void()>;
Loop(size_t queue_size);
virtual void
run() override;
bool
running() const override;
llarp_time_t
time_now() const override
{
return m_Impl->now();
}
void
call_later(llarp_time_t delay_ms, std::function<void(void)> callback) override;
void
tick_event_loop();
void
stop() override;
bool
add_ticker(std::function<void(void)> ticker) override;
bool
add_network_interface(
std::shared_ptr<llarp::vpn::NetworkInterface> netif,
std::function<void(llarp::net::IPPacket)> handler) override;
void
call_soon(std::function<void(void)> f) override;
std::shared_ptr<llarp::EventLoopWakeup>
make_waker(std::function<void()> callback) override;
std::shared_ptr<EventLoopRepeater>
make_repeater() override;
virtual std::shared_ptr<llarp::UDPHandle>
make_udp(UDPReceiveFunc on_recv) override;
void
FlushLogic();
std::shared_ptr<uvw::Loop>
MaybeGetUVWLoop() override;
bool
inEventLoop() const override;
protected:
std::shared_ptr<uvw::Loop> m_Impl;
std::optional<std::thread::id> m_EventLoopThreadID;
private:
std::shared_ptr<uvw::AsyncHandle> m_WakeUp;
std::atomic<bool> m_Run;
using AtomicQueue_t = llarp::thread::Queue<std::function<void(void)>>;
AtomicQueue_t m_LogicCalls;
#ifdef LOKINET_DEBUG
uint64_t last_time;
uint64_t loop_run_count;
#endif
std::atomic<uint32_t> m_nextID;
std::map<uint32_t, Callback> m_pendingCalls;
std::unordered_map<int, std::shared_ptr<uvw::PollHandle>> m_Polls;
void
wakeup() override;
};
} // namespace llarp::uv