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 | 1 -
25 dirmngr/ks-engine-hkp.c | 73 ++++++++++++++++++++++++-------------------------
26 3 files changed, 36 insertions(+), 41 deletions(-)
28 diff --git a/dirmngr/dirmngr.c b/dirmngr/dirmngr.c
29 index 061cfc300..a8be56fa4 100644
30 --- a/dirmngr/dirmngr.c
31 +++ b/dirmngr/dirmngr.c
32 @@ -1771,12 +1771,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 @@ -1789,7 +1787,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 35bc000fb..acd4c636d 100644
55 --- a/dirmngr/dirmngr.h
56 +++ b/dirmngr/dirmngr.h
57 @@ -193,7 +193,6 @@ const char* dirmngr_get_current_socket_name (void);
60 /*-- Various housekeeping functions. --*/
61 -void ks_hkp_housekeeping (time_t curtime);
62 void ks_hkp_reload (void);
65 diff --git a/dirmngr/ks-engine-hkp.c b/dirmngr/ks-engine-hkp.c
66 index 57e7529f3..2b90441e2 100644
67 --- a/dirmngr/ks-engine-hkp.c
68 +++ b/dirmngr/ks-engine-hkp.c
69 @@ -203,6 +203,25 @@ host_in_pool_p (int *pool, int tblidx)
74 +host_is_alive (hostinfo_t hi, time_t curtime)
81 + return 0; /* manually marked dead */
82 + if (hi->died_at + RESURRECT_INTERVAL <= curtime
83 + || hi->died_at > curtime)
86 + log_info ("resurrected host '%s'", hi->name);
92 /* Select a random host. Consult TABLE which indices into the global
93 hosttable. Returns index into TABLE or -1 if no host could be
95 @@ -212,11 +231,13 @@ select_random_host (int *table)
101 + curtime = gnupg_get_time ();
102 /* We create a new table so that we randomly select only from
103 currently alive hosts. */
104 for (idx=0; (pidx = table[idx]) != -1; idx++)
105 - if (hosttable[pidx] && !hosttable[pidx]->dead)
106 + if (hosttable[pidx] && host_is_alive (hosttable[pidx], curtime))
109 tbl = xtryrealloc(tbl, tblsize * sizeof *tbl);
110 @@ -395,6 +416,7 @@ map_host (ctrl_t ctrl, const char *name, const char *srvtag, int force_reselect,
118 @@ -531,6 +553,7 @@ map_host (ctrl_t ctrl, const char *name, const char *srvtag, int force_reselect,
122 + curtime = gnupg_get_time ();
126 @@ -547,7 +570,7 @@ map_host (ctrl_t ctrl, const char *name, const char *srvtag, int force_reselect,
129 else if (hi->poolidx >= 0 && hi->poolidx < hosttable_size
130 - && hosttable[hi->poolidx] && hosttable[hi->poolidx]->dead)
131 + && hosttable[hi->poolidx] && !host_is_alive (hosttable[hi->poolidx], curtime))
134 /* Select a host if needed. */
135 @@ -599,7 +622,7 @@ map_host (ctrl_t ctrl, const char *name, const char *srvtag, int force_reselect,
136 free_dns_addrinfo (aibuf);
140 + if (!host_is_alive (hi, curtime))
142 log_error ("host '%s' marked as dead\n", hi->name);
144 @@ -704,7 +727,8 @@ ks_hkp_mark_host (ctrl_t ctrl, const char *name, int alive)
148 - int idx, idx2, idx3, n;
149 + int idx, idx2, idx3, n, is_alive;
152 if (!name || !*name || !strcmp (name, "localhost"))
154 @@ -713,13 +737,15 @@ ks_hkp_mark_host (ctrl_t ctrl, const char *name, int alive)
156 return gpg_error (GPG_ERR_NOT_FOUND);
158 + curtime = gnupg_get_time ();
160 - if (alive && hi->dead)
161 + is_alive = host_is_alive (hi, curtime);
162 + if (alive && !is_alive)
165 err = ks_printf_help (ctrl, "marking '%s' as alive", name);
167 - else if (!alive && !hi->dead)
168 + else if (!alive && is_alive)
171 hi->died_at = 0; /* Manually set dead. */
172 @@ -751,14 +777,15 @@ ks_hkp_mark_host (ctrl_t ctrl, const char *name, int alive)
177 - else if (alive && hi2->dead)
179 + is_alive = host_is_alive (hi2, curtime);
180 + if (alive && !is_alive)
183 err = ks_printf_help (ctrl, "marking '%s' as alive",
186 - else if (!alive && !hi2->dead)
187 + else if (!alive && is_alive)
190 hi2->died_at = 0; /* Manually set dead. */
191 @@ -974,34 +1001,6 @@ ks_hkp_resolve (ctrl_t ctrl, parsed_uri_t uri)
195 -/* Housekeeping function called from the housekeeping thread. It is
196 - used to mark dead hosts alive so that they may be tried again after
199 -ks_hkp_housekeeping (time_t curtime)
204 - for (idx=0; idx < hosttable_size; idx++)
206 - hi = hosttable[idx];
212 - continue; /* Do not resurrect manually shot hosts. */
213 - if (hi->died_at + RESURRECT_INTERVAL <= curtime
214 - || hi->died_at > curtime)
217 - log_info ("resurrected host '%s'", hi->name);
223 /* Reload (SIGHUP) action for this module. We mark all host alive
224 * even those which have been manually shot. */