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.
 
 
 
 
 
 

69 lines
2.2 KiB

#ifndef INVITE_LINK_C_H
#define INVITE_LINK_C_H
#include <stdint.h>
#include <stddef.h>
#define INVITE_LINK_VERSION 0x03
#define INVITE_PUBKEY_SIZE 32
#define INVITE_ADDR_MAX 32
#define INVITE_PASS_MAX 128
#define INVITE_SNAME_MAX 64
#define INVITE_PROTO_UDP 0x01
#define INVITE_PROTO_TCP 0x02
#define INVITE_PROTO_REALITY 0x04 /* флаг reality-камуфляжа поверх TCP (reality-TCP = 0x06) */
#ifdef __cplusplus
extern "C" {
#endif
struct InviteAddrC {
int family;
uint8_t address[16];
uint8_t socketId;
uint8_t proto;
uint16_t port;
};
/* Reality-параметры узла (node-global: одинаковы для всех reality-сокетов). */
struct InviteRealityC {
uint8_t has;
uint8_t short_id[8];
uint8_t server_pubkey[32];
uint8_t version[3];
char server_name[INVITE_SNAME_MAX];
};
struct InviteDataC {
uint64_t channelId;
uint64_t join_key; /* 64-битный ключ входа (генерируется инвайтером) */
uint8_t pubkey[INVITE_PUBKEY_SIZE];
uint64_t nodeId;
uint8_t addrCount;
struct InviteAddrC addrs[INVITE_ADDR_MAX];
char password[INVITE_PASS_MAX]; /* empty = no password (v1 compat) */
uint8_t password_len;
struct InviteRealityC reality;
};
/* decode utun://base64 link string, returns 0 on success, -1 on error.
error buffer must be at least 256 bytes */
int invite_link_decode(const char* link, size_t link_len, struct InviteDataC* out,
char* error_buf, size_t error_buf_size);
/* encode invite data to utun://base64 string.
password may be NULL (v1 format, no password).
out buffer must be large enough (~512 bytes safe).
returns written length (excluding null), or -1 on error */
int invite_link_encode(const struct InviteDataC* data, const char* password, char* out, size_t out_size);
/* serialize per-addr format for chat_sync_connect_from_invite():
family(1) + socketId(1) + proto(1) + address(4|16) + port(2 BE)
returns total bytes written, or -1 if buf too small */
int invite_serialize_addrs(const struct InviteDataC* data, uint8_t* buf, size_t buf_size);
#ifdef __cplusplus
}
#endif
#endif /* INVITE_LINK_C_H */