gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r18386 - in gnunet/src: include transport
Date: Tue, 29 Nov 2011 21:03:12 +0100

Author: grothoff
Date: 2011-11-29 21:03:12 +0100 (Tue, 29 Nov 2011)
New Revision: 18386

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:
-cleaning up message format and code related to recent transport address 
stringification code

Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2011-11-29 19:26:17 UTC (rev 
18385)
+++ gnunet/src/include/gnunet_protocols.h       2011-11-29 20:03:12 UTC (rev 
18386)
@@ -1083,13 +1083,8 @@
 #define GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT 378
 
 /**
- * Request to look up addresses of peers.
+ * Request to monitor addresses used by a peer or all peers.
  */
-#define GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP 379
-
-/**
- * Request to iterate over all known addresses.
- */
 #define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE 380
 
 /**

Modified: gnunet/src/include/gnunet_transport_service.h
===================================================================
--- gnunet/src/include/gnunet_transport_service.h       2011-11-29 19:26:17 UTC 
(rev 18385)
+++ gnunet/src/include/gnunet_transport_service.h       2011-11-29 20:03:12 UTC 
(rev 18386)
@@ -99,10 +99,14 @@
 
 
 /**
- * Function to call with a binary format of an address
+ * Function to call with a textual representation of an address.
+ * This function will be called several times with different possible
+ * textual representations, and a last time with NULL to signal the end
+ * of the iteration.
  *
  * @param cls closure
- * @param address NULL on error, otherwise 0-terminated printable UTF-8 string
+ * @param address NULL on error or end of iteration,
+ *        otherwise 0-terminated printable UTF-8 string
  */
 typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
                                                         const char *address);
@@ -112,11 +116,12 @@
  * Function to call with a binary format of an address
  *
  * @param cls closure
- * @param address address
+ * @param peer peer this update is about (never NULL)
+ * @param address address, NULL for disconnect notification in monitor mode
  */
-// FIXME: use NULL for address on disconnect IF in monitor mode (one_shot = NO)
 typedef void (*GNUNET_TRANSPORT_PeerIterateCallback) (void *cls,
-                                                        const struct 
GNUNET_HELLO_Address *address);
+                                                     const struct 
GNUNET_PeerIdentity *peer,
+                                                     const struct 
GNUNET_HELLO_Address *address);
 
 
 /**
@@ -317,7 +322,7 @@
  * @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 cancelled)
+ *                 GNUNET_NO to monitor the set of addresses used 
(continuously, must be explicitly canceled, NOT implemented yet!)
  * @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
@@ -343,21 +348,6 @@
 
 
 /**
- * Return all the known addresses.
- * @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_PeerIterateCallback
-                                  peer_address_callback,
-                                  void *peer_address_callback_cls);
-
-
-/**
  * Handle for blacklisting peers.
  */
 struct GNUNET_TRANSPORT_Blacklist;

Modified: gnunet/src/transport/gnunet-service-transport_clients.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_clients.c     2011-11-29 
19:26:17 UTC (rev 18385)
+++ gnunet/src/transport/gnunet-service-transport_clients.c     2011-11-29 
20:03:12 UTC (rev 18386)
@@ -612,6 +612,7 @@
 transmit_address_to_client (void *cls, const char *buf)
 {
   struct GNUNET_SERVER_TransmitContext *tc = cls;
+
   if (NULL == buf)
   {
     GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
@@ -625,31 +626,6 @@
 
 
 /**
- * Take the given address and append it to the set of results sent back to
- * the client.
- *
- * @param cls the transmission context used ('struct 
GNUNET_SERVER_TransmitContext*')
- * @param buf data to transmit
- * @param size number of bytes in buf
- */
-static void
-transmit_binary_to_client (void *cls, void *buf, size_t size)
-{
-  struct GNUNET_SERVER_TransmitContext *tc = cls;
-
-  if (NULL == buf)
-  {
-    GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
-        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_ITERATE_RESPONSE);
-}
-
-
-/**
  * Client asked to resolve an address.  Process the request.
  *
  * @param cls unused
@@ -658,7 +634,7 @@
  */
 static void
 clients_handle_address_to_string (void *cls, struct GNUNET_SERVER_Client 
*client,
-                               const struct GNUNET_MessageHeader *message)
+                                 const struct GNUNET_MessageHeader *message)
 {
   const struct AddressLookupMessage *alum;
   struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -678,7 +654,7 @@
     return;
   }
   alum = (const struct AddressLookupMessage *) message;
-  address_len = ntohl (alum->addrlen);
+  address_len = ntohs (alum->addrlen);
   if (size <= sizeof (struct AddressLookupMessage) + address_len)
   {
     GNUNET_break (0);
@@ -695,7 +671,7 @@
     return;
   }
   rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
-  numeric = ntohl (alum->numeric_only);
+  numeric = ntohs (alum->numeric_only);
   tc = GNUNET_SERVER_transmit_context_create (client);
   papi = GST_plugins_find (plugin_name);
   if (NULL == papi)
@@ -711,75 +687,8 @@
                                 tc);
 }
 
-#if 0
 
-THIS FUNCTIONALITY IS NOT USED ANYWHERE!
-
 /**
- * Send an address to the client.
- *
- * @param cls our 'struct GNUNET_SERVER_TransmitContext' (for sending)
- * @param public_key public key for the peer, never NULL
- * @param valid_until until what time do we consider the address valid?
- * @param validation_block  is FOREVER if the address is for an unsupported 
plugin (from PEERINFO)
- *                          is ZERO if the address is considered valid (no 
validation needed)
- *                          is a time in the future if we're currently denying 
re-validation
- * @param address address to transmit
- */
-static void
-send_address_to_client (void *cls,
-                        const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
-                        *public_key,
-                        struct GNUNET_TIME_Absolute valid_until,
-                        struct GNUNET_TIME_Absolute validation_block,
-                        const struct GNUNET_HELLO_Address *address)
-{
-  struct GNUNET_SERVER_TransmitContext *tc = cls;
-  char *addr_buf;
-
-  /* FIXME: move to a binary format!!! */
-  GNUNET_asprintf (&addr_buf, "%s --- %s, %s",
-                   GST_plugins_a2s (address),
-                   (GNUNET_YES ==
-                    GST_neighbours_test_connected (&address->peer)) ? 
"CONNECTED" :
-                   "DISCONNECTED",
-                   (GNUNET_TIME_absolute_get_remaining (valid_until).rel_value 
>
-                    0) ? "VALIDATED" : "UNVALIDATED");
-  transmit_address_to_client (tc, addr_buf);
-  GNUNET_free (addr_buf);
-}
-
-
-/**
- * Client asked to obtain information about all addresses of a peer.
- * Process the request.
- *
- * @param cls unused
- * @param client the client
- * @param message the peer address information request
- */
-static void
-clients_handle_peer_address_iterate (void *cls,
-                                    struct GNUNET_SERVER_Client *client,
-                                    const struct GNUNET_MessageHeader *message)
-{
-  const struct PeerAddressLookupMessage *peer_address_lookup;
-  struct GNUNET_SERVER_TransmitContext *tc;
-
-  peer_address_lookup = (const struct PeerAddressLookupMessage *) message;
-  GNUNET_break (ntohl (peer_address_lookup->reserved) == 0);
-  tc = GNUNET_SERVER_transmit_context_create (client);
-
-  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_ITERATE_RESPONSE);
-  GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
-}
-#endif
-
-/**
  * Output the active address of connected neighbours to the given client.
  *
  * @param cls the 'struct GNUNET_SERVER_TransmitContext' for transmission to 
the client
@@ -789,9 +698,9 @@
  * @param address the address
  */
 static void
-output_addresses (void *cls, const struct GNUNET_PeerIdentity *peer,
-                  const struct GNUNET_ATS_Information *ats, uint32_t ats_count,
-                  const struct GNUNET_HELLO_Address *address)
+output_address (void *cls, const struct GNUNET_PeerIdentity *peer,
+               const struct GNUNET_ATS_Information *ats, uint32_t ats_count,
+               const struct GNUNET_HELLO_Address *address)
 {
   struct GNUNET_SERVER_TransmitContext *tc = cls;
   struct AddressIterateResponseMessage *msg;
@@ -802,19 +711,23 @@
 
   tlen = strlen (address->transport_name) + 1;
   alen = address->address_length;
-
   size = (sizeof (struct AddressIterateResponseMessage) + alen + tlen);
-  msg = GNUNET_malloc (size);
-  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_free (msg);
+  {
+    char buf[size];
+    
+    msg = (struct AddressIterateResponseMessage*) buf;
+    msg->reserved = htonl (0);
+    msg->peer = *peer;
+    msg->addrlen = htonl (alen);
+    msg->pluginlen = htonl (tlen);
+    addr = (char *) &msg[1];
+    memcpy (addr,address->address, alen);
+    memcpy (&addr[alen], address->transport_name, tlen);
+    GNUNET_SERVER_transmit_context_append_data (tc, 
+                                               &buf[sizeof(struct 
GNUNET_MessageHeader)], 
+                                               size - sizeof (struct 
GNUNET_MessageHeader),
+                                               
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
+  }
 }
 
 
@@ -831,44 +744,47 @@
 clients_handle_address_iterate (void *cls, struct GNUNET_SERVER_Client *client,
                                 const struct GNUNET_MessageHeader *message)
 {
+  static struct GNUNET_PeerIdentity all_zeros;
   struct GNUNET_SERVER_TransmitContext *tc;
   struct AddressIterateMessage * msg;
-  struct GNUNET_PeerIdentity dummy;
-  struct GNUNET_HELLO_Address * address;
+  struct GNUNET_HELLO_Address *address;
 
-
-  GNUNET_SERVER_disable_receive_done_warning (client);
-  tc = GNUNET_SERVER_transmit_context_create (client);
-
   if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE)
   {
-    GNUNET_break_op(0);
+    GNUNET_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
   if (ntohs (message->size) != sizeof (struct AddressIterateMessage))
   {
-    GNUNET_break_op(0);
+    GNUNET_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
-
   msg = (struct AddressIterateMessage *) message;
-  memset (&dummy, 0,  sizeof (struct GNUNET_PeerIdentity));
-
-  if (0 == memcmp (&msg->peer, &dummy, sizeof (struct GNUNET_PeerIdentity)))
+  if (GNUNET_YES != ntohl (msg->one_shot))
   {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               "Address monitoring not implemented\n");
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    return;
+  }
+  GNUNET_SERVER_disable_receive_done_warning (client);
+  tc = GNUNET_SERVER_transmit_context_create (client);
+  if (0 == memcmp (&msg->peer, &all_zeros, sizeof (struct 
GNUNET_PeerIdentity)))
+  {
     /* iterate over all neighbours */
-    GST_neighbours_iterate (&output_addresses, tc);
+    GST_neighbours_iterate (&output_address, tc);
   }
   else
   {
     /* just return one neighbour */
     address = GST_neighbour_get_current_address(&msg->peer);
     if (address != NULL)
-      output_addresses(tc, &msg->peer, NULL, 0, address);
+      output_address (tc, &msg->peer, NULL, 0, address);
   }
-
   GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
-      GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
+                                             
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
   GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
 }
 
@@ -891,15 +807,8 @@
     {&clients_handle_request_connect, NULL,
      GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT,
      sizeof (struct TransportRequestConnectMessage)},
-    /* converts a binary address to a human readable address */
     {&clients_handle_address_to_string, NULL,
      GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0},
-#if 0
-    /* Not used at the moment, gets all addresses of a peer */
-    {&clients_handle_peer_address_iterate, NULL,
-     GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP,
-     sizeof (struct PeerAddressLookupMessage)},
-#endif
      {&clients_handle_address_iterate, NULL,
      GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE,
      sizeof (struct AddressIterateMessage)},

Modified: gnunet/src/transport/gnunet-transport.c
===================================================================
--- gnunet/src/transport/gnunet-transport.c     2011-11-29 19:26:17 UTC (rev 
18385)
+++ gnunet/src/transport/gnunet-transport.c     2011-11-29 20:03:12 UTC (rev 
18386)
@@ -444,7 +444,7 @@
 
   if ((address != NULL))
   {
-    fprintf (stdout, _("Peer `%s' : %s\n"), GNUNET_i2s(peer), address);
+    fprintf (stdout, _("Peer `%s': %s\n"), GNUNET_i2s(peer), address);
   }
   else
   {
@@ -463,26 +463,29 @@
  * @param addrlen number of bytes in addr
  */
 static void
-process_address (void *cls, const struct GNUNET_HELLO_Address *address)
+process_address (void *cls, 
+                const struct GNUNET_PeerIdentity *peer,
+                const struct GNUNET_HELLO_Address *address)
 {
   const struct GNUNET_CONFIGURATION_Handle * cfg = cls;
+  struct GNUNET_PeerIdentity *peercp;
 
-  if (address == NULL)
+  if ( (address == NULL) || (peer == NULL) )
   {
     /* done */
     return;
   }
 
-  struct GNUNET_PeerIdentity * peer = GNUNET_malloc(sizeof (struct 
GNUNET_PeerIdentity));
-  *peer = address->peer;
+  peercp = GNUNET_malloc(sizeof (struct GNUNET_PeerIdentity));
+  *peercp = *peer;
 
   /* Resolve address to string */
   GNUNET_TRANSPORT_address_to_string (cfg,
-    address,
-    numeric,
-    GNUNET_TIME_UNIT_MINUTES,
-    &process_string,
-    peer);
+                                     address,
+                                     numeric,
+                                     GNUNET_TIME_UNIT_MINUTES,
+                                     &process_string,
+                                     peercp);
 }
 
 
@@ -538,8 +541,9 @@
   }
   if (iterate_connections)
   {
-    GNUNET_TRANSPORT_address_iterate (cfg, GNUNET_TIME_UNIT_MINUTES,
-                                      &process_address, (void *)cfg);
+    GNUNET_TRANSPORT_peer_get_active_addresses (cfg, NULL, GNUNET_YES,
+                                               GNUNET_TIME_UNIT_MINUTES,
+                                               &process_address, (void *)cfg);
   }
 }
 

