diff options
author | jospaeth <spaethj@in.tum.de> | 2020-08-21 18:44:43 +0200 |
---|---|---|
committer | jospaeth <spaethj@in.tum.de> | 2020-08-21 18:44:43 +0200 |
commit | 7cd8a4ba4ca75338e8ad932e70cead8e0faf3cba (patch) | |
tree | f28e842b4ac67108c70a9acca5c5d18dca466265 | |
parent | fad9b5ac52c85dacd2fe5f08687944ee8339f592 (diff) | |
download | gnunet-7cd8a4ba4ca75338e8ad932e70cead8e0faf3cba.tar.gz gnunet-7cd8a4ba4ca75338e8ad932e70cead8e0faf3cba.zip |
add timeout to GNS lookup
handles the case that the zone is not found
-rw-r--r-- | src/escrow/plugin_escrow_gns.c | 122 |
1 files changed, 120 insertions, 2 deletions
diff --git a/src/escrow/plugin_escrow_gns.c b/src/escrow/plugin_escrow_gns.c index 79b2519fa..4ece88ca9 100644 --- a/src/escrow/plugin_escrow_gns.c +++ b/src/escrow/plugin_escrow_gns.c | |||
@@ -137,6 +137,10 @@ struct NamestoreQueueEntry | |||
137 | }; | 137 | }; |
138 | 138 | ||
139 | 139 | ||
140 | // define TimeoutTaskEntry here, as it is already needed in GnsLookupRequest | ||
141 | struct TimeoutTaskEntry; | ||
142 | |||
143 | |||
140 | struct GnsLookupRequestEntry | 144 | struct GnsLookupRequestEntry |
141 | { | 145 | { |
142 | /** | 146 | /** |
@@ -163,6 +167,40 @@ struct GnsLookupRequestEntry | |||
163 | * index of the respective share | 167 | * index of the respective share |
164 | */ | 168 | */ |
165 | uint8_t i; | 169 | uint8_t i; |
170 | |||
171 | /** | ||
172 | * Timeout task scheduled for this lookup request | ||
173 | */ | ||
174 | struct TimeoutTaskEntry *tt; | ||
175 | }; | ||
176 | |||
177 | |||
178 | struct TimeoutTaskEntry | ||
179 | { | ||
180 | /** | ||
181 | * DLL | ||
182 | */ | ||
183 | struct TimeoutTaskEntry *prev; | ||
184 | |||
185 | /** | ||
186 | * DLL | ||
187 | */ | ||
188 | struct TimeoutTaskEntry *next; | ||
189 | |||
190 | /** | ||
191 | * Timeout task | ||
192 | */ | ||
193 | struct GNUNET_SCHEDULER_Task *tt; | ||
194 | |||
195 | /** | ||
196 | * GNS lookup request this timeout is for | ||
197 | */ | ||
198 | struct GnsLookupRequestEntry *gns_lr; | ||
199 | |||
200 | /** | ||
201 | * Plugin operation that started the timeout | ||
202 | */ | ||
203 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap; | ||
166 | }; | 204 | }; |
167 | 205 | ||
168 | 206 | ||
@@ -303,6 +341,16 @@ struct ESCROW_GnsPluginOperation | |||
303 | * DLL tail for GNS lookup requests | 341 | * DLL tail for GNS lookup requests |
304 | */ | 342 | */ |
305 | struct GnsLookupRequestEntry *gns_lrs_tail; | 343 | struct GnsLookupRequestEntry *gns_lrs_tail; |
344 | |||
345 | /** | ||
346 | * DLL head for GNS timeout tasks | ||
347 | */ | ||
348 | struct TimeoutTaskEntry *tts_head; | ||
349 | |||
350 | /** | ||
351 | * DLL tail for GNS timeout tasks | ||
352 | */ | ||
353 | struct TimeoutTaskEntry *tts_tail; | ||
306 | }; | 354 | }; |
307 | 355 | ||
308 | /** | 356 | /** |
@@ -328,6 +376,7 @@ cleanup_plugin_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap) | |||
328 | struct PkEntry *curr_pk, *next_pk; | 376 | struct PkEntry *curr_pk, *next_pk; |
329 | struct NamestoreQueueEntry *curr_ns_qe, *next_ns_qe; | 377 | struct NamestoreQueueEntry *curr_ns_qe, *next_ns_qe; |
330 | struct GnsLookupRequestEntry *curr_gns_lr, *next_gns_lr; | 378 | struct GnsLookupRequestEntry *curr_gns_lr, *next_gns_lr; |
379 | struct TimeoutTaskEntry *curr_tt, *next_tt; | ||
331 | 380 | ||
332 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; | 381 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; |
333 | 382 | ||
@@ -384,6 +433,16 @@ cleanup_plugin_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap) | |||
384 | GNUNET_GNS_lookup_cancel (curr_gns_lr->lr); | 433 | GNUNET_GNS_lookup_cancel (curr_gns_lr->lr); |
385 | GNUNET_free (curr_gns_lr); | 434 | GNUNET_free (curr_gns_lr); |
386 | } | 435 | } |
436 | /* clean up timeout task list */ | ||
437 | for (curr_tt = p_op->tts_head; NULL != curr_tt; curr_tt = next_tt) | ||
438 | { | ||
439 | next_tt = curr_tt->next; | ||
440 | GNUNET_CONTAINER_DLL_remove (p_op->tts_head, | ||
441 | p_op->tts_tail, | ||
442 | curr_tt); | ||
443 | GNUNET_SCHEDULER_cancel (curr_tt->tt); | ||
444 | GNUNET_free (curr_tt); | ||
445 | } | ||
387 | /* free the keyshares array */ | 446 | /* free the keyshares array */ |
388 | if (NULL != p_op->restored_keyshares) | 447 | if (NULL != p_op->restored_keyshares) |
389 | GNUNET_free (p_op->restored_keyshares); | 448 | GNUNET_free (p_op->restored_keyshares); |
@@ -1115,7 +1174,7 @@ process_keyshares (void *cls) | |||
1115 | { | 1174 | { |
1116 | /* the key cannot be restored */ | 1175 | /* the key cannot be restored */ |
1117 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1176 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1118 | "need %hhu shares, but could only get %hhu", | 1177 | "need %hhu shares, but could only get %hhu\n", |
1119 | p_op->share_threshold, | 1178 | p_op->share_threshold, |
1120 | keyshares_count); | 1179 | keyshares_count); |
1121 | 1180 | ||
@@ -1163,11 +1222,18 @@ process_gns_lookup_result (void *cls, | |||
1163 | plugin_op_wrap = gns_lr->plugin_op_wrap; | 1222 | plugin_op_wrap = gns_lr->plugin_op_wrap; |
1164 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; | 1223 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; |
1165 | 1224 | ||
1166 | // remove gns_lr from our list | 1225 | /* remove gns_lr from our list */ |
1167 | GNUNET_CONTAINER_DLL_remove (p_op->gns_lrs_head, | 1226 | GNUNET_CONTAINER_DLL_remove (p_op->gns_lrs_head, |
1168 | p_op->gns_lrs_tail, | 1227 | p_op->gns_lrs_tail, |
1169 | gns_lr); | 1228 | gns_lr); |
1170 | 1229 | ||
1230 | /* cancel the timeout for that lookup */ | ||
1231 | GNUNET_CONTAINER_DLL_remove (p_op->tts_head, | ||
1232 | p_op->tts_tail, | ||
1233 | gns_lr->tt); | ||
1234 | GNUNET_SCHEDULER_cancel (gns_lr->tt->tt); | ||
1235 | GNUNET_free (gns_lr->tt); | ||
1236 | |||
1171 | if (1 != rd_count) | 1237 | if (1 != rd_count) |
1172 | { | 1238 | { |
1173 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1239 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -1213,6 +1279,39 @@ process_gns_lookup_result (void *cls, | |||
1213 | 1279 | ||
1214 | 1280 | ||
1215 | static void | 1281 | static void |
1282 | timeout_gns_request (void *cls) | ||
1283 | { | ||
1284 | struct TimeoutTaskEntry *curr_tt = cls; | ||
1285 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap; | ||
1286 | struct ESCROW_GnsPluginOperation *p_op; | ||
1287 | |||
1288 | plugin_op_wrap = curr_tt->plugin_op_wrap; | ||
1289 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; | ||
1290 | |||
1291 | /* remove timeout task from our list */ | ||
1292 | GNUNET_CONTAINER_DLL_remove (p_op->tts_head, | ||
1293 | p_op->tts_tail, | ||
1294 | curr_tt); | ||
1295 | |||
1296 | /* cancel the GNS lookup and remove it from our list */ | ||
1297 | GNUNET_GNS_lookup_cancel (curr_tt->gns_lr->lr); | ||
1298 | GNUNET_CONTAINER_DLL_remove (p_op->gns_lrs_head, | ||
1299 | p_op->gns_lrs_tail, | ||
1300 | curr_tt->gns_lr); | ||
1301 | GNUNET_free (curr_tt->gns_lr); | ||
1302 | |||
1303 | GNUNET_free (curr_tt); | ||
1304 | |||
1305 | /* check if this was the last pending GNS lookup */ | ||
1306 | if (NULL == p_op->gns_lrs_head) | ||
1307 | { | ||
1308 | // no need to schedule, as the timeout is already scheduled | ||
1309 | process_keyshares (plugin_op_wrap); | ||
1310 | } | ||
1311 | } | ||
1312 | |||
1313 | |||
1314 | static void | ||
1216 | restore_private_key (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, | 1315 | restore_private_key (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, |
1217 | struct GNUNET_ESCROW_Anchor *escrowAnchor, | 1316 | struct GNUNET_ESCROW_Anchor *escrowAnchor, |
1218 | PkContinuation cont, | 1317 | PkContinuation cont, |
@@ -1223,6 +1322,8 @@ restore_private_key (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, | |||
1223 | struct GNUNET_CRYPTO_EcdsaPublicKey curr_escrow_pub; | 1322 | struct GNUNET_CRYPTO_EcdsaPublicKey curr_escrow_pub; |
1224 | char *label, *curr_escrow_pk_string; | 1323 | char *label, *curr_escrow_pk_string; |
1225 | struct GnsLookupRequestEntry *curr_gns_lr; | 1324 | struct GnsLookupRequestEntry *curr_gns_lr; |
1325 | struct GNUNET_TIME_Relative delay; | ||
1326 | struct TimeoutTaskEntry *curr_tt; | ||
1226 | 1327 | ||
1227 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; | 1328 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; |
1228 | 1329 | ||
@@ -1235,6 +1336,9 @@ restore_private_key (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, | |||
1235 | 1336 | ||
1236 | label = get_label (p_op->userSecret); | 1337 | label = get_label (p_op->userSecret); |
1237 | 1338 | ||
1339 | // init delay to 2s | ||
1340 | delay.rel_value_us = 2 * GNUNET_TIME_relative_get_second_().rel_value_us; | ||
1341 | |||
1238 | for (uint8_t i = 0; i < p_op->shares; i++) | 1342 | for (uint8_t i = 0; i < p_op->shares; i++) |
1239 | { | 1343 | { |
1240 | curr_escrow_pk = derive_private_key (p_op->egoName, p_op->userSecret, i); | 1344 | curr_escrow_pk = derive_private_key (p_op->egoName, p_op->userSecret, i); |
@@ -1260,6 +1364,20 @@ restore_private_key (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, | |||
1260 | GNUNET_CONTAINER_DLL_insert_tail (p_op->gns_lrs_head, | 1364 | GNUNET_CONTAINER_DLL_insert_tail (p_op->gns_lrs_head, |
1261 | p_op->gns_lrs_tail, | 1365 | p_op->gns_lrs_tail, |
1262 | curr_gns_lr); | 1366 | curr_gns_lr); |
1367 | |||
1368 | /* start timeout for GNS lookup (cancels the lr if not yet finished) */ | ||
1369 | curr_tt = GNUNET_new (struct TimeoutTaskEntry); | ||
1370 | curr_tt->gns_lr = curr_gns_lr; | ||
1371 | curr_tt->plugin_op_wrap = plugin_op_wrap; | ||
1372 | curr_tt->tt = GNUNET_SCHEDULER_add_delayed (delay, | ||
1373 | &timeout_gns_request, | ||
1374 | curr_tt); | ||
1375 | GNUNET_CONTAINER_DLL_insert_tail (p_op->tts_head, | ||
1376 | p_op->tts_tail, | ||
1377 | curr_tt); | ||
1378 | |||
1379 | // set the timeout task for the current gns lr entry | ||
1380 | curr_gns_lr->tt = curr_tt; | ||
1263 | } | 1381 | } |
1264 | GNUNET_free (label); | 1382 | GNUNET_free (label); |
1265 | } | 1383 | } |