mirror of https://github.com/oxen-io/lokinet
add dnslib unit test coverage
parent
1d1bde2e88
commit
40678f9019
@ -1,27 +1,50 @@
|
||||
#include <llarp/dns/question.hpp>
|
||||
#include <llarp/logger.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace dns
|
||||
{
|
||||
Question::Question(Question&& other)
|
||||
: qname(std::move(other.qname))
|
||||
, qtype(std::move(other.qtype))
|
||||
, qclass(std::move(other.qclass))
|
||||
{
|
||||
}
|
||||
Question::Question(const Question& other)
|
||||
: qname(other.qname), qtype(other.qtype), qclass(other.qclass)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
Question::Encode(llarp_buffer_t* buf) const
|
||||
{
|
||||
if(!EncodeName(buf, qname))
|
||||
return false;
|
||||
if(!EncodeInt(buf, qtype))
|
||||
if(!llarp_buffer_put_uint16(buf, qtype))
|
||||
return false;
|
||||
return EncodeInt(buf, qclass);
|
||||
return llarp_buffer_put_uint16(buf, qclass);
|
||||
}
|
||||
|
||||
bool
|
||||
Question::Decode(llarp_buffer_t* buf)
|
||||
{
|
||||
if(!DecodeName(buf, qname))
|
||||
{
|
||||
llarp::LogError("failed to decode name");
|
||||
return false;
|
||||
}
|
||||
if(!llarp_buffer_read_uint16(buf, &qtype))
|
||||
{
|
||||
llarp::LogError("failed to decode type");
|
||||
return false;
|
||||
if(!DecodeInt(buf, qtype))
|
||||
}
|
||||
if(!llarp_buffer_read_uint16(buf, &qclass))
|
||||
{
|
||||
llarp::LogError("failed to decode class");
|
||||
return false;
|
||||
return DecodeInt(buf, qclass);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace dns
|
||||
} // namespace llarp
|
||||
|
@ -1,35 +1,83 @@
|
||||
#include <llarp/dns/rr.hpp>
|
||||
#include <llarp/logger.hpp>
|
||||
|
||||
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))
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
ResourceRecord::Encode(llarp_buffer_t* buf) const
|
||||
{
|
||||
if(!EncodeName(buf, rr_name))
|
||||
{
|
||||
return false;
|
||||
if(!EncodeInt(buf, rr_type))
|
||||
}
|
||||
if(!llarp_buffer_put_uint16(buf, rr_type))
|
||||
{
|
||||
return false;
|
||||
if(!EncodeInt(buf, rr_class))
|
||||
}
|
||||
if(!llarp_buffer_put_uint16(buf, rr_class))
|
||||
{
|
||||
return false;
|
||||
if(!EncodeInt(buf, ttl))
|
||||
}
|
||||
if(!llarp_buffer_put_uint32(buf, ttl))
|
||||
{
|
||||
return false;
|
||||
return EncodeRData(buf, rData);
|
||||
}
|
||||
if(!EncodeRData(buf, rData))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
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");
|
||||
return false;
|
||||
if(!DecodeInt(buf, rr_type))
|
||||
}
|
||||
if(!llarp_buffer_read_uint16(buf, &rr_class))
|
||||
{
|
||||
llarp::LogError("failed to decode rr class");
|
||||
return false;
|
||||
if(!DecodeInt(buf, rr_class))
|
||||
}
|
||||
if(!llarp_buffer_read_uint32(buf, &ttl))
|
||||
{
|
||||
llarp::LogError("failed to decode ttl");
|
||||
return false;
|
||||
if(!DecodeInt(buf, ttl))
|
||||
}
|
||||
if(!DecodeRData(buf, rData))
|
||||
{
|
||||
llarp::LogError("failed to decode rr rdata");
|
||||
return false;
|
||||
return DecodeRData(buf, rData);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace dns
|
||||
} // namespace llarp
|
||||
|
Loading…
Reference in New Issue