2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2018-12-12 02:52:51 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/constants/proto.hpp>
|
|
|
|
#include "buffer.hpp"
|
|
|
|
#include "common.hpp"
|
2018-12-12 02:52:51 +00:00
|
|
|
|
2019-01-10 17:43:29 +00:00
|
|
|
#include <functional>
|
2019-07-30 23:42:13 +00:00
|
|
|
|
|
|
|
#include <cstdint>
|
2018-04-04 15:19:11 +00:00
|
|
|
|
2018-05-25 09:17:08 +00:00
|
|
|
/**
|
|
|
|
* bencode.h
|
|
|
|
*
|
|
|
|
* helper functions for handling bencoding
|
|
|
|
* https://en.wikipedia.org/wiki/Bencode for more information on the format
|
|
|
|
* we utilize llarp_buffer which provides memory management
|
|
|
|
*/
|
|
|
|
|
2018-06-01 17:47:37 +00:00
|
|
|
bool
|
2019-01-10 17:43:29 +00:00
|
|
|
bencode_read_integer(llarp_buffer_t* buffer, uint64_t* result);
|
2018-04-05 14:43:16 +00:00
|
|
|
|
2018-06-01 17:47:37 +00:00
|
|
|
bool
|
2019-01-10 17:43:29 +00:00
|
|
|
bencode_read_string(llarp_buffer_t* buffer, llarp_buffer_t* result);
|
2018-04-04 15:19:11 +00:00
|
|
|
|
2018-06-01 17:47:37 +00:00
|
|
|
bool
|
2019-01-10 17:43:29 +00:00
|
|
|
bencode_write_bytestring(llarp_buffer_t* buff, const void* data, size_t sz);
|
2018-04-05 14:43:16 +00:00
|
|
|
|
2018-06-01 17:47:37 +00:00
|
|
|
bool
|
2019-01-10 17:43:29 +00:00
|
|
|
bencode_write_uint64(llarp_buffer_t* buff, uint64_t i);
|
2018-04-05 14:43:16 +00:00
|
|
|
|
2019-11-22 17:39:35 +00:00
|
|
|
/// Write a dictionary entry with a uint64_t value
|
2018-06-01 17:47:37 +00:00
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
bencode_write_uint64_entry(llarp_buffer_t* buff, const void* name, size_t sz, uint64_t i);
|
2018-04-05 14:43:16 +00:00
|
|
|
|
2018-06-01 17:47:37 +00:00
|
|
|
bool
|
2019-01-10 17:43:29 +00:00
|
|
|
bencode_start_list(llarp_buffer_t* buff);
|
2018-04-04 15:19:11 +00:00
|
|
|
|
2018-06-01 17:47:37 +00:00
|
|
|
bool
|
2019-01-10 17:43:29 +00:00
|
|
|
bencode_start_dict(llarp_buffer_t* buff);
|
2018-05-22 15:54:19 +00:00
|
|
|
|
2018-06-01 17:47:37 +00:00
|
|
|
bool
|
2019-01-10 17:43:29 +00:00
|
|
|
bencode_end(llarp_buffer_t* buff);
|
2018-05-13 18:07:36 +00:00
|
|
|
|
2019-11-03 15:31:01 +00:00
|
|
|
/// read next member, discard it and advance buffer
|
|
|
|
bool
|
|
|
|
bencode_discard(llarp_buffer_t* buf);
|