/* Copyright (c) 2010-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "ioloop.h"
#include "array.h"
#include "str.h"
#include "mail-host.h"
#include "director.h"
#include "director-request.h"
REQUEST_DELAY_NONE = 0,
};
static const char *delay_reason_strings[] = {
"unknown",
"ring not handshaked",
"ring not synced",
"no hosts",
"weak user",
"kill waiting"
};
struct director_request {
unsigned int username_hash;
char *username_tag;
void *context;
};
{
}
static const char *
{
unsigned int secs;
str_truncate(str, 0);
else {
else
}
}
}
{
const char *errormsg;
if (request->create_time +
break;
/* weakness appears to have gotten stuck. this is a
bug, but try to fix it for future requests by
removing the weakness. */
}
T_BEGIN {
} T_END;
}
}
const char *tag,
{
unsigned int username_hash;
&username_hash)) {
return;
}
dir->num_requests++;
return;
/* need to queue it */
dir->to_request =
}
}
{
if (!dir->ring_handshaked) {
i_warning("Delaying all requests "
"until all directors have connected");
} else {
i_warning("Delaying new user requests until ring is synced");
}
}
{
if (dir->ring_handshake_warning_sent ||
return;
}
static bool
{
if (USER_IS_BEING_KILLED(user)) {
/* delay processing this user's connections until
its existing connections have been killed */
dir_debug("request: %u waiting for kill to finish",
return FALSE;
}
/* looks like all the other directors have died. we can do
whatever we want without breaking anything. remove the
user's weakness just in case it was set to TRUE when we
had more directors. */
return TRUE;
}
/* wait for user to become non-weak */
dir_debug("request: %u waiting for weakness",
return FALSE;
}
return TRUE;
/* user is close to being expired. another director may have
already expired it. */
if (!dir->ring_synced) {
/* try again later once ring is synced */
dir_debug("request: %u waiting for sync for making weak",
return FALSE;
}
/* doesn't matter, other directors would
assign the user the same way regardless */
return TRUE;
}
/* We have to worry about two separate timepoints in here:
a) some directors think the user isn't expiring, and
others think the user is near expiring
b) some directors think the user is near expiring, and
others think the user has already expired
What we don't have to worry about is:
!c) some directors think the user isn't expiring, and
others think the user has already expired
If !c) happens, the user might get redirected to different backends.
We'll use a large enough timeout between a) and b) states, so that
!c) should never happen.
So what we'll do here is:
1. Send a USER-WEAK notification to all directors with the new host.
2. Each director receiving USER-WEAK refreshes the user's timestamp
and host, but marks the user as being weak.
3. Once USER-WEAK has reached all directors, a real USER update is
sent, which removes the weak-flag.
4. If a director ever receives a USER update for a weak user, the
USER update overrides the host and removes the weak-flag.
5. Director doesn't let any weak user log in, until the weak-flag
gets removed.
*/
/* weak users not supported by ring currently */
return TRUE;
} else {
return FALSE;
}
}
{
const char *tag;
if (!dir->ring_handshaked) {
/* delay requests until ring handshaking is complete */
dir_debug("request: %u waiting for handshake",
return FALSE;
}
return FALSE;
dir_debug("request: %u refreshed timeout to %u",
} else {
if (!dir->ring_synced) {
/* delay adding new users until ring is again synced */
dir_debug("request: %u waiting for sync for adding",
return FALSE;
}
/* all hosts have been removed */
dir_debug("request: %u waiting for hosts",
return FALSE;
}
host, ioloop_time);
dir_debug("request: %u added timeout to %u (hosts_hash=%u)",
}
T_BEGIN {
} T_END;
return TRUE;
}
{
}
if (!director_request_continue_real(request)) {
return FALSE;
}
return TRUE;
}