lokinet/test/exit/test_llarp_exit_context.cpp

63 lines
1.7 KiB
C++
Raw Normal View History

2020-04-27 15:24:05 +00:00
#include <config/config.hpp>
#include <router/router.hpp>
#include <exit/context.hpp>
2020-06-12 13:28:31 +00:00
#include <crypto/types.hpp>
#include <llarp.h>
#include <llarp.hpp>
#include <catch2/catch.hpp>
2018-11-15 21:47:05 +00:00
static const llarp::RuntimeOptions opts = {.background = false, .debug = false, .isRouter = true};
std::shared_ptr<llarp::Context>
2020-06-12 13:28:31 +00:00
make_context()
2018-11-15 21:47:05 +00:00
{
auto conf = std::make_shared<llarp::Config>(fs::current_path());
conf->Load(std::nullopt, true);
2020-06-12 13:28:31 +00:00
// set testing defaults
conf->network.m_endpointType = "null";
conf->bootstrap.seednode = true;
conf->api.m_enableRPCServer = false;
conf->lokid.whitelistRouters = false;
conf->router.m_publicAddress = llarp::IpAddress("1.1.1.1");
2020-06-12 13:28:31 +00:00
// make a fake inbound link
conf->links.m_InboundLinks.emplace_back();
auto& link = conf->links.m_InboundLinks.back();
link.interface = "0.0.0.0";
2020-06-12 13:28:31 +00:00
link.addressFamily = AF_INET;
link.port = 0;
// configure
auto context = std::make_shared<llarp::Context>();
REQUIRE_NOTHROW(context->Configure(std::move(conf)));
return context;
2020-06-12 13:28:31 +00:00
}
2018-11-15 21:47:05 +00:00
2020-06-12 13:28:31 +00:00
TEST_CASE("ensure snode address allocation", "[snode]")
2018-11-15 21:47:05 +00:00
{
llarp::LogSilencer shutup;
2020-06-12 13:28:31 +00:00
auto ctx = make_context();
REQUIRE_NOTHROW(ctx->Setup(opts));
ctx->CallSafe([ctx]() {
REQUIRE(ctx->router->IsServiceNode());
auto& context = ctx->router->exitContext();
2020-06-12 13:28:31 +00:00
llarp::PubKey pk;
pk.Randomize();
2020-04-27 15:24:05 +00:00
2020-06-12 13:28:31 +00:00
llarp::PathID_t firstPath, secondPath;
firstPath.Randomize();
secondPath.Randomize();
2020-04-27 15:24:05 +00:00
2020-06-12 13:28:31 +00:00
REQUIRE(context.ObtainNewExit(pk, firstPath, false));
REQUIRE(context.ObtainNewExit(pk, secondPath, false));
REQUIRE(
context.FindEndpointForPath(firstPath)->LocalIP()
== context.FindEndpointForPath(secondPath)->LocalIP());
ctx->CloseAsync();
2020-06-12 13:28:31 +00:00
});
REQUIRE(ctx->Run(opts) == 0);
ctx.reset();
2019-04-25 23:21:19 +00:00
}