mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-15 12:13:24 +00:00
329da951b7
- Add a C callback interface (context_wrapper.h) between lokinet and the objective-C code so that: - we can use objective-C (rather than objective-C++), which seems more likely to be supported by Apple into the future; - we minimize the amount of code that needs to be aware of the Apple APIs. - this replaces apple logger objective c++ implementation with a plain c++ implementation that takes a very simple C callback (provided from the obj-c code) to actually make the call to NSLog. - Add various documentation to the code of what is going on. - Send all DNS traffic to the primary IP on the tun interface. The match prefixes simply don't work as advertised, and have weird shit (like even if you get it working for some domains, "instagram.com" still doesn't because of god-knows-what Apple internal politics). - Drop the dns proxy code as we don't need it anymore. - Don't use 9.9.9.9 for default DNS. (We might consider the unfiltered 9.9.9.10 as an alternative default, but if we do it should be a global lokinet change rather than a Mac-specific change). - Parse a lokinet.ini in the data directory, if it exists. (Since we are sandboxed, it is an app-specific "home" directory so is probably buried god knows where, but at least the GUI ought to be able to get it to let users add things to it). - This commit also adds a swift version of the PacketTunnelProvider glue, which ought to work in theory, but the *tooling* for cmake is so underdeveloped that I couldn't find any way to actually get the damn thing working. So I'm committing it here anyway (and will revert it away in the next commit) in case we someday want to switch to it. -
52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <llarp.hpp>
|
|
#include <llarp/ev/vpn.hpp>
|
|
#include <llarp/util/thread/queue.hpp>
|
|
#include <memory>
|
|
|
|
namespace llarp::apple
|
|
{
|
|
struct Context;
|
|
|
|
class VPNInterface final : public vpn::NetworkInterface,
|
|
public std::enable_shared_from_this<VPNInterface>
|
|
{
|
|
public:
|
|
using packet_write_callback = std::function<bool(int af_family, void* data, int size)>;
|
|
using on_readable_callback = std::function<void(VPNInterface&)>;
|
|
|
|
explicit VPNInterface(
|
|
Context& ctx, packet_write_callback packet_writer, on_readable_callback on_readable);
|
|
|
|
// Method to call when a packet has arrived to deliver the packet to lokinet
|
|
bool
|
|
OfferReadPacket(const llarp_buffer_t& buf);
|
|
|
|
int
|
|
PollFD() const override;
|
|
|
|
std::string
|
|
IfName() const override;
|
|
|
|
net::IPPacket
|
|
ReadNextPacket() override;
|
|
|
|
bool
|
|
WritePacket(net::IPPacket pkt) override;
|
|
|
|
private:
|
|
// Function for us to call when we have a packet to emit. Should return true if the packet was
|
|
// handed off to the OS successfully.
|
|
packet_write_callback m_PacketWriter;
|
|
|
|
// Called when we are ready to start reading packets
|
|
on_readable_callback m_OnReadable;
|
|
|
|
static inline constexpr auto PacketQueueSize = 1024;
|
|
|
|
thread::Queue<net::IPPacket> m_ReadQueue{PacketQueueSize};
|
|
};
|
|
|
|
} // namespace llarp::apple
|