commit 8e1c9b1: [Project] Store settings id directly
Vsevolod Stakhov
vsevolod at highsecure.ru
Fri Jun 7 15:21:04 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-06-07 13:40:37 +0100
URL: https://github.com/rspamd/rspamd/commit/8e1c9b1e7c1144abff211c93736164f9311d929f
[Project] Store settings id directly
---
src/libserver/mempool_vars_internal.h | 1 -
src/libserver/protocol.c | 13 ++++---------
src/libserver/task.h | 3 ++-
src/lua/lua_task.c | 7 ++-----
4 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/src/libserver/mempool_vars_internal.h b/src/libserver/mempool_vars_internal.h
index ad2958ab4..c062d44d4 100644
--- a/src/libserver/mempool_vars_internal.h
+++ b/src/libserver/mempool_vars_internal.h
@@ -21,7 +21,6 @@
#define RSPAMD_MEMPOOL_AVG_WORDS_LEN "avg_words_len"
#define RSPAMD_MEMPOOL_SHORT_WORDS_CNT "short_words_cnt"
#define RSPAMD_MEMPOOL_HEADERS_HASH "headers_hash"
-#define RSPAMD_MEMPOOL_SETTINGS_HASH "settings_hash"
#define RSPAMD_MEMPOOL_MTA_TAG "MTA-Tag"
#define RSPAMD_MEMPOOL_MTA_NAME "MTA-Name"
#define RSPAMD_MEMPOOL_SPF_DOMAIN "spf_domain"
diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c
index 34eaabe89..3574b94d2 100644
--- a/src/libserver/protocol.c
+++ b/src/libserver/protocol.c
@@ -406,16 +406,12 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
}
IF_HEADER (SETTINGS_ID_HEADER) {
guint64 h;
- guint32 *hp;
msg_debug_protocol ("read settings-id header, value: %V", hv);
h = rspamd_cryptobox_fast_hash_specific (RSPAMD_CRYPTOBOX_XXHASH64,
- hv_tok->begin, hv_tok->len, 0xdeadbabe);
- hp = rspamd_mempool_alloc (task->task_pool, sizeof (*hp));
- memcpy (hp, &h, sizeof (*hp));
- rspamd_mempool_set_variable (task->task_pool,
- RSPAMD_MEMPOOL_SETTINGS_HASH,
- hp, NULL);
+ hv_tok->begin, hv_tok->len, 0x0);
+ /* Take the lower part of hash as LE number */
+ task->settings_id = (guint32)GUINT64_TO_LE (h);
}
break;
case 'u':
@@ -1628,8 +1624,7 @@ rspamd_protocol_write_log_pipe (struct rspamd_task *task)
ls = g_malloc0 (sz);
/* Handle settings id */
- sid = rspamd_mempool_get_variable (task->task_pool,
- "settings_hash");
+ sid = task->settings_id;
if (sid) {
ls->settings_id = *sid;
diff --git a/src/libserver/task.h b/src/libserver/task.h
index 763866987..079e388df 100644
--- a/src/libserver/task.h
+++ b/src/libserver/task.h
@@ -136,7 +136,6 @@ enum rspamd_newlines_type;
*/
struct rspamd_task {
struct rspamd_worker *worker; /**< pointer to worker object */
- guint processed_stages; /**< bits of stages that are processed */
enum rspamd_command cmd; /**< command */
gint sock; /**< socket descriptor */
guint32 flags; /**< Bit flags */
@@ -206,6 +205,8 @@ struct rspamd_task {
gpointer checkpoint; /**< Opaque checkpoint data */
ucl_object_t *settings; /**< Settings applied to task */
+ guint32 processed_stages; /**< bits of stages that are processed */
+ guint32 settings_id; /**< hashed settings id */
const gchar *classifier; /**< Classifier to learn (if needed) */
struct rspamd_lang_detector *lang_det; /**< Languages detector */
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index c1b50484d..3218a958f 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -4869,14 +4869,11 @@ lua_task_get_settings_id (lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task (L, 1);
- guint32 *hp;
if (task != NULL) {
- hp = rspamd_mempool_get_variable (task->task_pool,
- RSPAMD_MEMPOOL_SETTINGS_HASH);
- if (hp) {
- lua_pushnumber (L, *hp);
+ if (task->settings_id) {
+ lua_pushnumber (L, task->settings_id);
}
else {
lua_pushnil (L);
More information about the Commits
mailing list