Skip to content

Commit

Permalink
replace LLARP_PROTO_VERSION macro
Browse files Browse the repository at this point in the history
  • Loading branch information
majestrate committed May 28, 2022
1 parent 0331db4 commit 1eba0f8
Show file tree
Hide file tree
Showing 40 changed files with 74 additions and 70 deletions.
16 changes: 6 additions & 10 deletions llarp/constants/proto.hpp
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion llarp/constants/version.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@";
Expand Down
2 changes: 1 addition & 1 deletion llarp/dht/message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions llarp/dht/messages/findintro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion llarp/dht/messages/gotrouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion llarp/dht/messages/gotrouter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion llarp/dht/messages/pubintro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion llarp/exit/policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions llarp/iwp/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions llarp/messages/dht_immediate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion llarp/messages/discard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions llarp/messages/link_intro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion llarp/messages/link_message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions llarp/messages/relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions llarp/messages/relay_commit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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")
{
Expand Down
12 changes: 7 additions & 5 deletions llarp/messages/relay_status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions llarp/net/address_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion llarp/net/address_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion llarp/net/exit_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion llarp/path/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
2 changes: 1 addition & 1 deletion llarp/path/pathbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion llarp/pow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion llarp/profiling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion llarp/router/router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion llarp/router_contact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion llarp/router_contact.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 1eba0f8

Please sign in to comment.