|
|
|
@ -7,6 +7,7 @@ namespace llarp
|
|
|
|
|
{
|
|
|
|
|
namespace dht
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
struct IntroSetLookupInformer
|
|
|
|
|
{
|
|
|
|
|
llarp_router* router;
|
|
|
|
@ -17,6 +18,7 @@ namespace llarp
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
FindIntroMessage::~FindIntroMessage()
|
|
|
|
|
{
|
|
|
|
@ -27,15 +29,13 @@ namespace llarp
|
|
|
|
|
{
|
|
|
|
|
uint64_t i = 0;
|
|
|
|
|
bool read = false;
|
|
|
|
|
if(BEncodeMaybeReadDictInt("I", i, read, k, val))
|
|
|
|
|
if(!BEncodeMaybeReadDictInt("I", i, read, k, val))
|
|
|
|
|
return false;
|
|
|
|
|
if(read)
|
|
|
|
|
{
|
|
|
|
|
if(read)
|
|
|
|
|
{
|
|
|
|
|
iterative = i != 0;
|
|
|
|
|
}
|
|
|
|
|
iterative = i != 0;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if(!BEncodeMaybeReadDictEntry("N", N, read, k, val))
|
|
|
|
|
return false;
|
|
|
|
@ -101,32 +101,27 @@ namespace llarp
|
|
|
|
|
llarp_dht_context* ctx,
|
|
|
|
|
std::vector< llarp::dht::IMessage* >& replies) const
|
|
|
|
|
{
|
|
|
|
|
auto& dht = ctx->impl;
|
|
|
|
|
const auto introset = dht.GetIntroSetByServiceAddress(S);
|
|
|
|
|
if(introset)
|
|
|
|
|
{
|
|
|
|
|
replies.push_back(new GotIntroMessage({*introset}, T));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if(iterative)
|
|
|
|
|
{
|
|
|
|
|
// we are iterative and don't have it, reply with a direct reply
|
|
|
|
|
replies.push_back(new GotIntroMessage({}, T));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
auto& dht = ctx->impl;
|
|
|
|
|
Key_t peer;
|
|
|
|
|
std::set< Key_t > exclude = {dht.OurKey(), From};
|
|
|
|
|
if(N.IsZero())
|
|
|
|
|
{
|
|
|
|
|
// we are recursive
|
|
|
|
|
Key_t peer;
|
|
|
|
|
std::set< Key_t > exclude = {dht.OurKey(), From};
|
|
|
|
|
|
|
|
|
|
if(N.IsZero())
|
|
|
|
|
const auto introset = dht.GetIntroSetByServiceAddress(S);
|
|
|
|
|
if(introset)
|
|
|
|
|
{
|
|
|
|
|
replies.push_back(new GotIntroMessage({*introset}, T));
|
|
|
|
|
}
|
|
|
|
|
else if(iterative)
|
|
|
|
|
{
|
|
|
|
|
// we are iterative and don't have it, reply with a direct reply
|
|
|
|
|
replies.push_back(new GotIntroMessage({}, T));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// service address lookup
|
|
|
|
|
// we are recursive
|
|
|
|
|
if(dht.nodes->FindCloseExcluding(S, peer, exclude))
|
|
|
|
|
{
|
|
|
|
|
dht.LookupIntroSet(S, From, T, peer);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -134,52 +129,51 @@ namespace llarp
|
|
|
|
|
S);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// tag lookup
|
|
|
|
|
if(dht.nodes->FindCloseExcluding(N, peer, exclude))
|
|
|
|
|
{
|
|
|
|
|
dht.LookupTag(N, From, T, peer);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
} // namespace dht
|
|
|
|
|
|
|
|
|
|
RelayedFindIntroMessage::~RelayedFindIntroMessage()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
RelayedFindIntroMessage::HandleMessage(
|
|
|
|
|
llarp_dht_context* ctx,
|
|
|
|
|
std::vector< llarp::dht::IMessage* >& replies) const
|
|
|
|
|
{
|
|
|
|
|
auto& dht = ctx->impl;
|
|
|
|
|
const auto introset = dht.GetIntroSetByServiceAddress(S);
|
|
|
|
|
if(introset)
|
|
|
|
|
{
|
|
|
|
|
replies.push_back(new GotIntroMessage({*introset}, T));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Key_t peer;
|
|
|
|
|
std::set< Key_t > exclude = {dht.OurKey()};
|
|
|
|
|
if(dht.nodes->FindCloseExcluding(S, peer, exclude))
|
|
|
|
|
if(relayed)
|
|
|
|
|
{
|
|
|
|
|
dht.LookupIntroSet(S, From, 0, peer);
|
|
|
|
|
return true;
|
|
|
|
|
// tag lookup
|
|
|
|
|
if(dht.nodes->FindCloseExcluding(N.Key(), peer, exclude))
|
|
|
|
|
{
|
|
|
|
|
dht.LookupTagForPath(N, T, pathID, peer);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
llarp::LogWarn("no closer peers for tag ", N.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
llarp::LogError("cannot find closer peers for introset lookup for ",
|
|
|
|
|
S);
|
|
|
|
|
auto introsets = dht.FindIntroSetsWithTag(N);
|
|
|
|
|
if(introsets.size())
|
|
|
|
|
{
|
|
|
|
|
replies.push_back(new GotIntroMessage(introsets, T));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(iterative)
|
|
|
|
|
{
|
|
|
|
|
// we are iterative and don't have it, reply with a direct reply
|
|
|
|
|
replies.push_back(new GotIntroMessage({}, T));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// tag lookup
|
|
|
|
|
if(dht.nodes->FindCloseExcluding(N.Key(), peer, exclude))
|
|
|
|
|
{
|
|
|
|
|
dht.LookupTag(N, From, T, peer);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
llarp::LogWarn("no closer peers for tag ", N.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace dht
|
|
|
|
|
} // namespace llarp
|