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.3KB

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