2018-06-08 13:12:17 +00:00
|
|
|
#include <llarp/messages/relay_ack.hpp>
|
|
|
|
|
2018-06-12 16:45:12 +00:00
|
|
|
#include "router.hpp"
|
|
|
|
|
|
|
|
namespace llarp
|
2018-06-08 13:12:17 +00:00
|
|
|
{
|
2018-06-12 16:45:12 +00:00
|
|
|
bool
|
|
|
|
LR_AckRecord::BEncode(llarp_buffer_t* buf) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
LR_AckRecord::BDecode(llarp_buffer_t* buf)
|
2018-06-08 13:12:17 +00:00
|
|
|
{
|
2018-06-12 16:45:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-06-08 13:12:17 +00:00
|
|
|
|
2018-06-12 16:45:12 +00:00
|
|
|
LR_AckMessage::LR_AckMessage(const RouterID& from) : ILinkMessage(from)
|
|
|
|
{
|
2018-06-08 13:12:17 +00:00
|
|
|
}
|
|
|
|
LR_AckMessage::~LR_AckMessage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-06-12 16:45:12 +00:00
|
|
|
bool
|
|
|
|
LR_AckMessage::BEncode(llarp_buffer_t* buf) const
|
2018-06-08 13:12:17 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-12 16:45:12 +00:00
|
|
|
bool
|
|
|
|
LR_AckMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf)
|
2018-06-08 13:12:17 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-12 16:45:12 +00:00
|
|
|
struct LRAM_Decrypt
|
2018-06-08 13:12:17 +00:00
|
|
|
{
|
2018-06-12 16:45:12 +00:00
|
|
|
typedef AsyncFrameDecrypter< LRAM_Decrypt > Decrypter;
|
|
|
|
|
|
|
|
llarp_router* router;
|
|
|
|
Decrypter* decrypt;
|
|
|
|
std::vector< EncryptedFrame > frames;
|
|
|
|
LR_AckRecord record;
|
|
|
|
|
|
|
|
LRAM_Decrypt(llarp_router* r, byte_t* seckey,
|
|
|
|
const std::vector< EncryptedFrame >& f)
|
|
|
|
: router(r), frames(f)
|
|
|
|
{
|
|
|
|
decrypt = new Decrypter(&r->crypto, seckey, &Decrypted);
|
|
|
|
}
|
|
|
|
|
|
|
|
~LRAM_Decrypt()
|
|
|
|
{
|
|
|
|
delete decrypt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Decrypted(llarp_buffer_t* buf, LRAM_Decrypt* self)
|
|
|
|
{
|
|
|
|
if(!buf)
|
|
|
|
{
|
|
|
|
llarp::Error("Failed to decrypt LRAM frame");
|
|
|
|
delete self;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(!self->record.BDecode(buf))
|
|
|
|
{
|
|
|
|
llarp::Error("LRAR invalid format");
|
|
|
|
delete self;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool
|
|
|
|
LR_AckMessage::HandleMessage(llarp_router* router) const
|
|
|
|
{
|
|
|
|
if(!router->paths.HasPendingRelayCommit(remote, txPathID))
|
|
|
|
{
|
|
|
|
llarp::Warn("got LRAM from ", remote,
|
|
|
|
" with no previous LRCM txid=", txPathID);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// TODO: use different private key for different path contexts as client
|
|
|
|
LRAM_Decrypt* lram = new LRAM_Decrypt(router, router->encryption, acks);
|
|
|
|
lram->decrypt->AsyncDecrypt(router->tp, &lram->frames[0], lram);
|
|
|
|
return true;
|
2018-06-08 13:12:17 +00:00
|
|
|
}
|
|
|
|
}
|