lokinet/include/llarp/link.h

126 lines
3.6 KiB
C
Raw Normal View History

2018-01-25 16:24:33 +00:00
#ifndef LLARP_LINK_H_
#define LLARP_LINK_H_
#include <llarp/address_info.h>
2018-01-29 14:27:24 +00:00
#include <llarp/crypto.h>
2018-04-05 14:43:16 +00:00
#include <llarp/ev.h>
2018-04-30 18:18:34 +00:00
#include <llarp/logic.h>
2018-01-29 14:27:24 +00:00
#include <llarp/mem.h>
2018-01-25 16:24:33 +00:00
2018-02-01 17:06:49 +00:00
#include <stdbool.h>
2018-02-01 17:07:01 +00:00
#include <stdint.h>
2018-02-01 17:06:49 +00:00
2018-01-25 16:24:33 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2018-04-05 14:43:16 +00:00
2018-06-01 14:08:54 +00:00
/** 2^15 bytes */
2018-06-06 12:59:15 +00:00
#define MAX_LINK_MSG_SIZE (32768)
2018-06-01 14:08:54 +00:00
2018-04-04 13:54:37 +00:00
/**
2018-04-05 14:43:16 +00:00
* wire layer transport interface
2018-04-04 13:54:37 +00:00
*/
2018-01-29 14:27:24 +00:00
struct llarp_link;
2018-04-04 13:54:37 +00:00
/**
2018-04-05 14:43:16 +00:00
* wire layer transport session for point to point communication between us and
* another
2018-04-04 13:54:37 +00:00
*/
2018-01-29 14:27:24 +00:00
struct llarp_link_session;
2018-01-27 01:18:10 +00:00
/** outbound session establish job */
struct llarp_link_establish_job
{
2018-01-29 14:27:24 +00:00
void *user;
void (*result)(struct llarp_link_establish_job *);
struct llarp_ai ai;
2018-01-29 14:27:24 +00:00
uint64_t timeout;
2018-06-13 12:58:51 +00:00
uint16_t retries;
byte_t pubkey[PUBKEYSIZE];
/** set on success by try_establish */
struct llarp_link *link;
/** set on success by try_establish */
struct llarp_link_session *session;
2018-01-29 14:27:24 +00:00
};
2018-01-27 01:18:10 +00:00
struct llarp_link_session_iter
{
2018-01-29 14:27:24 +00:00
void *user;
struct llarp_link *link;
bool (*visit)(struct llarp_link_session_iter *, struct llarp_link_session *);
};
2018-01-27 01:18:10 +00:00
struct llarp_link_ev_listener
{
2018-04-05 14:43:16 +00:00
void *user;
void (*established)(struct llarp_link_ev_listener *,
struct llarp_link_session *, bool);
2018-05-16 15:30:05 +00:00
void (*timeout)(struct llarp_link_ev_listener *, struct llarp_link_session *,
2018-04-05 14:43:16 +00:00
bool);
void (*tx)(struct llarp_link_ev_listener *, struct llarp_link_session *,
size_t);
void (*rx)(struct llarp_link_ev_listener *, struct llarp_link_session *,
size_t);
2018-05-16 15:30:05 +00:00
void (*error)(struct llarp_link_ev_listener *, struct llarp_link_session *,
2018-04-05 14:43:16 +00:00
const char *);
2018-04-05 14:23:14 +00:00
};
// forward declare
struct llarp_router;
struct llarp_link
{
2018-04-05 14:43:16 +00:00
void *impl;
struct llarp_router *router;
2018-05-16 16:41:20 +00:00
const char *(*name)(void);
2018-05-20 17:45:47 +00:00
void (*get_our_address)(struct llarp_link *, struct llarp_ai *);
2018-05-16 15:30:05 +00:00
/*
2018-04-05 14:23:14 +00:00
int (*register_listener)(struct llarp_link *, struct llarp_link_ev_listener);
void (*deregister_listener)(struct llarp_link *, int);
2018-05-16 15:30:05 +00:00
*/
bool (*configure)(struct llarp_link *, struct llarp_ev_loop *, const char *,
int, uint16_t);
2018-04-30 18:18:18 +00:00
bool (*start_link)(struct llarp_link *, struct llarp_logic *);
2018-04-05 14:23:14 +00:00
bool (*stop_link)(struct llarp_link *);
void (*iter_sessions)(struct llarp_link *, struct llarp_link_session_iter);
bool (*try_establish)(struct llarp_link *, struct llarp_link_establish_job *);
2018-06-01 14:08:54 +00:00
/// send to already established session given its public identity key
/// returns false if we don't have this session
/// returns true if the messages were queued
bool (*sendto)(struct llarp_link *, const byte_t *, llarp_buffer_t);
/// return true if we have a session to router given public identity key
bool (*has_session_to)(struct llarp_link *, const byte_t *);
2018-05-16 16:41:20 +00:00
void (*mark_session_active)(struct llarp_link *, struct llarp_link_session *);
2018-05-16 15:30:05 +00:00
void (*free_impl)(struct llarp_link *);
2018-04-04 13:54:37 +00:00
};
2018-01-27 01:18:10 +00:00
2018-05-16 15:49:16 +00:00
/** checks if all members are initialized */
bool
llarp_link_initialized(struct llarp_link *link);
struct llarp_link_session
{
2018-04-05 14:43:16 +00:00
void *impl;
/** send an entire message, splits up into smaller pieces and does encryption
*/
2018-05-18 17:10:48 +00:00
bool (*sendto)(struct llarp_link_session *, llarp_buffer_t);
2018-04-05 14:23:14 +00:00
/** return true if this session is timed out */
bool (*timeout)(struct llarp_link_session *);
/** explicit close session */
void (*close)(struct llarp_link_session *);
/** set session established */
void (*established)(struct llarp_link_session *);
/** get parent link */
struct llarp_link *(*get_parent)(struct llarp_link_session *);
/** get router contact of remote router */
struct llarp_rc *(*get_remote_router)(struct llarp_link_session *);
2018-04-04 13:54:37 +00:00
};
2018-01-27 01:18:10 +00:00
bool
llarp_link_session_initialized(struct llarp_link_session *s);
2018-05-16 16:41:20 +00:00
2018-01-25 16:24:33 +00:00
#ifdef __cplusplus
}
#endif
#endif