Move remaining messages around

pull/650/head
Michael 5 years ago
parent 66cf5cc73d
commit 2291d48bcc
No known key found for this signature in database
GPG Key ID: 2D51757B47E2434C

@ -165,7 +165,6 @@ set(LIB_SRC
exit/endpoint.cpp
exit/policy.cpp
exit/session.cpp
exit/transfer_traffic.cpp
handlers/exit.cpp
handlers/null.cpp
handlers/tun.cpp
@ -180,6 +179,7 @@ set(LIB_SRC
messages/discard.cpp
messages/exit.cpp
messages/link_intro.cpp
messages/link_message_parser.cpp
messages/link_message.cpp
messages/path_confirm.cpp
messages/path_latency.cpp
@ -205,13 +205,9 @@ set(LIB_SRC
router/router.cpp
router_contact.cpp
router_id.cpp
routing/dht_message.cpp
routing/handler.cpp
routing/message_parser.cpp
routing/message.cpp
routing/path_confirm.cpp
routing/path_latency.cpp
routing/path_transfer.cpp
rpc/rpc.cpp
service/address.cpp
service/async_key_exchange.cpp

@ -1,65 +0,0 @@
#include <messages/transfer_traffic.hpp>
#include <routing/handler.hpp>
#include <util/bencode.hpp>
#include <util/endian.hpp>
namespace llarp
{
namespace routing
{
bool
TransferTrafficMessage::PutBuffer(const llarp_buffer_t& buf,
uint64_t counter)
{
if(buf.sz > MaxExitMTU)
return false;
X.emplace_back(buf.sz + 8);
byte_t* ptr = X.back().data();
htobe64buf(ptr, counter);
ptr += 8;
memcpy(ptr, buf.base, buf.sz);
// 8 bytes encoding overhead and 8 bytes counter
_size += buf.sz + 16;
return true;
}
bool
TransferTrafficMessage::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "A", "I"))
return false;
if(!BEncodeWriteDictInt("S", S, buf))
return false;
if(!BEncodeWriteDictInt("V", version, buf))
return false;
if(!BEncodeWriteDictList("X", X, buf))
return false;
return bencode_end(buf);
}
bool
TransferTrafficMessage::DecodeKey(const llarp_buffer_t& key,
llarp_buffer_t* buf)
{
bool read = false;
if(!BEncodeMaybeReadDictInt("S", S, read, key, buf))
return false;
if(!BEncodeMaybeReadDictInt("V", version, read, key, buf))
return false;
if(!BEncodeMaybeReadDictList("X", X, read, key, buf))
return false;
return read;
}
bool
TransferTrafficMessage::HandleMessage(IMessageHandler* h,
AbstractRouter* r) const
{
return h->HandleTransferTrafficMessage(*this, r);
}
} // namespace routing
} // namespace llarp

@ -1 +1,63 @@
#include <messages/dht.hpp>
#include <router/abstractrouter.hpp>
#include <routing/handler.hpp>
namespace llarp
{
namespace routing
{
bool
DHTMessage::DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val)
{
llarp::dht::Key_t from;
from.Zero();
if(key == "M")
{
return llarp::dht::DecodeMesssageList(from, val, M, true);
}
else if(key == "S")
{
return bencode_read_integer(val, &S);
}
else if(key == "V")
{
return bencode_read_integer(val, &V);
}
return false;
}
bool
DHTMessage::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "A", "M"))
return false;
if(!BEncodeWriteDictBEncodeList("M", M, buf))
return false;
if(!BEncodeWriteDictInt("S", S, buf))
return false;
if(!BEncodeWriteDictInt("V", LLARP_PROTO_VERSION, buf))
return false;
return bencode_end(buf);
}
bool
DHTMessage::HandleMessage(IMessageHandler* h, AbstractRouter* r) const
{
// set source as us
llarp::dht::Key_t us{r->pubkey()};
for(const auto& msg : M)
{
msg->From = us;
msg->pathID = from;
if(!h->HandleDHTMessage(*msg, r))
return false;
}
return true;
}
} // namespace routing
} // namespace llarp

