2020-04-27 15:24:05 +00:00
|
|
|
#include <config/config.hpp>
|
2019-01-14 21:46:07 +00:00
|
|
|
#include <router/router.hpp>
|
2019-07-02 21:28:28 +00:00
|
|
|
#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
|
|
|
|
2020-07-02 17:12:04 +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
|
|
|
{
|
2021-02-02 14:35:40 +00:00
|
|
|
auto conf = std::make_shared<llarp::Config>(fs::current_path());
|
|
|
|
conf->Load(std::nullopt, true);
|
2020-07-02 17:12:04 +00:00
|
|
|
|
2020-06-12 13:28:31 +00:00
|
|
|
// set testing defaults
|
2021-02-02 14:35:40 +00:00
|
|
|
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
|
2021-02-02 14:35:40 +00:00
|
|
|
conf->links.m_InboundLinks.emplace_back();
|
|
|
|
auto& link = conf->links.m_InboundLinks.back();
|
2020-08-19 20:41:46 +00:00
|
|
|
link.interface = "0.0.0.0";
|
2020-06-12 13:28:31 +00:00
|
|
|
link.addressFamily = AF_INET;
|
|
|
|
link.port = 0;
|
|
|
|
// configure
|
2020-07-06 19:13:01 +00:00
|
|
|
|
|
|
|
auto context = std::make_shared<llarp::Context>();
|
|
|
|
REQUIRE_NOTHROW(context->Configure(std::move(conf)));
|
|
|
|
|
2020-07-02 17:12:04 +00:00
|
|
|
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
|
|
|
{
|
2020-06-16 14:40:24 +00:00
|
|
|
llarp::LogSilencer shutup;
|
2020-06-12 13:28:31 +00:00
|
|
|
auto ctx = make_context();
|
2020-07-02 17:12:04 +00:00
|
|
|
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());
|
2020-07-02 17:12:04 +00:00
|
|
|
ctx->CloseAsync();
|
2020-06-12 13:28:31 +00:00
|
|
|
});
|
2020-07-02 17:12:04 +00:00
|
|
|
REQUIRE(ctx->Run(opts) == 0);
|
|
|
|
|
|
|
|
ctx.reset();
|
2019-04-25 23:21:19 +00:00
|
|
|
}
|