bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2010-2018 Dovecot authors, see the included COPYING file */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstatic int director_host_cmp(const struct director_host *b1,
6e54fd2bedbbc0c6316eae8fb569eb9a96aa29abTimo Sirainenint director_host_cmp_p(struct director_host *const *host1,
85601125c9cae82957a57f7b02409c567a59300eTimo Sirainen i_assert(director_host_lookup(dir, ip, port) == NULL);
b7650f081ff781c39fe00a3b93375e5f2dd14236Timo Sirainen host->ip_str = i_strdup(net_ip2addr(&host->ip));
bd4bbe6478a97e3fab77b05257dd1397c7c090eaTimo Sirainen host->name = i_strdup_printf("%s:%u", host->ip_str, port);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* there are few enough directors that sorting after each
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen addition should be fine */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen array_sort(&dir->dir_hosts, director_host_cmp_p);
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainenvoid director_host_free(struct director_host **_host)
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainenvoid director_host_ref(struct director_host *host)
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainenvoid director_host_unref(struct director_host *host)
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainen hosts = array_get(&host->dir->dir_hosts, &count);
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainen for (i = 0; i < count; i++) {
ce28adabf2c47d3af9ef197787cdb5139424c69cTimo Sirainenvoid director_host_restarted(struct director_host *host)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainendirector_host_get(struct director *dir, const struct ip_addr *ip,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainendirector_host_lookup(struct director *dir, const struct ip_addr *ip,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainendirector_host_lookup_ip(struct director *dir, const struct ip_addr *ip)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenint director_host_cmp_to_self(const struct director_host *b1,
1055d8038122c4f4190d37d98fdff6791d1306f8Timo Sirainen return ret == 0 ? 0 : -director_host_cmp_to_self(b2, b1, self);
1055d8038122c4f4190d37d98fdff6791d1306f8Timo Sirainen /* order -> return:
1055d8038122c4f4190d37d98fdff6791d1306f8Timo Sirainen self, b1, b2 -> b2
1055d8038122c4f4190d37d98fdff6791d1306f8Timo Sirainen b1, self, b2 -> b1
1055d8038122c4f4190d37d98fdff6791d1306f8Timo Sirainen b1, b2, self -> b2
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstatic void director_host_add_string(struct director *dir, const char *host)
7c925149e49f7cce41c90d562ff3835b66ddca29Timo Sirainen if (net_str2hostport(host, dir->self_port, &host, &port) < 0)
7c925149e49f7cce41c90d562ff3835b66ddca29Timo Sirainen i_fatal("Invalid director host:port in '%s'", host);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen if (net_gethostbyname(host, &ips, &ips_count) < 0)
85601125c9cae82957a57f7b02409c567a59300eTimo Sirainen for (i = 0; i < ips_count; i++) {
85601125c9cae82957a57f7b02409c567a59300eTimo Sirainen if (director_host_lookup(dir, &ips[i], port) == NULL)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenvoid director_host_add_from_string(struct director *dir, const char *hosts)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* standalone director */