From be0ba43d7a81a8e44c047b93e8c19cc30d2f983a Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 9 Jan 2023 20:45:16 +0100 Subject: PQ: use exponential back-off when reconnecting to the database to listen on events --- src/pq/pq.h | 5 +++++ src/pq/pq_event.c | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/pq/pq.h b/src/pq/pq.h index 85cfcc070..f9b59e058 100644 --- a/src/pq/pq.h +++ b/src/pq/pq.h @@ -89,6 +89,11 @@ struct GNUNET_PQ_Context */ struct GNUNET_NETWORK_Handle *rfd; + /** + * How fast should we resubscribe again? + */ + struct GNUNET_TIME_Relative resubscribe_backoff; + /** * Flags controlling the connection. */ diff --git a/src/pq/pq_event.c b/src/pq/pq_event.c index b0ed6798a..6dbacf7ff 100644 --- a/src/pq/pq_event.c +++ b/src/pq/pq_event.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet - Copyright (C) 2021 GNUnet e.V. + Copyright (C) 2021, 2023 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -283,11 +283,17 @@ do_scheduler_notify (void *cls) "Resubscribing\n"); if (NULL == db->rfd) { + db->resubscribe_backoff + = GNUNET_TIME_relative_max (db->resubscribe_backoff, + GNUNET_TIME_UNIT_SECONDS); + db->resubscribe_backoff + = GNUNET_TIME_STD_BACKOFF (db->resubscribe_backoff); db->event_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_scheduler_notify, db); return; } + db->resubscribe_backoff = GNUNET_TIME_UNIT_SECONDS; db->event_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, db->rfd, @@ -387,7 +393,7 @@ manage_subscribe (struct GNUNET_PQ_Context *db, * @param value the event handler * @return #GNUNET_OK to continue to iterate */ -static int +static enum GNUNET_GenericReturnValue register_notify (void *cls, const struct GNUNET_ShortHashCode *sh, void *value) -- cgit v1.2.3