replace LLARP_PROTO_VERSION macro

pull/1923/head
Jeff 2 years ago
parent 0331db494e
commit 1eba0f836e
No known key found for this signature in database
GPG Key ID: 025C02EE3A092F2D

@ -1,13 +1,9 @@
#pragma once
#ifndef LLARP_PROTO_VERSION
#define LLARP_PROTO_VERSION (0)
#endif
namespace llarp::constants
{
/// current network wide protocol version
// TODO: enum class
constexpr auto proto_version = 0;
#ifndef LLARP_ETH_PROTO
#define LLARP_ETH_PROTO (0xD1CE)
#endif
#ifndef LLARP_KEYFILE_VERSION
#define LLARP_KEYFILE_VERSION (1)
#endif
} // namespace llarp::constants

@ -16,7 +16,7 @@ namespace llarp
{
// clang-format off
const std::array<uint16_t, 3> VERSION{{LLARP_VERSION_MAJOR, LLARP_VERSION_MINOR, LLARP_VERSION_PATCH}};
const std::array<uint64_t, 4> ROUTER_VERSION{{LLARP_PROTO_VERSION, LLARP_VERSION_MAJOR, LLARP_VERSION_MINOR, LLARP_VERSION_PATCH}};
const std::array<uint64_t, 4> ROUTER_VERSION{{llarp::constants::proto_version, LLARP_VERSION_MAJOR, LLARP_VERSION_MINOR, LLARP_VERSION_PATCH}};
const char* const VERSION_STR = LLARP_VERSION_STR;
const char* const VERSION_TAG = "@VERSIONTAG@";
const char* const VERSION_FULL = LLARP_NAME "-" LLARP_VERSION_STR "-@VERSIONTAG@";

@ -34,7 +34,7 @@ namespace llarp
Key_t From;
PathID_t pathID;
uint64_t version = LLARP_PROTO_VERSION;
uint64_t version = llarp::constants::proto_version;
};
IMessage::Ptr_t

@ -28,7 +28,7 @@ namespace llarp
if (!BEncodeMaybeReadDictInt("T", txID, read, k, val))
return false;
if (!BEncodeMaybeVerifyVersion("V", version, LLARP_PROTO_VERSION, read, k, val))
if (!BEncodeMaybeVerifyVersion("V", version, llarp::constants::proto_version, read, k, val))
return false;
return read;
@ -66,7 +66,7 @@ namespace llarp
if (!BEncodeWriteDictInt("T", txID, buf))
return false;
// protocol version
if (!BEncodeWriteDictInt("V", LLARP_PROTO_VERSION, buf))
if (!BEncodeWriteDictInt("V", llarp::constants::proto_version, buf))
return false;
return bencode_end(buf);

@ -73,7 +73,7 @@ namespace llarp
return bencode_read_integer(val, &txid);
}
bool read = false;
if (!BEncodeMaybeVerifyVersion("V", version, LLARP_PROTO_VERSION, read, key, val))
if (!BEncodeMaybeVerifyVersion("V", version, llarp::constants::proto_version, read, key, val))
return false;
return read;

@ -30,7 +30,7 @@ namespace llarp
/// gossip message
GotRouterMessage(const RouterContact rc) : IMessage({}), foundRCs({rc}), txid(0)
{
version = LLARP_PROTO_VERSION;
version = llarp::constants::proto_version;
}
GotRouterMessage(const GotRouterMessage& other)

@ -195,7 +195,7 @@ namespace llarp
return false;
if (!BEncodeWriteDictInt("T", txID, buf))
return false;
if (!BEncodeWriteDictInt("V", LLARP_PROTO_VERSION, buf))
if (!BEncodeWriteDictInt("V", llarp::constants::proto_version, buf))
return false;
return bencode_end(buf);
}

@ -11,7 +11,7 @@ namespace llarp
uint64_t proto = 0;
uint64_t port = 0;
uint64_t drop = 0;
uint64_t version = LLARP_PROTO_VERSION;
uint64_t version = llarp::constants::proto_version;
bool
BDecode(llarp_buffer_t* buf)

