1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/llarp/dns/name.hpp
Jason Rhinelander 9ea82edc07
DNS message parsing fixes and cleanup
Fixes:

- tighten reserved name detection to not match fooloki.loki, but instead
  only match "foo.loki.loki" and "loki.loki" (and similar for reserved
  name "snode.loki").
- IPv6 PTR parsing was completely broken.
- Added tests for the above two issues.

Cleanups:

- Eliminate llarp::dns::Name_t typedef for std::string
- Use optional return instead of bool + output param
- Use string_views; we were doing a *lot* of string substr's during
  parsing, each of which allocates a new string.
- Use fmt instead of stringstream
- Simplify IPv4 PTR parsing
2022-07-20 16:50:38 -03:00

29 lines
584 B
C++

#pragma once
#include <llarp/net/net_int.hpp>
#include <llarp/util/buffer.hpp>
#include <string>
#include <optional>
namespace llarp
{
namespace dns
{
/// decode name from buffer; return nullopt on failure
std::optional<std::string>
DecodeName(llarp_buffer_t* buf, bool trimTrailingDot = false);
/// encode name to buffer
bool
EncodeNameTo(llarp_buffer_t* buf, std::string_view name);
std::optional<huint128_t>
DecodePTR(std::string_view name);
bool
NameIsReserved(std::string_view name);
} // namespace dns
} // namespace llarp