commit be0ba43d7a81a8e44c047b93e8c19cc30d2f983a
parent 9ac05df446dc67f2fd937b9a54c3cc6050907e69
Author: Christian Grothoff <christian@grothoff.org>
Date: Mon, 9 Jan 2023 20:45:16 +0100
PQ: use exponential back-off when reconnecting to the database to listen on events
Diffstat:
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/pq/pq.h b/src/pq/pq.h
@@ -90,6 +90,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.
*/
enum GNUNET_PQ_Options flags;
diff --git 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)