lokinet/llarp/dns/question.hpp
Jason Rhinelander b81f7025c9
Replace logging with oxen-logger
Replaces custom logging system with spdlog-based oxen logging.  This
commit mainly replaces the backend logging with the spdlog-based system,
but doesn't (yet) convert all the existing LogWarn, etc. to use the new
format-based logging.

New logging statements will look like:

    llarp::log::warning(cat, "blah: {}", val);

where `cat` should be set up in each .cpp or cluster of .cpp files, as
described in the oxen-logging README.

As part of spdlog we get fmt, which gives us nice format strings, where
are applied generously in this commit.

Making types printable now requires two steps:
- add a ToString() method
- add this specialization:

      template <>
      constexpr inline bool llarp::IsToStringFormattable<llarp::Whatever> = true;

This will then allow the type to be printed as a "{}" value in a
fmt::format string.  This is applied to all our printable types here,
and all of the `operator<<` are removed.

This commit also:
- replaces various uses of `operator<<` to ToString()
- replaces various uses of std::stringstream with either fmt::format or
  plain std::string
- Rename some to_string and toString() methods to ToString() for
  consistency (and to work with fmt)
- Replace `stringify(...)` and `make_exception` usage with fmt::format
  (and remove stringify/make_exception from util/str.hpp).
2022-07-15 22:17:59 -03:00

75 lines
1.6 KiB
C++

#pragma once
#include "serialize.hpp"
#include "name.hpp"
#include <llarp/net/net_int.hpp>
namespace llarp
{
namespace dns
{
using QType_t = uint16_t;
using QClass_t = uint16_t;
struct Question : public Serialize
{
Question() = default;
explicit Question(std::string name, QType_t type);
Question(Question&& other);
Question(const Question& other);
bool
Encode(llarp_buffer_t* buf) const override;
bool
Decode(llarp_buffer_t* buf) override;
std::string
ToString() const;
std::ostream&
print(std::ostream& stream, int level, int spaces) const;
bool
operator==(const Question& other) const
{
return qname == other.qname && qtype == other.qtype && qclass == other.qclass;
}
Name_t qname;
QType_t qtype;
QClass_t qclass;
/// determine if we match a name
bool
IsName(const std::string& other) const;
/// is the name [something.]localhost.loki. ?
bool
IsLocalhost() const;
/// return true if we have subdomains in ths question
bool
HasSubdomains() const;
/// get subdomain(s), if any, from qname
std::string
Subdomains() const;
/// return qname with no trailing .
std::string
Name() const;
/// determine if we are using this TLD
bool
HasTLD(const std::string& tld) const;
util::StatusObject
ToJSON() const override;
};
} // namespace dns
} // namespace llarp
template <>
constexpr inline bool llarp::IsToStringFormattable<llarp::dns::Question> = true;