diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-12-23 13:42:14 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-12-23 13:42:14 +0000 |
commit | ba06982886382ec25a53b1672fe04d6b97a7a461 (patch) | |
tree | e49d37f5a57800248ccf790e4f1ab6b81fc1372a /src/libutil | |
parent | 6b441d3b8400954381a78ddc8ee2f524bdad28a0 (diff) | |
download | rspamd-ba06982886382ec25a53b1672fe04d6b97a7a461.tar.gz rspamd-ba06982886382ec25a53b1672fe04d6b97a7a461.zip |
Add sequential order for upstreams.
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/upstream.c | 9 | ||||
-rw-r--r-- | src/libutil/upstream.h | 3 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c index f4705b229..d2c1d2ee0 100644 --- a/src/libutil/upstream.c +++ b/src/libutil/upstream.c @@ -64,6 +64,7 @@ struct upstream_list { GPtrArray *alive; rspamd_mutex_t *lock; guint64 hash_seed; + guint cur_elt; }; static struct rdns_resolver *res = NULL; @@ -354,6 +355,7 @@ rspamd_upstreams_create (void) ls->ups = g_ptr_array_new (); ls->alive = g_ptr_array_new (); ls->lock = rspamd_mutex_new (); + ls->cur_elt = 0; return ls; } @@ -678,5 +680,12 @@ rspamd_upstream_get (struct upstream_list *ups, return rspamd_upstream_get_round_robin (ups, TRUE); case RSPAMD_UPSTREAM_MASTER_SLAVE: return rspamd_upstream_get_round_robin (ups, FALSE); + case RSPAMD_UPSTREAM_SEQUENTIAL: + if (ups->cur_elt >= ups->alive->len) { + ups->cur_elt = 0; + return NULL; + } + + return g_ptr_array_index (ups->alive, ups->cur_elt ++); } } diff --git a/src/libutil/upstream.h b/src/libutil/upstream.h index cff6acfb1..8c399ab03 100644 --- a/src/libutil/upstream.h +++ b/src/libutil/upstream.h @@ -10,7 +10,8 @@ enum rspamd_upstream_rotation { RSPAMD_UPSTREAM_RANDOM, RSPAMD_UPSTREAM_HASHED, RSPAMD_UPSTREAM_ROUND_ROBIN, - RSPAMD_UPSTREAM_MASTER_SLAVE + RSPAMD_UPSTREAM_MASTER_SLAVE, + RSPAMD_UPSTREAM_SEQUENTIAL }; |