@ -15,7 +15,7 @@ namespace llarp
std::vector< llarp::dht::IMessage::Ptr_t > M;
uint64_t V = 0;
~DHTMessage();
~DHTMessage() = default;
bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) override;

@ -4,10 +4,6 @@
namespace llarp
{
DHTImmediateMessage::~DHTImmediateMessage()
{
}
void
DHTImmediateMessage::Clear()
{

@ -8,13 +8,13 @@
namespace llarp
{
struct DHTImmediateMessage : public ILinkMessage
struct DHTImmediateMessage final : public ILinkMessage
{
DHTImmediateMessage() : ILinkMessage()
{
}
~DHTImmediateMessage();
~DHTImmediateMessage() = default;
std::vector< std::unique_ptr< dht::IMessage > > msgs;

@ -57,9 +57,7 @@ namespace llarp
{
PathID_t P;
DataDiscardMessage() : IMessage()
{
}
DataDiscardMessage() = default;
DataDiscardMessage(const PathID_t& dst, uint64_t s) : P(dst)
{

@ -1,148 +1 @@
#include <messages/link_message_parser.hpp>
#include <messages/dht_immediate.hpp>
#include <messages/discard.hpp>
#include <messages/link_intro.hpp>
#include <messages/link_message.hpp>
#include <messages/relay_commit.hpp>
#include <messages/relay.hpp>
#include <router_contact.hpp>
#include <util/buffer.hpp>
#include <util/logger.hpp>
#include <util/metrics.hpp>
#include <memory>
namespace llarp
{
struct InboundMessageParser::msg_holder_t
{
LinkIntroMessage i;
RelayDownstreamMessage d;
RelayUpstreamMessage u;
DHTImmediateMessage m;
LR_CommitMessage c;
DiscardMessage x;
msg_holder_t() = default;
};
InboundMessageParser::InboundMessageParser(AbstractRouter* _router)
: router(_router), from(nullptr), msg(nullptr), holder(new msg_holder_t())
{
}
InboundMessageParser::~InboundMessageParser()
{
delete holder;
}
bool
InboundMessageParser::operator()(llarp_buffer_t* buffer, llarp_buffer_t* key)
{
// we are reading the first key
if(firstkey)
{
llarp_buffer_t strbuf;
// check for empty dict
if(!key)
return false;
// we are expecting the first key to be 'a'
if(!(*key == "a"))
{
llarp::LogWarn("message has no message type");
return false;
}
if(!bencode_read_string(buffer, &strbuf))
{
llarp::LogWarn("could not read value of message type");
return false;
}
// bad key size
if(strbuf.sz != 1)
{
llarp::LogWarn("bad mesage type size: ", strbuf.sz);
return false;
}
// create the message to parse based off message type
llarp::LogDebug("inbound message ", *strbuf.cur);
bool isLIM = false;
switch(*strbuf.cur)
{
case 'i':
msg = &holder->i;
isLIM = true;
break;
case 'd':
msg = &holder->d;
break;
case 'u':
msg = &holder->u;
break;
case 'm':
msg = &holder->m;
break;
case 'c':
msg = &holder->c;
break;
case 'x':
msg = &holder->x;
break;
default:
return false;
}
if(!isLIM)
{
metrics::integerTick(msg->Name(), "RX", 1, "id",
RouterID(from->GetPubKey()).ToString());
}
msg->session = from;
firstkey = false;
return true;
}
// check for last element
if(!key)
return MessageDone();
return msg->DecodeKey(*key, buffer);
}
bool
InboundMessageParser::MessageDone()
{
bool result = false;
if(msg)
{
result = msg->HandleMessage(router);
}
Reset();
return result;
}
bool
InboundMessageParser::ProcessFrom(ILinkSession* src,
const llarp_buffer_t& buf)
{
if(!src)
{
llarp::LogWarn("no link session");
return false;
}
from = src;
firstkey = true;
ManagedBuffer copy(buf);
return bencode_read_dict(*this, &copy.underlying);
}
void
InboundMessageParser::Reset()
{
if(msg)
msg->Clear();
msg = nullptr;
}
} // namespace llarp

@ -21,9 +21,7 @@ namespace llarp
ILinkMessage() = default;
virtual ~ILinkMessage()
{
}
virtual ~ILinkMessage() = default;
virtual bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) = 0;

@ -0,0 +1,148 @@
#include <messages/link_message_parser.hpp>
#include <messages/dht_immediate.hpp>
#include <messages/discard.hpp>
#include <messages/link_intro.hpp>
#include <messages/link_message.hpp>
#include <messages/relay_commit.hpp>
#include <messages/relay.hpp>
#include <router_contact.hpp>
#include <util/buffer.hpp>
#include <util/logger.hpp>
#include <util/metrics.hpp>
#include <memory>
namespace llarp
{
struct InboundMessageParser::msg_holder_t
{
LinkIntroMessage i;
RelayDownstreamMessage d;
RelayUpstreamMessage u;
DHTImmediateMessage m;
LR_CommitMessage c;
DiscardMessage x;
msg_holder_t() = default;
};
InboundMessageParser::InboundMessageParser(AbstractRouter* _router)
: router(_router), from(nullptr), msg(nullptr), holder(new msg_holder_t())
{
}
InboundMessageParser::~InboundMessageParser()
{
delete holder;
}
bool
InboundMessageParser::operator()(llarp_buffer_t* buffer, llarp_buffer_t* key)
{
// we are reading the first key
if(firstkey)
{
llarp_buffer_t strbuf;
// check for empty dict
if(!key)
return false;
// we are expecting the first key to be 'a'
if(!(*key == "a"))
{
llarp::LogWarn("message has no message type");
return false;
}
if(!bencode_read_string(buffer, &strbuf))
{
llarp::LogWarn("could not read value of message type");
return false;
}
// bad key size
if(strbuf.sz != 1)
{
llarp::LogWarn("bad mesage type size: ", strbuf.sz);
return false;
}
// create the message to parse based off message type
llarp::LogDebug("inbound message ", *strbuf.cur);
bool isLIM = false;
switch(*strbuf.cur)
{
case 'i':
msg = &holder->i;
isLIM = true;
break;
case 'd':
msg = &holder->d;
break;
case 'u':
msg = &holder->u;
break;
case 'm':
msg = &holder->m;
break;
case 'c':
msg = &holder->c;
break;
case 'x':
msg = &holder->x;
break;
default:
return false;
}
if(!isLIM)
{
metrics::integerTick(msg->Name(), "RX", 1, "id",
RouterID(from->GetPubKey()).ToString());
}
msg->session = from;
firstkey = false;
return true;
}
// check for last element
if(!key)
return MessageDone();
return msg->DecodeKey(*key, buffer);
}
bool
InboundMessageParser::MessageDone()
{
bool result = false;
if(msg)
{
result = msg->HandleMessage(router);
}
Reset();
return result;
}
bool
InboundMessageParser::ProcessFrom(ILinkSession* src,
const llarp_buffer_t& buf)
{
if(!src)
{
llarp::LogWarn("no link session");
return false;
}
from = src;
firstkey = true;
ManagedBuffer copy(buf);
return bencode_read_dict(*this, &copy.underlying);
}
void
InboundMessageParser::Reset()
{
if(msg)
msg->Clear();
msg = nullptr;
}
} // namespace llarp

@ -1 +1,58 @@
#include <messages/path_confirm.hpp>
#include <routing/handler.hpp>
#include <util/bencode.hpp>
#include <util/time.hpp>
namespace llarp
{
namespace routing
{
PathConfirmMessage::PathConfirmMessage(uint64_t lifetime)
: pathLifetime(lifetime), pathCreated(time_now_ms())
{
}
bool
PathConfirmMessage::DecodeKey(const llarp_buffer_t& key,
llarp_buffer_t* val)
{
bool read = false;
if(!BEncodeMaybeReadDictInt("L", pathLifetime, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("S", S, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("T", pathCreated, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("V", version, read, key, val))
return false;
return read;
}
bool
PathConfirmMessage::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "A", "P"))
return false;
if(!BEncodeWriteDictInt("L", pathLifetime, buf))
return false;
if(!BEncodeWriteDictInt("S", S, buf))
return false;
if(!BEncodeWriteDictInt("T", pathCreated, buf))
return false;
if(!BEncodeWriteDictInt("V", version, buf))
return false;
return bencode_end(buf);
}
bool
PathConfirmMessage::HandleMessage(IMessageHandler* h,
AbstractRouter* r) const
{
return h && h->HandlePathConfirmMessage(*this, r);
}
} // namespace routing
} // namespace llarp

@ -9,13 +9,12 @@ namespace llarp
{
struct PathConfirmMessage final : public IMessage
{
uint64_t pathLifetime;
uint64_t pathCreated;
PathConfirmMessage();
uint64_t pathLifetime = 0;
uint64_t pathCreated = 0;
PathConfirmMessage() = default;
PathConfirmMessage(uint64_t lifetime);
~PathConfirmMessage()
{
}
~PathConfirmMessage() = default;
bool
BEncode(llarp_buffer_t* buf) const override;

@ -1 +1,58 @@
#include <messages/path_latency.hpp>
#include <routing/handler.hpp>
#include <util/bencode.hpp>
namespace llarp
{
namespace routing
{
PathLatencyMessage::PathLatencyMessage()
{
}
bool
PathLatencyMessage::DecodeKey(const llarp_buffer_t& key,
llarp_buffer_t* val)
{
bool read = false;
if(!BEncodeMaybeReadDictInt("L", L, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("S", S, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("T", T, read, key, val))
return false;
return read;
}
bool
PathLatencyMessage::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "A", "L"))
return false;
if(L)
{
if(!BEncodeWriteDictInt("L", L, buf))
return false;
}
if(T)
{
if(!BEncodeWriteDictInt("T", T, buf))
return false;
}
if(!BEncodeWriteDictInt("S", S, buf))
return false;
return bencode_end(buf);
}
bool
PathLatencyMessage::HandleMessage(IMessageHandler* h,
AbstractRouter* r) const
{
return h && h->HandlePathLatencyMessage(*this, r);
}
} // namespace routing
} // namespace llarp

@ -1 +1,60 @@
#include <messages/path_transfer.hpp>
#include <routing/handler.hpp>
#include <util/buffer.hpp>
namespace llarp
{
namespace routing
{
bool
PathTransferMessage::DecodeKey(const llarp_buffer_t& key,
llarp_buffer_t* val)
{
bool read = false;
if(!BEncodeMaybeReadDictEntry("P", P, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("S", S, read, key, val))
return false;
if(!BEncodeMaybeReadDictEntry("T", T, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("V", version, read, key, val))
return false;
if(!BEncodeMaybeReadDictEntry("Y", Y, read, key, val))
return false;
return read;
}
bool
PathTransferMessage::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "A", "T"))
return false;
if(!BEncodeWriteDictEntry("P", P, buf))
return false;
if(!BEncodeWriteDictInt("S", S, buf))
return false;
if(!BEncodeWriteDictEntry("T", T, buf))
return false;
if(!BEncodeWriteDictInt("V", LLARP_PROTO_VERSION, buf))
return false;
if(!BEncodeWriteDictEntry("Y", Y, buf))
return false;
return bencode_end(buf);
}
bool
PathTransferMessage::HandleMessage(IMessageHandler* h,
AbstractRouter* r) const
{
return h->HandlePathTransferMessage(*this, r);
}
} // namespace routing
} // namespace llarp

@ -16,13 +16,13 @@ namespace llarp
service::ProtocolFrame T;
TunnelNonce Y;
PathTransferMessage();
PathTransferMessage() = default;
PathTransferMessage(const service::ProtocolFrame& f, const PathID_t& p)
: P(p), T(f)
{
Y.Randomize();
}
~PathTransferMessage();
~PathTransferMessage() = default;
bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) override;

@ -40,6 +40,12 @@ namespace llarp
PathID_t pathid;
Encrypted< MAX_LINK_MSG_SIZE - 128 > X;
TunnelNonce Y;
<<<<<<< HEAD
=======
RelayDownstreamMessage() = default;
RelayDownstreamMessage(ILinkSession* from);
~RelayDownstreamMessage() = default;
>>>>>>> Move remaining messages around
bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override;

@ -16,10 +16,6 @@
namespace llarp
{
LR_CommitMessage::~LR_CommitMessage()
{
}
bool
LR_CommitMessage::DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf)
{
@ -38,14 +34,7 @@ namespace llarp
void
LR_CommitMessage::Clear()
{
frames[0].Clear();
frames[1].Clear();
frames[2].Clear();
frames[3].Clear();
frames[4].Clear();
frames[5].Clear();
frames[6].Clear();
frames[7].Clear();
std::for_each(frames.begin(), frames.end(), [](auto& f) { f.Clear(); });
}
bool

@ -54,11 +54,9 @@ namespace llarp
{
}
LR_CommitMessage() : ILinkMessage()
{
}
LR_CommitMessage() = default;
~LR_CommitMessage();
~LR_CommitMessage() = default;
void
Clear() override;

@ -1 +1,65 @@
#include <messages/transfer_traffic.hpp>
#include <routing/handler.hpp>
#include <util/bencode.hpp>
#include <util/endian.hpp>
namespace llarp
{
namespace routing
{
bool
TransferTrafficMessage::PutBuffer(const llarp_buffer_t& buf,
uint64_t counter)
{
if(buf.sz > MaxExitMTU)
return false;
X.emplace_back(buf.sz + 8);
byte_t* ptr = X.back().data();
htobe64buf(ptr, counter);
ptr += 8;
memcpy(ptr, buf.base, buf.sz);
// 8 bytes encoding overhead and 8 bytes counter
_size += buf.sz + 16;
return true;
}
bool
TransferTrafficMessage::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "A", "I"))
return false;
if(!BEncodeWriteDictInt("S", S, buf))
return false;
if(!BEncodeWriteDictInt("V", version, buf))
return false;
if(!BEncodeWriteDictList("X", X, buf))
return false;
return bencode_end(buf);
}
bool
TransferTrafficMessage::DecodeKey(const llarp_buffer_t& key,
llarp_buffer_t* buf)
{
bool read = false;
if(!BEncodeMaybeReadDictInt("S", S, read, key, buf))
return false;
if(!BEncodeMaybeReadDictInt("V", version, read, key, buf))
return false;
if(!BEncodeMaybeReadDictList("X", X, read, key, buf))
return false;
return read;
}
bool
TransferTrafficMessage::HandleMessage(IMessageHandler* h,
AbstractRouter* r) const
{
return h->HandleTransferTrafficMessage(*this, r);
}
} // namespace routing
} // namespace llarp

@ -1,68 +0,0 @@
#include <messages/dht.hpp>
#include <router/abstractrouter.hpp>
#include <routing/handler.hpp>
namespace llarp
{
namespace routing
{
DHTMessage::~DHTMessage()
{
}
bool
DHTMessage::DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val)
{
llarp::dht::Key_t from;
from.Zero();
if(key == "M")
{
return llarp::dht::DecodeMesssageList(from, val, M, true);
}
else if(key == "S")
{
return bencode_read_integer(val, &S);
}
else if(key == "V")
{
return bencode_read_integer(val, &V);
}
return false;
}
bool
DHTMessage::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "A", "M"))
return false;
if(!BEncodeWriteDictBEncodeList("M", M, buf))
return false;
if(!BEncodeWriteDictInt("S", S, buf))
return false;
if(!BEncodeWriteDictInt("V", LLARP_PROTO_VERSION, buf))
return false;
return bencode_end(buf);
}
bool
DHTMessage::HandleMessage(IMessageHandler* h, AbstractRouter* r) const
{
// set source as us
llarp::dht::Key_t us{r->pubkey()};
for(const auto& msg : M)
{
msg->From = us;
msg->pathID = from;
if(!h->HandleDHTMessage(*msg, r))
return false;
}
return true;
}
} // namespace routing
} // namespace llarp

