*/
const struct GNUNET_CONFIGURATION_Handle *cfg;
+ /**
+ * Tasked used for delayed re-connection attempt.
+ */
+ GNUNET_SCHEDULER_TaskIdentifier task;
+
};
receive_notifications (struct GNUNET_PEERINFO_NotifyContext *nc);
+/**
+ * Task to re-try connecting to peerinfo.
+ *
+ * @param cls the 'struct GNUNET_PEERINFO_NotifyContext'
+ * @param tc scheduler context
+ */
+static void
+reconnect (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct GNUNET_PEERINFO_NotifyContext *nc = cls;
+
+ nc->task = GNUNET_SCHEDULER_NO_TASK;
+ nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg);
+ if (NULL == nc->client)
+ {
+ /* ugh */
+ nc->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &reconnect,
+ nc);
+ return;
+ }
+ request_notifications (nc);
+}
+
+
/**
* Receive a peerinfo information message, process it and
* go for more.
if (msg == NULL)
{
GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO);
- nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg);
- request_notifications (nc);
+ reconnect (nc, NULL);
return;
}
ms = ntohs (msg->size);
"Received information about peer `%s' from peerinfo database\n",
GNUNET_i2s (&im->peer));
#endif
- nc->callback (nc->callback_cls, &im->peer, hello);
+ nc->callback (nc->callback_cls, &im->peer, hello, NULL);
receive_notifications (nc);
}
GNUNET_CLIENT_notify_transmit_ready_cancel (nc->init);
nc->init = NULL;
}
- GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO);
+ if (NULL != nc->client)
+ GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO);
+ if (GNUNET_SCHEDULER_NO_TASK != nc->task)
+ GNUNET_SCHEDULER_cancel (nc->task);
GNUNET_free (nc);
}