2018-07-09 03:08:41 +00:00
|
|
|
#include "encoder.hpp"
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
/// encode Link Introduce Message onto a buffer
|
|
|
|
/// if router is nullptr then the LIM's r member is omitted.
|
|
|
|
bool
|
2018-08-30 18:48:43 +00:00
|
|
|
EncodeLIM(llarp_buffer_t* buff, const llarp::RouterContact* router)
|
2018-07-09 03:08:41 +00:00
|
|
|
{
|
|
|
|
if(!bencode_start_dict(buff))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// message type
|
|
|
|
if(!bencode_write_bytestring(buff, "a", 1))
|
|
|
|
return false;
|
|
|
|
if(!bencode_write_bytestring(buff, "i", 1))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// router contact
|
|
|
|
if(router)
|
|
|
|
{
|
|
|
|
if(!bencode_write_bytestring(buff, "r", 1))
|
|
|
|
return false;
|
2018-08-30 18:48:43 +00:00
|
|
|
if(!router->BEncode(buff))
|
2018-07-09 03:08:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// version
|
|
|
|
if(!bencode_write_version_entry(buff))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return bencode_end(buff);
|
|
|
|
}
|
|
|
|
} // namespace llarp
|