aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/upstream.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil/upstream.c')
-rw-r--r--src/libutil/upstream.c63
1 files changed, 46 insertions, 17 deletions
diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c
index 2ff8f2651..010b2d0ff 100644
--- a/src/libutil/upstream.c
+++ b/src/libutil/upstream.c
@@ -26,6 +26,7 @@
#include "upstream.h"
#include "ottery.h"
#include "ref.h"
+#include "cfg_file.h"
#include "rdns.h"
#include "xxhash.h"
#include "utlist.h"
@@ -68,13 +69,41 @@ struct upstream_list {
static struct rdns_resolver *res = NULL;
static struct event_base *ev_base = NULL;
/* 4 errors in 10 seconds */
-const guint default_max_errors = 4;
-const guint default_revive_time = 60;
-const gdouble default_revive_jitter = 0.4;
-const guint default_error_time = 10;
-const gdouble default_dns_timeout = 1.0;
-const guint default_dns_retransmits = 2;
-const guint default_max_addresses = 1024;
+static guint default_max_errors = 4;
+static gdouble default_revive_time = 60;
+static gdouble default_revive_jitter = 0.4;
+static gdouble default_error_time = 10;
+static gdouble default_dns_timeout = 1.0;
+static guint default_dns_retransmits = 2;
+static guint default_max_addresses = 1024;
+
+void
+rspamd_upstreams_library_config (struct rspamd_config *cfg)
+{
+ if (cfg->upstream_error_time) {
+ default_error_time = cfg->upstream_error_time;
+ }
+ if (cfg->upstream_max_errors) {
+ default_max_errors = cfg->upstream_max_errors;
+ }
+ if (cfg->upstream_revive_time) {
+ default_revive_time = cfg->upstream_max_errors;
+ }
+ if (cfg->dns_retransmits) {
+ default_dns_retransmits = cfg->dns_retransmits;
+ }
+ if (cfg->dns_timeout) {
+ default_dns_timeout = cfg->dns_timeout;
+ }
+}
+
+void
+rspamd_upstreams_library_init (struct rdns_resolver *resolver,
+ struct event_base *base)
+{
+ res = resolver;
+ ev_base = base;
+}
static void
rspamd_upstream_set_active (struct upstream_list *ls, struct upstream *up)
@@ -188,6 +217,8 @@ rspamd_upstream_revive_cb (int fd, short what, void *arg)
static void
rspamd_upstream_set_inactive (struct upstream_list *ls, struct upstream *up)
{
+ gdouble ntim;
+
rspamd_mutex_lock (ls->lock);
g_ptr_array_remove_index (ls->alive, up->active_idx);
up->active_idx = -1;
@@ -212,23 +243,15 @@ rspamd_upstream_set_inactive (struct upstream_list *ls, struct upstream *up)
event_base_set (ev_base, &up->ev);
}
- up->tv.tv_sec = default_revive_time + ottery_rand_range (
+ ntim = default_revive_time + ottery_rand_range (
default_revive_time * default_revive_jitter);
- up->tv.tv_usec = 0;
+ double_to_tv (ntim, &up->tv);
event_add (&up->ev, &up->tv);
rspamd_mutex_unlock (ls->lock);
}
void
-rspamd_upstreams_library_init (struct rdns_resolver *resolver,
- struct event_base *base)
-{
- res = resolver;
- ev_base = base;
-}
-
-void
rspamd_upstream_fail (struct upstream *up)
{
struct timeval tv;
@@ -293,6 +316,12 @@ rspamd_upstreams_count (struct upstream_list *ups)
return ups->ups->len;
}
+gsize
+rspamd_upstreams_alive (struct upstream_list *ups)
+{
+ return ups->alive->len;
+}
+
static void
rspamd_upstream_dtor (struct upstream *up)
{