gint peer_fd;
struct event peer_ev;
/* Local keypair */
+ gpointer default_keypair; /* Bad clash, need for parse keypair */
gpointer default_key;
GHashTable *keys;
- GHashTable *keys_stats;
gboolean encrypted_only;
struct rspamd_keypair_cache *keypair_cache;
struct rspamd_fuzzy_backend *backend;
rspamd_lru_hash_t *last_ips;
};
+struct fuzzy_key {
+ struct rspamd_http_keypair *key;
+ struct fuzzy_key_stat *stat;
+};
+
static void rspamd_fuzzy_write_reply (struct fuzzy_session *session);
static gboolean
g_slice_free1 (sizeof (*st), st);
}
+static void
+fuzzy_key_dtor (gpointer p)
+{
+ struct fuzzy_key *key = p;
+
+ if (key->stat) {
+ fuzzy_key_stat_dtor (key->stat);
+ }
+ if (key->key) {
+ rspamd_http_connection_key_unref (key->key);
+ }
+
+ g_slice_free1 (sizeof (*key), key);
+}
+
static void
rspamd_fuzzy_process_updates_queue (struct rspamd_fuzzy_storage_ctx *ctx)
{
struct rspamd_fuzzy_encrypted_req_hdr *hdr;
guchar *payload;
gsize payload_len;
- struct rspamd_http_keypair rk, *lk;
+ struct rspamd_http_keypair rk;
+ struct fuzzy_key *key;
if (s->ctx->default_key == NULL) {
msg_warn ("received encrypted request when encryption is not enabled");
}
/* Try to find the desired key */
- lk = g_hash_table_lookup (s->ctx->keys, hdr->key_id);
- s->key_stat = g_hash_table_lookup (s->ctx->keys_stats, hdr->key_id);
+ key = g_hash_table_lookup (s->ctx->keys, hdr->key_id);
- if (lk == NULL) {
+ if (key == NULL) {
/* Unknown key, assume default one */
- lk = s->ctx->default_key;
+ key = s->ctx->default_key;
}
+ s->key_stat = key->stat;
+
/* Now process keypair */
memcpy (rk.pk, hdr->pubkey, sizeof (rk.pk));
- rspamd_keypair_cache_process (s->ctx->keypair_cache, lk, &rk);
+ rspamd_keypair_cache_process (s->ctx->keypair_cache, key->key, &rk);
/* Now decrypt request */
if (!rspamd_cryptobox_decrypt_nm_inplace (payload, payload_len, hdr->nonce,
GHashTableIter it, ip_it;
GHashTable *ip_hash;
struct fuzzy_key_stat *key_stat;
+ struct fuzzy_key *key;
struct rspamd_http_keypair *kp;
rspamd_lru_element_t *lru_elt;
ucl_object_t *obj, *elt, *ip_elt, *ip_cur;
g_hash_table_iter_init (&it, ctx->keys);
while (g_hash_table_iter_next (&it, &k, &v)) {
- kp = v;
- key_stat = g_hash_table_lookup (ctx->keys_stats, kp->pk);
+ key = v;
+ kp = key->key;
+ key_stat = key->stat;
if (key_stat) {
rspamd_snprintf (keyname, sizeof (keyname), "%8xs", k);
struct rspamd_fuzzy_storage_ctx *ctx;
struct rspamd_http_keypair *kp;
struct fuzzy_key_stat *keystat;
+ struct fuzzy_key *key;
const ucl_object_t *cur;
ucl_object_iter_t it = NULL;
gboolean ret;
ctx = pd->user_struct;
- pd->offset = G_STRUCT_OFFSET (struct rspamd_fuzzy_storage_ctx, default_key);
+ pd->offset = G_STRUCT_OFFSET (struct rspamd_fuzzy_storage_ctx, default_keypair);
/*
* Single key
}
/* Insert key to the hash table */
- kp = ctx->default_key;
+ kp = ctx->default_keypair;
if (kp == NULL) {
return FALSE;
}
- g_hash_table_insert (ctx->keys, kp->pk, kp);
+ key = g_slice_alloc (sizeof (*key));
+ key->key = kp;
keystat = g_slice_alloc0 (sizeof (*keystat));
/* Hash of ip -> fuzzy_key_stat */
keystat->last_ips = rspamd_lru_hash_new_full (0, 1024,
(GDestroyNotify)rspamd_inet_address_destroy, fuzzy_key_stat_dtor,
rspamd_inet_address_hash, rspamd_inet_address_equal);
- g_hash_table_insert (ctx->keys_stats, kp->pk, keystat);
+ key->stat = keystat;
+ g_hash_table_insert (ctx->keys, kp->pk, key);
+ ctx->default_key = key;
msg_info_pool ("loaded keypair %8xs", kp->pk);
}
else if (ucl_object_type (obj) == UCL_ARRAY) {
ctx->expire = DEFAULT_EXPIRE;
ctx->keypair_cache_size = DEFAULT_KEYPAIR_CACHE_SIZE;
ctx->keys = g_hash_table_new_full (fuzzy_kp_hash, fuzzy_kp_equal,
- NULL, rspamd_http_connection_key_unref);
- ctx->keys_stats = g_hash_table_new_full (fuzzy_kp_hash, fuzzy_kp_equal,
- NULL, fuzzy_key_stat_dtor);
+ NULL, fuzzy_key_dtor);
rspamd_rcl_register_worker_option (cfg, type, "hashfile",
rspamd_rcl_parse_struct_string, ctx,
}
g_hash_table_unref (ctx->keys);
- g_hash_table_unref (ctx->keys_stats);
exit (EXIT_SUCCESS);
}