#ifndef LC6_COMMON_H #define LC6_COMMON_H #include #include #include #include "../inc/libchat6.h" #include "../inc/lc6_helpers.h" #ifdef LC6_DEBUG #include "../inc/lc6_debug.h" #endif #define LC6_CRYPTO_HASHLEN crypto_generichash_BYTES #define LC6_CRYPTO_HASHSIGNLEN (crypto_secretbox_NONCEBYTES+crypto_box_MACBYTES+crypto_generichash_BYTES) #define LC6_CRYPTO_PUBLEN crypto_kx_PUBLICKEYBYTES #define LC6_CRYPTO_PRIVLEN crypto_kx_SECRETKEYBYTES #define LC6_CRYPTO_RXLEN crypto_kx_SESSIONKEYBYTES #define LC6_CRYPTO_TXLEN crypto_kx_SESSIONKEYBYTES typedef struct LC6_NODE { unsigned char *pub_key; unsigned char *priv_key; } LC6_NODE; typedef struct LC6_PEER { int sock; LC6_NODE keys; unsigned char bufi[65536]; unsigned char bufo[65536]; } LC6_PEER; typedef struct LC6_USER { struct LC6_USER *prev; struct LC6_USER *next; unsigned char nickname[256]; unsigned char pub_key[LC6_CRYPTO_PUBLEN]; unsigned char priv_key[LC6_CRYPTO_PRIVLEN]; uint8_t status; } LC6_USER; typedef struct LC6_FRIEND { struct LC6_FRIEND *prev; struct LC6_FRIEND *next; unsigned char nickname[256]; unsigned char pub_key[LC6_CRYPTO_PUBLEN]; unsigned char key_rx[LC6_CRYPTO_RXLEN]; unsigned char key_tx[LC6_CRYPTO_TXLEN]; uint8_t status; } LC6_FRIEND; typedef struct LC6_MSG_TLV { int type; int length; unsigned char *value; } LC6_MSG_TLV; typedef struct LC6_MSG { uint64_t timestamp; int type; LC6_MSG_TLV **tlv; } LC6_MSG; enum LC6_MSG_TYPE_ENUM { LC6_MSG_TYPE_CLIENT_ONLINE, LC6_MSG_TYPE_CLIENT_UPDATE, LC6_MSG_TYPE_CLIENT_OFFLINE, LC6_MSG_TYPE_KEEPALIVE_REQUEST, LC6_MSG_TYPE_KEEPALIVE_RESPONSE, LC6_MSG_TYPE_FRIEND_REQUEST, LC6_MSG_TYPE_FRIEND_RESPONSE, LC6_MSG_TYPE_MESSAGE_SEND, LC6_MSG_TYPE_MESSAGE_RECV, LC6_MSG_TYPE_MESSAGE_READ, LC6_MSG_TYPE_NEIGHBOURS_REQUEST, LC6_MSG_TYPE_NEIGHBOURS_RESPONSE }; enum LC6_MSG_TLV_ENUM { LC6_MSG_TLV_NICKNAME, LC6_MSG_TLV_KEY, LC6_MSG_TLV_NONCE, LC6_MSG_TLV_ICON, LC6_MSG_TLV_METRIC, LC6_MSG_TLV_MSGID, LC6_MSG_TLV_CHATID, LC6_MSG_TLV_NEIGHBOUR }; enum LC6_MSG_TLV_TYPE_ENUM { LC6_MSG_TLV_TYPE_UTF8, LC6_MSG_TLV_TYPE_BINARY, LC6_MSG_TLV_TYPE_INTEGER, LC6_MSG_TLV_TYPE_UUID, LC6_MSG_TLV_TYPE_IPPORT }; #define LC6_CONFIG_BOOTSTRAP "bootstrap.bin" #define LC6_CONFIG_USER "user.bin" #define LC6_CONFIG_FRIEND "friends.bin" #define LC6_CONFIG_MAXLEN 50 typedef struct LC6_IPADDR { uint8_t af; union addr { uint32_t inet; unsigned char inet6[16]; } addr; } LC6_IPADDR; typedef struct LC6_BOOTSTRAP { struct LC6_BOOTSTRAP *prev; struct LC6_BOOTSTRAP *next; uint64_t last_contact; LC6_IPADDR ip; } LC6_BOOTSTRAP; typedef struct LC6_CTX { char path[MAXPATHLEN-LC6_CONFIG_MAXLEN]; LIBCHAT_CB *callback; LC6_USER *user; LC6_NODE *node; LC6_FRIEND *friend; LC6_BOOTSTRAP *bootstrap; } LC6_CTX; extern int LC6_MSG_TLV_TYPE_INT[8]; extern unsigned char LC6_MSG_TYPE_STR[13][30]; extern unsigned char LC6_MSG_TLV_STR[8][20]; #endif