Modified: gnunet/src/transport/transport.h
===================================================================
--- gnunet/src/transport/transport.h    2011-11-29 19:26:17 UTC (rev 18385)
+++ gnunet/src/transport/transport.h    2011-11-29 20:03:12 UTC (rev 18386)
@@ -295,17 +295,17 @@
    * Should the conversion use numeric IP addresses (otherwise
    * a reverse DNS lookup is OK -- if applicable).
    */
-  int32_t numeric_only GNUNET_PACKED;
+  int16_t numeric_only GNUNET_PACKED;
 
   /**
-   * timeout to give up.
+   * Length of the (binary) address in bytes, in big-endian.
    */
-  struct GNUNET_TIME_RelativeNBO timeout;
+  uint16_t addrlen GNUNET_PACKED;
 
   /**
-   * Length of the (binary) address in bytes, in big-endian.
+   * timeout to give up.
    */
-  uint32_t addrlen GNUNET_PACKED;
+  struct GNUNET_TIME_RelativeNBO timeout;
 
   /* followed by 'addrlen' bytes of the actual address, then
    * followed by the 0-terminated name of the transport */
@@ -352,9 +352,9 @@
   struct GNUNET_MessageHeader header;
 
   /**
-   * For alignment.
+   * One shot call or continous replies?
    */
-  uint32_t reserved;
+  uint32_t one_shot;
 
   /**
    * timeout to give up.  FIXME: remove in the future
@@ -366,13 +366,9 @@
    */
   struct GNUNET_PeerIdentity peer;
 
-  /**
-   * One shot call or continous replies?
-   */
-  uint32_t one_shot;
-
 };
 
+
 /**
  * Message from the transport service to the library
  * containing binary addresses known for a peer.
@@ -382,7 +378,7 @@
 struct AddressIterateResponseMessage
 {
   /**
-   * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY
+   * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE
    */
   struct GNUNET_MessageHeader header;
 

Modified: gnunet/src/transport/transport_api_address_lookup.c
===================================================================
--- gnunet/src/transport/transport_api_address_lookup.c 2011-11-29 19:26:17 UTC 
(rev 18385)
+++ gnunet/src/transport/transport_api_address_lookup.c 2011-11-29 20:03:12 UTC 
(rev 18386)
@@ -65,6 +65,7 @@
   struct GNUNET_TIME_Absolute timeout;
 };
 
+
 /**
  * Function called with responses from the service.
  *
@@ -79,13 +80,16 @@
   struct GNUNET_TRANSPORT_PeerIterateContext *pal_ctx = cls;
   struct AddressIterateResponseMessage *air_msg;
   struct GNUNET_HELLO_Address *address;
+  const char *addr;
+  const char *transport_name;
   uint16_t size;
+  size_t alen;
+  size_t tlen;
 
   if (msg == NULL)
   {
-    pal_ctx->cb (pal_ctx->cb_cls, NULL);
-    GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO);
-    GNUNET_free (pal_ctx);
+    pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL);
+    GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pal_ctx);
     return;
   }
   size = ntohs (msg->size);
@@ -93,54 +97,53 @@
   if (size == sizeof (struct GNUNET_MessageHeader))
   {
     /* done! */
-    pal_ctx->cb (pal_ctx->cb_cls, NULL );
-    GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO);
-    GNUNET_free (pal_ctx);
+    pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL);
+    GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pal_ctx);
     return;
   }
 
-  if (size < sizeof (struct GNUNET_MessageHeader) + sizeof (struct 
AddressIterateResponseMessage))
+  if ( (size < sizeof (struct GNUNET_MessageHeader) + sizeof (struct 
AddressIterateResponseMessage)) ||
+       (ntohs (msg->type) != 
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE) )
   {
-    GNUNET_break_op (0);
-    pal_ctx->cb (pal_ctx->cb_cls, NULL );
-    GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO);
-    GNUNET_free (pal_ctx);
+    GNUNET_break (0);
+    pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL);
+    GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pal_ctx);
     return;
   }
 
