You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lokinet/llarp/dns/rr.cpp

84 lines
1.9 KiB
C++

6 years ago
#include <llarp/dns/rr.hpp>
#include <llarp/logger.hpp>
6 years ago
namespace llarp
{
namespace dns
{
ResourceRecord::ResourceRecord(const ResourceRecord& other)
: rr_name(other.rr_name)
, rr_type(other.rr_type)
, rr_class(other.rr_class)
, ttl(other.ttl)
, rData(other.rData)
{
}
ResourceRecord::ResourceRecord(ResourceRecord&& other)
: rr_name(std::move(other.rr_name))
, rr_type(std::move(other.rr_type))
, rr_class(std::move(other.rr_class))
, ttl(std::move(other.ttl))
, rData(std::move(other.rData))
{
}
6 years ago
bool
ResourceRecord::Encode(llarp_buffer_t* buf) const
{
if(!EncodeName(buf, rr_name))
{
6 years ago
return false;
}
if(!llarp_buffer_put_uint16(buf, rr_type))
{
6 years ago
return false;
}
if(!llarp_buffer_put_uint16(buf, rr_class))
{
6 years ago
return false;
}
if(!llarp_buffer_put_uint32(buf, ttl))
{
6 years ago
return false;
}
if(!EncodeRData(buf, rData))
{
return false;
}
return true;
6 years ago
}
bool
ResourceRecord::Decode(llarp_buffer_t* buf)
{
if(!DecodeName(buf, rr_name))
{
llarp::LogError("failed to decode rr name");
return false;
}
if(!llarp_buffer_read_uint16(buf, &rr_type))
{
llarp::LogError("failed to decode rr type");
6 years ago
return false;
}
if(!llarp_buffer_read_uint16(buf, &rr_class))
{
llarp::LogError("failed to decode rr class");
6 years ago
return false;
}
if(!llarp_buffer_read_uint32(buf, &ttl))
{
llarp::LogError("failed to decode ttl");
6 years ago
return false;
}
if(!DecodeRData(buf, rData))
{
llarp::LogError("failed to decode rr rdata");
6 years ago
return false;
}
return true;
6 years ago
}
} // namespace dns
} // namespace llarp