2018-01-25 16:24:33 +00:00
|
|
|
#ifndef LLARP_XI_H
|
|
|
|
#define LLARP_XI_H
|
2018-12-12 02:52:51 +00:00
|
|
|
|
|
|
|
#include <buffer.h>
|
|
|
|
#include <crypto.h>
|
|
|
|
#include <net.h>
|
|
|
|
|
2018-08-24 16:07:17 +00:00
|
|
|
#ifdef __cplusplus
|
2018-12-12 02:52:51 +00:00
|
|
|
#include <bits.hpp>
|
2018-08-24 16:07:17 +00:00
|
|
|
#include <iostream>
|
2018-08-24 23:46:48 +00:00
|
|
|
#include <string>
|
2018-08-24 16:07:17 +00:00
|
|
|
#endif
|
2018-01-08 13:49:05 +00:00
|
|
|
|
2018-05-25 09:17:08 +00:00
|
|
|
/**
|
|
|
|
* exit_info.h
|
|
|
|
*
|
|
|
|
* utilities for handling exits on the llarp network
|
|
|
|
*/
|
|
|
|
|
2018-08-24 16:07:17 +00:00
|
|
|
struct llarp_xi;
|
|
|
|
|
|
|
|
bool
|
|
|
|
llarp_xi_bdecode(struct llarp_xi *xi, llarp_buffer_t *buf);
|
|
|
|
bool
|
|
|
|
llarp_xi_bencode(const struct llarp_xi *xi, llarp_buffer_t *buf);
|
|
|
|
|
2018-05-25 09:17:08 +00:00
|
|
|
/// Exit info model
|
2018-05-22 15:54:19 +00:00
|
|
|
struct llarp_xi
|
|
|
|
{
|
2018-04-04 13:54:37 +00:00
|
|
|
struct in6_addr address;
|
|
|
|
struct in6_addr netmask;
|
2018-06-12 11:57:14 +00:00
|
|
|
byte_t pubkey[PUBKEYSIZE];
|
2018-01-29 14:27:24 +00:00
|
|
|
|
2018-08-24 16:07:17 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
bool
|
|
|
|
BEncode(llarp_buffer_t *buf) const
|
|
|
|
{
|
|
|
|
return llarp_xi_bencode(this, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BDecode(llarp_buffer_t *buf)
|
|
|
|
{
|
|
|
|
return llarp_xi_bdecode(this, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend std::ostream &
|
|
|
|
operator<<(std::ostream &out, const llarp_xi &xi)
|
|
|
|
{
|
|
|
|
char tmp[128] = {0};
|
2018-09-21 14:36:06 +00:00
|
|
|
if(inet_ntop(AF_INET6, (void *)&xi.address, tmp, sizeof(tmp)))
|
2018-08-24 16:07:17 +00:00
|
|
|
out << std::string(tmp);
|
|
|
|
else
|
|
|
|
return out;
|
|
|
|
out << std::string("/");
|
|
|
|
return out << std::to_string(
|
|
|
|
llarp::bits::count_array_bits(xi.netmask.s6_addr));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
};
|
2018-01-29 14:27:24 +00:00
|
|
|
|
|
|
|
struct llarp_xi_list;
|
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
struct llarp_xi_list *
|
2018-05-25 17:52:10 +00:00
|
|
|
llarp_xi_list_new();
|
2018-05-10 23:32:46 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
llarp_xi_list_free(struct llarp_xi_list *l);
|
2018-04-04 15:19:11 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
bool
|
|
|
|
llarp_xi_list_bdecode(struct llarp_xi_list *l, llarp_buffer_t *buf);
|
|
|
|
|
|
|
|
bool
|
|
|
|
llarp_xi_list_bencode(struct llarp_xi_list *l, llarp_buffer_t *buf);
|
|
|
|
|
|
|
|
void
|
|
|
|
llarp_xi_list_pushback(struct llarp_xi_list *l, struct llarp_xi *xi);
|
|
|
|
|
2018-05-30 20:56:47 +00:00
|
|
|
void
|
|
|
|
llarp_xi_list_copy(struct llarp_xi_list *dst, struct llarp_xi_list *src);
|
|
|
|
|
2018-08-24 16:07:17 +00:00
|
|
|
size_t
|
|
|
|
llarp_xi_list_size(const struct llarp_xi_list *l);
|
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
llarp_xi_copy(struct llarp_xi *dst, struct llarp_xi *src);
|
|
|
|
|
|
|
|
struct llarp_xi_list_iter
|
|
|
|
{
|
2018-04-05 14:43:16 +00:00
|
|
|
void *user;
|
|
|
|
struct llarp_xi_list *list;
|
|
|
|
bool (*visit)(struct llarp_xi_list_iter *, struct llarp_xi *);
|
|
|
|
};
|
2018-04-04 15:19:11 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
llarp_xi_list_iterate(struct llarp_xi_list *l, struct llarp_xi_list_iter *iter);
|
2018-04-04 15:19:11 +00:00
|
|
|
|
2018-01-08 13:49:05 +00:00
|
|
|
#endif
|