Changeset View
Changeset View
Standalone View
Standalone View
b/dirmngr/ks-engine-hkp.c
Context not available. | |||||
} | } | ||||
static int | |||||
host_is_alive (hostinfo_t hi, time_t curtime) | |||||
{ | |||||
if (!hi) | |||||
return 0; | |||||
if (!hi->dead) | |||||
return 1; | |||||
if (!hi->died_at) | |||||
return 0; /* manually marked dead */ | |||||
if (hi->died_at + RESURRECT_INTERVAL <= curtime | |||||
|| hi->died_at > curtime) | |||||
{ | |||||
hi->dead = 0; | |||||
log_info ("resurrected host '%s'", hi->name); | |||||
return 1; | |||||
} | |||||
return 0; | |||||
} | |||||
/* Select a random host. Consult TABLE which indices into the global | /* Select a random host. Consult TABLE which indices into the global | ||||
hosttable. Returns index into TABLE or -1 if no host could be | hosttable. Returns index into TABLE or -1 if no host could be | ||||
selected. */ | selected. */ | ||||
Context not available. | |||||
int *tbl = NULL; | int *tbl = NULL; | ||||
size_t tblsize = 0; | size_t tblsize = 0; | ||||
int pidx, idx; | int pidx, idx; | ||||
time_t curtime; | |||||
curtime = gnupg_get_time (); | |||||
/* We create a new table so that we randomly select only from | /* We create a new table so that we randomly select only from | ||||
currently alive hosts. */ | currently alive hosts. */ | ||||
for (idx=0; (pidx = table[idx]) != -1; idx++) | for (idx=0; (pidx = table[idx]) != -1; idx++) | ||||
if (hosttable[pidx] && !hosttable[pidx]->dead) | if (hosttable[pidx] && host_is_alive (hosttable[pidx], curtime)) | ||||
{ | { | ||||
tblsize++; | tblsize++; | ||||
tbl = xtryrealloc(tbl, tblsize * sizeof *tbl); | tbl = xtryrealloc(tbl, tblsize * sizeof *tbl); | ||||
Context not available. | |||||
gpg_error_t err = 0; | gpg_error_t err = 0; | ||||
hostinfo_t hi; | hostinfo_t hi; | ||||
int idx; | int idx; | ||||
time_t curtime; | |||||
*r_host = NULL; | *r_host = NULL; | ||||
if (r_httpflags) | if (r_httpflags) | ||||
Context not available. | |||||
xfree (reftbl); | xfree (reftbl); | ||||
} | } | ||||
curtime = gnupg_get_time (); | |||||
hi = hosttable[idx]; | hi = hosttable[idx]; | ||||
if (hi->pool) | if (hi->pool) | ||||
{ | { | ||||
Context not available. | |||||
if (force_reselect) | if (force_reselect) | ||||
hi->poolidx = -1; | hi->poolidx = -1; | ||||
else if (hi->poolidx >= 0 && hi->poolidx < hosttable_size | else if (hi->poolidx >= 0 && hi->poolidx < hosttable_size | ||||
&& hosttable[hi->poolidx] && hosttable[hi->poolidx]->dead) | && hosttable[hi->poolidx] && !host_is_alive (hosttable[hi->poolidx], curtime)) | ||||
hi->poolidx = -1; | hi->poolidx = -1; | ||||
/* Select a host if needed. */ | /* Select a host if needed. */ | ||||
Context not available. | |||||
assert (hi); | assert (hi); | ||||
} | } | ||||
if (hi->dead) | if (!host_is_alive (hi, curtime)) | ||||
{ | { | ||||
log_error ("host '%s' marked as dead\n", hi->name); | log_error ("host '%s' marked as dead\n", hi->name); | ||||
if (r_poolname) | if (r_poolname) | ||||
Context not available. | |||||
{ | { | ||||
gpg_error_t err = 0; | gpg_error_t err = 0; | ||||
hostinfo_t hi, hi2; | hostinfo_t hi, hi2; | ||||
int idx, idx2, idx3, n; | int idx, idx2, idx3, n, is_alive; | ||||
time_t curtime; | |||||
if (!name || !*name || !strcmp (name, "localhost")) | if (!name || !*name || !strcmp (name, "localhost")) | ||||
return 0; | return 0; | ||||
Context not available. | |||||
if (idx == -1) | if (idx == -1) | ||||
return gpg_error (GPG_ERR_NOT_FOUND); | return gpg_error (GPG_ERR_NOT_FOUND); | ||||
curtime = gnupg_get_time (); | |||||
hi = hosttable[idx]; | hi = hosttable[idx]; | ||||
if (alive && hi->dead) | is_alive = host_is_alive (hi, curtime); | ||||
if (alive && !is_alive) | |||||
{ | { | ||||
hi->dead = 0; | hi->dead = 0; | ||||
err = ks_printf_help (ctrl, "marking '%s' as alive", name); | err = ks_printf_help (ctrl, "marking '%s' as alive", name); | ||||
} | } | ||||
else if (!alive && !hi->dead) | else if (!alive && is_alive) | ||||
{ | { | ||||
hi->dead = 1; | hi->dead = 1; | ||||
hi->died_at = 0; /* Manually set dead. */ | hi->died_at = 0; /* Manually set dead. */ | ||||
Context not available. | |||||
hi2 = hosttable[n]; | hi2 = hosttable[n]; | ||||
if (!hi2) | if (!hi2) | ||||
; | continue; | ||||
else if (alive && hi2->dead) | is_alive = host_is_alive (hi2, curtime); | ||||
if (alive && !is_alive) | |||||
{ | { | ||||
hi2->dead = 0; | hi2->dead = 0; | ||||
err = ks_printf_help (ctrl, "marking '%s' as alive", | err = ks_printf_help (ctrl, "marking '%s' as alive", | ||||
hi2->name); | hi2->name); | ||||
} | } | ||||
else if (!alive && !hi2->dead) | else if (!alive && is_alive) | ||||
{ | { | ||||
hi2->dead = 1; | hi2->dead = 1; | ||||
hi2->died_at = 0; /* Manually set dead. */ | hi2->died_at = 0; /* Manually set dead. */ | ||||
Context not available. | |||||
} | } | ||||
/* Housekeeping function called from the housekeeping thread. It is | |||||
used to mark dead hosts alive so that they may be tried again after | |||||
some time. */ | |||||
void | |||||
ks_hkp_housekeeping (time_t curtime) | |||||
{ | |||||
int idx; | |||||
hostinfo_t hi; | |||||
for (idx=0; idx < hosttable_size; idx++) | |||||
{ | |||||
hi = hosttable[idx]; | |||||
if (!hi) | |||||
continue; | |||||
if (!hi->dead) | |||||
continue; | |||||
if (!hi->died_at) | |||||
continue; /* Do not resurrect manually shot hosts. */ | |||||
if (hi->died_at + RESURRECT_INTERVAL <= curtime | |||||
|| hi->died_at > curtime) | |||||
{ | |||||
hi->dead = 0; | |||||
log_info ("resurrected host '%s'", hi->name); | |||||
} | |||||
} | |||||
} | |||||
/* Send an HTTP request. On success returns an estream object at | /* Send an HTTP request. On success returns an estream object at | ||||
R_FP. HOSTPORTSTR is only used for diagnostics. If HTTPHOST is | R_FP. HOSTPORTSTR is only used for diagnostics. If HTTPHOST is | ||||
not NULL it will be used as HTTP "Host" header. If POST_CB is not | not NULL it will be used as HTTP "Host" header. If POST_CB is not | ||||
Context not available. |