diff options
-rw-r--r-- | src/controller.c | 6 | ||||
-rw-r--r-- | src/fuzzy_storage.c | 2 | ||||
-rw-r--r-- | src/libutil/map.c | 32 | ||||
-rw-r--r-- | src/libutil/map.h | 5 | ||||
-rw-r--r-- | src/libutil/map_private.h | 2 | ||||
-rw-r--r-- | src/lua_worker.c | 2 | ||||
-rw-r--r-- | src/rspamd_proxy.c | 2 | ||||
-rw-r--r-- | src/worker.c | 2 |
8 files changed, 36 insertions, 17 deletions
diff --git a/src/controller.c b/src/controller.c index f7e7bd043..cef428eba 100644 --- a/src/controller.c +++ b/src/controller.c @@ -3787,14 +3787,16 @@ start_controller_worker (struct rspamd_worker *worker) 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, ctx->resolver); rspamd_symbols_cache_start_refresh (worker->srv->cfg->cache, ctx->ev_base, worker); rspamd_stat_init (worker->srv->cfg, ctx->ev_base); if (worker->index == 0) { rspamd_worker_init_monitored (worker, ctx->ev_base, ctx->resolver); + rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver, TRUE); + } + else { + rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver, FALSE); } event_base_loop (ctx->ev_base, 0); diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index 8170b2810..66599d1f4 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -2833,7 +2833,7 @@ start_fuzzy (struct rspamd_worker *worker) ctx->resolver = dns_resolver_init (worker->srv->logger, ctx->ev_base, worker->srv->cfg); - rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver); + rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver, 0); /* Get peer pipe */ memset (&srv_cmd, 0, sizeof (srv_cmd)); diff --git a/src/libutil/map.c b/src/libutil/map.c index 4402a7910..0019aaa90 100644 --- a/src/libutil/map.c +++ b/src/libutil/map.c @@ -1061,8 +1061,10 @@ rspamd_map_read_cached (struct rspamd_map *map, struct rspamd_map_backend *bk, * Async HTTP callback */ static void -rspamd_map_common_http_callback (struct rspamd_map *map, struct rspamd_map_backend *bk, - struct map_periodic_cbdata *periodic, gboolean check) +rspamd_map_common_http_callback (struct rspamd_map *map, + struct rspamd_map_backend *bk, + struct map_periodic_cbdata *periodic, + gboolean check) { struct http_map_data *data; struct http_callback_data *cbd; @@ -1080,9 +1082,15 @@ rspamd_map_common_http_callback (struct rspamd_map *map, struct rspamd_map_backe rspamd_map_periodic_callback (-1, EV_TIMEOUT, periodic); } else { - /* Switch to the next backend */ - periodic->cur_backend ++; - rspamd_map_periodic_callback (-1, EV_TIMEOUT, periodic); + if (map->active_http) { + /* Check even if there is a cached version */ + goto check; + } + else { + /* Switch to the next backend */ + periodic->cur_backend++; + rspamd_map_periodic_callback (-1, EV_TIMEOUT, periodic); + } } return; @@ -1096,7 +1104,15 @@ rspamd_map_common_http_callback (struct rspamd_map *map, struct rspamd_map_backe return; } } + else if (!map->active_http) { + /* Switch to the next backend */ + periodic->cur_backend ++; + rspamd_map_periodic_callback (-1, EV_TIMEOUT, periodic); + + return; + } +check: cbd = g_slice_alloc0 (sizeof (struct http_callback_data)); cbd->ev_base = map->ev_base; @@ -1384,9 +1400,8 @@ rspamd_map_periodic_callback (gint fd, short what, void *ud) /* Start watching event for all maps */ void -rspamd_map_watch (struct rspamd_config *cfg, - struct event_base *ev_base, - struct rspamd_dns_resolver *resolver) +rspamd_map_watch (struct rspamd_config *cfg, struct event_base *ev_base, + struct rspamd_dns_resolver *resolver, gboolean active_http) { GList *cur = cfg->maps; struct rspamd_map *map; @@ -1396,6 +1411,7 @@ rspamd_map_watch (struct rspamd_config *cfg, map = cur->data; map->ev_base = ev_base; map->r = resolver; + map->active_http = active_http; rspamd_map_schedule_periodic (map, FALSE, TRUE, FALSE); diff --git a/src/libutil/map.h b/src/libutil/map.h index b25ef5c54..b1479a1b1 100644 --- a/src/libutil/map.h +++ b/src/libutil/map.h @@ -69,9 +69,8 @@ struct rspamd_map* rspamd_map_add_from_ucl (struct rspamd_config *cfg, /** * Start watching of maps by adding events to libevent event loop */ -void rspamd_map_watch (struct rspamd_config *cfg, - struct event_base *ev_base, - struct rspamd_dns_resolver *resolver); +void rspamd_map_watch (struct rspamd_config *cfg, struct event_base *ev_base, + struct rspamd_dns_resolver *resolver, gboolean active_http); /** * Remove all maps watched (remove events) diff --git a/src/libutil/map_private.h b/src/libutil/map_private.h index fc2d8e279..beb862cc2 100644 --- a/src/libutil/map_private.h +++ b/src/libutil/map_private.h @@ -81,6 +81,8 @@ struct rspamd_map { gchar *description; gchar *name; guint32 id; + /* Should we check HTTP or just load cached data */ + gboolean active_http; struct timeval tv; gdouble poll_timeout; /* Shared lock for temporary disabling of map reading (e.g. when this map is written by UI) */ diff --git a/src/lua_worker.c b/src/lua_worker.c index 7dcb94277..e5733058a 100644 --- a/src/lua_worker.c +++ b/src/lua_worker.c @@ -393,7 +393,7 @@ start_lua_worker (struct rspamd_worker *worker) } /* Maps events */ - rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver); + rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver, 0); event_base_loop (ctx->ev_base, 0); rspamd_worker_block_signals (); diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c index efb7e957b..7134c4b52 100644 --- a/src/rspamd_proxy.c +++ b/src/rspamd_proxy.c @@ -2047,7 +2047,7 @@ start_rspamd_proxy (struct rspamd_worker *worker) { ctx->ev_base, worker->srv->cfg); double_to_tv (ctx->timeout, &ctx->io_tv); - rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver); + rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver, 0); rspamd_upstreams_library_config (worker->srv->cfg, ctx->cfg->ups_ctx, ctx->ev_base, ctx->resolver->r); diff --git a/src/worker.c b/src/worker.c index 3889d0709..c6e419e36 100644 --- a/src/worker.c +++ b/src/worker.c @@ -679,7 +679,7 @@ start_worker (struct rspamd_worker *worker) ctx->resolver = dns_resolver_init (worker->srv->logger, ctx->ev_base, worker->srv->cfg); - rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver); + rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver, 0); rspamd_upstreams_library_config (worker->srv->cfg, ctx->cfg->ups_ctx, ctx->ev_base, ctx->resolver->r); |