You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lokinet/include/llarp/address_info.h

92 lines
2.2 KiB
C

7 years ago
#ifndef LLARP_AI_H
#define LLARP_AI_H
#include <llarp/crypto.h>
7 years ago
#include <llarp/mem.h>
7 years ago
#include <llarp/net.h>
#include <stdbool.h>
6 years ago
/**
* address_info.h
*
* utilities for handling addresses on the llarp network
*/
7 years ago
#define MAX_AI_DIALECT_SIZE 5
7 years ago
6 years ago
/// address information model
struct llarp_ai
{
7 years ago
uint16_t rank;
6 years ago
char dialect[MAX_AI_DIALECT_SIZE + 1];
byte_t enc_key[PUBKEYSIZE];
7 years ago
struct in6_addr ip;
uint16_t port;
};
6 years ago
/// convert address information struct to bencoded buffer
bool
llarp_ai_bencode(struct llarp_ai *ai, llarp_buffer_t *buff);
6 years ago
/// convert bencoded buffer to address information struct
bool
llarp_ai_bdecode(struct llarp_ai *ai, llarp_buffer_t *buff);
7 years ago
struct llarp_ai_list;
6 years ago
/// list of address information initialization
struct llarp_ai_list *
llarp_ai_list_new();
6 years ago
/// list of address information destruction
void
llarp_ai_list_free(struct llarp_ai_list *l);
6 years ago
/// copy AI
void
llarp_ai_copy(struct llarp_ai *dst, struct llarp_ai *src);
6 years ago
/// convert llarp_ai_list struct to bencoded buffer
bool
llarp_ai_list_bencode(struct llarp_ai_list *l, llarp_buffer_t *buff);
6 years ago
/// convert bencoded buffer to llarp_ai_list struct
bool
llarp_ai_list_bdecode(struct llarp_ai_list *l, llarp_buffer_t *buff);
6 years ago
/// return and remove first element from ai_list
struct llarp_ai
llarp_ai_list_popfront(struct llarp_ai_list *l);
6 years ago
/// 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);
6 years ago
6 years ago
/// get the number of entries in list
size_t
llarp_ai_list_size(struct llarp_ai_list *l);
7 years ago
6 years ago
void
llarp_ai_list_copy(struct llarp_ai_list *dst, struct llarp_ai_list *src);
6 years ago
/// does this index exist in list
bool
llarp_ai_list_index(struct llarp_ai_list *l, ssize_t idx,
struct llarp_ai *result);
7 years ago
6 years ago
/// ai_list iterator configuration
struct llarp_ai_list_iter
{
6 years ago
/// a customizable pointer to pass data to iteration functor
7 years ago
void *user;
6 years ago
/// set by llarp_ai_list_iterate()
7 years ago
struct llarp_ai_list *list;
6 years ago
/// return false to break iteration early
7 years ago
bool (*visit)(struct llarp_ai_list_iter *, struct llarp_ai *);
};
6 years ago
/// iterator over list and call visit functor
void
llarp_ai_list_iterate(struct llarp_ai_list *l, struct llarp_ai_list_iter *iter);
7 years ago
7 years ago
#endif