@ -24,7 +24,7 @@ namespace llarp
}
// randomize nounce
CryptoManager::instance()->randbytes(pkt.data() + HMACSIZE, TUNNONCESIZE);
pkt[PacketOverhead] = LLARP_PROTO_VERSION;
pkt[PacketOverhead] = llarp::constants::proto_version;
pkt[PacketOverhead + 1] = cmd;
return pkt;
}
@ -653,10 +653,13 @@ namespace llarp
LogError("failed to decrypt session data from ", m_RemoteAddr);
continue;
}
if (pkt[PacketOverhead] != LLARP_PROTO_VERSION)
if (pkt[PacketOverhead] != llarp::constants::proto_version)
{
LogError(
"protocol version mismatch ", int(pkt[PacketOverhead]), " != ", LLARP_PROTO_VERSION);
"protocol version mismatch ",
int(pkt[PacketOverhead]),
" != ",
llarp::constants::proto_version);
itr = msgs.erase(itr);
continue;
}

@ -20,7 +20,7 @@ namespace llarp
{
if (!bencode_read_integer(buf, &version))
return false;
return version == LLARP_PROTO_VERSION;
return version == llarp::constants::proto_version;
}
// bad key
return false;
@ -54,7 +54,7 @@ namespace llarp
return false;
// protocol version
if (!bencode_write_uint64_entry(buf, "v", 1, LLARP_PROTO_VERSION))
if (!bencode_write_uint64_entry(buf, "v", 1, llarp::constants::proto_version))
return false;
return bencode_end(buf);

@ -69,7 +69,7 @@ namespace llarp
DataDiscardMessage(const PathID_t& dst, uint64_t s) : P(dst)
{
S = s;
version = LLARP_PROTO_VERSION;
version = llarp::constants::proto_version;
}
void

