/*
This file is part of GNUnet.
- (C)
+ Copyright (C) 2014, 2015 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
*/
static struct ClientEntry *client_tail;
+/**
+ * Task run to clean up expired records.
+ */
+static struct GNUNET_SCHEDULER_Task *expire_task;
+
/**
* Are we in the process of shutting down the service? #GNUNET_YES / #GNUNET_NO
*/
GNUNET_CONTAINER_multihashmap_destroy (watchers);
watchers = NULL;
}
+ if (NULL != expire_task)
+ {
+ GNUNET_SCHEDULER_cancel (expire_task);
+ expire_task = NULL;
+ }
GNUNET_SCHEDULER_shutdown ();
}
* Task run during shutdown.
*
* @param cls unused
- * @param tc unused
*/
static void
-shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls)
{
in_shutdown = GNUNET_YES;
if (NULL == client_head) /* Only when no connected clients. */
* Deletes any expired records from storage
*/
static void
-cleanup_expired_records (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+cleanup_expired_records (void *cls)
{
int ret;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ expire_task = NULL;
GNUNET_assert (NULL != db);
- ret =
- db->expire_records (db->cls, GNUNET_TIME_absolute_get (),
- expire_records_continuation, NULL);
+ ret = db->expire_records (db->cls, GNUNET_TIME_absolute_get (),
+ &expire_records_continuation, NULL);
if (GNUNET_OK != ret)
{
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS,
- EXPIRED_RECORDS_CLEANUP_INTERVAL),
- &cleanup_expired_records, NULL);
+ GNUNET_assert (NULL == expire_task);
+ expire_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ EXPIRED_RECORDS_CLEANUP_INTERVAL),
+ &cleanup_expired_records, NULL);
}
}
* @param success count of records deleted or #GNUNET_SYSERR
*/
static void
-expire_records_continuation (void *cls, int success)
+expire_records_continuation (void *cls,
+ int success)
{
if (success > 0)
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", success);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS,
- EXPIRED_RECORDS_CLEANUP_INTERVAL),
- &cleanup_expired_records, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%d records expired.\n",
+ success);
+ GNUNET_assert (NULL == expire_task);
+ expire_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ EXPIRED_RECORDS_CLEANUP_INTERVAL),
+ &cleanup_expired_records, NULL);
}
* @param emsg error message or NULL if no errors
* @return #GNUNET_YES to continue iteration
*/
-static int
+static void
record_iterator (void *cls, const struct GNUNET_PEERSTORE_Record *record,
const char *emsg)
{
GNUNET_SERVER_receive_done (cls_record->client,
NULL == emsg ? GNUNET_OK : GNUNET_SYSERR);
PEERSTORE_destroy_record (cls_record);
- return GNUNET_NO;
+ return;
}
srm =
(struct GNUNET_MessageHeader *)
srm, GNUNET_NO);
GNUNET_free (srm);
- return GNUNET_YES;
}
if (NULL == db)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not load database backend `%s'\n"), db_lib_name);
+ _("Could not load database backend `%s'\n"),
+ db_lib_name);
GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
return;
}
nc = GNUNET_SERVER_notification_context_create (server, 16);
watchers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
- GNUNET_SCHEDULER_add_now (&cleanup_expired_records, NULL);
+ expire_task = GNUNET_SCHEDULER_add_now (&cleanup_expired_records,
+ NULL);
GNUNET_SERVER_add_handlers (server, handlers);
GNUNET_SERVER_connect_notify (server, &handle_client_connect, NULL);
GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}