---
title: llarp/layers/platform/dns_bridge.hpp

---

# llarp/layers/platform/dns_bridge.hpp



## Namespaces

| Name           |
| -------------- |
| **[llarp](Namespaces/namespacellarp.md)** <br>[crypto.hpp] |
| **[llarp::layers](Namespaces/namespacellarp_1_1layers.md)**  |
| **[llarp::layers::flow](Namespaces/namespacellarp_1_1layers_1_1flow.md)**  |
| **[llarp::layers::platform](Namespaces/namespacellarp_1_1layers_1_1platform.md)**  |

## Classes

|                | Name           |
| -------------- | -------------- |
| class | **[llarp::layers::platform::DNSZone](Classes/classllarp_1_1layers_1_1platform_1_1DNSZone.md)** <br>synthesizes authoritative RR for a .loki or .snode address.  |
| class | **[llarp::layers::platform::DNSQueryHandler](Classes/classllarp_1_1layers_1_1platform_1_1DNSQueryHandler.md)** <br>handles dns queries, for .loki / .snode  |




## Source code

```cpp
#pragma once

#include <cstdint>
#include <llarp/dns/server.hpp>
#include <memory>
#include <string_view>
#include <type_traits>
#include <unordered_map>
#include <vector>
#include <llarp/layers/flow/flow_addr.hpp>
#include <llarp/dns/question.hpp>
#include <llarp/dns/rr.hpp>

namespace llarp::layers::flow
{
  class FlowLayer;
}

namespace llarp::layers::platform
{

  class PlatformLayer;
  class AddrMapper;

  class DNSZone
  {
    flow::FlowAddr _flow_addr;

    std::vector<std::string> _ons_names;
    std::vector<dns::SRVData> _srv;
    const AddrMapper* _addr_mapper{nullptr};

   public:
    DNSZone() = default;

    DNSZone(const AddrMapper& mapper, flow::FlowAddr addr);

    std::vector<dns::RData>
    srv_records() const;

    std::vector<dns::RData>
    cname_records() const;

    uint32_t
    ttl(dns::RRType rr_type) const;

    std::string
    zone_name() const;

    constexpr const AddrMapper&
    addr_mapper() const
    {
      return *_addr_mapper;
    }

    void
    add_srv_record(dns::SRVTuple record);

    std::vector<dns::ResourceRecord>
    synth_rr_for(dns::RRType r_type) const;
  };

  class DNSQueryHandler : public dns::Resolver_Base
  {
    PlatformLayer& _plat;

    std::unordered_map<flow::FlowAddr, DNSZone> _zones;

    void
    async_obtain_dns_zone(
        const dns::Question& qestion, std::function<void(std::optional<DNSZone>)> result_handler);

   public:
    explicit DNSQueryHandler(PlatformLayer& parent);
    ~DNSQueryHandler() override = default;
    DNSQueryHandler(DNSQueryHandler&&) = delete;
    DNSQueryHandler(const DNSQueryHandler&) = delete;

    int
    Rank() const override;
    std::string_view
    ResolverName() const override;
    bool
    MaybeHookDNS(
        std::shared_ptr<dns::PacketSource_Base> source,
        const dns::Message& query,
        const SockAddr& to,
        const SockAddr& from) override;
  };
}  // namespace llarp::layers::platform
```


-------------------------------

Updated on 2023-04-27 at 04:17:17 +0000
