lokinet/test/exit/test_llarp_exit_context.cpp

61 lines
1.6 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
{
llarp::Config conf;
conf.LoadDefault(true, fs::current_path());
2020-06-12 13:28:31 +00:00
// set testing defaults
conf.network.m_endpointType = "null";
conf.bootstrap.skipBootstrap = true;
conf.api.m_enableRPCServer = false;
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();
2020-06-12 13:28:31 +00:00
link.interface = llarp::net::LoopbackInterfaceName();
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
}