*/
static struct GNUNET_PEERSTORE_Handle *peerstore;
+/**
+ * Task used to flush respect values to disk.
+ */
+static struct GNUNET_SCHEDULER_Task *fr_task;
+
/**
* Update the latency information kept for the given peer.
* @param cls handle to connected peer entry
* @param record peerstore record information
* @param emsg error message, or NULL if no errors
- * @return #GNUNET_NO to stop iterating since we only expect 0 or 1 records
*/
-static int
+static void
peer_respect_cb (void *cls,
const struct GNUNET_PEERSTORE_Record *record,
const char *emsg)
struct GSF_ConnectedPeer *cp = cls;
GNUNET_assert (NULL != cp->respect_iterate_req);
- cp->respect_iterate_req = NULL;
+ printf("Got a record!\n");
if ((NULL != record) && (sizeof (cp->disk_respect) == record->value_size))
cp->disk_respect = cp->ppd.respect = *((uint32_t *)record->value);
GSF_push_start_ (cp);
if (NULL != cp->creation_cb)
cp->creation_cb (cp->creation_cb_cls, cp);
- return GNUNET_NO;
+ if (NULL != record)
+ {
+ printf("Cancelling!\n");
+ GNUNET_PEERSTORE_iterate_cancel (cp->respect_iterate_req);
+ cp->respect_iterate_req = NULL;
+ }
}
{
struct GSF_DelayedHandle *dh = cls;
struct GSF_ConnectedPeer *cp = dh->cp;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
GNUNET_CONTAINER_DLL_remove (cp->delayed_head,
cp->delayed_tail,
dh);
cp->delay_queue_size--;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- {
- GNUNET_free (dh->pm);
- GNUNET_free (dh);
- return;
- }
(void) GSF_peer_transmit_ (cp,
GNUNET_NO,
UINT32_MAX,
static void
cron_flush_respect (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- if (NULL == cp_map)
- return;
+ fr_task = NULL;
GNUNET_CONTAINER_multipeermap_iterate (cp_map,
- &flush_respect, NULL);
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
- GNUNET_SCHEDULER_add_delayed_with_priority (RESPECT_FLUSH_FREQ,
- GNUNET_SCHEDULER_PRIORITY_HIGH,
- &cron_flush_respect, NULL);
+ &flush_respect,
+ NULL);
+ fr_task = GNUNET_SCHEDULER_add_delayed_with_priority (RESPECT_FLUSH_FREQ,
+ GNUNET_SCHEDULER_PRIORITY_HIGH,
+ &cron_flush_respect, NULL);
}
{
cp_map = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES);
peerstore = GNUNET_PEERSTORE_connect (GSF_cfg);
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_HIGH,
- &cron_flush_respect, NULL);
+ fr_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_HIGH,
+ &cron_flush_respect, NULL);
}
&flush_respect,
NULL);
GNUNET_CONTAINER_multipeermap_iterate (cp_map,
- &clean_peer, NULL);
+ &clean_peer,
+ NULL);
+ GNUNET_SCHEDULER_cancel (fr_task);
+ fr_task = NULL;
GNUNET_CONTAINER_multipeermap_destroy (cp_map);
cp_map = NULL;
- GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_YES);
+ GNUNET_PEERSTORE_disconnect (peerstore,
+ GNUNET_YES);
+
}