A library for a decentralised peer-to-peer chat over IPv6 only.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

lc6_common.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #ifndef LC6_COMMON_H
  2. #define LC6_COMMON_H
  3. #include <pthread.h>
  4. #include <sys/param.h>
  5. #include <arpa/inet.h>
  6. #include <sodium.h>
  7. #include "../inc/libchat6.h"
  8. #include "../inc/lc6_helpers.h"
  9. #ifdef LC6_DEBUG
  10. #include "../inc/lc6_debug.h"
  11. #endif
  12. #define LC6_CRYPTO_HASHLEN crypto_generichash_BYTES
  13. #define LC6_CRYPTO_HASHSIGNLEN (crypto_secretbox_NONCEBYTES+crypto_box_MACBYTES+crypto_generichash_BYTES)
  14. #define LC6_CRYPTO_PUBLEN crypto_kx_PUBLICKEYBYTES
  15. #define LC6_CRYPTO_PRIVLEN crypto_kx_SECRETKEYBYTES
  16. #define LC6_CRYPTO_RXLEN crypto_kx_SESSIONKEYBYTES
  17. #define LC6_CRYPTO_TXLEN crypto_kx_SESSIONKEYBYTES
  18. #define LC6_EVENT_MAXPEERS_OUT 5
  19. #define LC6_EVENT_MAXPEERS_IN 5
  20. typedef struct LC6_NODE {
  21. unsigned char *pub_key;
  22. unsigned char *priv_key;
  23. } LC6_NODE;
  24. typedef struct LC6_PEER {
  25. int sock;
  26. LC6_NODE keys;
  27. unsigned char bufi[65536];
  28. unsigned char bufo[65536];
  29. } LC6_PEER;
  30. typedef struct LC6_USER {
  31. struct LC6_USER *prev;
  32. struct LC6_USER *next;
  33. unsigned char nickname[256];
  34. unsigned char pub_key[LC6_CRYPTO_PUBLEN];
  35. unsigned char priv_key[LC6_CRYPTO_PRIVLEN];
  36. uint8_t status;
  37. } LC6_USER;
  38. typedef struct LC6_FRIEND {
  39. struct LC6_FRIEND *prev;
  40. struct LC6_FRIEND *next;
  41. unsigned char nickname[256];
  42. unsigned char pub_key[LC6_CRYPTO_PUBLEN];
  43. unsigned char key_rx[LC6_CRYPTO_RXLEN];
  44. unsigned char key_tx[LC6_CRYPTO_TXLEN];
  45. uint8_t status;
  46. } LC6_FRIEND;
  47. typedef struct LC6_MSG_TLV {
  48. int type;
  49. int length;
  50. unsigned char *value;
  51. } LC6_MSG_TLV;
  52. typedef struct LC6_MSG {
  53. uint64_t timestamp;
  54. int type;
  55. LC6_MSG_TLV **tlv;
  56. } LC6_MSG;
  57. enum LC6_MSG_TYPE_ENUM {
  58. LC6_MSG_TYPE_CLIENT_ONLINE,
  59. LC6_MSG_TYPE_CLIENT_UPDATE,
  60. LC6_MSG_TYPE_CLIENT_OFFLINE,
  61. LC6_MSG_TYPE_KEEPALIVE_REQUEST,
  62. LC6_MSG_TYPE_KEEPALIVE_RESPONSE,
  63. LC6_MSG_TYPE_FRIEND_REQUEST,
  64. LC6_MSG_TYPE_FRIEND_RESPONSE,
  65. LC6_MSG_TYPE_MESSAGE_SEND,
  66. LC6_MSG_TYPE_MESSAGE_RECV,
  67. LC6_MSG_TYPE_MESSAGE_READ,
  68. LC6_MSG_TYPE_NEIGHBOURS_REQUEST,
  69. LC6_MSG_TYPE_NEIGHBOURS_RESPONSE
  70. };
  71. enum LC6_MSG_TLV_ENUM {
  72. LC6_MSG_TLV_NICKNAME,
  73. LC6_MSG_TLV_KEY,
  74. LC6_MSG_TLV_NONCE,
  75. LC6_MSG_TLV_ICON,
  76. LC6_MSG_TLV_METRIC,
  77. LC6_MSG_TLV_MSGID,
  78. LC6_MSG_TLV_CHATID,
  79. LC6_MSG_TLV_NEIGHBOUR
  80. };
  81. enum LC6_MSG_TLV_TYPE_ENUM {
  82. LC6_MSG_TLV_TYPE_UTF8,
  83. LC6_MSG_TLV_TYPE_BINARY,
  84. LC6_MSG_TLV_TYPE_INTEGER,
  85. LC6_MSG_TLV_TYPE_UUID,
  86. LC6_MSG_TLV_TYPE_IPPORT
  87. };
  88. #define LC6_CONFIG_BOOTSTRAP "bootstrap.bin"
  89. #define LC6_CONFIG_USER "user.bin"
  90. #define LC6_CONFIG_FRIEND "friends.bin"
  91. #define LC6_CONFIG_MAXLEN 50
  92. typedef struct LC6_IPADDR {
  93. uint8_t af;
  94. union addr {
  95. uint32_t inet;
  96. unsigned char inet6[16];
  97. } addr;
  98. } LC6_IPADDR;
  99. typedef struct LC6_BOOTSTRAP {
  100. struct LC6_BOOTSTRAP *prev;
  101. struct LC6_BOOTSTRAP *next;
  102. uint64_t last_contact;
  103. uint8_t hardcoded;
  104. LC6_IPADDR ip;
  105. } LC6_BOOTSTRAP;
  106. typedef struct LC6_CTX {
  107. char path[MAXPATHLEN-LC6_CONFIG_MAXLEN];
  108. LIBCHAT_CB *callback;
  109. LC6_USER *user;
  110. LC6_NODE *node;
  111. LC6_FRIEND *friend;
  112. LC6_BOOTSTRAP *bootstrap;
  113. pthread_t ev_thread;
  114. } LC6_CTX;
  115. extern int LC6_MSG_TLV_TYPE_INT[8];
  116. extern unsigned char LC6_MSG_TYPE_STR[13][30];
  117. extern unsigned char LC6_MSG_TLV_STR[8][20];
  118. #endif