mirror of https://github.com/oxen-io/lokinet
wire up dns srv records
This commit is contained in:
parent
74362149eb
commit
2d586145ee
|
@ -833,20 +833,29 @@ namespace llarp
|
|||
}
|
||||
else if (msg.questions[0].qtype == dns::qTypeSRV)
|
||||
{
|
||||
llarp::service::Address addr;
|
||||
|
||||
auto srv_for = msg.questions[0].Subdomains();
|
||||
auto name = msg.questions[0].qname;
|
||||
if (is_localhost_loki(msg))
|
||||
{
|
||||
msg.AddSRVReply(introSet().GetMatchingSRVRecords(msg.questions[0].Subdomains()));
|
||||
msg.AddSRVReply(introSet().GetMatchingSRVRecords(srv_for));
|
||||
reply(msg);
|
||||
return true;
|
||||
}
|
||||
else if (addr.FromString(qname, ".loki"))
|
||||
{
|
||||
llarp::LogDebug("SRV request for: ", qname);
|
||||
|
||||
return ReplyToLokiSRVWhenReady(addr, std::make_shared<dns::Message>(msg));
|
||||
}
|
||||
LookupServiceAsync(
|
||||
name,
|
||||
srv_for,
|
||||
[reply, msg = std::make_shared<dns::Message>(std::move(msg))](auto records) {
|
||||
if (records.empty())
|
||||
{
|
||||
msg->AddNXReply();
|
||||
}
|
||||
else
|
||||
{
|
||||
msg->AddSRVReply(records);
|
||||
}
|
||||
reply(*msg);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -222,39 +222,81 @@ namespace llarp
|
|||
std::string service,
|
||||
std::function<void(std::vector<dns::SRVData>)> resultHandler)
|
||||
{
|
||||
auto fail = [resultHandler]() { resultHandler({}); };
|
||||
// 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({});
|
||||
};
|
||||
|
||||
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 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;
|
||||
|
|
Loading…
Reference in New Issue