@ -43,9 +43,10 @@ namespace llarp
{
if (!bencode_read_integer(buf, &version))
return false;
if (version != LLARP_PROTO_VERSION)
if (version != llarp::constants::proto_version)
{
llarp::LogWarn("llarp protocol version mismatch ", version, " != ", LLARP_PROTO_VERSION);
llarp::LogWarn(
"llarp protocol version mismatch ", version, " != ", llarp::constants::proto_version);
return false;
}
llarp::LogDebug("LIM version ", version);
@ -86,7 +87,7 @@ namespace llarp
if (!rc.BEncode(buf))
return false;
if (!bencode_write_uint64_entry(buf, "v", 1, LLARP_PROTO_VERSION))
if (!bencode_write_uint64_entry(buf, "v", 1, llarp::constants::proto_version))
return false;
if (!bencode_write_bytestring(buf, "z", 1))

@ -17,7 +17,7 @@ namespace llarp
{
/// who did this message come from or is going to
ILinkSession* session = nullptr;
uint64_t version = LLARP_PROTO_VERSION;
uint64_t version = llarp::constants::proto_version;
PathID_t pathid;

@ -25,7 +25,7 @@ namespace llarp
if (!BEncodeWriteDictEntry("p", pathid, buf))
return false;
if (!BEncodeWriteDictInt("v", LLARP_PROTO_VERSION, buf))
if (!BEncodeWriteDictInt("v", llarp::constants::proto_version, buf))
return false;
if (!BEncodeWriteDictEntry("x", X, buf))
return false;
@ -40,7 +40,7 @@ namespace llarp
bool read = false;
if (!BEncodeMaybeReadDictEntry("p", pathid, read, key, buf))
return false;
if (!BEncodeMaybeVerifyVersion("v", version, LLARP_PROTO_VERSION, read, key, buf))
if (!BEncodeMaybeVerifyVersion("v", version, llarp::constants::proto_version, read, key, buf))
return false;
if (!BEncodeMaybeReadDictEntry("x", X, read, key, buf))
return false;
@ -79,7 +79,7 @@ namespace llarp
if (!BEncodeWriteDictEntry("p", pathid, buf))
return false;
if (!BEncodeWriteDictInt("v", LLARP_PROTO_VERSION, buf))
if (!BEncodeWriteDictInt("v", llarp::constants::proto_version, buf))
return false;
if (!BEncodeWriteDictEntry("x", X, buf))
return false;
@ -94,7 +94,7 @@ namespace llarp
bool read = false;
if (!BEncodeMaybeReadDictEntry("p", pathid, read, key, buf))
return false;
if (!BEncodeMaybeVerifyVersion("v", version, LLARP_PROTO_VERSION, read, key, buf))
if (!BEncodeMaybeVerifyVersion("v", version, llarp::constants::proto_version, read, key, buf))
return false;
if (!BEncodeMaybeReadDictEntry("x", X, read, key, buf))
return false;

@ -29,7 +29,7 @@ namespace llarp
return BEncodeReadArray(frames, buf);
}
bool read = false;
if (!BEncodeMaybeVerifyVersion("v", version, LLARP_PROTO_VERSION, read, key, buf))
if (!BEncodeMaybeVerifyVersion("v", version, llarp::constants::proto_version, read, key, buf))
return false;
return read;
@ -54,7 +54,7 @@ namespace llarp
if (!BEncodeWriteDictArray("c", frames, buf))
return false;
// version
if (!bencode_write_uint64_entry(buf, "v", 1, LLARP_PROTO_VERSION))
if (!bencode_write_uint64_entry(buf, "v", 1, llarp::constants::proto_version))
return false;
return bencode_end(buf);
@ -102,9 +102,10 @@ namespace llarp
if (!BEncodeWriteDictEntry("u", *nextRC, buf))
return false;
}
if (!bencode_write_uint64_entry(buf, "v", 1, LLARP_PROTO_VERSION))
if (not bencode_write_uint64_entry(buf, "v", 1, llarp::constants::proto_version))
return false;
if (work && !BEncodeWriteDictEntry("w", *work, buf))
if (work and not BEncodeWriteDictEntry("w", *work, buf))
return false;
return bencode_end(buf);
@ -135,7 +136,8 @@ namespace llarp
nextRC = std::make_unique<RouterContact>();
return nextRC->BDecode(buffer);
}
if (!BEncodeMaybeVerifyVersion("v", version, LLARP_PROTO_VERSION, read, *key, buffer))
if (!BEncodeMaybeVerifyVersion(
"v", version, llarp::constants::proto_version, read, *key, buffer))
return false;
if (*key == "w")
{

@ -80,7 +80,7 @@ namespace llarp
}
else if (key == "v")
{
if (!BEncodeMaybeVerifyVersion("v", version, LLARP_PROTO_VERSION, read, key, buf))
if (!BEncodeMaybeVerifyVersion("v", version, llarp::constants::proto_version, read, key, buf))
{
return false;
}
@ -115,7 +115,7 @@ namespace llarp
if (!BEncodeWriteDictInt("s", status, buf))
return false;
// version
if (!bencode_write_uint64_entry(buf, "v", 1, LLARP_PROTO_VERSION))
if (!bencode_write_uint64_entry(buf, "v", 1, llarp::constants::proto_version))
return false;
return bencode_end(buf);
@ -190,7 +190,7 @@ namespace llarp
LR_StatusRecord record;
record.status = newStatus;
record.version = LLARP_PROTO_VERSION;
record.version = llarp::constants::proto_version;
llarp_buffer_t buf(frame.data(), frame.size());
buf.cur = buf.base + EncryptedFrameOverheadSize;
@ -256,7 +256,8 @@ namespace llarp
LR_StatusRecord::BEncode(llarp_buffer_t* buf) const
{
return bencode_start_dict(buf) && BEncodeWriteDictInt("s", status, buf)
&& bencode_write_uint64_entry(buf, "v", 1, LLARP_PROTO_VERSION) && bencode_end(buf);
&& bencode_write_uint64_entry(buf, "v", 1, llarp::constants::proto_version)
&& bencode_end(buf);
}
bool
@ -269,7 +270,8 @@ namespace llarp
if (!BEncodeMaybeReadDictInt("s", status, read, *key, buffer))
return false;
if (!BEncodeMaybeVerifyVersion("v", version, LLARP_PROTO_VERSION, read, *key, buffer))
if (!BEncodeMaybeVerifyVersion(
"v", version, llarp::constants::proto_version, read, *key, buffer))
return false;
return read;

@ -105,7 +105,7 @@ namespace llarp
{
if (!bencode_read_integer(buf, &i))
return false;
return i == LLARP_PROTO_VERSION;
return i == llarp::constants::proto_version;
}
// bad key
@ -149,7 +149,7 @@ namespace llarp
return false;
/** version */
if (!bencode_write_uint64_entry(buff, "v", 1, LLARP_PROTO_VERSION))
if (!bencode_write_uint64_entry(buff, "v", 1, llarp::constants::proto_version))
return false;
/** end */
return bencode_end(buff);

@ -27,7 +27,7 @@ namespace llarp
llarp::PubKey pubkey;
in6_addr ip = {};
uint16_t port;
uint64_t version = LLARP_PROTO_VERSION;
uint64_t version = llarp::constants::proto_version;
bool
BDecode(llarp_buffer_t* buf)

@ -21,7 +21,7 @@ namespace llarp
IpAddress ipAddress;
IpAddress netmask;
PubKey pubkey;
uint64_t version = LLARP_PROTO_VERSION;
uint64_t version = llarp::constants::proto_version;
ExitInfo() = default;

@ -646,7 +646,7 @@ namespace llarp
llarp_buffer_t buf(tmp);
// should help prevent bad paths with uninitialized members
// FIXME: Why would we get uninitialized IMessages?
if (msg.version != LLARP_PROTO_VERSION)
if (msg.version != llarp::constants::proto_version)
return false;
if (!msg.BEncode(&buf))
{

@ -68,7 +68,7 @@ namespace llarp
}
// build record
record.lifetime = path::default_lifetime;
record.version = LLARP_PROTO_VERSION;
record.version = llarp::constants::proto_version;
record.txid = hop.txID;
record.rxid = hop.rxID;
record.tunnelNonce = hop.nonce;

@ -12,7 +12,7 @@ namespace llarp
llarp_time_t timestamp = 0s;
llarp_time_t extendedLifetime = 0s;
AlignedBuffer<32> nonce;
uint64_t version = LLARP_PROTO_VERSION;
uint64_t version = llarp::constants::proto_version;
~PoW();

@ -20,7 +20,7 @@ namespace llarp
uint64_t pathTimeoutCount = 0;
llarp_time_t lastUpdated = 0s;
llarp_time_t lastDecay = 0s;
uint64_t version = LLARP_PROTO_VERSION;
uint64_t version = llarp::constants::proto_version;
bool
BEncode(llarp_buffer_t* buf) const;

@ -1210,7 +1210,7 @@ namespace llarp
// set router version if service node
if (IsServiceNode())
{
_rc.routerVersion = RouterVersion(llarp::VERSION, LLARP_PROTO_VERSION);
_rc.routerVersion = RouterVersion(llarp::VERSION, llarp::constants::proto_version);
}
_linkManager.ForEachInboundLink([&](LinkLayer_ptr link) {

@ -221,7 +221,7 @@ namespace llarp
routerVersion = std::optional<RouterVersion>{};
last_updated = 0s;
srvRecords.clear();
version = LLARP_PROTO_VERSION;
version = llarp::constants::proto_version;
}
util::StatusObject

@ -101,7 +101,7 @@ namespace llarp
llarp::AlignedBuffer<NICKLEN> nickname;
llarp_time_t last_updated = 0s;
uint64_t version = LLARP_PROTO_VERSION;
uint64_t version = llarp::constants::proto_version;
std::optional<RouterVersion> routerVersion;
/// should we serialize the exit info?
const static bool serializeExit = true;

@ -57,7 +57,7 @@ namespace llarp
private:
Version_t m_Version = {{0, 0, 0}};
int64_t m_ProtoVersion = LLARP_PROTO_VERSION;
int64_t m_ProtoVersion = llarp::constants::proto_version;
};
inline std::ostream&

@ -39,7 +39,7 @@ namespace llarp
return false;
if (!BEncodeWriteDictInt("S", S, buf))
return false;
if (!BEncodeWriteDictInt("V", LLARP_PROTO_VERSION, buf))
if (!BEncodeWriteDictInt("V", llarp::constants::proto_version, buf))
return false;
return bencode_end(buf);

@ -16,7 +16,7 @@ namespace llarp
{
PathID_t from;
uint64_t S{0};
uint64_t version = LLARP_PROTO_VERSION;
uint64_t version = llarp::constants::proto_version;
IMessage() = default;

@ -40,7 +40,7 @@ namespace llarp
if (!BEncodeWriteDictEntry("T", T, buf))
return false;
if (!BEncodeWriteDictInt("V", LLARP_PROTO_VERSION, buf))
if (!BEncodeWriteDictInt("V", llarp::constants::proto_version, buf))
return false;
if (!BEncodeWriteDictEntry("Y", Y, buf))
return false;

@ -70,7 +70,7 @@ namespace llarp
// set sender
self->msg.sender = self->m_LocalIdentity.pub;
// set version
self->msg.version = LLARP_PROTO_VERSION;
self->msg.version = llarp::constants::proto_version;
// encrypt and sign
if (frame->EncryptAndSign(self->msg, K, self->m_LocalIdentity))
self->loop->call([self, frame] { AsyncKeyExchange::Result(self, frame); });

@ -22,7 +22,7 @@ namespace llarp
SecretKey signkey;
PrivateKey derivedSignKey;
PQKeyPair pq;
uint64_t version = LLARP_PROTO_VERSION;
uint64_t version = llarp::constants::proto_version;
VanityNonce vanity;
// public service info

@ -56,7 +56,7 @@ namespace llarp
return false;
if (!BEncodeWriteDictEntry("s", signkey, buf))
return false;
if (!BEncodeWriteDictInt("v", LLARP_PROTO_VERSION, buf))
if (!BEncodeWriteDictInt("v", llarp::constants::proto_version, buf))
return false;
if (!vanity.IsZero())
{

@ -20,7 +20,7 @@ namespace llarp
public:
VanityNonce vanity;
uint64_t version = LLARP_PROTO_VERSION;
uint64_t version = llarp::constants::proto_version;
void
RandomizeVanity()

@ -17,7 +17,7 @@ namespace llarp
PathID_t pathID;
llarp_time_t latency = 0s;
llarp_time_t expiresAt = 0s;
uint64_t version = LLARP_PROTO_VERSION;
uint64_t version = llarp::constants::proto_version;
util::StatusObject
ExtractStatus() const;

@ -49,7 +49,7 @@ namespace llarp
std::optional<net::TrafficPolicy> exitTrafficPolicy;
Signature signature;
uint64_t version = LLARP_PROTO_VERSION;
uint64_t version = llarp::constants::proto_version;
bool
OtherIsNewer(const IntroSet& other) const

@ -191,7 +191,7 @@ namespace llarp
return false;
if (!BEncodeMaybeReadDictEntry("T", T, read, key, val))
return false;
if (!BEncodeMaybeVerifyVersion("V", version, LLARP_PROTO_VERSION, read, key, val))
if (!BEncodeMaybeVerifyVersion("V", version, llarp::constants::proto_version, read, key, val))
return false;
if (!BEncodeMaybeReadDictEntry("Z", Z, read, key, val))
return false;

@ -45,7 +45,7 @@ namespace llarp
Endpoint* handler = nullptr;
ConvoTag tag;
uint64_t seqno = 0;
uint64_t version = LLARP_PROTO_VERSION;
uint64_t version = llarp::constants::proto_version;
/// encode metainfo for lmq endpoint auth
std::vector<char>
@ -155,7 +155,7 @@ namespace llarp
N.Zero();
Z.Zero();
R = 0;
version = LLARP_PROTO_VERSION;
version = llarp::constants::proto_version;
}
bool

@ -24,14 +24,14 @@ TEST_CASE("Compatibility when protocol unequal", "[RouterVersion]")
TEST_CASE("Empty compatibility", "[RouterVersion]")
{
llarp::RouterVersion v1({0, 0, 1}, LLARP_PROTO_VERSION);
llarp::RouterVersion v1({0, 0, 1}, llarp::constants::proto_version);
CHECK_FALSE(v1.IsCompatableWith(llarp::emptyRouterVersion));
}
TEST_CASE("IsEmpty", "[RouterVersion]")
{
llarp::RouterVersion notEmpty({0, 0, 1}, LLARP_PROTO_VERSION);
llarp::RouterVersion notEmpty({0, 0, 1}, llarp::constants::proto_version);
CHECK_FALSE(notEmpty.IsEmpty());
CHECK(llarp::emptyRouterVersion.IsEmpty());
@ -39,7 +39,7 @@ TEST_CASE("IsEmpty", "[RouterVersion]")
TEST_CASE("Clear", "[RouterVersion]")
{
llarp::RouterVersion version({0, 0, 1}, LLARP_PROTO_VERSION);
llarp::RouterVersion version({0, 0, 1}, llarp::constants::proto_version);
CHECK_FALSE(version.IsEmpty());
version.Clear();

@ -28,6 +28,6 @@ TEST_CASE_METHOD(LlarpTest<>, "Sign-verify")
CHECK(msg.Sign(alice));
CHECK(msg.Verify());
CHECK(msg.I == PubKey{seckey_topublic(alice)});
CHECK(msg.version == LLARP_PROTO_VERSION);
CHECK(msg.version == llarp::constants::proto_version);
CHECK_FALSE(msg.Z.IsZero());
}

Loading…
Cancel
Save