director.h revision b93ec4e5b569e1216d0c7a6f28cbdccfe4fb32ca
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen/* weak users supported in protocol */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen/* director ring remove supported */
e6d7d19c328e7043ad35d5a52c1617bde915a16fTimo Sirainen/* quit reason supported */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen/* user-kick supported */
d7095f3a4466fbb78b2d5eb3d322bc15a5b0ab1fTimo Sirainen/* options supported in handshake */
d7095f3a4466fbb78b2d5eb3d322bc15a5b0ab1fTimo Sirainen/* user tags supported */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen/* up/down state is tracked */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen/* user tag version 2 supported */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen/* user-kick-alt supported */
e6d7d19c328e7043ad35d5a52c1617bde915a16fTimo Sirainen/* Minimum time between even attempting to communicate with a director that
e6d7d19c328e7043ad35d5a52c1617bde915a16fTimo Sirainen failed due to a protocol error. */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen#define DIRECTOR_PROTOCOL_FAILURE_RETRY_SECS 60
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* User isn't being killed */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* We're still killing the user's connections */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* Like above, but our left side already announced it was finished
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen with killing its user connections */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* We're done killing, but we have to wait for the left side to
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen finish killing its user connections before sending USER-KILLED to
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen our right side */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* We're done killing, but waiting for USER-KILLED-EVERYWHERE
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen notification until this state gets reset. */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* Waiting for the flush socket to finish. */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* Wait for a while for the user connections to actually die. Note that
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen only at this stage we can be sure that all the directors know about
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen the user move (although it could be earlier if we added a new
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen USER-MOVED notification). */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* NOTE: remember to update also user_kill_state_names[] */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainenextern const char *user_kill_state_names[USER_KILL_STATE_DELAY+1];
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainentypedef void director_state_change_callback_t(struct director *dir);
cf83d475b1b4cc252d48858130f4c9e5a1ddbd99Timo Sirainen/* When a user gets freed, the kill_ctx may still be left alive. It's also
cf83d475b1b4cc252d48858130f4c9e5a1ddbd99Timo Sirainen possible for the user to come back, in which case the kill_ctx is usually
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen NULL, but another kill could have also started. The previous kill_ctx is
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen valid only if it matches the current user's kill_ctx. */
cf83d475b1b4cc252d48858130f4c9e5a1ddbd99Timo Sirainen#define DIRECTOR_KILL_CONTEXT_IS_VALID(user, ctx) \
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* Move timeout to make sure user's connections won't silently hang
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen indefinitely if there is some trouble moving it. */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* these are set only for director_flush_socket handling: */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* IP and port of this director. self_host->ip/port must equal these. */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* left and right connections are set only after they have finished
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen handshaking. until then they're in the connections list, although
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen updates are still sent to them during handshaking if the USER list
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* all director connections */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen ARRAY(struct director_connection *) connections;
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* current mail hosts */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* original mail hosts configured in config file.
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen this is used only for doveadm lookups */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* temporary user -> host associations */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* Number of users currently being moved */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* these requests are waiting for directors to be in synced */
dc2d666a911bfab4c7fa85d5f9cd6df78aafdb1fTimo Sirainen ARRAY(struct director_request *) pending_requests;
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen director_state_change_callback_t *state_change_callback;
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* director hosts are sorted by IP (and port) */
2382b8f17365dbdb758630f0d7a488af5336d7b5Timo Sirainen unsigned int last_sync_sent_ring_change_counter;
2382b8f17365dbdb758630f0d7a488af5336d7b5Timo Sirainen /* the lowest minor version supported by the ring */
dc2d666a911bfab4c7fa85d5f9cd6df78aafdb1fTimo Sirainen uint64_t ring_traffic_input, ring_traffic_output;
dc2d666a911bfab4c7fa85d5f9cd6df78aafdb1fTimo Sirainen /* director ring handshaking is complete.
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen director can start serving clients. */
d482b35af87f5fd872bad007da0475813a401a49Timo Sirainen/* Create a new director. If listen_ip specifies an actual IP, it's used with
d482b35af87f5fd872bad007da0475813a401a49Timo Sirainen listen_port for finding ourself from the director_servers setting.
d482b35af87f5fd872bad007da0475813a401a49Timo Sirainen listen_port is used regardless by director_host_add_from_string() for hosts
d482b35af87f5fd872bad007da0475813a401a49Timo Sirainen without specified port. */
d482b35af87f5fd872bad007da0475813a401a49Timo Sirainendirector_init(const struct director_settings *set,
d482b35af87f5fd872bad007da0475813a401a49Timo Sirainen const struct ip_addr *listen_ip, in_port_t listen_port,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Start connecting to other directors */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid director_set_ring_handshaked(struct director *dir);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid director_set_ring_synced(struct director *dir);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid director_set_ring_unsynced(struct director *dir);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid director_set_state_changed(struct director *dir);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid director_sync_send(struct director *dir, struct director_host *host,
d482b35af87f5fd872bad007da0475813a401a49Timo Sirainen unsigned int timestamp, unsigned int hosts_hash);
d482b35af87f5fd872bad007da0475813a401a49Timo Sirainenbool director_resend_sync(struct director *dir);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid director_notify_ring_added(struct director_host *added_host,
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainenvoid director_ring_remove(struct director_host *removed_host,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid director_update_host(struct director *dir, struct director_host *src,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid director_resend_hosts(struct director *dir);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid director_remove_host(struct director *dir, struct director_host *src,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid director_flush_host(struct director *dir, struct director_host *src,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid director_update_user(struct director *dir, struct director_host *src,
53238473bf77147660aa6db9daa68a8a685e9381Timo Sirainenvoid director_update_user_weak(struct director *dir, struct director_host *src,
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainenvoid director_move_user(struct director *dir, struct director_host *src,
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen unsigned int username_hash, struct mail_host *host)
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainenvoid director_kick_user(struct director *dir, struct director_host *src,
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen struct director_host *orig_src, const char *username)
03dbd273251103f745c08966f1809c02870390ffTimo Sirainenvoid director_kick_user_alt(struct director *dir, struct director_host *src,
03dbd273251103f745c08966f1809c02870390ffTimo Sirainenvoid director_kick_user_hash(struct director *dir, struct director_host *src,
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenvoid director_user_killed(struct director *dir, unsigned int username_hash);
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenvoid director_user_killed_everywhere(struct director *dir,
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenvoid director_user_weak(struct director *dir, struct user *user);
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainenvoid director_sync_freeze(struct director *dir);
567e57b09a49bbb2a146b13f8617698eb56237feTimo Sirainen/* Send data to all directors using both left and right connections
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen (unless they're the same). */
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainenvoid director_update_send(struct director *dir, struct director_host *src,
53238473bf77147660aa6db9daa68a8a685e9381Timo Sirainen const char *cmd);
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainenvoid director_update_send_version(struct director *dir,
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainenint director_connect_host(struct director *dir, struct director_host *host);
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainenvoid dir_debug(const char *fmt, ...) ATTR_FORMAT(1, 2);