lokinet/include/llarp/link.h

94 lines
2.7 KiB
C
Raw Normal View History

2018-01-25 16:24:33 +00:00
#ifndef LLARP_LINK_H_
#define LLARP_LINK_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-01-29 14:27:24 +00:00
#include <llarp/mem.h>
2018-02-01 17:07:01 +00:00
#include <llarp/msg_handler.h>
2018-01-27 01:18:10 +00:00
#include <llarp/obmd.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-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
2018-01-29 14:27:24 +00:00
struct llarp_link_session_listener {
void *user;
2018-04-04 13:54:37 +00:00
/** set by try_establish */
2018-01-29 14:27:24 +00:00
struct llarp_link *link;
2018-04-04 13:54:37 +00:00
/** set by try_establish */
2018-04-05 14:23:14 +00:00
struct llarp_ai *ai;
2018-04-04 13:54:37 +00:00
/** callback to handle result */
2018-01-29 14:27:24 +00:00
void (*result)(struct llarp_link_session_listener *,
struct llarp_link_session *);
};
2018-01-27 01:18:10 +00:00
2018-01-29 14:27:24 +00:00
/** information for establishing an outbound session */
struct llarp_link_establish_job {
2018-04-05 14:23:14 +00:00
struct llarp_ai *ai;
2018-01-29 14:27:24 +00:00
uint64_t timeout;
};
2018-01-27 01:18:10 +00:00
2018-01-29 14:27:24 +00:00
struct llarp_link_session_iter {
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
2018-04-05 14:43:16 +00:00
struct llarp_link_ev_listener {
void *user;
void (*established)(struct llarp_ev_listener *, struct llarp_link_session *,
bool);
void (*timeout)(struct llarp_ev_listener *, struct llarp_link_session *,
bool);
2018-04-05 14:23:14 +00:00
void (*tx)(struct llarp_ev_listener *, struct llarp_link_session *, size_t);
void (*rx)(struct llarp_ev_listener *, struct llarp_link_session *, size_t);
2018-04-05 14:43:16 +00:00
void (*error)(struct llarp_ev_listener *, struct llarp_link_session *,
const char *);
2018-04-05 14:23:14 +00:00
};
2018-04-05 14:43:16 +00:00
struct llarp_link {
void *impl;
const char *(*name)(struct llarp_link *);
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);
bool (*configure)(struct llarp_link *, const char *, int, uint16_t);
bool (*start_link)(struct llarp_link *, struct llarp_ev_loop *);
bool (*stop_link)(struct llarp_link *);
bool (*put_ai)(struct llarp_link *, struct llarp_ai *);
2018-04-04 13:54:37 +00:00
void (*iter_sessions)(struct llarp_link *, struct llarp_link_session_iter);
2018-04-05 14:43:16 +00:00
void (*try_establish)(struct llarp_link *, struct llarp_link_establish_job,
2018-04-04 13:54:37 +00:00
struct llarp_link_session_listener);
void (*free)(struct llarp_link *);
};
2018-01-27 01:18:10 +00:00
2018-04-05 14:43:16 +00:00
struct llarp_link_session {
void *impl;
struct llarp_rc *(*remote_rc)(struct llarp_link_session *);
/** send an entire message, splits up into smaller pieces and does encryption
*/
2018-04-04 13:54:37 +00:00
ssize_t (*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 *);
2018-04-04 13:54:37 +00:00
};
2018-01-27 01:18:10 +00:00
2018-01-25 16:24:33 +00:00
#ifdef __cplusplus
}
#endif
#endif