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.

fuzzy_wire.h 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef RSPAMD_FUZZY_STORAGE_H
  2. #define RSPAMD_FUZZY_STORAGE_H
  3. #include "config.h"
  4. #include "rspamd.h"
  5. #include "shingles.h"
  6. #include "cryptobox.h"
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. #define RSPAMD_FUZZY_VERSION 4
  11. #define RSPAMD_FUZZY_KEYLEN 8
  12. /* Commands for fuzzy storage */
  13. #define FUZZY_CHECK 0
  14. #define FUZZY_WRITE 1
  15. #define FUZZY_DEL 2
  16. #define FUZZY_STAT 3
  17. #define FUZZY_CLIENT_MAX 3
  18. /* Internal commands */
  19. #define FUZZY_REFRESH 100 /* Update expire */
  20. #define FUZZY_DUP 101 /* Skip duplicate in update queue */
  21. /**
  22. * The epoch of the fuzzy client
  23. */
  24. enum rspamd_fuzzy_epoch {
  25. RSPAMD_FUZZY_EPOCH6 = 0, /**< pre 0.6.x */
  26. RSPAMD_FUZZY_EPOCH8, /**< 0.8 till 0.9 */
  27. RSPAMD_FUZZY_EPOCH9, /**< 0.9 + */
  28. RSPAMD_FUZZY_EPOCH10, /**< 1.0+ encryption */
  29. RSPAMD_FUZZY_EPOCH11, /**< 1.7+ extended reply */
  30. RSPAMD_FUZZY_EPOCH_MAX
  31. };
  32. RSPAMD_PACKED(rspamd_fuzzy_cmd) {
  33. guint8 version;
  34. guint8 cmd;
  35. guint8 shingles_count;
  36. guint8 flag;
  37. gint32 value;
  38. guint32 tag;
  39. gchar digest[rspamd_cryptobox_HASHBYTES];
  40. };
  41. RSPAMD_PACKED(rspamd_fuzzy_shingle_cmd) {
  42. struct rspamd_fuzzy_cmd basic;
  43. struct rspamd_shingle sgl;
  44. };
  45. RSPAMD_PACKED(rspamd_fuzzy_reply_v1) {
  46. gint32 value;
  47. guint32 flag;
  48. guint32 tag;
  49. float prob;
  50. };
  51. RSPAMD_PACKED(rspamd_fuzzy_reply) {
  52. struct rspamd_fuzzy_reply_v1 v1;
  53. gchar digest[rspamd_cryptobox_HASHBYTES];
  54. guint32 ts;
  55. guchar reserved[12];
  56. };
  57. RSPAMD_PACKED(rspamd_fuzzy_encrypted_req_hdr) {
  58. guchar magic[4];
  59. guchar key_id[RSPAMD_FUZZY_KEYLEN];
  60. guchar pubkey[32];
  61. guchar nonce[rspamd_cryptobox_MAX_NONCEBYTES];
  62. guchar mac[rspamd_cryptobox_MAX_MACBYTES];
  63. };
  64. RSPAMD_PACKED(rspamd_fuzzy_encrypted_cmd) {
  65. struct rspamd_fuzzy_encrypted_req_hdr hdr;
  66. struct rspamd_fuzzy_cmd cmd;
  67. };
  68. RSPAMD_PACKED(rspamd_fuzzy_encrypted_shingle_cmd) {
  69. struct rspamd_fuzzy_encrypted_req_hdr hdr;
  70. struct rspamd_fuzzy_shingle_cmd cmd;
  71. };
  72. RSPAMD_PACKED(rspamd_fuzzy_encrypted_rep_hdr) {
  73. guchar nonce[rspamd_cryptobox_MAX_NONCEBYTES];
  74. guchar mac[rspamd_cryptobox_MAX_MACBYTES];
  75. };
  76. RSPAMD_PACKED(rspamd_fuzzy_encrypted_reply) {
  77. struct rspamd_fuzzy_encrypted_rep_hdr hdr;
  78. struct rspamd_fuzzy_reply rep;
  79. };
  80. static const guchar fuzzy_encrypted_magic[4] = {'r', 's', 'f', 'e'};
  81. enum rspamd_fuzzy_extension_type {
  82. RSPAMD_FUZZY_EXT_SOURCE_DOMAIN = 'd',
  83. RSPAMD_FUZZY_EXT_SOURCE_IP4 = '4',
  84. RSPAMD_FUZZY_EXT_SOURCE_IP6 = '6',
  85. };
  86. struct rspamd_fuzzy_cmd_extension {
  87. enum rspamd_fuzzy_extension_type ext;
  88. guint length;
  89. struct rspamd_fuzzy_cmd_extension *next;
  90. guchar *payload;
  91. };
  92. struct rspamd_fuzzy_stat_entry {
  93. const gchar *name;
  94. guint32 fuzzy_cnt;
  95. };
  96. RSPAMD_PACKED(fuzzy_peer_cmd) {
  97. gint32 is_shingle;
  98. union {
  99. struct rspamd_fuzzy_cmd normal;
  100. struct rspamd_fuzzy_shingle_cmd shingle;
  101. } cmd;
  102. };
  103. #ifdef __cplusplus
  104. }
  105. #endif
  106. #endif