mirror of https://github.com/oxen-io/lokinet
more
parent
4cc5059cbe
commit
76d885d39e
@ -0,0 +1,17 @@
|
||||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"type": "shell",
|
||||
"command": "make"
|
||||
},
|
||||
{
|
||||
"label": "rebuild",
|
||||
"type": "shell",
|
||||
"command": "make clean all"
|
||||
}
|
||||
]
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
#ifndef LLARP_AI_HPP
|
||||
#define LLARP_AI_HPP
|
||||
#include <llarp/address_info.h>
|
||||
#include <cstring>
|
||||
#include <list>
|
||||
|
||||
struct llarp_ai_list {
|
||||
llarp_ai *data;
|
||||
llarp_ai_list *next = nullptr;
|
||||
};
|
||||
|
||||
static std::list<llarp_ai> ai_list_to_std(struct llarp_ai_list *l) {
|
||||
std::list<llarp_ai> list;
|
||||
if (l && l->data) {
|
||||
do {
|
||||
llarp_ai copy;
|
||||
memcpy(©, l->data, sizeof(llarp_ai));
|
||||
list.push_back(copy);
|
||||
l = l->next;
|
||||
} while (l->next);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,17 +0,0 @@
|
||||
#ifndef LLARP_XI_HPP
|
||||
#define LLARP_XI_HPP
|
||||
#include <llarp/exit_info.h>
|
||||
#include <list>
|
||||
|
||||
struct llarp_xi_list {
|
||||
std::list<llarp_xi> list;
|
||||
};
|
||||
|
||||
static std::list<llarp_xi> xi_list_to_std(struct llarp_xi_list *l) {
|
||||
std::list<llarp_xi> list;
|
||||
if (l->list.size())
|
||||
for (const auto &xi : l->list) list.push_back(xi);
|
||||
return list;
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,37 @@
|
||||
#include <llarp/bencode.h>
|
||||
#include <llarp/router_contact.h>
|
||||
#include <llarp/version.h>
|
||||
|
||||
void llarp_rc_free(struct llarp_rc *rc) {
|
||||
llarp_xi_list_free(&rc->exits);
|
||||
llarp_ai_list_free(&rc->addrs);
|
||||
}
|
||||
|
||||
bool llarp_rc_bencode(struct llarp_rc *rc, llarp_buffer_t *buff) {
|
||||
/* write dict begin */
|
||||
if (!bencode_start_dict(buff)) return false;
|
||||
if (rc->addrs) {
|
||||
/* write ai if they exist */
|
||||
if (!bencode_write_bytestring(buff, "a", 1)) return false;
|
||||
if (!llarp_ai_list_bencode(rc->addrs, buff)) return false;
|
||||
}
|
||||
/* write pubkey */
|
||||
if (!bencode_write_bytestring(buff, "k", 1)) return false;
|
||||
if (!bencode_write_bytestring(buff, rc->pubkey, sizeof(llarp_pubkey_t)))
|
||||
return false;
|
||||
|
||||
/* write version */
|
||||
if (!bencode_write_version_entry(buff)) return false;
|
||||
|
||||
if (rc->exits) {
|
||||
/* write ai if they exist */
|
||||
if (!bencode_write_bytestring(buff, "x", 1)) return false;
|
||||
if (!llarp_xi_list_bencode(rc->exits, buff)) return false;
|
||||
}
|
||||
|
||||
/* write signature */
|
||||
if (!bencode_write_bytestring(buff, "z", 1)) return false;
|
||||
if (!bencode_write_bytestring(buff, rc->signature, sizeof(llarp_sig_t)))
|
||||
return false;
|
||||
return bencode_end(buff);
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
#include "router_contact.hpp"
|
||||
#include <llarp/bencode.h>
|
||||
#include <llarp/version.h>
|
||||
#include "address_info.hpp"
|
||||
#include "exit_info.hpp"
|
||||
|
||||
namespace llarp {
|
||||
|
||||
static bool bencode_rc_ai_write(struct llarp_ai_list_iter *i,
|
||||
struct llarp_ai *ai) {
|
||||
llarp_buffer_t *buff = static_cast<llarp_buffer_t *>(i->user);
|
||||
return llarp_ai_bencode(ai, buff);
|
||||
}
|
||||
|
||||
static bool bencode_rc_xi_write(struct llarp_xi_list_iter *i,
|
||||
struct llarp_xi *xi) {
|
||||
llarp_buffer_t *buff = static_cast<llarp_buffer_t *>(i->user);
|
||||
return llarp_xi_bencode(xi, buff);
|
||||
}
|
||||
} // namespace llarp
|
||||
|
||||
extern "C" {
|
||||
|
||||
void llarp_rc_free(struct llarp_rc *rc) {
|
||||
if (rc->exits) llarp_xi_list_free(rc->exits);
|
||||
if (rc->addrs) llarp_ai_list_free(rc->addrs);
|
||||
}
|
||||
|
||||
bool llarp_rc_bencode(struct llarp_rc *rc, llarp_buffer_t *buff) {
|
||||
/* write dict begin */
|
||||
if (!bencode_start_dict(buff)) return false;
|
||||
if (rc->addrs) {
|
||||
/* write ai if they exist */
|
||||
if (!bencode_write_bytestring(buff, "a", 1)) return false;
|
||||
if (!bencode_start_list(buff)) return false;
|
||||
struct llarp_ai_list_iter ai_itr = {
|
||||
.user = buff, .list = nullptr, .visit = &llarp::bencode_rc_ai_write};
|
||||
llarp_ai_list_iterate(rc->addrs, &ai_itr);
|
||||
if (!bencode_end(buff)) return false;
|
||||
}
|
||||
/* write pubkey */
|
||||
if (!bencode_write_bytestring(buff, "k", 1)) return false;
|
||||
if (!bencode_write_bytestring(buff, rc->pubkey, sizeof(llarp_pubkey_t)))
|
||||
return false;
|
||||
|
||||
/* write version */
|
||||
if (!bencode_write_version_entry(buff)) return false;
|
||||
|
||||
if (rc->exits) {
|
||||
/* write ai if they exist */
|
||||
if (!bencode_write_bytestring(buff, "x", 1)) return false;
|
||||
if (!bencode_start_list(buff)) return false;
|
||||
struct llarp_xi_list_iter xi_itr = {
|
||||
.user = buff, .list = nullptr, .visit = &llarp::bencode_rc_xi_write};
|
||||
llarp_xi_list_iterate(rc->exits, &xi_itr);
|
||||
if (!bencode_end(buff)) return false;
|
||||
}
|
||||
|
||||
/* write signature */
|
||||
if (!bencode_write_bytestring(buff, "z", 1)) return false;
|
||||
if (!bencode_write_bytestring(buff, rc->signature, sizeof(llarp_sig_t)))
|
||||
return false;
|
||||
return bencode_end(buff);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue