gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r18377 - in gnunet/src: include transport


From: gnunet
Subject: [GNUnet-SVN] r18377 - in gnunet/src: include transport
Date: Tue, 29 Nov 2011 16:43:11 +0100

Author: wachs
Date: 2011-11-29 16:43:11 +0100 (Tue, 29 Nov 2011)
New Revision: 18377

Modified:
   gnunet/src/include/gnunet_protocols.h
   gnunet/src/include/gnunet_transport_service.h
   gnunet/src/transport/gnunet-service-transport_clients.c
   gnunet/src/transport/gnunet-transport.c
   gnunet/src/transport/transport.h
   gnunet/src/transport/transport_api_address_lookup.c
   gnunet/src/transport/transport_api_address_to_string.c
Log:
- latest changes for refactoring: iterate sends disassembled hello-address


Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2011-11-29 15:16:56 UTC (rev 
18376)
+++ gnunet/src/include/gnunet_protocols.h       2011-11-29 15:43:11 UTC (rev 
18377)
@@ -1020,12 +1020,12 @@
 /**
  * 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.
@@ -1106,9 +1106,14 @@
 
 
 /**
+ * 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
 
 
 /**

Modified: gnunet/src/include/gnunet_transport_service.h
===================================================================
--- gnunet/src/include/gnunet_transport_service.h       2011-11-29 15:16:56 UTC 
(rev 18376)
+++ gnunet/src/include/gnunet_transport_service.h       2011-11-29 15:43:11 UTC 
(rev 18377)
@@ -112,12 +112,8 @@
  * 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 @@
 
 
 /**
- * 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

Modified: gnunet/src/transport/gnunet-service-transport_clients.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_clients.c     2011-11-29 
15:16:56 UTC (rev 18376)
+++ gnunet/src/transport/gnunet-service-transport_clients.c     2011-11-29 
15:43:11 UTC (rev 18377)
@@ -616,12 +616,12 @@
   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 @@
   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 @@
  * @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 @@
   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 @@
   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 @@
   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 @@
 
   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 @@
     {&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)},

Modified: gnunet/src/transport/gnunet-transport.c
===================================================================
--- gnunet/src/transport/gnunet-transport.c     2011-11-29 15:16:56 UTC (rev 
18376)
+++ gnunet/src/transport/gnunet-transport.c     2011-11-29 15:43:11 UTC (rev 
18377)
@@ -150,6 +150,7 @@
 
 };
 
+struct GNUNET_CONFIGURATION_Handle * cfg;
 
 /**
  * Display the result of the test.
@@ -432,6 +433,11 @@
   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 @@
 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)
+    return;
+  }
 
-#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
-  }
+  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 @@
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
+  cfg = cfg;
   if (test_configuration)
   {
     do_test_configuration (cfg);

Modified: gnunet/src/transport/transport.h
===================================================================
--- gnunet/src/transport/transport.h    2011-11-29 15:16:56 UTC (rev 18376)
+++ gnunet/src/transport/transport.h    2011-11-29 15:43:11 UTC (rev 18377)
@@ -360,11 +360,24 @@
    * 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 @@
    */
   uint32_t reserved;
 
-  /**
+    /**
    * Peer identity
    */
   struct GNUNET_PeerIdentity peer;
@@ -392,6 +405,7 @@
    * length of the plugin name
    */
   uint32_t pluginlen GNUNET_PACKED;
+  
 };
 
 

Modified: gnunet/src/transport/transport_api_address_lookup.c
===================================================================
--- gnunet/src/transport/transport_api_address_lookup.c 2011-11-29 15:16:56 UTC 
(rev 18376)
+++ gnunet/src/transport/transport_api_address_lookup.c 2011-11-29 15:43:11 UTC 
(rev 18377)
@@ -65,7 +65,6 @@
   struct GNUNET_TIME_Absolute timeout;
 };
 
-
 /**
  * Function called with responses from the service.
  *
@@ -77,46 +76,61 @@
 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)
   {
-    /* 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
+
+  char * addr = (char *) &air_msg[1];
+  char * transport_name = &addr[alen];
+
+  if (transport_name[tlen] != '\0')
+  {
+    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;
+  }
+
+  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 @@
  */
 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,65 +203,8 @@
 }
 
 /**
- * Function called with responses from the service.
+ * Return all the known addresses for all peers.
  *
- * @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
@@ -250,32 +217,12 @@
                                   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 */

Modified: gnunet/src/transport/transport_api_address_to_string.c
===================================================================
--- gnunet/src/transport/transport_api_address_to_string.c      2011-11-29 
15:16:56 UTC (rev 18376)
+++ gnunet/src/transport/transport_api_address_to_string.c      2011-11-29 
15:43:11 UTC (rev 18377)
@@ -76,7 +76,7 @@
     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 @@
  *
  * @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 @@
   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_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);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]