1 From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2 Date: Sat, 29 Oct 2016 02:00:50 -0400
3 Subject: dimrngr: Avoid need for hkp housekeeping.
5 * dirmngr/ks-engine-hkp.c (host_is_alive): New function. Test whether
6 host is alive and resurrects it if it has been dead long enough.
7 (select_random_host, map_host, ks_hkp_mark_host): Use host_is_alive
8 instead of testing hostinfo_t->dead directly.
9 (ks_hkp_housekeeping): Remove function, no longer needed.
10 * dirmngr/dirmngr.c (housekeeping_thread): Remove call to
15 Rather than resurrecting hosts upon scheduled resurrection times, test
16 whether hosts should be resurrected as they're inspected for being
17 dead. This removes the need for explicit housekeeping, and makes host
18 resurrections happen "just in time", rather than being clustered on
19 HOUSEKEEPING_INTERVAL seconds.
21 Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
23 dirmngr/dirmngr.c | 3 --
24 dirmngr/dirmngr.h | 4 ---
25 dirmngr/ks-engine-hkp.c | 73 ++++++++++++++++++++++++-------------------------
26 3 files changed, 36 insertions(+), 44 deletions(-)
28 diff --git a/dirmngr/dirmngr.c b/dirmngr/dirmngr.c
29 index 5ee589e93..130f74bc7 100644
30 --- a/dirmngr/dirmngr.c
31 +++ b/dirmngr/dirmngr.c
32 @@ -1773,12 +1773,10 @@ static void *
33 housekeeping_thread (void *arg)
37 struct server_control_s ctrlbuf;
41 - curtime = gnupg_get_time ();
44 log_info ("housekeeping is already going on\n");
45 @@ -1791,7 +1789,6 @@ housekeeping_thread (void *arg)
46 memset (&ctrlbuf, 0, sizeof ctrlbuf);
47 dirmngr_init_default_ctrl (&ctrlbuf);
49 - ks_hkp_housekeeping (curtime);
50 if (network_activity_seen)
52 network_activity_seen = 0;
53 diff --git a/dirmngr/dirmngr.h b/dirmngr/dirmngr.h
54 index 9a8787842..0469d55bc 100644
55 --- a/dirmngr/dirmngr.h
56 +++ b/dirmngr/dirmngr.h
57 @@ -192,10 +192,6 @@ void dirmngr_sighup_action (void);
58 const char* dirmngr_get_current_socket_name (void);
61 -/*-- Various housekeeping functions. --*/
62 -void ks_hkp_housekeeping (time_t curtime);
66 ldap_server_t get_ldapservers_from_ctrl (ctrl_t ctrl);
67 ksba_cert_t get_cert_local (ctrl_t ctrl, const char *issuer);
68 diff --git a/dirmngr/ks-engine-hkp.c b/dirmngr/ks-engine-hkp.c
69 index 2d1240bb3..6f1c2e8e0 100644
70 --- a/dirmngr/ks-engine-hkp.c
71 +++ b/dirmngr/ks-engine-hkp.c
72 @@ -203,6 +203,25 @@ host_in_pool_p (int *pool, int tblidx)
77 +host_is_alive (hostinfo_t hi, time_t curtime)
84 + return 0; /* manually marked dead */
85 + if (hi->died_at + RESURRECT_INTERVAL <= curtime
86 + || hi->died_at > curtime)
89 + log_info ("resurrected host '%s'", hi->name);
95 /* Select a random host. Consult TABLE which indices into the global
96 hosttable. Returns index into TABLE or -1 if no host could be
98 @@ -212,11 +231,13 @@ select_random_host (int *table)
104 + curtime = gnupg_get_time ();
105 /* We create a new table so that we randomly select only from
106 currently alive hosts. */
107 for (idx=0; (pidx = table[idx]) != -1; idx++)
108 - if (hosttable[pidx] && !hosttable[pidx]->dead)
109 + if (hosttable[pidx] && host_is_alive (hosttable[pidx], curtime))
112 tbl = xtryrealloc(tbl, tblsize * sizeof *tbl);
113 @@ -392,6 +413,7 @@ map_host (ctrl_t ctrl, const char *name, int force_reselect,
121 @@ -538,6 +560,7 @@ map_host (ctrl_t ctrl, const char *name, int force_reselect,
125 + curtime = gnupg_get_time ();
129 @@ -554,7 +577,7 @@ map_host (ctrl_t ctrl, const char *name, int force_reselect,
132 else if (hi->poolidx >= 0 && hi->poolidx < hosttable_size
133 - && hosttable[hi->poolidx] && hosttable[hi->poolidx]->dead)
134 + && hosttable[hi->poolidx] && !host_is_alive (hosttable[hi->poolidx], curtime))
137 /* Select a host if needed. */
138 @@ -578,7 +601,7 @@ map_host (ctrl_t ctrl, const char *name, int force_reselect,
143 + if (!host_is_alive (hi, curtime))
145 log_error ("host '%s' marked as dead\n", hi->name);
147 @@ -683,7 +706,8 @@ ks_hkp_mark_host (ctrl_t ctrl, const char *name, int alive)
151 - int idx, idx2, idx3, n;
152 + int idx, idx2, idx3, n, is_alive;
155 if (!name || !*name || !strcmp (name, "localhost"))
157 @@ -692,13 +716,15 @@ ks_hkp_mark_host (ctrl_t ctrl, const char *name, int alive)
159 return gpg_error (GPG_ERR_NOT_FOUND);
161 + curtime = gnupg_get_time ();
163 - if (alive && hi->dead)
164 + is_alive = host_is_alive (hi, curtime);
165 + if (alive && !is_alive)
168 err = ks_printf_help (ctrl, "marking '%s' as alive", name);
170 - else if (!alive && !hi->dead)
171 + else if (!alive && is_alive)
174 hi->died_at = 0; /* Manually set dead. */
175 @@ -730,14 +756,15 @@ ks_hkp_mark_host (ctrl_t ctrl, const char *name, int alive)
180 - else if (alive && hi2->dead)
182 + is_alive = host_is_alive (hi2, curtime);
183 + if (alive && !is_alive)
186 err = ks_printf_help (ctrl, "marking '%s' as alive",
189 - else if (!alive && !hi2->dead)
190 + else if (!alive && is_alive)
193 hi2->died_at = 0; /* Manually set dead. */
194 @@ -939,34 +966,6 @@ ks_hkp_resolve (ctrl_t ctrl, parsed_uri_t uri)
198 -/* Housekeeping function called from the housekeeping thread. It is
199 - used to mark dead hosts alive so that they may be tried again after
202 -ks_hkp_housekeeping (time_t curtime)
207 - for (idx=0; idx < hosttable_size; idx++)
209 - hi = hosttable[idx];
215 - continue; /* Do not resurrect manually shot hosts. */
216 - if (hi->died_at + RESURRECT_INTERVAL <= curtime
217 - || hi->died_at > curtime)
220 - log_info ("resurrected host '%s'", hi->name);
226 /* Send an HTTP request. On success returns an estream object at
227 R_FP. HOSTPORTSTR is only used for diagnostics. If HTTPHOST is
228 not NULL it will be used as HTTP "Host" header. If POST_CB is not