director.h revision cf9d67e4a9bfee31cf3be05244555d51a3d1b9fe
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#ifndef DIRECTOR_H
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define DIRECTOR_H
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
8aacc9e7c84f8376822823ec98c2f551d4919b2eTimo Sirainen#include "network.h"
16f816d3f3c32ae3351834253f52ddd0212bcbf3Timo Sirainen#include "director-settings.h"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct director;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct mail_host;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct user;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainentypedef void director_state_change_callback_t(struct director *dir);
463e82bdf0e990f4f2252d2b53ea23a5abe5883cTimo Sirainen
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainenstruct director_host_change {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* originating director for this change. keep ip/port here separately,
a0d34d3982507f513a9d800082481e9faeb9a943Timo Sirainen because by the time its sync comes, the director itself may have
a0d34d3982507f513a9d800082481e9faeb9a943Timo Sirainen already been removed. */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen struct ip_addr ip;
e6d7d19c328e7043ad35d5a52c1617bde915a16fTimo Sirainen unsigned int port;
d7095f3a4466fbb78b2d5eb3d322bc15a5b0ab1fTimo Sirainen /* highest change sequence from this director */
153de7823e64c67678b3fc95719c41a8ec5b864dTimo Sirainen unsigned int seq;
153de7823e64c67678b3fc95719c41a8ec5b864dTimo Sirainen};
d7095f3a4466fbb78b2d5eb3d322bc15a5b0ab1fTimo Sirainen
d7095f3a4466fbb78b2d5eb3d322bc15a5b0ab1fTimo Sirainenstruct director {
8f7b00599e73fe71b1d2c6c65f8ae98aac1b23fbTimo Sirainen const struct director_settings *set;
8f7b00599e73fe71b1d2c6c65f8ae98aac1b23fbTimo Sirainen
d7095f3a4466fbb78b2d5eb3d322bc15a5b0ab1fTimo Sirainen /* IP and port of this director. self_host->ip/port must equal these. */
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen struct ip_addr self_ip;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen unsigned int self_port;
e6d7d19c328e7043ad35d5a52c1617bde915a16fTimo Sirainen
9315dd69233d554452df0c12bc57002d2042a8f4Timo Sirainen struct director_host *self_host;
9315dd69233d554452df0c12bc57002d2042a8f4Timo Sirainen struct director_connection *left, *right;
153de7823e64c67678b3fc95719c41a8ec5b864dTimo Sirainen
153de7823e64c67678b3fc95719c41a8ec5b864dTimo Sirainen struct mail_host_list *mail_hosts;
9315dd69233d554452df0c12bc57002d2042a8f4Timo Sirainen /* temporary user -> host associations */
9315dd69233d554452df0c12bc57002d2042a8f4Timo Sirainen struct user_directory *users;
9315dd69233d554452df0c12bc57002d2042a8f4Timo Sirainen
153de7823e64c67678b3fc95719c41a8ec5b864dTimo Sirainen /* these requests are waiting for directors to be in synced */
9315dd69233d554452df0c12bc57002d2042a8f4Timo Sirainen ARRAY_DEFINE(pending_requests, struct director_request *);
9315dd69233d554452df0c12bc57002d2042a8f4Timo Sirainen struct timeout *to_request;
9315dd69233d554452df0c12bc57002d2042a8f4Timo Sirainen
9315dd69233d554452df0c12bc57002d2042a8f4Timo Sirainen director_state_change_callback_t *state_change_callback;
9315dd69233d554452df0c12bc57002d2042a8f4Timo Sirainen
41bb0aa8e357876bc9a1916a37c9e3e78e5f8185Timo Sirainen /* director hosts are sorted by IP (and port) */
538c58fc95200fcc5e91abdda8b912b574a2f968Timo Sirainen ARRAY_DEFINE(dir_hosts, struct director_host *);
538c58fc95200fcc5e91abdda8b912b574a2f968Timo Sirainen
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen /* this array contains host changes done by directors.
8aacc9e7c84f8376822823ec98c2f551d4919b2eTimo Sirainen while it's non-empty, new user mappings can't be added, because
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen different directors may see different hosts. SYNC events remove
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen these changes. */
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen ARRAY_DEFINE(desynced_host_changes, struct director_host_change);
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen unsigned int sync_seq;
d482b35af87f5fd872bad007da0475813a401a49Timo Sirainen
d482b35af87f5fd872bad007da0475813a401a49Timo Sirainen /* director ring handshaking is complete.
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen director can start serving clients. */
d482b35af87f5fd872bad007da0475813a401a49Timo Sirainen unsigned int ring_handshaked:1;
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen unsigned int ring_handshake_warning_sent:1;
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen};
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen/* Create a new director. If listen_ip specifies an actual IP, it's used with
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen listen_port for finding ourself from the director_servers setting.
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen listen_port is used regardless by director_host_add_from_string() for hosts
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen without specified port. */
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainenstruct director *
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainendirector_init(const struct director_settings *set,
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen const struct ip_addr *listen_ip, unsigned int listen_port,
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen director_state_change_callback_t *callback);
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainenvoid director_deinit(struct director **dir);
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen/* Start connecting to other directors */
d482b35af87f5fd872bad007da0475813a401a49Timo Sirainenvoid director_connect(struct director *dir);
d482b35af87f5fd872bad007da0475813a401a49Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid director_set_ring_handshaked(struct director *dir);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid director_set_state_changed(struct director *dir);
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainenvoid director_update_host(struct director *dir, struct director_host *src,
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen struct mail_host *host);
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainenvoid director_remove_host(struct director *dir, struct director_host *src,
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen struct mail_host *host);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid director_update_user(struct director *dir, struct director_host *src,
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen struct user *user);
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen/* Send data to all directors using both left and right connections
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen (unless they're the same). */
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainenvoid director_update_send(struct director *dir, struct director_host *src,
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen const char *data);
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainenint director_connect_host(struct director *dir, struct director_host *host);
1cad0dd34667548ba39f794ddeb9fc486cf4c666Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#endif
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen