-/**
- * Function called with responses from the service.
- *
- * @param cls our 'struct AddressLookupCtx*'
- * @param msg NULL on timeout or error, otherwise presumably a
- * message with the human-readable peer and address
- */
-static void
-peer_address_iteration_response_processor (void *cls,
- const struct GNUNET_MessageHeader *msg)
-{
- struct GNUNET_TRANSPORT_PeerAddressLookupContext *alucb = cls;
- struct AddressIterateResponseMessage *arm;
- struct GNUNET_HELLO_Address * address;
- uint16_t size;
-
- if (msg == NULL)
- {
- alucb->cb (alucb->cb_cls, NULL);
- GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
- GNUNET_free (alucb);
- return;
- }
-
- GNUNET_break (ntohs (msg->type) ==
- GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
- size = ntohs (msg->size);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message type %u size %u\n",
- ntohs (msg->type), size);
- if (size == sizeof (struct GNUNET_MessageHeader))
- {
- /* done! */
- alucb->cb (alucb->cb_cls, NULL);
- GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
- GNUNET_free (alucb);
- return;
- }
- if (size < sizeof (struct AddressIterateResponseMessage))
- {
- /* invalid reply */
- GNUNET_break (0);
- alucb->cb (alucb->cb_cls, NULL);
- GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
- GNUNET_free (alucb);
- return;
- }
-
- arm = (struct AddressIterateResponseMessage *) &msg[1];
- address = (struct GNUNET_HELLO_Address *) &arm[1];
-
- /* expect more replies */
- GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb,
- GNUNET_TIME_absolute_get_remaining (alucb->timeout));
- alucb->cb (alucb->cb_cls, address);
-}
-
-
-/**
- * Return all the known addresses for a peer.
- *
- * @param cfg configuration to use
- * @param timeout how long is the lookup allowed to take at most
- * @param peer_address_callback function to call with the results
- * @param peer_address_callback_cls closure for peer_address_callback
- */
-void
-GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressLookUpCallback
- peer_address_callback,
- void *peer_address_callback_cls)
-{
- struct AddressIterateMessage msg;
- struct GNUNET_TIME_Absolute abs_timeout;
- struct GNUNET_TRANSPORT_PeerAddressLookupContext *peer_address_lookup_cb;
- struct GNUNET_CLIENT_Connection *client;
-
- client = GNUNET_CLIENT_connect ("transport", cfg);
- if (client == NULL)
- {
- peer_address_callback (peer_address_callback_cls, NULL);
- return;
- }
- abs_timeout = GNUNET_TIME_relative_to_absolute (timeout);
-
- msg.header.size = htons (sizeof (struct AddressIterateMessage));
- msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE);
- msg.timeout = GNUNET_TIME_absolute_hton (abs_timeout);
- peer_address_lookup_cb = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext));
- peer_address_lookup_cb->cb = peer_address_callback;
- peer_address_lookup_cb->cb_cls = peer_address_callback_cls;
- peer_address_lookup_cb->timeout = abs_timeout;
- peer_address_lookup_cb->client = client;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CLIENT_transmit_and_get_response (client, &msg.header,
- timeout, GNUNET_YES,
- &peer_address_iteration_response_processor,
- peer_address_lookup_cb));
-}