- latest changes for refactoring: iterate sends disassembled hello-address
authorMatthias Wachs <wachs@net.in.tum.de>
Tue, 29 Nov 2011 15:43:11 +0000 (15:43 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Tue, 29 Nov 2011 15:43:11 +0000 (15:43 +0000)
src/include/gnunet_protocols.h
src/include/gnunet_transport_service.h
src/transport/gnunet-service-transport_clients.c
src/transport/gnunet-transport.c
src/transport/transport.h
src/transport/transport_api_address_lookup.c
src/transport/transport_api_address_to_string.c

index 81b5ce6b8520d7bb303596c92cf39b66d58363bb..f386d87688c26b788ffe565e786f8276f35d8bb4 100644 (file)
@@ -1020,12 +1020,12 @@ extern "C"
 /**
  * Request to look addresses of peers in server.
  */
-#define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP 367
+#define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING 367
 
 /**
  * Response to the address lookup request.
  */
-#define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY 368
+#define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY 368
 
 /**
  * Register a client that wants to do blacklisting.
@@ -1105,10 +1105,15 @@ extern "C"
 #define GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE 382
 
 
+/**
+ * Request to iterate over all known addresses.
+ */
+#define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE 383
+
 /**
  * Message send by a peer to notify the other to keep the session alive.
  */
-#define GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON 383
+#define GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON 384
 
 
 /**
index 7e7fc7fa659c46cd0c161c51f44b3ca188df2ab8..98436065bf0565f4ae71c9db714cb05b0135d6c1 100644 (file)
@@ -112,12 +112,8 @@ typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
  * Function to call with a binary format of an address
  *
  * @param cls closure
- * @param peer peer identity
- * @param transport transport plugin
- * @param addr address
- * @param addrlen address length
+ * @param address address
  */
-// FIXME: use GNUNET_HELLO_Address (as 2nd arg, replacing others)
 // FIXME: use NULL for address on disconnect IF in monitor mode (one_shot = NO)
 typedef void (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls,
                                                         const struct GNUNET_HELLO_Address *address);
@@ -310,17 +306,18 @@ GNUNET_TRANSPORT_address_to_string_cancel (struct
 
 
 /**
- * Return all the known addresses for a peer.
+ * Return all the known addresses for a specific peer or all peers.
+ * Returns continously 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 cancelled.
- * TODO: change code that uses this API to see if this is fine...
  *
  * @param cfg configuration to use
  * @param peer peer identity to look up the addresses of, CHANGE: allow NULL for all (connected) peers
- * FIXME: @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 cancelled)
+ * @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 cancelled)
  * @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
index d60514565fb9ff21e89333e701808779d9cf89b7..7c50218e097de5c5f01660fc5b9e8cd76e6b694c 100644 (file)
@@ -616,12 +616,12 @@ transmit_address_to_client (void *cls, const char *buf)
   if (NULL == buf)
   {
     GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
-                                                GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+                                                GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
     GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
     return;
   }
   GNUNET_SERVER_transmit_context_append_data (tc, buf, strlen (buf) + 1,
-                                              GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+                                              GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
 }
 
 
@@ -641,12 +641,12 @@ transmit_binary_to_client (void *cls, void *buf, size_t size)
   if (NULL == buf)
   {
     GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
-                                                GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+        GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
     GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
     return;
   }
   GNUNET_SERVER_transmit_context_append_data (tc, buf, size,
-                                              GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+      GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
 }
 
 
@@ -658,7 +658,7 @@ transmit_binary_to_client (void *cls, void *buf, size_t size)
  * @param message the resolution request
  */
 static void
-clients_handle_address_lookup (void *cls, struct GNUNET_SERVER_Client *client,
+clients_handle_address_to_string (void *cls, struct GNUNET_SERVER_Client *client,
                                const struct GNUNET_MessageHeader *message)
 {
   const struct AddressLookupMessage *alum;
@@ -702,7 +702,7 @@ clients_handle_address_lookup (void *cls, struct GNUNET_SERVER_Client *client,
   if (NULL == papi)
   {
     GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
-                                                GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+                                                GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
     GNUNET_SERVER_transmit_context_run (tc, rtimeout);
     return;
   }
@@ -771,7 +771,7 @@ clients_handle_peer_address_lookup (void *cls,
   GST_validation_get_addresses (&peer_address_lookup->peer,
                                 &send_address_to_client, tc);
   GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
-                                              GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+      GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
   GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
 }
 
@@ -793,17 +793,26 @@ output_addresses (void *cls, const struct GNUNET_PeerIdentity *peer,
   struct GNUNET_SERVER_TransmitContext *tc = cls;
   struct AddressIterateResponseMessage *msg;
   size_t size;
-  size_t slen;
+  size_t tlen;
+  size_t alen;
+  char * addr;
 
-  slen = strlen (address->transport_name) + 1;
-  size = (sizeof (struct AddressIterateResponseMessage) + slen);
+  tlen = strlen (address->transport_name) + 1;
+  alen = address->address_length;
+
+  size = (sizeof (struct AddressIterateResponseMessage) + alen + tlen);
   msg = GNUNET_malloc (size);
-  memcpy (&msg->peer, peer, sizeof (struct GNUNET_PeerIdentity));
-  memcpy (&msg[0], address->transport_name, slen);
-  msg->addrlen = ntohs (address->address_length);
-  msg->pluginlen = ntohs (slen);
-  // FIXME: what about 'address->address'!?
+  msg->addrlen = htonl (alen);
+  msg->pluginlen = htonl (tlen);
+  msg->peer = *peer;
+
+  addr = (char *) &msg[1];
+  memcpy(addr,address->address, alen);
+  memcpy(&addr[alen], address->transport_name, tlen);
+
   transmit_binary_to_client (tc, msg, size);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "output_addresses: peer `%s' transport %s address %s   %s\n",GNUNET_i2s(&msg->peer), &addr[alen], GNUNET_a2s((struct sockaddr *) addr, alen), GNUNET_a2s((struct sockaddr *) address->address, address->address_length));
   GNUNET_free (msg);
 }
 
@@ -824,9 +833,10 @@ clients_handle_address_iterate (void *cls, struct GNUNET_SERVER_Client *client,
 
   GNUNET_SERVER_disable_receive_done_warning (client);
   tc = GNUNET_SERVER_transmit_context_create (client);
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "clients_handle_address_iterate: \n");
   GST_neighbours_iterate (&output_addresses, tc);
   GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
-                                              GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+      GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
   GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
 }
 
@@ -849,8 +859,8 @@ GST_clients_start (struct GNUNET_SERVER_Handle *server)
     {&clients_handle_request_connect, NULL,
      GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT,
      sizeof (struct TransportRequestConnectMessage)},
-    {&clients_handle_address_lookup, NULL,
-     GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP, 0},
+    {&clients_handle_address_to_string, NULL,
+     GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0},
     {&clients_handle_peer_address_lookup, NULL,
      GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP,
      sizeof (struct PeerAddressLookupMessage)},
index 1dc85a9039a6cd75b0eae4dac7a27529a8b50972..58d20e16daffa7b71dda6a3d6c34579dc6dde4cc 100644 (file)
@@ -150,6 +150,7 @@ struct TestContext
 
 };
 
+struct GNUNET_CONFIGURATION_Handle * cfg;
 
 /**
  * Display the result of the test.
@@ -432,6 +433,11 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
   traffic_received += ntohs (message->size);
 }
 
+void process_string (void *cls,
+                     const char *address)
+{
+  fprintf (stdout, _("process_string\n"));
+}
 
 /**
  * Function to call with a human-readable format of an address
@@ -445,23 +451,23 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
 static void
 process_address (void *cls, const struct GNUNET_HELLO_Address *address)
 {
-  if ((address->transport_name != NULL) ||
-      ((address->address != NULL) && (address->address_length > 0)))
+  if (address == NULL)
   {
-    /* Call GNUNET_TRANSPORT_address_to_string to convert to human readable */
-    //GNUNET_TRANSPORT_address_to_string(cfg, address, GNUNET_NO)
-
-#if 0
-    fprintf (stdout, _("Peer `%s' plugin: `%s' address `%s'\n"),
-             (peer != NULL) ? GNUNET_i2s (peer) : "<unknown>",
-             (transport != NULL) ? transport : "<unknown>", ((addr != NULL) &&
-                                                             (addrlen > 0) &&
-                                                             (transport !=
-                                                              NULL)) ?
-             "how do i resolve the name without transport service?" :
-             "<unknown>");
-#endif
+    return;
   }
+
+  fprintf (stdout, _("Peer `%s'\n"),
+           GNUNET_i2s (&address->peer));
+
+  /* Resolve address to string */
+  /*
+  GNUNET_TRANSPORT_address_to_string (cfg,
+      address,
+      GNUNET_NO,
+      GNUNET_TIME_UNIT_MINUTES,
+      &process_string,
+      NULL);
+      */
 }
 
 
