Remove all use of IBEncodeMessage

pull/622/head
Michael 5 years ago
parent 82491305dd
commit 3f53965b71
No known key found for this signature in database
GPG Key ID: 2D51757B47E2434C

@ -14,7 +14,7 @@ namespace llarp
{
constexpr size_t MAX_MSG_SIZE = 2048;
struct IMessage : public IBEncodeMessage
struct IMessage
{
virtual ~IMessage()
{
@ -31,8 +31,15 @@ namespace llarp
HandleMessage(struct llarp_dht_context* dht,
std::vector< Ptr_t >& replies) const = 0;
virtual bool
BEncode(llarp_buffer_t* buf) const = 0;
virtual bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) = 0;
Key_t From;
PathID_t pathID;
uint64_t version = LLARP_PROTO_VERSION;
};
IMessage::Ptr_t

@ -4,10 +4,6 @@ namespace llarp
{
namespace exit
{
Policy::~Policy()
{
}
bool
Policy::BEncode(llarp_buffer_t *buf) const
{

@ -7,19 +7,24 @@ namespace llarp
{
namespace exit
{
struct Policy final : public llarp::IBEncodeMessage
struct Policy
{
~Policy();
uint64_t proto = 0;
uint64_t port = 0;
uint64_t drop = 0;
uint64_t version = LLARP_PROTO_VERSION;
uint64_t proto;
uint64_t port;
uint64_t drop;
bool
BDecode(llarp_buffer_t* buf)
{
return bencode_decode_dict(*this, buf);
}
bool
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* val) override;
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* val);
bool
BEncode(llarp_buffer_t* buf) const override;
BEncode(llarp_buffer_t* buf) const;
};
} // namespace exit
} // namespace llarp

@ -1,6 +1,7 @@
#include <messages/transfer_traffic.hpp>
#include <routing/handler.hpp>
#include <util/bencode.hpp>
#include <util/endian.hpp>
namespace llarp

@ -13,11 +13,11 @@ namespace llarp
struct AbstractRouter;
/// parsed link layer message
struct ILinkMessage : public IBEncodeMessage
struct ILinkMessage
{
/// who did this message come from or is going to
ILinkSession* session = nullptr;
uint64_t version = 0;
uint64_t version = LLARP_PROTO_VERSION;
ILinkMessage() = default;
@ -25,6 +25,18 @@ namespace llarp
{
}
virtual bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) = 0;
bool
BDecode(llarp_buffer_t* buf)
{
return bencode_decode_dict(*this, buf);
}
virtual bool
BEncode(llarp_buffer_t* buf) const = 0;
virtual bool
HandleMessage(AbstractRouter* router) const = 0;

@ -152,7 +152,7 @@ namespace llarp
}
work = std::make_unique< PoW >();
return work->BDecode(buffer);
return bencode_decode_dict(*work, buffer);
}
return read;
}

