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 "
"don't forget: something something MUH traffic shape "
"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
self->_rc.netID = llarp::NetID();
}

View File

@ -1,10 +1,11 @@
#include <router_contact.hpp>
#include <bencode.hpp>
#include <buffer.hpp>
#include <crypto.hpp>
#include <logger.hpp>
#include <mem.hpp>
#include <net.hpp>
#include <router_contact.hpp>
#include <time.hpp>
#include <version.hpp>
@ -12,8 +13,13 @@
namespace llarp
{
const byte_t *NetID::DefaultValue =
reinterpret_cast< const byte_t * >(Version::LLARP_NET_ID);
NetID &
NetID::DefaultValue()
{
static NetID defaultID(
reinterpret_cast< const byte_t * >(Version::LLARP_NET_ID));
return defaultID;
}
bool RouterContact::IgnoreBogons = false;
@ -25,11 +31,14 @@ namespace llarp
llarp_time_t RouterContact::Lifetime = 24 * 60 * 60 * 1000;
#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

View File

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

View File

@ -90,7 +90,7 @@ namespace llarp
if(key_itr->IsString())
{
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();
}

View File

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