@@ -477,6 +483,7 @@ static void
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
+  cfg = cfg;
   if (test_configuration)
   {
     do_test_configuration (cfg);
index 66f40cd06a6199453f1754b35690fadbcbe447f5..97620a9b6ab0ad0b0f47dcd91d86cc6efeaea033 100644 (file)
@@ -360,11 +360,24 @@ struct AddressIterateMessage
    * timeout to give up.  FIXME: remove in the future
    */
   struct GNUNET_TIME_AbsoluteNBO timeout;
+
+  /**
+   * The identity of the peer to look up.
+   */
+  struct GNUNET_PeerIdentity peer;
+
+  /**
+   * One shot call or continous replies?
+   */
+  uint32_t one_shot;
+
 };
 
 /**
- * Message from the library to the transport service
- * asking for human readable addresses known for a peer.
+ * Message from the transport service to the library
+ * containing binary addresses known for a peer.
+ * Memory layout:
+ * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
  */
 struct AddressIterateResponseMessage
 {
@@ -378,7 +391,7 @@ struct AddressIterateResponseMessage
    */
   uint32_t reserved;
 
-  /**
+    /**
    * Peer identity
    */
   struct GNUNET_PeerIdentity peer;
@@ -392,6 +405,7 @@ struct AddressIterateResponseMessage
    * length of the plugin name
    */
   uint32_t pluginlen GNUNET_PACKED;
+  
 };
 
 