@ -12,22 +12,6 @@
namespace llarp
{
AddressInfo::~AddressInfo()
{
}
AddressInfo &
AddressInfo::operator=(const AddressInfo &other)
{
rank = other.rank;
dialect = other.dialect;
pubkey = other.pubkey;
memcpy(ip.s6_addr, other.ip.s6_addr, 16);
port = other.port;
version = other.version;
return *this;
}
bool
operator==(const AddressInfo &lhs, const AddressInfo &rhs)
{

@ -19,38 +19,26 @@
/// address information model
namespace llarp
{
struct AddressInfo final : public IBEncodeMessage
struct AddressInfo
{
uint16_t rank;
std::string dialect;
llarp::PubKey pubkey;
struct in6_addr ip;
uint16_t port;
uint64_t version = LLARP_PROTO_VERSION;
AddressInfo() : IBEncodeMessage()
{
}
AddressInfo(const AddressInfo& other)
: IBEncodeMessage(other.version)
, rank(other.rank)
, dialect(other.dialect)
, pubkey(other.pubkey)
, port(other.port)
bool
BDecode(llarp_buffer_t* buf)
{
memcpy(ip.s6_addr, other.ip.s6_addr, 16);
return bencode_decode_dict(*this, buf);
}
~AddressInfo();
AddressInfo&
operator=(const AddressInfo& other);
bool
BEncode(llarp_buffer_t* buf) const override;
BEncode(llarp_buffer_t* buf) const;
bool
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf) override;
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf);
std::ostream&
print(std::ostream& stream, int level, int spaces) const;

@ -12,20 +12,6 @@
namespace llarp
{
ExitInfo::~ExitInfo()
{
}
ExitInfo&
ExitInfo::operator=(const ExitInfo& other)
{
memcpy(address.s6_addr, other.address.s6_addr, 16);
memcpy(netmask.s6_addr, other.netmask.s6_addr, 16);
pubkey = other.pubkey;
version = other.version;
return *this;
}
bool
ExitInfo::BEncode(llarp_buffer_t* buf) const
{

@ -16,14 +16,18 @@
/// Exit info model
namespace llarp
{
struct ExitInfo final : public IBEncodeMessage
struct ExitInfo
{
struct in6_addr address;
struct in6_addr netmask;
PubKey pubkey;
uint64_t version = LLARP_PROTO_VERSION;
ExitInfo(const PubKey &pk, const nuint32_t &ipv4_exit)
: IBEncodeMessage(), pubkey(pk)
ExitInfo()
{
}
ExitInfo(const PubKey &pk, const nuint32_t &ipv4_exit) : pubkey(pk)
{
memset(address.s6_addr, 0, 16);
address.s6_addr[11] = 0xff;
@ -32,27 +36,17 @@ namespace llarp
memset(netmask.s6_addr, 0xff, 16);
}
ExitInfo() : IBEncodeMessage()
{
}
bool
BEncode(llarp_buffer_t *buf) const;
ExitInfo(const ExitInfo &other)
: IBEncodeMessage(other.version), pubkey(other.pubkey)
bool
BDecode(llarp_buffer_t *buf)
{
memcpy(address.s6_addr, other.address.s6_addr, 16);
memcpy(netmask.s6_addr, other.netmask.s6_addr, 16);
return bencode_decode_dict(*this, buf);
}
~ExitInfo();
bool
BEncode(llarp_buffer_t *buf) const override;
bool
DecodeKey(const llarp_buffer_t &k, llarp_buffer_t *buf) override;
ExitInfo &
operator=(const ExitInfo &other);
DecodeKey(const llarp_buffer_t &k, llarp_buffer_t *buf);
std::ostream &
print(std::ostream &stream, int level, int spaces) const;

@ -3,17 +3,18 @@
#include <crypto/crypto.hpp>
#include <router_id.hpp>
#include <util/bencode.hpp>
#include <util/buffer.hpp>
namespace llarp
{
/// proof of work
struct PoW final : public IBEncodeMessage
struct PoW
{
static constexpr size_t MaxSize = 128;
uint64_t timestamp = 0;
uint32_t extendedLifetime = 0;
AlignedBuffer< 32 > nonce;
uint64_t version = LLARP_PROTO_VERSION;
~PoW();
@ -21,10 +22,10 @@ namespace llarp
IsValid(shorthash_func hashfunc, llarp_time_t now) const;
bool
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* val) override;
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* val);
bool
BEncode(llarp_buffer_t* buf) const override;
BEncode(llarp_buffer_t* buf) const;
bool
operator==(const PoW& other) const

@ -96,12 +96,7 @@ namespace llarp
return checkIsGood(pathFailCount, pathSuccessCount, chances);
}
Profiling::Profiling() : IBEncodeMessage()
{
m_DisableProfiling.store(false);
}
Profiling::~Profiling()
Profiling::Profiling() : m_DisableProfiling(false)
{
}
@ -267,7 +262,7 @@ namespace llarp
if(k.sz != 32)
return false;
RouterProfile profile;
if(!profile.BDecode(buf))
if(!bencode_decode_dict(profile, buf))
return false;
RouterID pk = k.base;
return m_Profiles.emplace(pk, profile).second;
@ -278,7 +273,7 @@ namespace llarp
{
lock_t lock(&m_ProfilesMutex);
m_Profiles.clear();
if(!BDecodeReadFile(fname, *this))
if(!BDecodeReadFromFile(fname, *this))
{
llarp::LogWarn("failed to load router profiles from ", fname);
return false;

@ -11,7 +11,7 @@
namespace llarp
{
struct RouterProfile final : public IBEncodeMessage
struct RouterProfile
{
static constexpr size_t MaxSize = 256;
uint64_t connectTimeoutCount = 0;
@ -20,18 +20,13 @@ namespace llarp
uint64_t pathFailCount = 0;
llarp_time_t lastUpdated = 0;
llarp_time_t lastDecay = 0;
RouterProfile() : IBEncodeMessage()
{
}
~RouterProfile() = default;
uint64_t version = LLARP_PROTO_VERSION;
bool
BEncode(llarp_buffer_t* buf) const override;
BEncode(llarp_buffer_t* buf) const;
bool
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf) override;
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf);
bool
IsGood(uint64_t chances) const;
@ -51,17 +46,16 @@ namespace llarp
Tick();
};
struct Profiling final : public IBEncodeMessage
struct Profiling
{
Profiling();
~Profiling();
/// generic variant
bool
IsBad(const RouterID& r, uint64_t chances = 8)
LOCKS_EXCLUDED(m_ProfilesMutex);
/// check if this rotuer should have paths built over it
/// check if this router should have paths built over it
bool
IsBadForPath(const RouterID& r, uint64_t chances = 8)
LOCK_RETURNED(m_ProfilesMutex);
@ -90,11 +84,12 @@ namespace llarp
Tick() LOCKS_EXCLUDED(m_ProfilesMutex);
bool
BEncode(llarp_buffer_t* buf) const override LOCKS_EXCLUDED(m_ProfilesMutex);
BEncode(llarp_buffer_t* buf) const LOCKS_EXCLUDED(m_ProfilesMutex);
bool
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf) override
SHARED_LOCKS_REQUIRED(m_ProfilesMutex);
DecodeKey(const llarp_buffer_t& k,
llarp_buffer_t* buf) NO_THREAD_SAFETY_ANALYSIS;
// disabled because we do load -> bencode::BDecodeReadFromFile -> DecodeKey
bool
Load(const char* fname) LOCKS_EXCLUDED(m_ProfilesMutex);

@ -506,7 +506,7 @@ namespace llarp
LogDebug("verify RC signature");
if(!_rc.Verify(crypto(), Now()))
{
rc().Dump< MAX_RC_SIZE >();
Dump< MAX_RC_SIZE >(rc());
LogError("RC is invalid, not saving");
return false;
}

@ -65,31 +65,18 @@ namespace llarp
}
/// RouterContact
struct RouterContact final : public IBEncodeMessage
struct RouterContact
{
/// for unit tests
static bool IgnoreBogons;
static llarp_time_t Lifetime;
RouterContact() : IBEncodeMessage()
RouterContact()
{
Clear();
}
RouterContact(const RouterContact &other)
: IBEncodeMessage(other.version)
, addrs(other.addrs)
, netID(other.netID)
, enckey(other.enckey)
, pubkey(other.pubkey)
, exits(other.exits)
, signature(other.signature)
, nickname(other.nickname)
, last_updated(other.last_updated)
{
}
struct Hash
{
size_t
@ -115,12 +102,13 @@ namespace llarp
llarp::AlignedBuffer< NICKLEN > nickname;
uint64_t last_updated = 0;
uint64_t version = LLARP_PROTO_VERSION;
util::StatusObject
ExtractStatus() const;
bool
BEncode(llarp_buffer_t *buf) const override;
BEncode(llarp_buffer_t *buf) const;
bool
operator==(const RouterContact &other) const
@ -153,14 +141,14 @@ namespace llarp
}
bool
BDecode(llarp_buffer_t *buf) override
BDecode(llarp_buffer_t *buf)
{
Clear();
return IBEncodeMessage::BDecode(buf);
return bencode_decode_dict(*this, buf);
}
bool
DecodeKey(const llarp_buffer_t &k, llarp_buffer_t *buf) override;
DecodeKey(const llarp_buffer_t &k, llarp_buffer_t *buf);
RouterContact &
operator=(const RouterContact &other);

@ -1,8 +1,8 @@
#ifndef LLARP_ROUTING_MESSAGE_HPP
#define LLARP_ROUTING_MESSAGE_HPP
#include <constants/proto.hpp>
#include <path/path_types.hpp>
#include <util/bencode.hpp>
#include <util/buffer.hpp>
namespace llarp
@ -12,12 +12,13 @@ namespace llarp
{
struct IMessageHandler;
struct IMessage : public llarp::IBEncodeMessage
struct IMessage
{
PathID_t from;
uint64_t S;
uint64_t version = LLARP_PROTO_VERSION;
IMessage() : llarp::IBEncodeMessage(), S(0)
IMessage() : S(0)
{
}
@ -25,6 +26,12 @@ namespace llarp
{
}
virtual bool
BEncode(llarp_buffer_t* buf) const = 0;
virtual bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) = 0;
virtual bool
HandleMessage(IMessageHandler* h, AbstractRouter* r) const = 0;

@ -1,5 +1,6 @@
#include <messages/path_latency.hpp>
#include <routing/handler.hpp>
#include <util/bencode.hpp>
namespace llarp
{

@ -120,7 +120,7 @@ namespace llarp
return false;
// decode
inf.read((char*)buf.base, sz);
if(!BDecode(&buf))
if(!bencode_decode_dict(*this, &buf))
return false;
ServiceInfo::OptNonce van;

@ -1,11 +1,12 @@
#ifndef LLARP_SERVICE_IDENTITY_HPP
#define LLARP_SERVICE_IDENTITY_HPP
#include <constants/proto.hpp>
#include <crypto/types.hpp>
#include <service/info.hpp>
#include <service/intro_set.hpp>
#include <service/vanity.hpp>
#include <util/bencode.hpp>
#include <util/buffer.hpp>
#include <tuple>
@ -16,12 +17,12 @@ namespace llarp
namespace service
{
// private keys
struct Identity final : public IBEncodeMessage
struct Identity
{
SecretKey enckey;
SecretKey signkey;
PQKeyPair pq;
uint64_t version = 0;
uint64_t version = LLARP_PROTO_VERSION;
VanityNonce vanity;
// public service info
@ -32,7 +33,7 @@ namespace llarp
RegenerateKeys(Crypto* c);
bool
BEncode(llarp_buffer_t* buf) const override;
BEncode(llarp_buffer_t* buf) const;
bool
EnsureKeys(const std::string& fpath, Crypto* c);
@ -42,7 +43,7 @@ namespace llarp
const ServiceInfo& other, const KeyExchangeNonce& N) const;
bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override;
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf);
bool
SignIntroSet(IntroSet& i, Crypto* c, llarp_time_t now) const;

@ -14,7 +14,7 @@ namespace llarp
namespace service
{
struct ServiceInfo final : public IBEncodeMessage
struct ServiceInfo
{
private:
PubKey enckey;
@ -22,30 +22,11 @@ namespace llarp
public:
VanityNonce vanity;
Address m_CachedAddr;
uint64_t version = LLARP_PROTO_VERSION;
using OptNonce = absl::optional< VanityNonce >;
ServiceInfo() = default;
ServiceInfo(ServiceInfo&& other)
{
enckey = std::move(other.enckey);
signkey = std::move(other.signkey);
version = std::move(other.version);
vanity = std::move(other.vanity);
m_CachedAddr = std::move(other.m_CachedAddr);
}
ServiceInfo(const ServiceInfo& other)
: IBEncodeMessage(other.version)
, enckey(other.enckey)
, signkey(other.signkey)
, vanity(other.vanity)
, m_CachedAddr(other.m_CachedAddr)
{
version = other.version;
}
void
RandomizeVanity()
{
@ -126,21 +107,18 @@ namespace llarp
bool CalculateAddress(std::array< byte_t, 32 >& data) const;
bool
BDecode(llarp_buffer_t* buf) override
BDecode(llarp_buffer_t* buf)
{
if(IBEncodeMessage::BDecode(buf))
if(bencode_decode_dict(*this, buf))
return CalculateAddress(m_CachedAddr.as_array());
return false;
}
bool
BEncode(llarp_buffer_t* buf) const override;
BEncode(llarp_buffer_t* buf) const;
bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override;
private:
Address m_CachedAddr;
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf);
};
inline std::ostream&

@ -4,10 +4,6 @@ namespace llarp
{
namespace service
{
Introduction::~Introduction()
{
}
util::StatusObject
Introduction::ExtractStatus() const
{

@ -12,14 +12,13 @@ namespace llarp
{
namespace service
{
struct Introduction final : public IBEncodeMessage
struct Introduction
{
PubKey router;
PathID_t pathID;
uint64_t latency = 0;
uint64_t expiresAt = 0;
Introduction() = default;
uint64_t version = LLARP_PROTO_VERSION;
util::StatusObject
ExtractStatus() const;
@ -38,16 +37,20 @@ namespace llarp
return IsExpired(now);
}
~Introduction();
std::ostream&
print(std::ostream& stream, int level, int spaces) const;
bool
BEncode(llarp_buffer_t* buf) const override;
BEncode(llarp_buffer_t* buf) const;
bool
BDecode(llarp_buffer_t* buf)
{
return bencode_decode_dict(*this, buf);
}
bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override;
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf);
void
Clear();

@ -44,7 +44,7 @@ namespace llarp
if(key == "w")
{
W = absl::make_optional< PoW >();
return W->BDecode(buf);
return bencode_decode_dict(*W, buf);
}
if(!BEncodeMaybeReadDictInt("v", version, read, key, buf))

@ -25,7 +25,7 @@ namespace llarp
constexpr std::size_t MAX_INTROSET_SIZE = 4096;
// 10 seconds clock skew permitted for introset expiration
constexpr llarp_time_t MAX_INTROSET_TIME_DELTA = (10 * 1000);
struct IntroSet final : public IBEncodeMessage
struct IntroSet
{
ServiceInfo A;
std::vector< Introduction > I;
@ -34,6 +34,7 @@ namespace llarp
llarp_time_t T = 0;
absl::optional< PoW > W;
Signature Z;
uint64_t version = LLARP_PROTO_VERSION;
bool
OtherIsNewer(const IntroSet& other) const
@ -57,10 +58,16 @@ namespace llarp
IsExpired(llarp_time_t now) const;
bool
BEncode(llarp_buffer_t* buf) const override;
BEncode(llarp_buffer_t* buf) const;
bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override;
BDecode(llarp_buffer_t* buf)
{
return bencode_decode_dict(*this, buf);
}
bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf);
bool
Verify(Crypto* crypto, llarp_time_t now) const;

@ -179,7 +179,7 @@ namespace llarp
Encrypted_t tmp = D;
auto buf = tmp.Buffer();
crypto->xchacha20(*buf, sharedkey, N);
return msg.BDecode(buf);
return bencode_decode_dict(msg, buf);
}
bool
@ -287,7 +287,7 @@ namespace llarp
// decrypt
auto buf = frame.D.Buffer();
crypto->xchacha20(*buf, K, self->frame.N);
if(!self->msg->BDecode(buf))
if(!bencode_decode_dict(*self->msg, buf))
{
LogError("failed to decode inner protocol message");
DumpBuffer(*buf);
@ -300,8 +300,8 @@ namespace llarp
{
LogError("intro frame has invalid signature Z=", self->frame.Z,
" from ", self->msg->sender.Addr());
self->frame.Dump< MAX_PROTOCOL_MESSAGE_SIZE >();
self->msg->Dump< MAX_PROTOCOL_MESSAGE_SIZE >();
Dump< MAX_PROTOCOL_MESSAGE_SIZE >(self->frame);
Dump< MAX_PROTOCOL_MESSAGE_SIZE >(*self->msg);
self->msg.reset();
delete self;
return;
@ -326,7 +326,7 @@ namespace llarp
self->msg->sender, self->frame.N))
{
LogError("x25519 key exchange failed");
self->frame.Dump< MAX_PROTOCOL_MESSAGE_SIZE >();
Dump< MAX_PROTOCOL_MESSAGE_SIZE >(self->frame);
self->msg.reset();
delete self;
return;

@ -38,7 +38,7 @@ namespace llarp
constexpr ProtocolType eProtocolTraffic = 1UL;
/// inner message
struct ProtocolMessage final : public IBEncodeMessage
struct ProtocolMessage
{
ProtocolMessage(const ConvoTag& tag);
ProtocolMessage();
@ -52,13 +52,14 @@ namespace llarp
/// local path we got this message from
PathID_t srcPath;
ConvoTag tag;
uint64_t seqno = 0;
uint64_t seqno = 0;
uint64_t version = LLARP_PROTO_VERSION;
bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) override;
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val);
bool
BEncode(llarp_buffer_t* buf) const override;
BEncode(llarp_buffer_t* buf) const;
void
PutBuffer(const llarp_buffer_t& payload);
@ -141,6 +142,12 @@ namespace llarp
bool
BEncode(llarp_buffer_t* buf) const override;
bool
BDecode(llarp_buffer_t* buf)
{
return bencode_decode_dict(*this, buf);
}
void
Clear() override
{

@ -12,6 +12,10 @@
namespace llarp
{
template < typename List_t >
bool
BEncodeReadList(List_t& result, llarp_buffer_t* buf);
inline bool
BEncodeWriteDictMsgType(llarp_buffer_t* buf, const char* k, const char* t)
{
@ -185,6 +189,24 @@ namespace llarp
return sink(buffer, nullptr);
}
template < typename Sink >
bool
bencode_decode_dict(Sink&& sink, llarp_buffer_t* buff)
{
return bencode_read_dict(
[&](llarp_buffer_t* buffer, llarp_buffer_t* key) {
if(key == nullptr)
return true;
if(sink.DecodeKey(*key, buffer))
return true;
llarp::LogWarnTag("llarp/bencode.hpp", "undefined key '", *key->cur,
"' for entry in dict");
return false;
},
buff);
}
template < typename Sink >
bool
bencode_read_list(Sink&& sink, llarp_buffer_t* buffer)
@ -255,69 +277,50 @@ namespace llarp
&& BEncodeWriteList(list.begin(), list.end(), buf);
}
/// bencode serializable message
struct IBEncodeMessage
template < size_t bufsz, typename T >
void
Dump(const T& val)
{
virtual ~IBEncodeMessage()
{
}
IBEncodeMessage(uint64_t v = LLARP_PROTO_VERSION)
{
version = v;
}
virtual bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) = 0;
virtual bool
BEncode(llarp_buffer_t* buf) const = 0;
virtual bool
BDecode(llarp_buffer_t* buf)
{
return bencode_read_dict(*this, buf);
}
// TODO: check for shadowed values elsewhere
uint64_t version = 0;
bool
operator()(llarp_buffer_t* buffer, llarp_buffer_t* key)
{
return HandleKey(key, buffer);
}
bool
HandleKey(llarp_buffer_t* k, llarp_buffer_t* val)
std::array< byte_t, bufsz > tmp;
llarp_buffer_t buf(tmp);
if(val.BEncode(&buf))
{
if(k == nullptr)
return true;
if(DecodeKey(*k, val))
return true;
llarp::LogWarnTag("llarp/bencode.hpp", "undefined key '", *k->cur,
"' for entry in dict");
return false;
llarp::DumpBuffer< decltype(buf), 128 >(buf);
}
}
template < size_t bufsz, size_t align = 128 >
void
Dump() const
/// read entire file and decode its contents into t
template < typename T >
bool
BDecodeReadFile(const char* fpath, T& t)
{
std::vector< byte_t > ptr;
{
std::array< byte_t, bufsz > tmp;
llarp_buffer_t buf(tmp);
if(BEncode(&buf))
std::ifstream f;
f.open(fpath);
if(!f.is_open())
{
llarp::DumpBuffer< decltype(buf), align >(buf);
return false;
}
f.seekg(0, std::ios::end);
const std::streampos sz = f.tellg();
f.seekg(0, std::ios::beg);
ptr.resize(sz);
f.read((char*)ptr.data(), sz);
}
llarp_buffer_t buf(ptr);
auto result = t.BDecode(&buf);
if(!result)
{
DumpBuffer(buf);
}
};
return result;
}
/// read entire file and decode its contents into t
template < typename T >
bool
BDecodeReadFile(const char* fpath, T& t)
BDecodeReadFromFile(const char* fpath, T& t)
{
std::vector< byte_t > ptr;
{
@ -334,7 +337,7 @@ namespace llarp
f.read((char*)ptr.data(), sz);
}
llarp_buffer_t buf(ptr);
auto result = t.BDecode(&buf);
auto result = bencode_decode_dict(t, &buf);
if(!result)
{
DumpBuffer(buf);

Loading…
Cancel
Save