]> source.dussan.org Git - rspamd.git/commitdiff
Update keypairs cache.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 2 Feb 2015 22:17:48 +0000 (22:17 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 2 Feb 2015 22:17:48 +0000 (22:17 +0000)
src/libutil/hash.c
src/libutil/http.c
src/libutil/keypair_private.h
src/libutil/keypairs_cache.c
src/libutil/keypairs_cache.h

index ec952e87bb37ad0dcd68643c9daa008e0e6b5a14..9a9f98e2eb5b7078a2bdc77f6ca624b4727e6ef3 100644 (file)
@@ -151,6 +151,10 @@ rspamd_lru_hash_lookup (rspamd_lru_hash_t *hash, gpointer key, time_t now)
                                return NULL;
                        }
                }
+               else {
+                       res->store_time = now;
+               }
+
                return res->data;
        }
 
@@ -188,6 +192,9 @@ rspamd_lru_hash_insert (rspamd_lru_hash_t *hash, gpointer key, gpointer value,
                                        }
                                }
                        }
+                       else {
+                               /* XXX: use binary heap here */
+                       }
                        if (removed == 0) {
                                rspamd_lru_hash_destroy_node (hash->elements);
                        }
index 9b8e2a98c7ac2ca9df831674ff55926cc4708db4..b2a33b97f5b0a561495c119a47d96e8308fe1418 100644 (file)
 #include "tweetnacl.h"
 #include "blake2.h"
 #include "ottery.h"
-
+#include "keypair_private.h"
 #include <limits.h>
 
-struct rspamd_http_keypair {
-       guchar pk[crypto_box_PUBLICKEYBYTES];
-       guchar sk[crypto_box_SECRETKEYBYTES];
-       guchar id[BLAKE2B_OUTBYTES];
-       ref_entry_t ref;
-};
-
 struct rspamd_http_connection_private {
        struct _rspamd_http_privbuf {
                GString *data;
index 66d04ad7a8411cd26b6d1a6a7d454927cd62603b..287a302b358b53c45fe75f471da4be12ace34569 100644 (file)
@@ -34,6 +34,7 @@ struct rspamd_http_keypair {
        guchar pk[crypto_box_PUBLICKEYBYTES];
        guchar sk[crypto_box_SECRETKEYBYTES];
        guchar id[BLAKE2B_OUTBYTES];
+       guchar nm[crypto_box_BEFORENMBYTES];
        ref_entry_t ref;
 };
 
index 91478bf12c0d85871d3f7f8d39da732ee714b570..1e747028f04ef25ad8a895946b85464c979d4e37 100644 (file)
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "config.h"
+#include "main.h"
+#include "keypairs_cache.h"
+#include "keypair_private.h"
+#include "hash.h"
+
+struct rspamd_keypair_elt {
+       guchar nm[crypto_box_BEFORENMBYTES];
+};
+
+struct rspamd_keypair_cache {
+       rspamd_lru_hash_t *hash;
+};
+
+struct rspamd_keypair_cache *
+rspamd_keypair_cache_new (guint max_items)
+{
+       struct rspamd_keypair_cache *c;
+
+       g_assert (max_items > 0);
+
+       c = g_slice_alloc (sizeof (*c));
+       c->hash = rspamd_lru_hash_new (max_items, -1, g_free, g_free);
+
+       return c;
+}
+
+void
+rspamd_keypair_cache_process (struct rspamd_keypair_cache *c,
+               gpointer lk, gpointer rk)
+{
+       struct rspamd_http_keypair *kp_local = (struct rspamd_http_keypair *)lk,
+                       *kp_remote = (struct rspamd_http_keypair *)rk;
+       guchar nm[crypto_box_BEFORENMBYTES];
+
+       g_assert (kp_local != NULL);
+       g_assert (kp_remote != NULL);
+
+       /*
+        * XXX: at this point we do nothing, since LRU hash is completely broken
+        * and useless for our purposes
+        */
+       crypto_box_beforenm (nm, kp_remote->pk, kp_local->sk);
+       memcpy (kp_remote->nm, nm, sizeof (nm));
+       memcpy (kp_local->nm, nm, sizeof (nm));
+}
+
+void
+rspamd_keypair_cache_destroy (struct rspamd_keypair_cache *c)
+{
+       if (c != NULL) {
+               rspamd_lru_hash_destroy (c->hash);
+               g_slice_free1 (sizeof (*c), c);
+       }
+}
index 88bc8ba326a880c643fad910afdeba067270119e..544d73456aa92b770807106b4c3aab869578722f 100644 (file)
 #ifndef KEYPAIRS_CACHE_H_
 #define KEYPAIRS_CACHE_H_
 
+#include "config.h"
+
+struct rspamd_keypair_cache;
+
+/**
+ * Create new keypair cache of the specified size
+ * @param max_items defines maximum count of elements in the cache
+ * @return new cache
+ */
+struct rspamd_keypair_cache * rspamd_keypair_cache_new (guint max_items);
+
+
+/**
+ * Process local and remote keypair setting beforenm value as appropriate
+ * @param c cache of keypairs
+ * @param lk local key
+ * @param rk remote key
+ */
+void rspamd_keypair_cache_process (struct rspamd_keypair_cache *c,
+               gpointer lk, gpointer rk);
+
+/**
+ * Destroy old keypair cache
+ * @param c cache object
+ */
+void rspamd_keypair_cache_destroy (struct rspamd_keypair_cache *c);
 
 
 #endif /* KEYPAIRS_CACHE_H_ */