index 385abd423f3754f923bee5d39bc25e85bfca3251..5904de5e25aa2119800be5e3582e238eccb92563 100644 (file)
@@ -65,7 +65,6 @@ struct GNUNET_TRANSPORT_PeerAddressLookupContext
   struct GNUNET_TIME_Absolute timeout;
 };
 
-
 /**
  * Function called with responses from the service.
  *
@@ -77,46 +76,61 @@ static void
 peer_address_response_processor (void *cls,
                                  const struct GNUNET_MessageHeader *msg)
 {
-  struct GNUNET_TRANSPORT_PeerAddressLookupContext *alucb = cls;
+  struct GNUNET_TRANSPORT_PeerAddressLookupContext *pal_ctx = cls;
+  struct AddressIterateResponseMessage *air_msg = (struct AddressIterateResponseMessage *) &msg[1];
   const struct GNUNET_HELLO_Address *address;
   uint16_t size;
-
-  if (msg == NULL)
+  if (air_msg == NULL)
   {
-    alucb->cb (alucb->cb_cls, NULL);
-    GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
-    GNUNET_free (alucb);
+    pal_ctx->cb (pal_ctx->cb_cls, NULL);
+    GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO);
+    GNUNET_free (pal_ctx);
     return;
   }
-  GNUNET_break (ntohs (msg->type) ==
-                GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
   size = ntohs (msg->size);
+  GNUNET_break (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
   if (size == sizeof (struct GNUNET_MessageHeader))
   {
     /* done! */
-    alucb->cb (alucb->cb_cls, NULL );
-    GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
-    GNUNET_free (alucb);
+    pal_ctx->cb (pal_ctx->cb_cls, NULL );
+    GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO);
+    GNUNET_free (pal_ctx);
     return;
   }
-  address = (const struct GNUNET_HELLO_Address *) &msg[1];
-#if 0
-  if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
+
+  size_t tlen = ntohl(air_msg->pluginlen);
+  size_t alen = ntohl(air_msg->addrlen);
+
+  if (size != sizeof (struct GNUNET_MessageHeader) + sizeof (struct AddressIterateResponseMessage) + tlen + alen)
+  {
+    GNUNET_break_op (0);
+    pal_ctx->cb (pal_ctx->cb_cls, NULL );
+    GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO);
+    GNUNET_free (pal_ctx);
+    return;
+  }
+
+  char * addr = (char *) &air_msg[1];
+  char * transport_name = &addr[alen];
+
+  if (transport_name[tlen] != '\0')
   {
-    /* invalid reply */
-    GNUNET_break (0);
-    alucb->cb (alucb->cb_cls, NULL );
-    GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
-    GNUNET_free (alucb);
+    GNUNET_break_op (0);
+    pal_ctx->cb (pal_ctx->cb_cls, NULL );
+    GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO);
+    GNUNET_free (pal_ctx);
     return;
   }
-#endif
+
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "peer %s transport_name: %s\n",GNUNET_i2s(&air_msg->peer), transport_name);
+
+  address = GNUNET_HELLO_address_allocate(&air_msg->peer, transport_name, addr, alen);
+
   /* expect more replies */
-  GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb,
-                         GNUNET_TIME_absolute_get_remaining (alucb->timeout));
+  GNUNET_CLIENT_receive (pal_ctx->client, &peer_address_response_processor, pal_ctx,
+                         GNUNET_TIME_absolute_get_remaining (pal_ctx->timeout));
 
-  /* REFACTOR FIX THIS */
-  alucb->cb (alucb->cb_cls, address );
+  pal_ctx->cb (pal_ctx->cb_cls, address);
 }
 
 
