Merge pull request #193 from michael-loki/fix_rctest

Fix RCTest.TestSignVerify
This commit is contained in:
Jeff 2019-01-02 18:18:46 -05:00 committed by GitHub
commit 7a7a4f1e52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 18 deletions

View File

@ -1542,7 +1542,7 @@ namespace llarp
if(strlen(val) <= self->_rc.netID.size())
{
llarp::LogWarn("!!!! you have manually set netid to be '", val,
"' which does not equal '", LLARP_NET_ID,
"' which does not equal '", Version::LLARP_NET_ID,
"' you will run as a different network, good luck and "
"don't forget: something something MUH traffic shape "
"correlation !!!!");

View File

@ -12,7 +12,8 @@
namespace llarp
{
const byte_t *NetID::DefaultValue = (const byte_t *)LLARP_NET_ID;
const byte_t *NetID::DefaultValue =
reinterpret_cast< const byte_t * >(Version::LLARP_NET_ID);
bool RouterContact::IgnoreBogons = false;
@ -23,6 +24,7 @@ namespace llarp
/// 1 day for real network
llarp_time_t RouterContact::Lifetime = 24 * 60 * 60 * 1000;
#endif
NetID::NetID() : AlignedBuffer< 8 >()
{
size_t len =
@ -161,8 +163,7 @@ namespace llarp
if(strbuf.sz > nickname.size())
return false;
nickname.Zero();
std::copy(strbuf.base, strbuf.base + strbuf.sz,
nickname.begin());
std::copy(strbuf.base, strbuf.base + strbuf.sz, nickname.begin());
return true;
}
@ -216,7 +217,9 @@ namespace llarp
RouterContact::ExpiresSoon(llarp_time_t now, llarp_time_t dlt) const
{
if(IsExpired(now))
{
return true;
}
auto expiresAt = last_updated + Lifetime;
return expiresAt - now <= dlt;
}

View File

@ -60,7 +60,7 @@ namespace llarp
}
RouterContact(const RouterContact &other)
: IBEncodeMessage()
: IBEncodeMessage(other.version)
, addrs(other.addrs)
, netID(other.netID)
, enckey(other.enckey)
@ -70,7 +70,6 @@ namespace llarp
, nickname(other.nickname)
, last_updated(other.last_updated)
{
version = other.version;
}
// advertised addresses

View File

@ -1 +1,3 @@
#include <version.hpp>
const char Version::LLARP_NET_ID[] = "testnet";

View File

@ -29,8 +29,9 @@
#define LLARP_RELEASE_MOTTO "(dev build)"
#endif
#ifndef LLARP_NET_ID
#define LLARP_NET_ID "testnet"
#endif
struct Version
{
static const char LLARP_NET_ID[];
};
#endif

View File

@ -3,32 +3,32 @@
#include <router_contact.hpp>
#include <crypto.hpp>
static const byte_t DEF_VALUE[] = "unittest";
struct RCTest : public ::testing::Test
{
using RC_t = llarp::RouterContact;
using SecKey_t = llarp::SecretKey;
RCTest() : crypto(llarp::Crypto::sodium{})
static void
SetUpTestCase()
{
llarp::NetID::DefaultValue = DEF_VALUE;
}
void
SetUp()
RCTest() : crypto(llarp::Crypto::sodium{}), oldval(llarp::NetID::DefaultValue)
{
oldval = llarp::NetID::DefaultValue;
llarp::NetID::DefaultValue = (const byte_t*)"unittest";
rc.Clear();
}
void
TearDown()
~RCTest()
{
llarp::NetID::DefaultValue = oldval;
}
RC_t rc;
llarp::Crypto crypto;
const byte_t* oldval = nullptr;
const byte_t* oldval;
};
TEST_F(RCTest, TestSignVerify)
@ -37,7 +37,7 @@ TEST_F(RCTest, TestSignVerify)
SecKey_t sign;
crypto.encryption_keygen(encr);
crypto.identity_keygen(sign);
rc.enckey = llarp::seckey_topublic(encr);
rc.enckey = encr.toPublic();
ASSERT_TRUE(rc.Sign(&crypto, sign));
ASSERT_TRUE(rc.Verify(&crypto, llarp::time_now_ms()));
}