#ifndef INVITE_LINK_C_H #define INVITE_LINK_C_H #include #include #define INVITE_LINK_VERSION 0x01 #define INVITE_PUBKEY_SIZE 32 #define INVITE_ADDR_MAX 32 #define INVITE_PASS_MAX 128 #define INVITE_PROTO_UDP 0x01 #define INVITE_PROTO_TCP 0x02 #define INVITE_PROTO_BOTH 0x03 #ifdef __cplusplus extern "C" { #endif struct InviteAddrC { int family; uint8_t address[16]; uint8_t socketId; uint8_t proto; uint16_t port; }; struct InviteDataC { uint64_t channelId; 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; }; /* 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 */