@ -1,62 +0,0 @@
#include <messages/path_confirm.hpp>
#include <routing/handler.hpp>
#include <util/bencode.hpp>
#include <util/time.hpp>
namespace llarp
{
namespace routing
{
PathConfirmMessage::PathConfirmMessage() : pathLifetime(0), pathCreated(0)
{
}
PathConfirmMessage::PathConfirmMessage(uint64_t lifetime)
: pathLifetime(lifetime), pathCreated(time_now_ms())
{
}
bool
PathConfirmMessage::DecodeKey(const llarp_buffer_t& key,
llarp_buffer_t* val)
{
bool read = false;
if(!BEncodeMaybeReadDictInt("L", pathLifetime, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("S", S, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("T", pathCreated, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("V", version, read, key, val))
return false;
return read;
}
bool
PathConfirmMessage::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "A", "P"))
return false;
if(!BEncodeWriteDictInt("L", pathLifetime, buf))
return false;
if(!BEncodeWriteDictInt("S", S, buf))
return false;
if(!BEncodeWriteDictInt("T", pathCreated, buf))
return false;
if(!BEncodeWriteDictInt("V", version, buf))
return false;
return bencode_end(buf);
}
bool
PathConfirmMessage::HandleMessage(IMessageHandler* h,
AbstractRouter* r) const
{
return h && h->HandlePathConfirmMessage(*this, r);
}
} // namespace routing
} // namespace llarp

