From 535c65ca5228a49b12cee2831fe84cf05662f72a Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 5 Jan 2019 00:49:06 +0000 Subject: [PATCH] Fix RCTest dependency ordering --- llarp/router.cpp | 3 ++- llarp/router_contact.cpp | 23 ++++++++++++++++------- llarp/router_contact.hpp | 7 ++++++- llarp/rpc.cpp | 2 +- test/test_router_contact.cpp | 14 +++++--------- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/llarp/router.cpp b/llarp/router.cpp index 5ad9fc446..7643f26b3 100644 --- a/llarp/router.cpp +++ b/llarp/router.cpp @@ -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(); } diff --git a/llarp/router_contact.cpp b/llarp/router_contact.cpp index 5a25c0d3c..4b0c9beec 100644 --- a/llarp/router_contact.cpp +++ b/llarp/router_contact.cpp @@ -1,10 +1,11 @@ +#include + #include #include #include #include #include #include -#include #include #include @@ -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 diff --git a/llarp/router_contact.hpp b/llarp/router_contact.hpp index db03111e3..f7c47152e 100644 --- a/llarp/router_contact.hpp +++ b/llarp/router_contact.hpp @@ -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; diff --git a/llarp/rpc.cpp b/llarp/rpc.cpp index 0d7e9aaca..b887f8aad 100644 --- a/llarp/rpc.cpp +++ b/llarp/rpc.cpp @@ -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(); } diff --git a/test/test_router_contact.cpp b/test/test_router_contact.cpp index ffce6f4e5..a0f09f8f4 100644 --- a/test/test_router_contact.cpp +++ b/test/test_router_contact.cpp @@ -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)