#include "upstream.h"
#include "ottery.h"
#include "ref.h"
+#include "cfg_file.h"
#include "rdns.h"
#include "xxhash.h"
#include "utlist.h"
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)
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;
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)
{
return ups->ups->len;
}
+gsize
+rspamd_upstreams_alive (struct upstream_list *ups)
+{
+ return ups->alive->len;
+}
+
static void
rspamd_upstream_dtor (struct upstream *up)
{
RSPAMD_UPSTREAM_MASTER_SLAVE
};
+
+struct rspamd_config;
/* Opaque upstream structures */
struct upstream;
struct upstream_list;
void rspamd_upstreams_library_init (struct rdns_resolver *resolver,
struct event_base *base);
+/**
+ * Configure attributes of upstreams library
+ * @param cfg
+ */
+void rspamd_upstreams_library_config (struct rspamd_config *cfg);
+
/**
* Upstream error logic
* 1. During error time we count upstream_ok and upstream_fail
*/
gsize rspamd_upstreams_count (struct upstream_list *ups);
+/**
+ * Returns the number of upstreams in the list
+ * @param ups
+ * @return
+ */
+gsize rspamd_upstreams_alive (struct upstream_list *ups);
+
/**
* Add upstream from the string
* @param ups upstream list