- ic->callback (ic->callback_cls, NULL, NULL, 2);
- reconnect (ic->h);
- trigger_transmit (ic->h);
- GNUNET_free (ic);
- return;
- }
- GNUNET_CLIENT_receive (ic->h->client,
- &peerinfo_handler,
- ic,
- GNUNET_TIME_absolute_get_remaining (ic->timeout));
-}
-
-
-/**
- * Call a method for each known matching host and change its trust
- * value. The callback method will be invoked once for each matching
- * host and then finally once with a NULL pointer. After that final
- * invocation, the iterator context must no longer be used.
- *
- * Note that the last call can be triggered by timeout or by simply
- * being done; however, the trust argument will be set to zero if we
- * are done, 1 if we timed out and 2 for fatal error.
- *
- * Instead of calling this function with 'peer == NULL' and 'trust ==
- * 0', it is often better to use 'GNUNET_PEERINFO_notify'.
- *
- * @param h handle to the peerinfo service
- * @param peer restrict iteration to this peer only (can be NULL)
- * @param trust_delta how much to change the trust in all matching peers
- * @param timeout how long to wait until timing out
- * @param callback the method to call for each peer
- * @param callback_cls closure for callback
- * @return NULL on error (in this case, 'callback' is never called!),
- * otherwise an iterator context
- */
-struct GNUNET_PEERINFO_NewIteratorContext *
-GNUNET_PEERINFO_iterate_new (struct GNUNET_PEERINFO_Handle *h,
- const struct GNUNET_PeerIdentity *peer,
- int trust_delta,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_PEERINFO_Processor callback,
- void *callback_cls)
-{
- struct ListAllPeersMessage *lapm;
- struct ListPeerMessage *lpm;
- struct GNUNET_PEERINFO_NewIteratorContext *ic;
- struct TransmissionQueueEntry *tqe;
-
-#if DEBUG_PEERINFO
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Requesting list of peers from peerinfo database\n");
-#endif
- if (peer == NULL)
- {
- tqe = GNUNET_malloc (sizeof (struct TransmissionQueueEntry) +
- sizeof (struct ListAllPeersMessage));
- tqe->size = sizeof (struct ListAllPeersMessage);
- lapm = (struct ListAllPeersMessage *) &tqe[1];
- lapm->header.size = htons (sizeof (struct ListAllPeersMessage));
- lapm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL);
- lapm->trust_change = htonl (trust_delta);
- }
- else
- {
- tqe = GNUNET_malloc (sizeof (struct TransmissionQueueEntry) +
- sizeof (struct ListPeerMessage));
- tqe->size = sizeof (struct ListPeerMessage);
- lpm = (struct ListPeerMessage *) &tqe[1];
- lpm->header.size = htons (sizeof (struct ListPeerMessage));
- lpm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET);
- lpm->trust_change = htonl (trust_delta);
- memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity));
- }
- ic = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_NewIteratorContext));
- ic->callback = callback;
- ic->callback_cls = callback_cls;
- ic->timeout = GNUNET_TIME_relative_to_absolute (timeout);
- tqe->timeout = ic->timeout;
- tqe->cont = &iterator_start_receive;
- tqe->cont_cls = ic;
- /* FIXME: sort DLL by timeout? */
- /* FIXME: add timeout task!? */
- GNUNET_CONTAINER_DLL_insert_after (h->tq_head,
- h->tq_tail,
- h->tq_tail,
- tqe);
- trigger_transmit (h);
- return ic;
-}
-
-
-
-/**
- * Cancel an iteration over peer information.
- *
- * @param ic context of the iterator to cancel
- */
-void
-GNUNET_PEERINFO_iterate_cancel_new (struct GNUNET_PEERINFO_NewIteratorContext *ic)
-{
- GNUNET_assert (0);
- // FIXME: not implemented
-}
-
-
-
-
-
-/* ***************************** OLD API ****************************** */
-
-
-
-
-#define ADD_PEER_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
-
-
-struct CAFContext
-{
- struct GNUNET_CLIENT_Connection *client;
- struct GNUNET_MessageHeader *msg;
-};
-
-
-static size_t
-copy_and_free (void *cls, size_t size, void *buf)
-{
- struct CAFContext *cc = cls;
- struct GNUNET_MessageHeader *msg = cc->msg;
- uint16_t msize;
-
- if (buf == NULL)
- {
-#if DEBUG_PEERINFO
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _
- ("Failed to transmit message of type %u to `%s' service.\n"),
- ntohs (msg->type), "peerinfo");
-#endif
- GNUNET_free (msg);
- GNUNET_CLIENT_disconnect (cc->client, GNUNET_NO);
- GNUNET_free (cc);
- return 0;