Bencode/decode relayOrder in lexigraphical order, make it uint64_t

This commit is contained in:
Stephen Shelton 2020-02-14 11:06:19 -07:00 committed by Jason Rhinelander
parent 127e7ef31b
commit 9dfcfbc3ac
10 changed files with 29 additions and 27 deletions

View File

@ -50,7 +50,7 @@ namespace llarp
void
LookupIntroSetRecursive(
const Key_t& target, const Key_t& whoasked, uint64_t whoaskedTX,
const Key_t& askpeer, uint64_t recursionDepth, uint32_t relayOrder,
const Key_t& askpeer, uint64_t recursionDepth, uint64_t relayOrder,
service::EncryptedIntroSetLookupHandler result = nullptr) override;
void
@ -95,7 +95,7 @@ namespace llarp
LookupIntroSetForPath(const Key_t& addr, uint64_t txid,
const llarp::PathID_t& path, const Key_t& askpeer,
uint64_t recursionDepth,
uint32_t relayOrder) override;
uint64_t relayOrder) override;
/// send a dht message to peer, if keepalive is true then keep the session
/// with that peer alive for 10 seconds
@ -543,7 +543,7 @@ namespace llarp
Context::LookupIntroSetForPath(const Key_t& addr, uint64_t txid,
const llarp::PathID_t& path,
const Key_t& askpeer,
uint64_t recursionDepth, uint32_t relayOrder)
uint64_t recursionDepth, uint64_t relayOrder)
{
TXOwner asker(OurKey(), txid);
TXOwner peer(askpeer, ++ids);
@ -571,7 +571,7 @@ namespace llarp
void
Context::LookupIntroSetRecursive(
const Key_t& addr, const Key_t& whoasked, uint64_t txid,
const Key_t& askpeer, uint64_t recursionDepth, uint32_t relayOrder,
const Key_t& askpeer, uint64_t recursionDepth, uint64_t relayOrder,
service::EncryptedIntroSetLookupHandler handler)
{
TXOwner asker(whoasked, txid);

View File

@ -47,7 +47,7 @@ namespace llarp
virtual void
LookupIntroSetRecursive(
const Key_t& target, const Key_t& whoasked, uint64_t whoaskedTX,
const Key_t& askpeer, uint64_t recursionDepth, uint32_t relayOrder,
const Key_t& askpeer, uint64_t recursionDepth, uint64_t relayOrder,
service::EncryptedIntroSetLookupHandler result =
service::EncryptedIntroSetLookupHandler()) = 0;
@ -69,7 +69,7 @@ namespace llarp
virtual void
LookupIntroSetForPath(const Key_t& addr, uint64_t txid,
const PathID_t& path, const Key_t& askpeer,
uint64_t recursionDepth, uint32_t relayOrder) = 0;
uint64_t recursionDepth, uint64_t relayOrder) = 0;
virtual void
DHTSendTo(const RouterID& peer, IMessage* msg, bool keepalive = true) = 0;

View File

@ -12,7 +12,7 @@ namespace llarp
namespace dht
{
LocalServiceAddressLookup::LocalServiceAddressLookup(
const PathID_t &pathid, uint64_t txid, uint32_t relayOrder,
const PathID_t &pathid, uint64_t txid, uint64_t relayOrder,
const Key_t &addr, AbstractContext *ctx,
__attribute__((unused)) const Key_t &askpeer)
: ServiceAddressLookup(TXOwner{ctx->OurKey(), txid}, addr, ctx, 2,

View File

@ -14,7 +14,7 @@ namespace llarp
PathID_t localPath;
LocalServiceAddressLookup(const PathID_t &pathid, uint64_t txid,
uint32_t relayOrder, const Key_t &addr,
uint64_t relayOrder, const Key_t &addr,
AbstractContext *ctx,
__attribute__((unused)) const Key_t &askpeer);

View File

@ -18,15 +18,12 @@ namespace llarp
{
bool read = false;
uint64_t tmp;
if(!BEncodeMaybeReadDictInt("O", tmp, read, k, val))
return false;
if(read)
relayOrder = tmp;
if(!BEncodeMaybeReadDictEntry("N", tagName, read, k, val))
return false;
if(!BEncodeMaybeReadDictInt("O", relayOrder, read, k, val))
return false;
if(!BEncodeMaybeReadDictInt("R", recursionDepth, read, k, val))
return false;
@ -49,15 +46,15 @@ namespace llarp
if(!bencode_start_dict(buf))
return false;
// relay order
if(!BEncodeWriteDictInt("O", relayOrder, buf))
return false;
// message id
if(!BEncodeWriteDictMsgType(buf, "A", "F"))
return false;
if(tagName.Empty())
{
// relay order
if(!BEncodeWriteDictInt("O", relayOrder, buf))
return false;
// recursion
if(!BEncodeWriteDictInt("R", recursionDepth, buf))
return false;
@ -69,6 +66,11 @@ namespace llarp
{
if(!BEncodeWriteDictEntry("N", tagName, buf))
return false;
// relay order
if(!BEncodeWriteDictInt("O", relayOrder, buf))
return false;
// recursion
if(!BEncodeWriteDictInt("R", recursionDepth, buf))
return false;

View File

@ -18,9 +18,9 @@ namespace llarp
llarp::service::Tag tagName;
uint64_t txID = 0;
bool relayed = false;
uint32_t relayOrder = 0;
uint64_t relayOrder = 0;
FindIntroMessage(const Key_t& from, bool relay, uint32_t order)
FindIntroMessage(const Key_t& from, bool relay, uint64_t order)
: IMessage(from)
{
relayed = relay;
@ -38,7 +38,7 @@ namespace llarp
}
explicit FindIntroMessage(uint64_t txid, const Key_t& addr,
uint64_t maxRecursionDepth, uint32_t order)
uint64_t maxRecursionDepth, uint64_t order)
: IMessage({})
, recursionDepth(maxRecursionDepth)
, location(addr)

View File

@ -10,7 +10,7 @@ namespace llarp
{
HiddenServiceAddressLookup::HiddenServiceAddressLookup(
Endpoint* p, HandlerFunc h, const dht::Key_t& l, const PubKey& k,
uint32_t order, uint64_t tx)
uint64_t order, uint64_t tx)
: IServiceLookup(p, tx, "HSLookup")
, rootkey(k)
, relayOrder(order)

View File

@ -13,7 +13,7 @@ namespace llarp
struct HiddenServiceAddressLookup : public IServiceLookup
{
const PubKey rootkey;
uint32_t relayOrder;
uint64_t relayOrder;
const dht::Key_t location;
using HandlerFunc = std::function< bool(
const Address&, absl::optional< const IntroSet >, const RouterID&) >;
@ -21,7 +21,7 @@ namespace llarp
HiddenServiceAddressLookup(Endpoint* p, HandlerFunc h,
const dht::Key_t& location,
const PubKey& rootkey, uint32_t relayOrder,
const PubKey& rootkey, uint64_t relayOrder,
uint64_t tx);
~HiddenServiceAddressLookup() override = default;

View File

@ -229,7 +229,7 @@ namespace llarp
const auto addr = currentIntroSet.A.Addr();
const auto paths = GetManyPathsWithUniqueEndpoints(this, 2);
uint32_t relayOrder = 0;
uint64_t relayOrder = 0;
for(const auto& path : paths)
{
HiddenServiceAddressLookup* job = new HiddenServiceAddressLookup(

View File

@ -21,7 +21,7 @@ namespace llarp
MOCK_METHOD7(LookupIntroSetRecursive,
void(const dht::Key_t&, const dht::Key_t&, uint64_t,
const dht::Key_t&, uint64_t, uint32_t,
const dht::Key_t&, uint64_t, uint64_t,
service::EncryptedIntroSetLookupHandler));
MOCK_METHOD5(LookupIntroSetIterative,
@ -37,7 +37,7 @@ namespace llarp
MOCK_METHOD6(LookupIntroSetForPath,
void(const dht::Key_t&, uint64_t, const PathID_t&,
const dht::Key_t&, uint64_t, uint32_t));
const dht::Key_t&, uint64_t, uint64_t));
MOCK_METHOD3(DHTSendTo, void(const RouterID&, dht::IMessage*, bool));