summaryrefslogtreecommitdiffstats
path: root/src/libutil/upstream.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-11-21 13:20:37 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-11-21 13:20:37 +0000
commit19fdaf580a3746442173f10da662629bdc1b62b9 (patch)
tree3dc19676bfa5036b7a075dd67639ef995d8614a2 /src/libutil/upstream.c
parent0af6082b4444aa613bef109c6edd44509aa732ec (diff)
downloadrspamd-19fdaf580a3746442173f10da662629bdc1b62b9.tar.gz
rspamd-19fdaf580a3746442173f10da662629bdc1b62b9.zip
Rework rotation for upstreams
Diffstat (limited to 'src/libutil/upstream.c')
-rw-r--r--src/libutil/upstream.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c
index 33c5e4403..0054be93a 100644
--- a/src/libutil/upstream.c
+++ b/src/libutil/upstream.c
@@ -741,11 +741,10 @@ rspamd_upstream_get_hashed (struct upstream_list *ups, const guint8 *key, guint
struct upstream*
rspamd_upstream_get (struct upstream_list *ups,
- enum rspamd_upstream_rotation type, ...)
+ enum rspamd_upstream_rotation default_type,
+ const guchar *key, gsize keylen)
{
- va_list ap;
- const guint8 *key;
- guint keylen;
+ enum rspamd_upstream_rotation type;
rspamd_mutex_lock (ups->lock);
if (ups->alive->len == 0) {
@@ -754,14 +753,18 @@ rspamd_upstream_get (struct upstream_list *ups,
}
rspamd_mutex_unlock (ups->lock);
+ type = ups->rot_alg != RSPAMD_UPSTREAM_UNDEF ? ups->rot_alg : default_type;
+
+ if (type == RSPAMD_UPSTREAM_HASHED && (keylen == 0 || key == NULL)) {
+ /* Cannot use hashed rotation when no key is specified, switch to random */
+ type = RSPAMD_UPSTREAM_RANDOM;
+ }
+
switch (type) {
+ default:
case RSPAMD_UPSTREAM_RANDOM:
return rspamd_upstream_get_random (ups);
case RSPAMD_UPSTREAM_HASHED:
- va_start (ap, type);
- key = va_arg (ap, const guint8 *);
- keylen = va_arg (ap, guint);
- va_end (ap);
return rspamd_upstream_get_hashed (ups, key, keylen);
case RSPAMD_UPSTREAM_ROUND_ROBIN:
return rspamd_upstream_get_round_robin (ups, TRUE);