}
static void
-rspamd_fuzzy_process_command (struct fuzzy_session *session)
+rspamd_fuzzy_process_command (struct fuzzy_session *session,
+ enum rspamd_fuzzy_epoch epoch)
{
struct rspamd_fuzzy_reply rep = {0, 0, 0, 0.0};
gboolean res = FALSE;
if (session->cmd->cmd == FUZZY_CHECK) {
rep = rspamd_fuzzy_backend_check (session->ctx->backend, session->cmd,
session->ctx->expire);
+ /* XXX: actually, these updates are not atomic, but we don't care */
+ server_stat->fuzzy_hashes_checked[epoch] ++;
+
+ if (rep.prob > 0.5) {
+ server_stat->fuzzy_hashes_found[epoch] ++;
+ }
}
else {
rep.flag = session->cmd->flag;
}
-static gboolean
+static enum rspamd_fuzzy_epoch
rspamd_fuzzy_command_valid (struct rspamd_fuzzy_cmd *cmd, gint r)
{
+ enum rspamd_fuzzy_epoch ret = RSPAMD_FUZZY_EPOCH_MAX;
+
if (cmd->version == RSPAMD_FUZZY_VERSION) {
if (cmd->shingles_count > 0) {
if (r == sizeof (struct rspamd_fuzzy_shingle_cmd)) {
- return TRUE;
+ ret = RSPAMD_FUZZY_EPOCH9;
}
}
else {
- return (r == sizeof (*cmd));
+ if (r == sizeof (*cmd)) {
+ ret = RSPAMD_FUZZY_EPOCH9;
+ }
}
}
else if (cmd->version == 2) {
*/
if (cmd->shingles_count > 0) {
if (r == sizeof (struct rspamd_fuzzy_shingle_cmd)) {
- return TRUE;
+ ret = RSPAMD_FUZZY_EPOCH8;
}
}
else {
- return (r == sizeof (*cmd));
+ ret = RSPAMD_FUZZY_EPOCH8;
}
}
- return FALSE;
+ return ret;
}
/*
* Accept new connection and construct task
guint8 buf[2048];
struct rspamd_fuzzy_cmd *cmd = NULL, lcmd;
struct legacy_fuzzy_cmd *l;
+ enum rspamd_fuzzy_epoch epoch = RSPAMD_FUZZY_EPOCH_MAX;
session.worker = worker;
session.fd = fd;
lcmd.value = l->value;
lcmd.tag = 0;
cmd = &lcmd;
+ epoch = RSPAMD_FUZZY_EPOCH6;
}
else if ((guint)r >= sizeof (struct rspamd_fuzzy_cmd)) {
/* Check shingles count sanity */
session.legacy = FALSE;
cmd = (struct rspamd_fuzzy_cmd *)buf;
- if (!rspamd_fuzzy_command_valid (cmd, r)) {
+ epoch = rspamd_fuzzy_command_valid (cmd, r);
+ if (epoch == RSPAMD_FUZZY_EPOCH_MAX) {
/* Bad input */
msg_debug ("invalid fuzzy command of size %d received", r);
+ cmd = NULL;
}
}
else {
}
if (cmd != NULL) {
session.cmd = cmd;
- rspamd_fuzzy_process_command (&session);
+ rspamd_fuzzy_process_command (&session, epoch);
}
rspamd_inet_address_destroy (session.addr);
struct rspamd_dns_resolver;
struct rspamd_task;
+/**
+ * The epoch of the fuzzy client
+ */
+enum rspamd_fuzzy_epoch {
+ RSPAMD_FUZZY_EPOCH6 = 0, /**< pre 0.6.x */
+ RSPAMD_FUZZY_EPOCH8, /**< 0.8 till 0.9 */
+ RSPAMD_FUZZY_EPOCH9, /**< 0.9 + */
+ RSPAMD_FUZZY_EPOCH_MAX
+};
+
/**
* Server statistics
*/
guint messages_learned; /**< messages learned */
guint fuzzy_hashes; /**< number of fuzzy hashes stored */
guint fuzzy_hashes_expired; /**< number of fuzzy hashes expired */
+ guint64 fuzzy_hashes_checked[RSPAMD_FUZZY_EPOCH_MAX]; /**< ammount of check requests for each epoch */
+ guint64 fuzzy_hashes_found[RSPAMD_FUZZY_EPOCH_MAX]; /**< amount of hashes found by epoch */
};
/**