2018-06-01 14:08:54 +00:00
|
|
|
#include <llarp/bencode.h>
|
|
|
|
#include <llarp/router_contact.h>
|
|
|
|
#include <llarp/messages/link_intro.hpp>
|
|
|
|
#include "logger.hpp"
|
2018-07-03 13:13:56 +00:00
|
|
|
#include "router.hpp"
|
2018-06-01 14:08:54 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
LinkIntroMessage::~LinkIntroMessage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
LinkIntroMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf)
|
|
|
|
{
|
|
|
|
if(llarp_buffer_eq(key, "r"))
|
|
|
|
{
|
|
|
|
if(!llarp_rc_bdecode(RC, buf))
|
|
|
|
{
|
2018-06-01 17:47:37 +00:00
|
|
|
llarp::Warn("failed to decode RC");
|
2018-06-01 14:08:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-06-01 17:47:37 +00:00
|
|
|
remote = (byte_t*)RC->pubkey;
|
|
|
|
llarp::Debug("decoded RC from ", remote);
|
2018-06-01 14:08:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if(llarp_buffer_eq(key, "v"))
|
|
|
|
{
|
2018-06-01 17:47:37 +00:00
|
|
|
if(!bencode_read_integer(buf, &version))
|
2018-06-01 14:08:54 +00:00
|
|
|
return false;
|
|
|
|
if(version != LLARP_PROTO_VERSION)
|
|
|
|
{
|
2018-06-01 17:47:37 +00:00
|
|
|
llarp::Warn("llarp protocol version missmatch ", version,
|
2018-06-01 14:08:54 +00:00
|
|
|
" != ", LLARP_PROTO_VERSION);
|
|
|
|
return false;
|
|
|
|
}
|
2018-06-01 17:47:37 +00:00
|
|
|
llarp::Debug("LIM version ", version);
|
2018-06-01 14:08:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-01 17:47:37 +00:00
|
|
|
llarp::Warn("invalid LIM key: ", *key.cur);
|
2018-06-01 14:08:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
LinkIntroMessage::BEncode(llarp_buffer_t* buf) const
|
|
|
|
{
|
|
|
|
if(!bencode_start_dict(buf))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(!bencode_write_bytestring(buf, "a", 1))
|
|
|
|
return false;
|
|
|
|
if(!bencode_write_bytestring(buf, "i", 1))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(RC)
|
|
|
|
{
|
|
|
|
if(!bencode_write_bytestring(buf, "r", 1))
|
|
|
|
return false;
|
|
|
|
if(!llarp_rc_bencode(RC, buf))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!bencode_write_version_entry(buf))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
LinkIntroMessage::HandleMessage(llarp_router* router) const
|
|
|
|
{
|
2018-07-03 13:13:56 +00:00
|
|
|
router->async_verify_RC(RC, !llarp_rc_is_public_router(RC));
|
2018-06-01 14:08:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-07-03 13:13:56 +00:00
|
|
|
} // namespace llarp
|