dovecot-2.2: director: Added mail_hosts_hash(), which identifies...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Oct 12 12:43:44 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/eb9b9519db7a
changeset: 19291:eb9b9519db7a
user: Timo Sirainen <tss at iki.fi>
date: Mon Oct 12 15:41:25 2015 +0300
description:
director: Added mail_hosts_hash(), which identifies the current mail_hosts configuration.
diffstat:
src/director/mail-host.c | 24 ++++++++++++++++++++++++
src/director/mail-host.h | 1 +
2 files changed, 25 insertions(+), 0 deletions(-)
diffs (70 lines):
diff -r c4fa1bf6da57 -r eb9b9519db7a src/director/mail-host.c
--- a/src/director/mail-host.c Mon Oct 12 15:39:36 2015 +0300
+++ b/src/director/mail-host.c Mon Oct 12 15:41:25 2015 +0300
@@ -3,6 +3,7 @@
#include "lib.h"
#include "array.h"
#include "bsearch-insert-pos.h"
+#include "crc32.h"
#include "md5.h"
#include "mail-host.h"
@@ -16,6 +17,7 @@
struct mail_host_list {
ARRAY_TYPE(mail_host) hosts;
ARRAY(struct mail_vhost) vhosts;
+ unsigned int hosts_hash;
bool hosts_unsorted;
bool consistent_hashing;
};
@@ -114,10 +116,23 @@
static void mail_hosts_sort(struct mail_host_list *list)
{
+ struct mail_host *const *hostp;
+ uint32_t num;
+
if (list->consistent_hashing)
mail_hosts_sort_ring(list);
else
mail_hosts_sort_direct(list);
+
+ list->hosts_hash = 0;
+ array_foreach(&list->hosts, hostp) {
+ num = ((*hostp)->down ? 1 : 0) ^ (*hostp)->vhost_count;
+ list->hosts_hash = crc32_data_more(list->hosts_hash,
+ &num, sizeof(num));
+ num = net_ip_hash(&(*hostp)->ip);
+ list->hosts_hash = crc32_data_more(list->hosts_hash,
+ &num, sizeof(num));
+ }
}
struct mail_host *
@@ -396,6 +411,15 @@
(*hostp)->desynced = FALSE;
}
+unsigned int mail_hosts_hash(struct mail_host_list *list)
+{
+ if (list->hosts_unsorted)
+ mail_hosts_sort(list);
+ /* don't retun 0 as hash, since we're using it as "doesn't exist" in
+ some places. */
+ return list->hosts_hash == 0 ? 1 : list->hosts_hash;
+}
+
bool mail_hosts_have_usable(struct mail_host_list *list)
{
if (list->hosts_unsorted)
diff -r c4fa1bf6da57 -r eb9b9519db7a src/director/mail-host.h
--- a/src/director/mail-host.h Mon Oct 12 15:39:36 2015 +0300
+++ b/src/director/mail-host.h Mon Oct 12 15:41:25 2015 +0300
@@ -41,6 +41,7 @@
void mail_host_remove(struct mail_host_list *list, struct mail_host *host);
void mail_hosts_set_synced(struct mail_host_list *list);
+unsigned int mail_hosts_hash(struct mail_host_list *list);
bool mail_hosts_have_usable(struct mail_host_list *list);
const ARRAY_TYPE(mail_host) *mail_hosts_get(struct mail_host_list *list);
More information about the dovecot-cvs
mailing list