diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-11-20 17:03:51 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-11-20 17:03:51 +0000 |
commit | 3d10a9ead7d1241035160ab3355577051186b0fd (patch) | |
tree | 7413ffa6f6ecf18422e95be046f06b9a40e4bc43 | |
parent | 64e6d18a31fd069a83baafe308a8c5d6ec3591e1 (diff) | |
download | rspamd-3d10a9ead7d1241035160ab3355577051186b0fd.tar.gz rspamd-3d10a9ead7d1241035160ab3355577051186b0fd.zip |
Rework upstreams initialization
-rw-r--r-- | src/controller.c | 5 | ||||
-rw-r--r-- | src/http_proxy.c | 5 | ||||
-rw-r--r-- | src/libserver/cfg_utils.c | 1 | ||||
-rw-r--r-- | src/libutil/upstream.c | 20 | ||||
-rw-r--r-- | src/libutil/upstream.h | 6 | ||||
-rw-r--r-- | src/smtp_proxy.c | 5 | ||||
-rw-r--r-- | src/worker.c | 5 | ||||
-rw-r--r-- | test/rspamd_upstream_test.c | 9 |
8 files changed, 28 insertions, 28 deletions
diff --git a/src/controller.c b/src/controller.c index 31274f5d6..c0783ce9d 100644 --- a/src/controller.c +++ b/src/controller.c @@ -2550,9 +2550,8 @@ start_controller_worker (struct rspamd_worker *worker) ctx->ev_base, worker->srv->cfg); - worker->srv->cfg->ups_ctx = rspamd_upstreams_library_init (ctx->resolver->r, - ctx->ev_base); - rspamd_upstreams_library_config (worker->srv->cfg, worker->srv->cfg->ups_ctx); + rspamd_upstreams_library_config (worker->srv->cfg, worker->srv->cfg->ups_ctx, + ctx->ev_base, ctx->resolver->r); /* Maps events */ rspamd_map_watch (worker->srv->cfg, ctx->ev_base); rspamd_symbols_cache_start_refresh (worker->srv->cfg->cache, ctx->ev_base); diff --git a/src/http_proxy.c b/src/http_proxy.c index a5290de63..c35c02bd1 100644 --- a/src/http_proxy.c +++ b/src/http_proxy.c @@ -459,9 +459,8 @@ start_http_proxy (struct rspamd_worker *worker) worker->srv->cfg); double_to_tv (ctx->timeout, &ctx->io_tv); - ctx->cfg->ups_ctx = rspamd_upstreams_library_init (ctx->resolver->r, - ctx->ev_base); - rspamd_upstreams_library_config (worker->srv->cfg, ctx->cfg->ups_ctx); + rspamd_upstreams_library_config (worker->srv->cfg, ctx->cfg->ups_ctx, + ctx->ev_base, ctx->resolver->r); /* XXX: stupid default */ ctx->keys_cache = rspamd_keypair_cache_new (256); diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index ce704f8cf..53ce5add4 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -197,6 +197,7 @@ rspamd_config_new (void) cfg->lua_state = rspamd_lua_init (cfg); cfg->cache = rspamd_symbols_cache_new (cfg); + cfg->ups_ctx = rspamd_upstreams_library_init (); REF_INIT_RETAIN (cfg, rspamd_config_free); diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c index 2218220b6..5ef913f45 100644 --- a/src/libutil/upstream.c +++ b/src/libutil/upstream.c @@ -79,6 +79,7 @@ struct upstream_ctx { gdouble dns_timeout; guint dns_retransmits; GQueue *upstreams; + gboolean configured; ref_entry_t ref; }; @@ -92,8 +93,12 @@ static guint default_dns_retransmits = 2; void rspamd_upstreams_library_config (struct rspamd_config *cfg, - struct upstream_ctx *ctx) + struct upstream_ctx *ctx, struct event_base *ev_base, + struct rdns_resolver *resolver) { + g_assert (ctx != NULL); + g_assert (cfg != NULL); + if (cfg->upstream_error_time) { ctx->error_time = cfg->upstream_error_time; } @@ -109,6 +114,10 @@ rspamd_upstreams_library_config (struct rspamd_config *cfg, if (cfg->dns_timeout) { ctx->dns_timeout = cfg->dns_timeout; } + + ctx->ev_base = ev_base; + ctx->res = resolver; + ctx->configured = TRUE; } static void @@ -131,8 +140,7 @@ rspamd_upstream_ctx_dtor (struct upstream_ctx *ctx) } struct upstream_ctx * -rspamd_upstreams_library_init (struct rdns_resolver *resolver, - struct event_base *base) +rspamd_upstreams_library_init (void) { struct upstream_ctx *ctx; @@ -144,8 +152,6 @@ rspamd_upstreams_library_init (struct rdns_resolver *resolver, ctx->revive_jitter = default_revive_jitter; ctx->revive_time = default_revive_time; - ctx->res = resolver; - ctx->ev_base = base; ctx->upstreams = g_queue_new (); REF_INIT_RETAIN (ctx, rspamd_upstream_ctx_dtor); @@ -302,7 +308,7 @@ rspamd_upstream_set_inactive (struct upstream_list *ls, struct upstream *up) g_ptr_array_remove_index (ls->alive, up->active_idx); up->active_idx = -1; - if (up->ctx->res != NULL) { + if (up->ctx->res != NULL && up->ctx->configured) { /* Resolve name of the upstream one more time */ if (up->name[0] != '/') { REF_RETAIN (up); @@ -318,7 +324,7 @@ rspamd_upstream_set_inactive (struct upstream_list *ls, struct upstream *up) REF_RETAIN (up); evtimer_set (&up->ev, rspamd_upstream_revive_cb, up); - if (up->ctx->ev_base != NULL) { + if (up->ctx->ev_base != NULL && up->ctx->configured) { event_base_set (up->ctx->ev_base, &up->ev); } diff --git a/src/libutil/upstream.h b/src/libutil/upstream.h index 4e48a4289..a22a44589 100644 --- a/src/libutil/upstream.h +++ b/src/libutil/upstream.h @@ -25,15 +25,15 @@ struct upstream_ctx; * Init upstreams library * @param resolver */ -struct upstream_ctx* rspamd_upstreams_library_init (struct rdns_resolver *resolver, - struct event_base *base); +struct upstream_ctx* rspamd_upstreams_library_init (void); /** * Configure attributes of upstreams library * @param cfg */ void rspamd_upstreams_library_config (struct rspamd_config *cfg, - struct upstream_ctx *ctx); + struct upstream_ctx *ctx, struct event_base *ev_base, + struct rdns_resolver *resolver); /** * Upstream error logic diff --git a/src/smtp_proxy.c b/src/smtp_proxy.c index 390ca292b..74c1da4c7 100644 --- a/src/smtp_proxy.c +++ b/src/smtp_proxy.c @@ -1073,9 +1073,8 @@ start_smtp_proxy (struct rspamd_worker *worker) ctx->ev_base, worker->srv->cfg); - worker->srv->cfg->ups_ctx = rspamd_upstreams_library_init (ctx->resolver->r, - ctx->ev_base); - rspamd_upstreams_library_config (worker->srv->cfg, worker->srv->cfg->ups_ctx); + rspamd_upstreams_library_config (worker->srv->cfg, worker->srv->cfg->ups_ctx, + ctx->ev_base, ctx->resolver->r); /* Set umask */ umask (S_IWGRP | S_IWOTH | S_IROTH | S_IRGRP); diff --git a/src/worker.c b/src/worker.c index cd63a4e00..e63624848 100644 --- a/src/worker.c +++ b/src/worker.c @@ -352,9 +352,8 @@ start_worker (struct rspamd_worker *worker) ctx->ev_base, worker->srv->cfg); - ctx->cfg->ups_ctx = rspamd_upstreams_library_init (ctx->resolver->r, - ctx->ev_base); - rspamd_upstreams_library_config (worker->srv->cfg, ctx->cfg->ups_ctx); + rspamd_upstreams_library_config (worker->srv->cfg, ctx->cfg->ups_ctx, + ctx->ev_base, ctx->resolver->r); /* XXX: stupid default */ ctx->keys_cache = rspamd_keypair_cache_new (256); diff --git a/test/rspamd_upstream_test.c b/test/rspamd_upstream_test.c index 0cf163322..6ed14dbf5 100644 --- a/test/rspamd_upstream_test.c +++ b/test/rspamd_upstream_test.c @@ -74,9 +74,7 @@ rspamd_upstream_test_func (void) struct timeval tv; rspamd_inet_addr_t *addr, *next_addr, *paddr; - cfg = (struct rspamd_config *)g_malloc (sizeof (struct rspamd_config)); - bzero (cfg, sizeof (struct rspamd_config)); - cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL); + cfg = rspamd_config_new (); cfg->dns_retransmits = 2; cfg->dns_timeout = 0.5; cfg->upstream_max_errors = 1; @@ -84,9 +82,7 @@ rspamd_upstream_test_func (void) cfg->upstream_error_time = 2; resolver = dns_resolver_init (NULL, ev_base, cfg); - - cfg->ups_ctx = rspamd_upstreams_library_init (resolver->r, ev_base); - rspamd_upstreams_library_config (cfg, cfg->ups_ctx); + rspamd_upstreams_library_config (cfg, cfg->ups_ctx, ev_base, resolver->r); ls = rspamd_upstreams_create (cfg->ups_ctx); g_assert (rspamd_upstreams_parse_line (ls, test_upstream_list, 443, NULL)); @@ -170,4 +166,5 @@ rspamd_upstream_test_func (void) g_assert (rspamd_upstreams_alive (ls) == 3); rspamd_upstreams_destroy (ls); + REF_RELEASE (cfg); } |