diff --git a/llarp/dht/messages/findintro.cpp b/llarp/dht/messages/findintro.cpp index ad654f33c..fcac8e893 100644 --- a/llarp/dht/messages/findintro.cpp +++ b/llarp/dht/messages/findintro.cpp @@ -26,7 +26,7 @@ namespace llarp if(!BEncodeMaybeReadDictInt("T", T, read, k, val)) return false; - if(!BEncodeMaybeReadVersion("V", version, LLARP_PROTO_VERSION, read, k, + if(!BEncodeMaybeVerifyVersion("V", version, LLARP_PROTO_VERSION, read, k, val)) return false; diff --git a/llarp/dht/messages/gotrouter.cpp b/llarp/dht/messages/gotrouter.cpp index 64115bbe9..a6c6b1d87 100644 --- a/llarp/dht/messages/gotrouter.cpp +++ b/llarp/dht/messages/gotrouter.cpp @@ -71,7 +71,7 @@ namespace llarp return bencode_read_integer(val, &txid); } bool read = false; - if(!BEncodeMaybeReadVersion("V", version, LLARP_PROTO_VERSION, read, key, + if(!BEncodeMaybeVerifyVersion("V", version, LLARP_PROTO_VERSION, read, key, val)) return false; diff --git a/llarp/messages/relay.cpp b/llarp/messages/relay.cpp index 38f72eb05..3c54b078b 100644 --- a/llarp/messages/relay.cpp +++ b/llarp/messages/relay.cpp @@ -41,7 +41,7 @@ namespace llarp bool read = false; if(!BEncodeMaybeReadDictEntry("p", pathid, read, key, buf)) return false; - if(!BEncodeMaybeReadVersion("v", version, LLARP_PROTO_VERSION, read, key, + if(!BEncodeMaybeVerifyVersion("v", version, LLARP_PROTO_VERSION, read, key, buf)) return false; if(!BEncodeMaybeReadDictEntry("x", X, read, key, buf)) @@ -97,7 +97,7 @@ namespace llarp bool read = false; if(!BEncodeMaybeReadDictEntry("p", pathid, read, key, buf)) return false; - if(!BEncodeMaybeReadVersion("v", version, LLARP_PROTO_VERSION, read, key, + if(!BEncodeMaybeVerifyVersion("v", version, LLARP_PROTO_VERSION, read, key, buf)) return false; if(!BEncodeMaybeReadDictEntry("x", X, read, key, buf)) diff --git a/llarp/messages/relay_commit.cpp b/llarp/messages/relay_commit.cpp index 604d9746a..7862f6f7a 100644 --- a/llarp/messages/relay_commit.cpp +++ b/llarp/messages/relay_commit.cpp @@ -26,7 +26,7 @@ namespace llarp return BEncodeReadArray(frames, buf); } bool read = false; - if(!BEncodeMaybeReadVersion("v", version, LLARP_PROTO_VERSION, read, key, + if(!BEncodeMaybeVerifyVersion("v", version, LLARP_PROTO_VERSION, read, key, buf)) return false; @@ -134,7 +134,7 @@ namespace llarp nextRC = std::make_unique< RouterContact >(); return nextRC->BDecode(buffer); } - if(!BEncodeMaybeReadVersion("v", version, LLARP_PROTO_VERSION, read, *key, + if(!BEncodeMaybeVerifyVersion("v", version, LLARP_PROTO_VERSION, read, *key, buffer)) return false; if(*key == "w") diff --git a/llarp/messages/relay_status.cpp b/llarp/messages/relay_status.cpp index 9eaf75b75..5e3cea935 100644 --- a/llarp/messages/relay_status.cpp +++ b/llarp/messages/relay_status.cpp @@ -76,7 +76,7 @@ namespace llarp } else if(key == "v") { - if(!BEncodeMaybeReadVersion("v", version, LLARP_PROTO_VERSION, read, key, + if(!BEncodeMaybeVerifyVersion("v", version, LLARP_PROTO_VERSION, read, key, buf)) { return false; @@ -262,7 +262,7 @@ namespace llarp if(!BEncodeMaybeReadDictInt("s", status, read, *key, buffer)) return false; - if(!BEncodeMaybeReadVersion("v", version, LLARP_PROTO_VERSION, read, *key, + if(!BEncodeMaybeVerifyVersion("v", version, LLARP_PROTO_VERSION, read, *key, buffer)) return false; diff --git a/llarp/service/protocol.cpp b/llarp/service/protocol.cpp index 8f723c1f2..878c247a8 100644 --- a/llarp/service/protocol.cpp +++ b/llarp/service/protocol.cpp @@ -163,7 +163,7 @@ namespace llarp return false; if(!BEncodeMaybeReadDictEntry("T", T, read, key, val)) return false; - if(!BEncodeMaybeReadVersion("V", version, LLARP_PROTO_VERSION, read, key, + if(!BEncodeMaybeVerifyVersion("V", version, LLARP_PROTO_VERSION, read, key, val)) return false; if(!BEncodeMaybeReadDictEntry("Z", Z, read, key, val)) diff --git a/llarp/util/bencode.hpp b/llarp/util/bencode.hpp index f1f333dd3..05cd575f4 100644 --- a/llarp/util/bencode.hpp +++ b/llarp/util/bencode.hpp @@ -99,9 +99,11 @@ namespace llarp return true; } + /// If the key matches, reads in the version and ensures that it equals the + /// expected version template < typename Item_t > bool - BEncodeMaybeReadVersion(const char* k, Item_t& item, uint64_t expect, + BEncodeMaybeVerifyVersion(const char* k, Item_t& item, uint64_t expect, bool& read, const llarp_buffer_t& key, llarp_buffer_t* buf) {