2018-12-12 01:06:46 +00:00
|
|
|
#include <exit/policy.hpp>
|
2018-11-12 16:43:40 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace exit
|
|
|
|
{
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
Policy::BEncode(llarp_buffer_t* buf) const
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!bencode_start_dict(buf))
|
2018-11-12 16:43:40 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("a", proto, buf))
|
2018-11-12 16:43:40 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("b", port, buf))
|
2018-11-12 16:43:40 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("d", drop, buf))
|
2018-11-12 16:43:40 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("v", version, buf))
|
2018-11-12 16:43:40 +00:00
|
|
|
return false;
|
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
Policy::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
|
|
|
bool read = false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("a", proto, read, k, buf))
|
2018-11-12 16:43:40 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("b", port, read, k, buf))
|
2018-11-12 16:43:40 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("d", drop, read, k, buf))
|
2018-11-12 16:43:40 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("v", version, read, k, buf))
|
2018-11-12 16:43:40 +00:00
|
|
|
return false;
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace exit
|
2018-12-12 01:06:46 +00:00
|
|
|
} // namespace llarp
|