- abs_timeout = GNUNET_TIME_relative_to_absolute (timeout);
- msg = GNUNET_malloc (len);
- msg->header->size = htons (len);
- msg->header->type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP);
- msg->timeout = GNUNET_TIME_absolute_hton (abs_timeout);
- msg->addrlen = htonl (addressLen);
- char *addrbuf = (char *) &msg[1];
- memcpy (addrbuf, address, addressLen);
- char *tbuf = &addrbuf[addressLen];
- memcpy (tbuf, nameTrans, strlen (nameTrans) + 1);
- aluCB = GNUNET_malloc (sizeof (struct AddressLookUpCB));
- aluCB->cb = aluc;
- aluCB->cb_cls = aluc_cls;
- aluCB->timeout = abs_timeout;
- aluCB->client = client;
- GNUNET_CLIENT_transmit_and_get_response (client, msg->header, timeout,
- GNUNET_YES,
- &address_response_processor,
- aluCB);
- GNUNET_free (msg);
+
+ /* notify client */
+ address =
+ GNUNET_HELLO_address_allocate (&air_msg->peer, transport_name, addr,
+ alen);
+ pal_ctx->cb (pal_ctx->cb_cls, &air_msg->peer, address);
+ GNUNET_HELLO_address_free (address);
+ }
+
+ /* expect more replies */
+ GNUNET_CLIENT_receive (pal_ctx->client, &peer_address_response_processor,
+ pal_ctx,
+ GNUNET_TIME_absolute_get_remaining (pal_ctx->timeout));
+}
+
+
+/**
+ * Return all the known addresses for a specific peer or all peers.
+ * Returns continuously all address if one_shot is set to GNUNET_NO
+ *
+ * CHANGE: Returns the address(es) that we are currently using for this
+ * peer. Upon completion, the 'AddressLookUpCallback' is called one more
+ * time with 'NULL' for the address and the peer. After this, the operation must no
+ * longer be explicitly canceled.
+ *
+ * @param cfg configuration to use
+ * @param peer peer identity to look up the addresses of, CHANGE: allow NULL for all (connected) peers
+ * @param one_shot GNUNET_YES to return the current state and then end (with NULL+NULL),
+ * GNUNET_NO to monitor the set of addresses used (continuously, must be explicitly canceled)
+ * @param timeout how long is the lookup allowed to take at most (irrelevant if one_shot is set to GNUNET_NO)
+ * @param peer_address_callback function to call with the results
+ * @param peer_address_callback_cls closure for peer_address_callback
+ */
+struct GNUNET_TRANSPORT_PeerIterateContext *
+GNUNET_TRANSPORT_peer_get_active_addresses (const struct
+ GNUNET_CONFIGURATION_Handle *cfg,
+ const struct GNUNET_PeerIdentity
+ *peer, int one_shot,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_TRANSPORT_PeerIterateCallback
+ peer_address_callback,
+ void *peer_address_callback_cls)
+{
+ struct GNUNET_TRANSPORT_PeerIterateContext *pal_ctx;
+ struct GNUNET_CLIENT_Connection *client;
+
+ client = GNUNET_CLIENT_connect ("transport", cfg);
+ if (client == NULL)
+ return NULL;
+ if (GNUNET_YES != one_shot)
+ timeout = GNUNET_TIME_UNIT_FOREVER_REL;
+ pal_ctx = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerIterateContext));
+ pal_ctx->cb = peer_address_callback;
+ pal_ctx->cb_cls = peer_address_callback_cls;
+ pal_ctx->cfg = cfg;
+ pal_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
+ if (NULL != peer)
+ pal_ctx->peer = *peer;
+ pal_ctx->one_shot = one_shot;
+ pal_ctx->client = client;
+ send_request (pal_ctx);
+
+ return pal_ctx;