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.
63 lines
2.0 KiB
63 lines
2.0 KiB
#ifndef NODE_CONN_DIRECT_H |
|
#define NODE_CONN_DIRECT_H |
|
|
|
#include <stdint.h> |
|
|
|
struct UTUN_INSTANCE; |
|
struct ETCP_CONN; |
|
struct TOPO_NODE; |
|
|
|
/* ─── Return codes ─── */ |
|
#define NCD_NEW 0 |
|
#define NCD_REUSED 1 |
|
#define NCD_ERR -1 |
|
|
|
/* ─── Opaque handle ─── */ |
|
struct NODE_CONN_DIRECT; |
|
|
|
/* ─── Callback events (единый callback на handle) ─── */ |
|
enum ncd_event { |
|
NCD_EVENT_UP = 0, |
|
NCD_EVENT_DOWN = 1, |
|
NCD_EVENT_TIMEOUT = 2, |
|
}; |
|
|
|
typedef void (*ncd_callback)(struct NODE_CONN_DIRECT* h, enum ncd_event event, void* arg); |
|
|
|
/* |
|
* Открыть handle к узлу по node_id. |
|
* Node info — из node_registry, fallback SQLite. |
|
* cb — вызывается при каждом изменении статуса / таймауте. |
|
* Если conn уже готов — cb(h, NCD_EVENT_UP) через uasync_call_soon (не синхронно). |
|
* |
|
* Возвращает NCD_NEW / NCD_REUSED / NCD_ERR. |
|
*/ |
|
int node_conn_direct_open(struct UTUN_INSTANCE* inst, uint64_t node_id, |
|
ncd_callback cb, void* cb_arg, |
|
struct NODE_CONN_DIRECT** out_handle); |
|
|
|
int node_conn_direct_open_node(struct UTUN_INSTANCE* inst, uint64_t node_id, |
|
ncd_callback cb, void* cb_arg, |
|
struct NODE_CONN_DIRECT** out_handle, |
|
struct TOPO_NODE* ni); |
|
|
|
void node_conn_direct_close(struct NODE_CONN_DIRECT* h); |
|
|
|
struct ETCP_CONN* node_conn_direct_get_conn(struct NODE_CONN_DIRECT* h); |
|
|
|
/* ─── Протокол CLOSE / KEEP_ALIVE (ETCP_RT_ID_NCD_CONTROL = 0x12) ─── */ |
|
|
|
#define NCD_SUBCMD_CLOSE 0x01 |
|
#define NCD_SUBCMD_KEEP_ALIVE 0x02 |
|
|
|
#pragma pack(push, 1) |
|
struct ncd_control_msg { |
|
uint8_t cmd; /* ETCP_RT_ID_NCD_CONTROL */ |
|
uint8_t subcmd; /* NCD_SUBCMD_CLOSE / KEEP_ALIVE */ |
|
uint64_t node_id; /* node_id отправителя */ |
|
}; |
|
#pragma pack(pop) |
|
|
|
#define NCD_CONTROL_MSG_SIZE sizeof(struct ncd_control_msg) |
|
|
|
#endif
|
|
|