Fix RCTest dependency ordering

This commit is contained in:
Michael 2019-01-05 00:49:06 +00:00
parent 578cbbeb07
commit 535c65ca52
No known key found for this signature in database
GPG Key ID: 2D51757B47E2434C
5 changed files with 30 additions and 19 deletions

View File

@ -1543,7 +1543,8 @@ namespace llarp
"' you will run as a different network, good luck and " "' you will run as a different network, good luck and "
"don't forget: something something MUH traffic shape " "don't forget: something something MUH traffic shape "
"correlation !!!!"); "correlation !!!!");
llarp::NetID::DefaultValue = (const byte_t *)strdup(val); llarp::NetID::DefaultValue() =
llarp::NetID(reinterpret_cast< const byte_t * >(strdup(val)));
// re set netid in our rc // re set netid in our rc
self->_rc.netID = llarp::NetID(); self->_rc.netID = llarp::NetID();
} }

View File

@ -1,10 +1,11 @@
#include <router_contact.hpp>
#include <bencode.hpp> #include <bencode.hpp>
#include <buffer.hpp> #include <buffer.hpp>
#include <crypto.hpp> #include <crypto.hpp>
#include <logger.hpp> #include <logger.hpp>
#include <mem.hpp> #include <mem.hpp>
#include <net.hpp> #include <net.hpp>
#include <router_contact.hpp>
#include <time.hpp> #include <time.hpp>
#include <version.hpp> #include <version.hpp>
@ -12,8 +13,13 @@
namespace llarp namespace llarp
{ {
const byte_t *NetID::DefaultValue = NetID &
reinterpret_cast< const byte_t * >(Version::LLARP_NET_ID); NetID::DefaultValue()
{
static NetID defaultID(
reinterpret_cast< const byte_t * >(Version::LLARP_NET_ID));
return defaultID;
}
bool RouterContact::IgnoreBogons = false; bool RouterContact::IgnoreBogons = false;
@ -25,11 +31,14 @@ namespace llarp
llarp_time_t RouterContact::Lifetime = 24 * 60 * 60 * 1000; llarp_time_t RouterContact::Lifetime = 24 * 60 * 60 * 1000;
#endif #endif
NetID::NetID() : AlignedBuffer< 8 >() NetID::NetID(const byte_t *val) : AlignedBuffer< 8 >()
{
size_t len = strnlen(reinterpret_cast< const char * >(val), size());
std::copy(val, val + len, begin());
}
NetID::NetID() : NetID(DefaultValue().data())
{ {
size_t len =
strnlen(reinterpret_cast< const char * >(DefaultValue), size());
std::copy(DefaultValue, DefaultValue + len, begin());
} }
bool bool

View File

@ -17,10 +17,15 @@ namespace llarp
/// NetID /// NetID
struct NetID final : public AlignedBuffer< 8 > struct NetID final : public AlignedBuffer< 8 >
{ {
static const byte_t *DefaultValue; static NetID &
DefaultValue();
NetID(); NetID();
explicit NetID(const byte_t *val);
explicit NetID(const NetID &other) = default;
bool bool
operator==(const NetID &other) const; operator==(const NetID &other) const;

View File

@ -90,7 +90,7 @@ namespace llarp
if(key_itr->IsString()) if(key_itr->IsString())
{ {
keys.emplace_back(); keys.emplace_back();
if(!HexDecode(key_itr->GetString(), keys.back(), PUBKEYSIZE)) if(!HexDecode(key_itr->GetString(), keys.back().begin(), decltype(keys)::value_type::SIZE))
{ {
keys.pop_back(); keys.pop_back();
} }

View File

@ -10,25 +10,21 @@ struct RCTest : public ::testing::Test
using RC_t = llarp::RouterContact; using RC_t = llarp::RouterContact;
using SecKey_t = llarp::SecretKey; using SecKey_t = llarp::SecretKey;
static void RCTest()
SetUpTestCase() : crypto(llarp::Crypto::sodium{}), oldval(llarp::NetID::DefaultValue())
{
llarp::NetID::DefaultValue = DEF_VALUE;
}
RCTest() : crypto(llarp::Crypto::sodium{}), oldval(llarp::NetID::DefaultValue)
{ {
llarp::NetID::DefaultValue() = llarp::NetID(DEF_VALUE);
rc.Clear(); rc.Clear();
} }
~RCTest() ~RCTest()
{ {
llarp::NetID::DefaultValue = oldval; llarp::NetID::DefaultValue() = oldval;
} }
RC_t rc; RC_t rc;
llarp::Crypto crypto; llarp::Crypto crypto;
const byte_t* oldval; const llarp::NetID oldval;
}; };
TEST_F(RCTest, TestSignVerify) TEST_F(RCTest, TestSignVerify)