lokinet/test/mocks/mock_vpn.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

88 lines
2.0 KiB
C++

#pragma once
#include <llarp/ev/vpn.hpp>
#include "mock_network.hpp"
namespace mocks
{
class MockInterface : public llarp::vpn::NetworkInterface
{
int _pipes[2];
public:
MockInterface(llarp::vpn::InterfaceInfo info) : llarp::vpn::NetworkInterface{std::move(info)}
{
if (pipe(_pipes))
throw std::runtime_error{strerror(errno)};
}
virtual ~MockInterface()
{
close(_pipes[1]);
}
int
PollFD() const override
{
return _pipes[0];
};
llarp::net::IPPacket
ReadNextPacket() override
{
return llarp::net::IPPacket{};
};
bool WritePacket(llarp::net::IPPacket) override
{
return true;
}
};
class MockVPN : public llarp::vpn::Platform, public llarp::vpn::IRouteManager
{
const Network& _net;
public:
MockVPN(const Network& net) : llarp::vpn::Platform{}, llarp::vpn::IRouteManager{}, _net{net}
{}
virtual std::shared_ptr<llarp::vpn::NetworkInterface>
ObtainInterface(llarp::vpn::InterfaceInfo info, llarp::AbstractRouter*) override
{
return std::make_shared<MockInterface>(info);
};
const llarp::net::Platform*
Net_ptr() const override
{
return &_net;
};
void AddRoute(llarp::net::ipaddr_t, llarp::net::ipaddr_t) override{};
void DelRoute(llarp::net::ipaddr_t, llarp::net::ipaddr_t) override{};
void AddDefaultRouteViaInterface(llarp::vpn::NetworkInterface&) override{};
void DelDefaultRouteViaInterface(llarp::vpn::NetworkInterface&) override{};
void
AddRouteViaInterface(llarp::vpn::NetworkInterface&, llarp::IPRange) override{};
void
DelRouteViaInterface(llarp::vpn::NetworkInterface&, llarp::IPRange) override{};
std::vector<llarp::net::ipaddr_t> GetGatewaysNotOnInterface(llarp::vpn::NetworkInterface&) override
{
return std::vector<llarp::net::ipaddr_t>{};
};
/// get owned ip route manager for managing routing table
virtual llarp::vpn::IRouteManager&
RouteManager() override
{
return *this;
};
};
} // namespace mocks