Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

fuzzy_wire.h 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_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. enum rspamd_fuzzy_extension_type {
  79. RSPAMD_FUZZY_EXT_SOURCE_DOMAIN = 'd',
  80. RSPAMD_FUZZY_EXT_SOURCE_IP4 = '4',
  81. RSPAMD_FUZZY_EXT_SOURCE_IP6 = '6',
  82. };
  83. struct rspamd_fuzzy_cmd_extension {
  84. enum rspamd_fuzzy_extension_type ext;
  85. guint length;
  86. struct rspamd_fuzzy_cmd_extension *next;
  87. guchar *payload;
  88. };
  89. struct rspamd_fuzzy_stat_entry {
  90. const gchar *name;
  91. guint32 fuzzy_cnt;
  92. };
  93. RSPAMD_PACKED(fuzzy_peer_cmd) {
  94. gint32 is_shingle;
  95. union {
  96. struct rspamd_fuzzy_cmd normal;
  97. struct rspamd_fuzzy_shingle_cmd shingle;
  98. } cmd;
  99. };
  100. #ifdef __cplusplus
  101. }
  102. #endif
  103. #endif