123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- #ifndef LC6_COMMON_H
- #define LC6_COMMON_H
-
- #include <pthread.h>
- #include <sys/param.h>
- #include <arpa/inet.h>
- #include <sodium.h>
-
- #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
-
- #define LC6_EVENT_MAXPEERS_OUT 5
- #define LC6_EVENT_MAXPEERS_IN 5
-
- 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;
- uint8_t hardcoded;
- 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;
- pthread_t ev_thread;
- } 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
|