|
|
|
@ -222,39 +222,81 @@ namespace llarp
|
|
|
|
|
std::string service,
|
|
|
|
|
std::function<void(std::vector<dns::SRVData>)> resultHandler)
|
|
|
|
|
{
|
|
|
|
|
auto fail = [resultHandler]() { resultHandler({}); };
|
|
|
|
|
|
|
|
|
|
auto lookupByAddress = [service, fail, resultHandler](auto address) {
|
|
|
|
|
// TODO: remove me after implementing the rest
|
|
|
|
|
fail();
|
|
|
|
|
if (auto* ptr = std::get_if<RouterID>(&address))
|
|
|
|
|
{}
|
|
|
|
|
else if (auto* ptr = std::get_if<Address>(&address))
|
|
|
|
|
{}
|
|
|
|
|
// handles when we aligned to a loki address
|
|
|
|
|
auto handleGotPathToService = [resultHandler, service, this](auto addr) {
|
|
|
|
|
// we can probably get this info before we have a path to them but we do this after we
|
|
|
|
|
// have a path so when we send the response back they can send shit to them immediately
|
|
|
|
|
const auto& container = m_state->m_RemoteSessions;
|
|
|
|
|
if (auto itr = container.find(addr); itr != container.end())
|
|
|
|
|
{
|
|
|
|
|
// parse the stuff we need from this guy
|
|
|
|
|
resultHandler(itr->second->GetCurrentIntroSet().GetMatchingSRVRecords(service));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
resultHandler({});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// handles when we resolved a .snode
|
|
|
|
|
auto handleResolvedSNodeName = [resultHandler, nodedb = Router()->nodedb()](auto router_id) {
|
|
|
|
|
std::vector<dns::SRVData> result{};
|
|
|
|
|
if (auto maybe_rc = nodedb->Get(router_id))
|
|
|
|
|
{
|
|
|
|
|
result = maybe_rc->srvRecords;
|
|
|
|
|
}
|
|
|
|
|
resultHandler(std::move(result));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// handles when we got a path to a remote thing
|
|
|
|
|
auto handleGotPathTo = [handleGotPathToService, handleResolvedSNodeName, resultHandler](
|
|
|
|
|
auto maybe_tag, auto address) {
|
|
|
|
|
if (not maybe_tag)
|
|
|
|
|
{
|
|
|
|
|
resultHandler({});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (auto* addr = std::get_if<Address>(&address))
|
|
|
|
|
{
|
|
|
|
|
// .loki case
|
|
|
|
|
handleGotPathToService(*addr);
|
|
|
|
|
}
|
|
|
|
|
else if (auto* router_id = std::get_if<RouterID>(&address))
|
|
|
|
|
{
|
|
|
|
|
// .snode case
|
|
|
|
|
handleResolvedSNodeName(*router_id);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fail();
|
|
|
|
|
// fallback case
|
|
|
|
|
// XXX: never should happen but we'll handle it anyways
|
|
|
|
|
resultHandler({});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
if (auto maybe = ParseAddress(name))
|
|
|
|
|
{
|
|
|
|
|
lookupByAddress(*maybe);
|
|
|
|
|
}
|
|
|
|
|
else if (NameIsValid(name))
|
|
|
|
|
{
|
|
|
|
|
LookupNameAsync(name, [lookupByAddress, fail](auto maybe) {
|
|
|
|
|
if (maybe)
|
|
|
|
|
{
|
|
|
|
|
lookupByAddress(*maybe);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fail();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
fail();
|
|
|
|
|
|
|
|
|
|
// handles when we know a long address of a remote resource
|
|
|
|
|
auto handleGotAddress = [resultHandler, handleGotPathTo, this](auto address) {
|
|
|
|
|
// we will attempt a build to whatever we looked up
|
|
|
|
|
const auto result = EnsurePathTo(
|
|
|
|
|
address,
|
|
|
|
|
[address, handleGotPathTo](auto maybe_tag) { handleGotPathTo(maybe_tag, address); },
|
|
|
|
|
PathAlignmentTimeout());
|
|
|
|
|
|
|
|
|
|
// on path build start fail short circuit
|
|
|
|
|
if (not result)
|
|
|
|
|
resultHandler({});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// look up this name async and start the entire chain of events
|
|
|
|
|
LookupNameAsync(name, [handleGotAddress, resultHandler](auto maybe_addr) {
|
|
|
|
|
if (maybe_addr)
|
|
|
|
|
{
|
|
|
|
|
handleGotAddress(*maybe_addr);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
resultHandler({});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
@ -912,7 +954,7 @@ namespace llarp
|
|
|
|
|
{
|
|
|
|
|
if (not NameIsValid(name))
|
|
|
|
|
{
|
|
|
|
|
handler(std::nullopt);
|
|
|
|
|
handler(ParseAddress(name));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
auto& cache = m_state->nameCache;
|
|
|
|
|