From: Vsevolod Stakhov Date: Mon, 22 Dec 2014 17:47:26 +0000 (+0000) Subject: Fix shingles key init. X-Git-Tag: 0.8.0~32 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f912ce34c0fa3a4472f05a4428a3062bf537bd3d;p=rspamd.git Fix shingles key init. --- diff --git a/src/libserver/fuzzy_backend.c b/src/libserver/fuzzy_backend.c index 1c0ceb8b5..3a4c198a7 100644 --- a/src/libserver/fuzzy_backend.c +++ b/src/libserver/fuzzy_backend.c @@ -144,14 +144,14 @@ static struct rspamd_fuzzy_stmts { }, { .idx = RSPAMD_FUZZY_BACKEND_CHECK_SHINGLE, - .sql = "SELECT digest_id FROM shingles WHERE value=? AND number=?", + .sql = "SELECT digest_id FROM shingles WHERE value=?1 AND number=?2", .args = "IS", .stmt = NULL, .result = SQLITE_ROW }, { .idx = RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID, - .sql = "SELECT digest, value, time, flag FROM digests WHERE id=?", + .sql = "SELECT digest, value, time, flag FROM digests WHERE id=?1", .args = "I", .stmt = NULL, .result = SQLITE_ROW @@ -591,6 +591,7 @@ rspamd_fuzzy_backend_check (struct rspamd_fuzzy_backend *backend, else { shingle_values[i] = -1; } + msg_debug ("looking for shingle %d -> %L: %d", i, shcmd->sgl.hashes[i], rc); } qsort (shingle_values, RSPAMD_SHINGLE_SIZE, sizeof (gint64), rspamd_fuzzy_backend_int64_cmp); @@ -621,6 +622,7 @@ rspamd_fuzzy_backend_check (struct rspamd_fuzzy_backend *backend, if (sel_id != -1) { /* We have some id selected here */ rep.prob = (gdouble)max_cnt / (gdouble)RSPAMD_SHINGLE_SIZE; + msg_debug ("found fuzzy hash with probability %.2f", rep.prob); rc = rspamd_fuzzy_backend_run_stmt (backend, RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID, sel_id); if (rc == SQLITE_OK) { @@ -680,6 +682,7 @@ rspamd_fuzzy_backend_add (struct rspamd_fuzzy_backend *backend, rspamd_fuzzy_backend_run_stmt (backend, RSPAMD_FUZZY_BACKEND_INSERT_SHINGLE, shcmd->sgl.hashes[i], i, id); + msg_debug ("add shingle %d -> %L: %d", i, shcmd->sgl.hashes[i], id); } } } diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 55e155bf4..7f70ae2d1 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -383,8 +383,8 @@ fuzzy_parse_rule (struct rspamd_config *cfg, const ucl_object_t *obj) k = "rspamd"; } rule->shingles_key = g_string_sized_new (16); - blake2 (rule->hash_key->str, k, NULL, 16, strlen (k), 0); - rule->hash_key->len = 16; + blake2 (rule->shingles_key->str, k, NULL, 16, strlen (k), 0); + rule->shingles_key->len = 16; if (rspamd_upstreams_count (rule->servers) == 0) { msg_err ("no servers defined for fuzzy rule with symbol: %s", @@ -578,6 +578,7 @@ fuzzy_cmd_from_text_part (struct fuzzy_rule *rule, } blake2b_final (&st, shcmd->basic.digest, sizeof (shcmd->basic.digest)); + msg_debug ("loading shingles with key %*xs", 16, rule->shingles_key->str); sh = rspamd_shingles_generate (part->words, rule->shingles_key->str, pool, rspamd_shingles_default_filter, NULL); if (sh != NULL) {