1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/include/llarp/address_info.h

97 lines
2.2 KiB
C
Raw Normal View History

2018-01-25 17:24:33 +01:00
#ifndef LLARP_AI_H
#define LLARP_AI_H
#include <llarp/crypto.h>
2018-01-26 15:17:51 +01:00
#include <llarp/mem.h>
2018-01-25 17:24:33 +01:00
#include <llarp/net.h>
#include <stdbool.h>
2018-05-25 11:17:08 +02:00
/**
* address_info.h
*
* utilities for handling addresses on the llarp network
*/
2018-01-25 17:24:33 +01:00
#ifdef __cplusplus
extern "C" {
#endif
2018-01-26 15:17:51 +01:00
#define MAX_AI_DIALECT_SIZE 5
2018-01-29 15:27:24 +01:00
2018-05-25 11:17:08 +02:00
/// address information model
struct llarp_ai
{
2018-01-29 15:27:24 +01:00
uint16_t rank;
2018-04-04 17:19:11 +02:00
char dialect[MAX_AI_DIALECT_SIZE + 1];
2018-01-29 15:27:24 +01:00
llarp_pubkey_t enc_key;
struct in6_addr ip;
uint16_t port;
};
2018-05-25 11:17:08 +02:00
/// convert address information struct to bencoded buffer
bool
llarp_ai_bencode(struct llarp_ai *ai, llarp_buffer_t *buff);
2018-05-25 11:17:08 +02:00
/// convert bencoded buffer to address information struct
bool
llarp_ai_bdecode(struct llarp_ai *ai, llarp_buffer_t *buff);
2018-01-29 15:27:24 +01:00
struct llarp_ai_list;
2018-05-25 11:17:08 +02:00
/// list of address information initialization
struct llarp_ai_list *
llarp_ai_list_new(struct llarp_alloc *mem);
2018-05-25 11:17:08 +02:00
/// list of address information destruction
void
llarp_ai_list_free(struct llarp_ai_list *l);
2018-05-25 11:17:08 +02:00
/// copy AI
void
llarp_ai_copy(struct llarp_ai *dst, struct llarp_ai *src);
2018-05-25 11:17:08 +02:00
/// convert llarp_ai_list struct to bencoded buffer
bool
llarp_ai_list_bencode(struct llarp_ai_list *l, llarp_buffer_t *buff);
2018-05-25 11:17:08 +02:00
/// convert bencoded buffer to llarp_ai_list struct
bool
llarp_ai_list_bdecode(struct llarp_ai_list *l, llarp_buffer_t *buff);
2018-05-25 11:17:08 +02:00
/// return and remove first element from ai_list
struct llarp_ai
llarp_ai_list_popfront(struct llarp_ai_list *l);
2018-05-25 11:17:08 +02:00
/// pushes a copy of ai to the end of the list
void
llarp_ai_list_pushback(struct llarp_ai_list *l, struct llarp_ai *ai);
2018-05-11 01:32:46 +02:00
2018-05-25 11:17:08 +02:00
/// get the number of entries in list
size_t
llarp_ai_list_size(struct llarp_ai_list *l);
2018-01-29 15:27:24 +01:00
2018-05-25 11:17:08 +02:00
/// does this index exist in list
bool
llarp_ai_list_index(struct llarp_ai_list *l, ssize_t idx,
struct llarp_ai *result);
2018-01-29 15:27:24 +01:00
2018-05-25 11:17:08 +02:00
/// ai_list iterator configuration
struct llarp_ai_list_iter
{
2018-05-25 11:17:08 +02:00
/// a customizable pointer to pass data to iteration functor
2018-01-29 15:27:24 +01:00
void *user;
2018-05-25 11:17:08 +02:00
/// set by llarp_ai_list_iterate()
2018-01-29 15:27:24 +01:00
struct llarp_ai_list *list;
2018-05-25 11:17:08 +02:00
/// return false to break iteration early
2018-01-29 15:27:24 +01:00
bool (*visit)(struct llarp_ai_list_iter *, struct llarp_ai *);
};
2018-05-25 11:17:08 +02:00
/// iterator over list and call visit functor
void
llarp_ai_list_iterate(struct llarp_ai_list *l, struct llarp_ai_list_iter *iter);
2018-01-29 15:27:24 +01:00
2018-01-25 17:24:33 +01:00
#ifdef __cplusplus
}
#endif
2018-01-29 15:27:24 +01:00
2018-01-25 17:24:33 +01:00
#endif