]> source.dussan.org Git - rspamd.git/commitdiff
Add sequential order for upstreams.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 23 Dec 2014 13:42:14 +0000 (13:42 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 23 Dec 2014 13:42:14 +0000 (13:42 +0000)
src/libutil/upstream.c
src/libutil/upstream.h

index f4705b2298f946b2798e3e4bec6d7f97460f311c..d2c1d2ee0a23d16a77b4c80c0e2663547525eb48 100644 (file)
@@ -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 ++);
        }
 }
index cff6acfb1eeba04fd4676380522ebd1effe20b03..8c399ab039825370006fc2776cbe5629a464ba09 100644 (file)
@@ -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
 };