]> source.dussan.org Git - rspamd.git/commitdiff
Allow to specify keypairs cache externally.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 11 Feb 2015 22:13:02 +0000 (22:13 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 11 Feb 2015 22:13:02 +0000 (22:13 +0000)
src/controller.c
src/libutil/http.c
src/libutil/http.h
test/rspamd_http_test.c

index a8dbdec96fcf6dc759dd2b1d823e2b025821d3e7..a0677f49e74991b656fc7a7a894f4e2172bf9912 100644 (file)
@@ -1589,7 +1589,7 @@ start_controller_worker (struct rspamd_worker *worker)
        struct module_ctx *mctx;
        GHashTableIter iter;
        gpointer key, value;
-
+       struct rspamd_keypair_cache *cache;
 
        ctx->ev_base = rspamd_prepare_worker (worker,
                        "controller",
@@ -1614,9 +1614,10 @@ start_controller_worker (struct rspamd_worker *worker)
                }
        }
        /* Accept event */
+       cache = rspamd_keypair_cache_new (256);
        ctx->http = rspamd_http_router_new (rspamd_controller_error_handler,
                        rspamd_controller_finish_handler, &ctx->io_tv, ctx->ev_base,
-                       ctx->static_files_dir);
+                       ctx->static_files_dir, cache);
 
        /* Add callbacks for different methods */
        rspamd_http_router_add_path (ctx->http,
@@ -1706,6 +1707,8 @@ start_controller_worker (struct rspamd_worker *worker)
        event_base_loop (ctx->ev_base, 0);
 
        g_mime_shutdown ();
+       rspamd_http_router_free (ctx->http);
+       rspamd_keypair_cache_destroy (cache);
        rspamd_log_close (rspamd_main->logger);
        exit (EXIT_SUCCESS);
 }
index 2f948f452c5bd24655faf687445680a08d3b6f9c..cafcbf6ead0edff8619edb58d35107ff6b95c1f8 100644 (file)
@@ -1600,7 +1600,8 @@ struct rspamd_http_connection_router *
 rspamd_http_router_new (rspamd_http_router_error_handler_t eh,
        rspamd_http_router_finish_handler_t fh,
        struct timeval *timeout, struct event_base *base,
-       const char *default_fs_path)
+       const char *default_fs_path,
+       struct rspamd_keypair_cache *cache)
 {
        struct rspamd_http_connection_router * new;
        struct stat st;
@@ -1635,8 +1636,7 @@ rspamd_http_router_new (rspamd_http_router_error_handler_t eh,
                }
        }
 
-       /* XXX: stupid default value, should be configurable */
-       new->cache = rspamd_keypair_cache_new (256);
+       new->cache = cache;
 
        return new;
 }
index 1c79fb45c9745f7013120b7147f252454ef4b7cc..c581cb6f6cd79cb6c2bc7199507d6871eb210d6d 100644 (file)
@@ -333,7 +333,8 @@ struct rspamd_http_connection_router * rspamd_http_router_new (
        rspamd_http_router_finish_handler_t fh,
        struct timeval *timeout,
        struct event_base *base,
-       const char *default_fs_path);
+       const char *default_fs_path,
+       struct rspamd_keypair_cache *cache);
 
 /**
  * Set encryption key for the HTTP router
index 77b71cee60ec75ba5aa3e62654f9d933d1781863..2bb1c2deecd6f9b5666199f5770a953c97a38840 100644 (file)
@@ -29,7 +29,7 @@
 #include "ottery.h"
 #include "cryptobox.h"
 
-static const int file_blocks = 8;
+static const int file_blocks = 16;
 static const int pconns = 100;
 static const int ntests = 300;
 
@@ -69,7 +69,7 @@ rspamd_server_accept (gint fd, short what, void *arg)
 
 static void
 rspamd_http_server_func (const gchar *path, rspamd_inet_addr_t *addr,
-               rspamd_mempool_mutex_t *mtx, gpointer kp)
+               rspamd_mempool_mutex_t *mtx, gpointer kp, struct rspamd_keypair_cache *c)
 {
        struct rspamd_http_connection_router *rt;
        struct event_base *ev_base = event_init ();
@@ -77,7 +77,7 @@ rspamd_http_server_func (const gchar *path, rspamd_inet_addr_t *addr,
        gint fd;
 
        rt = rspamd_http_router_new (rspamd_server_error, rspamd_server_finish,
-                       NULL, ev_base, path);
+                       NULL, ev_base, path, c);
        g_assert (rt != NULL);
 
        rspamd_http_router_set_key (rt, kp);
@@ -190,7 +190,7 @@ rspamd_http_test_func (void)
        g_assert (sfd != -1);
 
        if (sfd == 0) {
-               rspamd_http_server_func ("/tmp/", &addr, mtx, serv_key);
+               rspamd_http_server_func ("/tmp/", &addr, mtx, serv_key, c);
                exit (EXIT_SUCCESS);
        }
 
@@ -242,12 +242,24 @@ rspamd_http_test_func (void)
                        sizeof (buf) * file_blocks,
                        total_diff, ntests * pconns / total_diff * 1000.);
 
+       /* Restart server */
+       kill (sfd, SIGTERM);
+       wait (&i);
+       sfd = fork ();
+       g_assert (sfd != -1);
+
+       if (sfd == 0) {
+               rspamd_http_server_func ("/tmp/", &addr, mtx, serv_key, NULL);
+               exit (EXIT_SUCCESS);
+       }
+
+       rspamd_mempool_lock_mutex (mtx);
        total_diff = 0.0;
 
        for (i = 0; i < ntests; i ++) {
                for (j = 0; j < pconns; j ++) {
                        rspamd_http_client_func (filepath + sizeof ("/tmp") - 1, &addr,
-                                       client_key, peer_key, NULL, ev_base);
+                                       client_key, peer_key, c, ev_base);
                }
                clock_gettime (CLOCK_MONOTONIC, &ts1);
                event_base_loop (ev_base, 0);