@@ -132,35 +146,45 @@ peer_address_response_processor (void *cls,
  */
 struct GNUNET_TRANSPORT_PeerAddressLookupContext *
 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_AddressLookUpCallback peer_address_callback,
-                                      void *peer_address_callback_cls)
+                                            const struct GNUNET_PeerIdentity *peer,
+                                            int one_shot,
+                                            struct GNUNET_TIME_Relative timeout,
+                                            GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback,
+                                            void *peer_address_callback_cls)
 {
-  struct PeerAddressLookupMessage msg;
-  struct GNUNET_TRANSPORT_PeerAddressLookupContext *alc;
+  struct GNUNET_TRANSPORT_PeerAddressLookupContext *pal_ctx;
+  struct AddressIterateMessage msg;
   struct GNUNET_CLIENT_Connection *client;
+  struct GNUNET_TIME_Absolute abs_timeout;
 
   client = GNUNET_CLIENT_connect ("transport", cfg);
   if (client == NULL)
+  {
+    peer_address_callback (peer_address_callback_cls, NULL);
     return NULL;
-  msg.header.size = htons (sizeof (struct PeerAddressLookupMessage));
-  msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP);
-  msg.reserved = htonl (0);
-  msg.timeout = GNUNET_TIME_relative_hton (timeout);
-  memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity));
-  alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext));
-  alc->cb = peer_address_callback;
-  alc->cb_cls = peer_address_callback_cls;
-  alc->timeout = GNUNET_TIME_relative_to_absolute (timeout);
-  alc->client = client;
+  }
+
+  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);
+  if (peer == NULL)
+   memset (&msg.peer, 0 , sizeof (struct GNUNET_PeerIdentity));
+  else
+   memcpy (&msg.peer, peer , sizeof (struct GNUNET_PeerIdentity));
+
+  pal_ctx = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext));
+  pal_ctx->cb = peer_address_callback;
+  pal_ctx->cb_cls = peer_address_callback_cls;
+  pal_ctx->timeout = abs_timeout;
+  pal_ctx->client = client;
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_CLIENT_transmit_and_get_response (client, &msg.header,
                                                           timeout, GNUNET_YES,
                                                           &peer_address_response_processor,
-                                                          alc));
-  return alc;
+                                                          pal_ctx));
+  return pal_ctx;
 }
 
 
@@ -179,64 +203,7 @@ GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct
 }
 
 /**
- * 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.
+ * Return all the known addresses for all peers.
  *
  * @param cfg configuration to use
  * @param timeout how long is the lookup allowed to take at most
@@ -250,32 +217,12 @@ GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
                                   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));
+  GNUNET_TRANSPORT_peer_get_active_addresses (cfg,
+      NULL,
+      GNUNET_YES,
+      timeout,
+      peer_address_callback,
+      peer_address_callback_cls);
 }
 
 /* end of transport_api_peer_address_lookup.c */
index 259c77152ac203bf49505238ab347484d94da183..2e5a34ce22e6f79da5a3cb097080f228747ed9eb 100644 (file)
@@ -76,7 +76,7 @@ address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
     return;
   }
   GNUNET_break (ntohs (msg->type) ==
-                GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+      GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
   size = ntohs (msg->size);
   if (size == sizeof (struct GNUNET_MessageHeader))
   {
@@ -108,10 +108,8 @@ address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
  *
  * @param cfg configuration to use
  * @param address address to convert (binary format)
- * @param addressLen number of bytes in address
  * @param numeric should (IP) addresses be displayed in numeric form
  *                (otherwise do reverse DNS lookup)
- * @param nameTrans name of the transport to which the address belongs
  * @param timeout how long is the lookup allowed to take at most
  * @param aluc function to call with the results
  * @param aluc_cls closure for aluc
@@ -132,6 +130,7 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cf
   struct GNUNET_CLIENT_Connection *client;
   char *addrbuf;
 
+  GNUNET_assert (address != NULL);
   alen = GNUNET_HELLO_address_get_size (address);
   len = sizeof (struct AddressLookupMessage) + alen;
   if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
@@ -139,12 +138,15 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cf
     GNUNET_break (0);
     return NULL;
   }
+
   client = GNUNET_CLIENT_connect ("transport", cfg);
   if (client == NULL)
     return NULL;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "GNUNET_TRANSPORT_address_to_string\n");
   msg = GNUNET_malloc (len);
   msg->header.size = htons (len);
-  msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP);
+  msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING);
   msg->numeric_only = htonl (numeric);
   msg->timeout = GNUNET_TIME_relative_hton (timeout);
   msg->addrlen = htonl (alen);