-  air_msg = (struct AddressIterateResponseMessage *) &msg[1];
-  size_t tlen = ntohl(air_msg->pluginlen);
-  size_t alen = ntohl(air_msg->addrlen);
+  air_msg = (struct AddressIterateResponseMessage *) msg;
+  tlen = ntohl(air_msg->pluginlen);
+  alen = ntohl(air_msg->addrlen);
 
-  if (size != sizeof (struct GNUNET_MessageHeader) + sizeof (struct 
AddressIterateResponseMessage) + tlen + alen)
+  if (size != 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);
+    GNUNET_break (0);
+    pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL);
+    GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pal_ctx);
     return;
   }
 
-  char * addr = (char *) &air_msg[1];
-  char * transport_name = &addr[alen];
+  addr = (const char *) &air_msg[1];
+  transport_name = &addr[alen];
 
   if (transport_name[tlen-1] != '\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);
+    pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL);
+    GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pal_ctx);
     return;
   }
 
-  address = GNUNET_HELLO_address_allocate(&air_msg->peer, transport_name, 
addr, alen);
-
   /* expect more replies */
-  GNUNET_CLIENT_receive (pal_ctx->client, &peer_address_response_processor, 
pal_ctx,
+  GNUNET_CLIENT_receive (pal_ctx->client, 
+                        &peer_address_response_processor, pal_ctx,
                          GNUNET_TIME_absolute_get_remaining 
(pal_ctx->timeout));
 
-  pal_ctx->cb (pal_ctx->cb_cls, address);
-  GNUNET_free (address);
+  /* 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);
 }
 
 
@@ -174,23 +177,24 @@
   struct GNUNET_CLIENT_Connection *client;
   struct GNUNET_TIME_Absolute abs_timeout;
 
-  client = GNUNET_CLIENT_connect ("transport", cfg);
-  if (client == NULL)
+  if (GNUNET_YES != one_shot)
   {
-    peer_address_callback (peer_address_callback_cls, NULL);
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               "Address monitoring not implemented\n");
     return NULL;
   }
-
+  client = GNUNET_CLIENT_connect ("transport", cfg);
+  if (client == NULL)
+    return NULL;
   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.one_shot = htonl (one_shot);
   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));
-
+    msg.peer = *peer;
   pal_ctx = GNUNET_malloc (sizeof (struct 
GNUNET_TRANSPORT_PeerIterateContext));
   pal_ctx->cb = peer_address_callback;
   pal_ctx->cb_cls = peer_address_callback_cls;
@@ -219,27 +223,5 @@
   GNUNET_free (alc);
 }
 
-/**
- * Return all addresses for all peers.
- *
- * @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_PeerIterateCallback
-                                  peer_address_callback,
-                                  void *peer_address_callback_cls)
-{
-  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 
19:26:17 UTC (rev 18385)
+++ gnunet/src/transport/transport_api_address_to_string.c      2011-11-29 
20:03:12 UTC (rev 18386)
@@ -125,13 +125,16 @@
 {
   size_t len;
   size_t alen;
+  size_t slen;
   struct AddressLookupMessage *msg;
   struct GNUNET_TRANSPORT_AddressToStringContext *alc;
   struct GNUNET_CLIENT_Connection *client;
   char *addrbuf;
 
   GNUNET_assert (address != NULL);
-  len = sizeof (struct AddressLookupMessage) + GNUNET_HELLO_address_get_size 
(address);
+  alen = address->address_length;
+  slen = strlen (address->transport_name) + 1;
+  len = sizeof (struct AddressLookupMessage) + alen + slen;
   if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
   {
     GNUNET_break (0);
@@ -141,19 +144,19 @@
   client = GNUNET_CLIENT_connect ("transport", cfg);
   if (client == NULL)
     return NULL;
+#if DEBUG_TRANSPORT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "GNUNET_TRANSPORT_address_to_string\n");
-
-  alen = address->address_length;
+#endif
   msg = GNUNET_malloc (len);
   msg->header.size = htons (len);
   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING);
-  msg->numeric_only = htonl (numeric);
+  msg->numeric_only = htons ((int16_t) numeric);
+  msg->addrlen = htons ((uint16_t) alen);
   msg->timeout = GNUNET_TIME_relative_hton (timeout);
-  msg->addrlen = htonl (alen);
   addrbuf = (char *) &msg[1];
   memcpy (addrbuf, address->address, alen);
-  strcpy (&addrbuf[alen], address->transport_name);
+  memcpy (&addrbuf[alen], address->transport_name, slen);
 
   alc = GNUNET_malloc (sizeof (struct 
GNUNET_TRANSPORT_AddressToStringContext));
   alc->cb = aluc;




reply via email to

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