@ -1,57 +1 @@
#include <messages/path_latency.hpp>
#include <routing/handler.hpp>
#include <util/bencode.hpp>
namespace llarp
{
namespace routing
{
PathLatencyMessage::PathLatencyMessage()
{
}
bool
PathLatencyMessage::DecodeKey(const llarp_buffer_t& key,
llarp_buffer_t* val)
{
bool read = false;
if(!BEncodeMaybeReadDictInt("L", L, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("S", S, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("T", T, read, key, val))
return false;
return read;
}
bool
PathLatencyMessage::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "A", "L"))
return false;
if(L)
{
if(!BEncodeWriteDictInt("L", L, buf))
return false;
}
if(T)
{
if(!BEncodeWriteDictInt("T", T, buf))
return false;
}
if(!BEncodeWriteDictInt("S", S, buf))
return false;
return bencode_end(buf);
}
bool
PathLatencyMessage::HandleMessage(IMessageHandler* h,
AbstractRouter* r) const
{
return h && h->HandlePathLatencyMessage(*this, r);
}
} // namespace routing
} // namespace llarp

@ -1,68 +0,0 @@
#include <messages/path_transfer.hpp>
#include <routing/handler.hpp>
#include <util/buffer.hpp>
namespace llarp
{
namespace routing
{
PathTransferMessage::PathTransferMessage() : IMessage()
{
}
PathTransferMessage::~PathTransferMessage()
{
}
bool
PathTransferMessage::DecodeKey(const llarp_buffer_t& key,
llarp_buffer_t* val)
{
bool read = false;
if(!BEncodeMaybeReadDictEntry("P", P, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("S", S, read, key, val))
return false;
if(!BEncodeMaybeReadDictEntry("T", T, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("V", version, read, key, val))
return false;
if(!BEncodeMaybeReadDictEntry("Y", Y, read, key, val))
return false;
return read;
}
bool
PathTransferMessage::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "A", "T"))
return false;
if(!BEncodeWriteDictEntry("P", P, buf))
return false;
if(!BEncodeWriteDictInt("S", S, buf))
return false;
if(!BEncodeWriteDictEntry("T", T, buf))
return false;
if(!BEncodeWriteDictInt("V", LLARP_PROTO_VERSION, buf))
return false;
if(!BEncodeWriteDictEntry("Y", Y, buf))
return false;
return bencode_end(buf);
}
bool
PathTransferMessage::HandleMessage(IMessageHandler* h,
AbstractRouter* r) const
{
return h->HandlePathTransferMessage(*this, r);
}
} // namespace routing
} // namespace llarp
Loading…
Cancel
Save