director.h revision aa797403d51ff047727b77d64532001d6b6cc21a
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#ifndef DIRECTOR_H
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#define DIRECTOR_H
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "network.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "director-settings.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
aa797403d51ff047727b77d64532001d6b6cc21aTimo Sirainen#define DIRECTOR_VERSION_NAME "director"
aa797403d51ff047727b77d64532001d6b6cc21aTimo Sirainen#define DIRECTOR_VERSION_MAJOR 1
aa797403d51ff047727b77d64532001d6b6cc21aTimo Sirainen#define DIRECTOR_VERSION_MINOR 0
aa797403d51ff047727b77d64532001d6b6cc21aTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstruct director;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstruct mail_host;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstruct user;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainentypedef void director_state_change_callback_t(struct director *dir);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstruct director {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen const struct director_settings *set;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* IP and port of this director. self_host->ip/port must equal these. */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen struct ip_addr self_ip;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen unsigned int self_port;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen unsigned int test_port;
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen struct director_host *self_host;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen struct director_connection *left, *right;
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen /* all director connections */
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen struct director_connection *connections;
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen struct timeout *to_reconnect;
433f5c9cc560a8cbff47257513d0bacb1cf250f4Timo Sirainen struct timeout *to_sync;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
edd318d5866ac3fbc6e8df28fb24a4dfef93c884Timo Sirainen /* current mail hosts */
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainen struct mail_host_list *mail_hosts;
edd318d5866ac3fbc6e8df28fb24a4dfef93c884Timo Sirainen /* original mail hosts configured in config file.
edd318d5866ac3fbc6e8df28fb24a4dfef93c884Timo Sirainen this is used only for doveadm lookups */
edd318d5866ac3fbc6e8df28fb24a4dfef93c884Timo Sirainen struct mail_host_list *orig_config_hosts;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* temporary user -> host associations */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen struct user_directory *users;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* these requests are waiting for directors to be in synced */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen ARRAY_DEFINE(pending_requests, struct director_request *);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen struct timeout *to_request;
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen struct timeout *to_handshake_warning;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen director_state_change_callback_t *state_change_callback;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* director hosts are sorted by IP (and port) */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen ARRAY_DEFINE(dir_hosts, struct director_host *);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
15ab2452b0220a115f4351ad9d7fd5ec70ae7966Timo Sirainen struct ipc_client *ipc_proxy;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen unsigned int sync_seq;
aa797403d51ff047727b77d64532001d6b6cc21aTimo Sirainen /* the lowest minor version supported by the ring */
aa797403d51ff047727b77d64532001d6b6cc21aTimo Sirainen unsigned int synced_minor_version;
152db3f90f298b7fb2dbbd4276f0fc30a9bc30f6Timo Sirainen time_t ring_last_sync_time;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* director ring handshaking is complete.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen director can start serving clients. */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen unsigned int ring_handshaked:1;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen unsigned int ring_handshake_warning_sent:1;
242abe3ad2423776e9cf05e1304eb8fda4831b23Timo Sirainen unsigned int ring_synced:1;
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen unsigned int sync_frozen:1;
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen unsigned int sync_pending:1;
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen unsigned int debug:1;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen};
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen/* Create a new director. If listen_ip specifies an actual IP, it's used with
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen listen_port for finding ourself from the director_servers setting.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen listen_port is used regardless by director_host_add_from_string() for hosts
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen without specified port. */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstruct director *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainendirector_init(const struct director_settings *set,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen const struct ip_addr *listen_ip, unsigned int listen_port,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen director_state_change_callback_t *callback);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenvoid director_deinit(struct director **dir);
c4900d31385344bfadaee53a897daeafdb3063d8Timo Sirainenvoid director_find_self(struct director *dir);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen/* Start connecting to other directors */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenvoid director_connect(struct director *dir);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
4aab01f4eade3d278b61471516c062ce30a84b5fTimo Sirainenvoid director_set_ring_handshaked(struct director *dir);
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainenvoid director_set_ring_synced(struct director *dir);
152db3f90f298b7fb2dbbd4276f0fc30a9bc30f6Timo Sirainenvoid director_set_ring_unsynced(struct director *dir);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenvoid director_set_state_changed(struct director *dir);
aa797403d51ff047727b77d64532001d6b6cc21aTimo Sirainenvoid director_sync_send(struct director *dir, struct director_host *host,
aa797403d51ff047727b77d64532001d6b6cc21aTimo Sirainen uint32_t seq, unsigned int minor_version);
433f5c9cc560a8cbff47257513d0bacb1cf250f4Timo Sirainenbool director_resend_sync(struct director *dir);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenvoid director_update_host(struct director *dir, struct director_host *src,
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen struct director_host *orig_src,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen struct mail_host *host);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenvoid director_remove_host(struct director *dir, struct director_host *src,
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen struct director_host *orig_src,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen struct mail_host *host);
5e9bb72de1209cd39fdf3e95bdb26e047cc5594eTimo Sirainenvoid director_flush_host(struct director *dir, struct director_host *src,
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen struct director_host *orig_src,
5e9bb72de1209cd39fdf3e95bdb26e047cc5594eTimo Sirainen struct mail_host *host);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenvoid director_update_user(struct director *dir, struct director_host *src,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen struct user *user);
15ab2452b0220a115f4351ad9d7fd5ec70ae7966Timo Sirainenvoid director_move_user(struct director *dir, struct director_host *src,
15ab2452b0220a115f4351ad9d7fd5ec70ae7966Timo Sirainen struct director_host *orig_src,
15ab2452b0220a115f4351ad9d7fd5ec70ae7966Timo Sirainen unsigned int username_hash, struct mail_host *host);
15ab2452b0220a115f4351ad9d7fd5ec70ae7966Timo Sirainenvoid director_user_killed(struct director *dir, unsigned int username_hash);
15ab2452b0220a115f4351ad9d7fd5ec70ae7966Timo Sirainenvoid director_user_killed_everywhere(struct director *dir,
15ab2452b0220a115f4351ad9d7fd5ec70ae7966Timo Sirainen struct director_host *src,
15ab2452b0220a115f4351ad9d7fd5ec70ae7966Timo Sirainen struct director_host *orig_src,
15ab2452b0220a115f4351ad9d7fd5ec70ae7966Timo Sirainen unsigned int username_hash);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainenvoid director_sync_freeze(struct director *dir);
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainenvoid director_sync_thaw(struct director *dir);
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen/* Send data to all directors using both left and right connections
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen (unless they're the same). */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenvoid director_update_send(struct director *dir, struct director_host *src,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen const char *data);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenint director_connect_host(struct director *dir, struct director_host *host);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#endif