You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.8 KiB
57 lines
1.8 KiB
// stcp_link.h — STCP link management (TCP connection via STCP protocol) |
|
#ifndef STCP_LINK_H |
|
#define STCP_LINK_H |
|
|
|
#ifdef __cplusplus |
|
extern "C" { |
|
#endif |
|
|
|
|
|
#include "secure_channel.h" |
|
#include "../lib/u_async.h" |
|
#include "../lib/socket_compat.h" |
|
#include <stdint.h> |
|
|
|
struct stcp_link; // opaque |
|
struct stcp_server; // opaque |
|
struct ETCP_CONN; |
|
struct UTUN_INSTANCE; |
|
|
|
// ====== Link config ====== |
|
|
|
struct stcp_link_config { |
|
struct UASYNC *ua; |
|
struct SC_MYKEYS *my_keys; // ключи этой стороны |
|
struct UTUN_INSTANCE *inst; // для диспатча через api_bindings |
|
const uint8_t *peer_pubkey; // pubkey пира (клиент) |
|
int peer_pubkey_mode; // 0=binary, 1=hex |
|
const struct sockaddr_storage *remote_addr; // адрес пира (клиент) |
|
uint16_t remote_port; // порт пира (клиент) |
|
}; |
|
|
|
// ====== TCP server ====== |
|
|
|
typedef void (*stcp_server_on_link_cb)(struct stcp_link *link, void *arg); |
|
|
|
struct stcp_server *stcp_server_listen(struct stcp_link_config *cfg, uint16_t port, |
|
stcp_server_on_link_cb on_link, void *arg); |
|
void stcp_link_server_destroy(struct stcp_server *srv); |
|
|
|
// ====== TCP client link ====== |
|
|
|
struct stcp_link *stcp_link_connect(struct stcp_link_config *cfg); |
|
void stcp_link_close(struct stcp_link *link); |
|
int stcp_link_send(struct stcp_link *link, const uint8_t *data, size_t len); |
|
int stcp_link_is_ready(struct stcp_link *link); |
|
|
|
struct ETCP_CONN *stcp_link_get_etcp_conn(struct stcp_link *link); |
|
|
|
typedef void (*stcp_link_cb)(struct stcp_link *link, void *arg); |
|
void stcp_link_set_on_ready(struct stcp_link *link, stcp_link_cb cb, void *arg); |
|
void stcp_link_set_on_close(struct stcp_link *link, void (*cb)(struct stcp_link *link, int err, void *arg), void *arg); |
|
|
|
|
|
#ifdef __cplusplus |
|
} |
|
#endif |
|
#endif
|
|
|