A library for a decentralised peer-to-peer chat over IPv6 only.
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.

lc6_common.h 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef LC6_COMMON_H
  2. #define LC6_COMMON_H
  3. #include <sys/param.h>
  4. #include <arpa/inet.h>
  5. #include "../inc/libchat6.h"
  6. #include "../inc/lc6_helpers.h"
  7. #ifdef LC6_DEBUG
  8. #include "../inc/lc6_debug.h"
  9. #endif
  10. typedef struct LC6_NODE {
  11. unsigned char *pub_key;
  12. unsigned char *priv_key;
  13. } LC6_NODE;
  14. typedef struct LC6_USER {
  15. struct LC6_USER *prev;
  16. struct LC6_USER *next;
  17. unsigned char nickname[256];
  18. unsigned char pub_key[32];
  19. unsigned char priv_key[32];
  20. uint8_t status;
  21. } LC6_USER;
  22. typedef struct LC6_FRIEND {
  23. struct LC6_FRIEND *prev;
  24. struct LC6_FRIEND *next;
  25. unsigned char nickname[256];
  26. unsigned char pub_key[32];
  27. uint8_t status;
  28. } LC6_FRIEND;
  29. typedef struct LC6_MSG_TLV {
  30. int type;
  31. int length;
  32. unsigned char *value;
  33. } LC6_MSG_TLV;
  34. typedef struct LC6_MSG {
  35. uint64_t timestamp;
  36. int type;
  37. LC6_MSG_TLV **tlv;
  38. } LC6_MSG;
  39. enum LC6_MSG_TYPE_ENUM {
  40. LC6_MSG_TYPE_CLIENT_ONLINE,
  41. LC6_MSG_TYPE_CLIENT_UPDATE,
  42. LC6_MSG_TYPE_CLIENT_OFFLINE,
  43. LC6_MSG_TYPE_KEEPALIVE_QUERY,
  44. LC6_MSG_TYPE_KEEPALIVE_RESPONSE,
  45. LC6_MSG_TYPE_FRIEND_REQUEST,
  46. LC6_MSG_TYPE_FRIEND_CONFIRM,
  47. LC6_MSG_TYPE_MESSAGE_SEND,
  48. LC6_MSG_TYPE_MESSAGE_RECV,
  49. LC6_MSG_TYPE_MESSAGE_READ,
  50. LC6_MSG_TYPE_NEIGHBOURS_REQUEST,
  51. LC6_MSG_TYPE_NEIGHBOURS_RESPONSE
  52. };
  53. enum LC6_MSG_TLV_ENUM {
  54. LC6_MSG_TLV_NICKNAME,
  55. LC6_MSG_TLV_KEY,
  56. LC6_MSG_TLV_NONCE,
  57. LC6_MSG_TLV_ICON,
  58. LC6_MSG_TLV_METRIC,
  59. LC6_MSG_TLV_MSGID,
  60. LC6_MSG_TLV_CHATID,
  61. LC6_MSG_TLV_NEIGHBOUR
  62. };
  63. enum LC6_MSG_TLV_TYPE_ENUM {
  64. LC6_MSG_TLV_TYPE_UTF8,
  65. LC6_MSG_TLV_TYPE_BINARY,
  66. LC6_MSG_TLV_TYPE_INTEGER,
  67. LC6_MSG_TLV_TYPE_UUID,
  68. LC6_MSG_TLV_TYPE_IPPORT
  69. };
  70. #define LC6_CONFIG_BOOTSTRAP "bootstrap.bin"
  71. #define LC6_CONFIG_USER "user.bin"
  72. #define LC6_CONFIG_FRIEND "friends.bin"
  73. #define LC6_CONFIG_MAXLEN 50
  74. typedef struct LC6_IPADDR {
  75. uint8_t af;
  76. union addr {
  77. uint32_t inet;
  78. unsigned char inet6[16];
  79. } addr;
  80. } LC6_IPADDR;
  81. typedef struct LC6_BOOTSTRAP {
  82. struct LC6_BOOTSTRAP *prev;
  83. struct LC6_BOOTSTRAP *next;
  84. uint64_t last_contact;
  85. LC6_IPADDR ip;
  86. } LC6_BOOTSTRAP;
  87. typedef struct LC6_CTX {
  88. char path[MAXPATHLEN-LC6_CONFIG_MAXLEN];
  89. LC6_USER *user;
  90. LC6_USER *node;
  91. LC6_FRIEND *friend;
  92. LC6_BOOTSTRAP *bootstrap;
  93. } LC6_CTX;
  94. extern int LC6_MSG_TLV_TYPE_INT[8];
  95. extern unsigned char LC6_MSG_TYPE_STR[13][30];
  96. extern unsigned char LC6_MSG_TLV_STR[8][20];
  97. #endif