first steps to transport_api cleanup
authorMatthias Wachs <wachs@net.in.tum.de>
Tue, 29 Nov 2011 09:37:54 +0000 (09:37 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Tue, 29 Nov 2011 09:37:54 +0000 (09:37 +0000)
compiles but no guarante to work!

src/core/gnunet-core-list-connections.c
src/hello/address.c
src/include/gnunet_hello_lib.h
src/include/gnunet_transport_service.h
src/peerinfo-tool/gnunet-peerinfo.c
src/transport/gnunet-transport.c
src/transport/transport_api_address_iterate.c
src/transport/transport_api_address_lookup.c
src/transport/transport_api_peer_address_lookup.c

index 79490bcc5e06bf03330203504f431588d8f84647..3f3288d7944b1d4be71365a7ad6e31f9ecde97c3 100644 (file)
@@ -97,7 +97,7 @@ dump_pc (struct PrintContext *pc)
  * @param address NULL on error, otherwise 0-terminated printable UTF-8 string
  */
 static void
-process_resolved_address (void *cls, const char *address)
+process_resolved_address (void *cls, const struct GNUNET_HELLO_Address *address)
 {
   struct PrintContext *pc = cls;
   struct AddressStringList *new_address;
@@ -112,7 +112,8 @@ process_resolved_address (void *cls, const char *address)
 #if VERBOSE
   fprintf (stderr, "Received address %s\n", address);
 #endif
-  new_address->address_string = GNUNET_strdup (address);
+  // FIXME : GNUNET_TRANSPORT_address_to_string
+  new_address->address_string = GNUNET_strdup ("FIXME");
   GNUNET_CONTAINER_DLL_insert (pc->address_list_head, pc->address_list_tail,
                                new_address);
 }
@@ -136,7 +137,7 @@ connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
 #endif
     pc = GNUNET_malloc (sizeof (struct PrintContext));
     pc->peer = *peer;
-    GNUNET_TRANSPORT_peer_address_lookup (cfg, peer, GNUNET_TIME_UNIT_MINUTES,
+    GNUNET_TRANSPORT_peer_get_active_addresses (cfg, peer, GNUNET_TIME_UNIT_MINUTES,
                                           &process_resolved_address, pc);
   }
 #if VERBOSE
index 5cfa10185fdc4ccc63c40f5836dc80d10a41e97f..b511ca9df8e609c825f4f2f95b1b9a2198d093b2 100644 (file)
@@ -62,6 +62,21 @@ GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer,
 }
 
 
+/**
+ * Get the size of an address struct.
+ *
+ * @param address address
+ * @return the size
+ */
+size_t
+GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address)
+{
+  return sizeof (struct GNUNET_HELLO_Address) +
+         address->address_length +
+         strlen(address->transport_name) + 1;
+}
+
+
 /**
  * Copy an address struct.
  *
index 886a410935939e35e563355a0e47cda72c2d9ce8..09f5f1c7d151cfe49d6638d88674f8c28f1b00bc 100644 (file)
@@ -111,6 +111,14 @@ GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1,
                          const struct GNUNET_HELLO_Address *a2);
 
 
+/**
+ * Get the size of an address struct.
+ *
+ * @param address address
+ * @return the size
+ */
+size_t
+GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address);
 
 /**
  * Free an address.
index 1de59d796c83fac99c9fba1cb91e161b77faa312..b0d9e34b046cfb3073013eb42cd4ce363f2a50a2 100644 (file)
@@ -104,8 +104,7 @@ typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls,
  * @param cls closure
  * @param address NULL on error, otherwise 0-terminated printable UTF-8 string
  */
-// RENAME: AddressToStringCallback
-typedef void (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls,
+typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
                                                         const char *address);
 
 
@@ -119,16 +118,9 @@ typedef void (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls,
  * @param addrlen address length
  */
 // FIXME: use GNUNET_HELLO_Address (as 2nd arg, replacing others)
-// FIXME: rename: remove "Binary"
 // FIXME: use NULL for address on disconnect IF in monitor mode (one_shot = NO)
-typedef void (*GNUNET_TRANSPORT_AddressLookUpBinaryCallback) (void *cls,
-                                                              const struct
-                                                              GNUNET_PeerIdentity
-                                                              * peer,
-                                                              const char
-                                                              *transport,
-                                                              const void *addr,
-                                                              size_t addrlen);
+typedef void (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls,
+                                                        const struct GNUNET_HELLO_Address *address);
 
 
 /**
@@ -280,7 +272,7 @@ GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
 /**
  * Handle to cancel a pending address lookup.
  */
-struct GNUNET_TRANSPORT_AddressLookupContext;
+struct GNUNET_TRANSPORT_AddressToStringContext;
 
 
 /**
@@ -297,14 +289,12 @@ struct GNUNET_TRANSPORT_AddressLookupContext;
  * @param aluc_cls closure for aluc
  * @return handle to cancel the operation, NULL on error
  */
-// FIXME: use 'GNUNET_HELLO_Address' here!
-// => rename: address_to_string
-struct GNUNET_TRANSPORT_AddressLookupContext *
-GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                                 const char *address, size_t addressLen,
-                                 int numeric, const char *nameTrans,
+struct GNUNET_TRANSPORT_AddressToStringContext *
+GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                                 const struct GNUNET_HELLO_Address *address,
+                                 int numeric,
                                  struct GNUNET_TIME_Relative timeout,
-                                 GNUNET_TRANSPORT_AddressLookUpCallback aluc,
+                                 GNUNET_TRANSPORT_AddressToStringCallback aluc,
                                  void *aluc_cls);
 
 
@@ -314,17 +304,11 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
  * @param alc handle for the request to cancel
  */
 void
-GNUNET_TRANSPORT_address_lookup_cancel (struct
-                                        GNUNET_TRANSPORT_AddressLookupContext
+GNUNET_TRANSPORT_address_to_string_cancel (struct
+                                        GNUNET_TRANSPORT_AddressToStringContext
                                         *alc);
 
 
-/**
- * Handle to cancel a pending address lookup.
- */
-struct GNUNET_TRANSPORT_AddressLookupContext;
-
-
 /**
  * Return all the known addresses for a peer. FIXME: document better!
  * FIXME: use better name!
@@ -342,17 +326,12 @@ struct GNUNET_TRANSPORT_AddressLookupContext;
  * @param peer_address_callback function to call with the results
  * @param peer_address_callback_cls closure for peer_address_callback
  */
-// RENAME: peer_get_active_addresses
 struct GNUNET_TRANSPORT_PeerAddressLookupContext *
-GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle
-                                      *cfg,
+GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg,
                                       const struct GNUNET_PeerIdentity *peer,
                                      // FIXME: add argument: one_shot
                                       struct GNUNET_TIME_Relative timeout,
-                                     // FIXME: change to the 'Binary' lookup callback (which will
-                                     // be renamed, so the argument type actually won't change)
-                                      GNUNET_TRANSPORT_AddressLookUpCallback
-                                      peer_address_callback,
+                                      GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback,
                                       void *peer_address_callback_cls);
 
 
@@ -362,9 +341,9 @@ GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle
  * @param alc handle for the request to cancel
  */
 void
-GNUNET_TRANSPORT_peer_address_lookup_cancel (struct
+GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct
                                              GNUNET_TRANSPORT_PeerAddressLookupContext
-                                             *alc);
+*alc);
 
 
 /**
@@ -381,7 +360,7 @@ GNUNET_TRANSPORT_peer_address_lookup_cancel (struct
 void
 GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
                                   struct GNUNET_TIME_Relative timeout,
-                                  GNUNET_TRANSPORT_AddressLookUpBinaryCallback
+                                  GNUNET_TRANSPORT_AddressLookUpCallback
                                   peer_address_callback,
                                   void *peer_address_callback_cls);
 
index e40615a9b2e28099409a8daa046c6e74c9874675..d54eb10819fa921cce14684321ac43d9b74049d9 100644 (file)
@@ -126,11 +126,9 @@ print_address (void *cls,
                struct GNUNET_TIME_Absolute expiration)
 {
   struct PrintContext *pc = cls;
-
-  GNUNET_TRANSPORT_address_lookup (cfg, 
-                                  address->address, 
-                                  address->address_length, no_resolve, 
-                                  address->transport_name,
+  GNUNET_TRANSPORT_address_to_string (cfg, 
+                                   address,
+                                  no_resolve,
                                    GNUNET_TIME_relative_multiply
                                    (GNUNET_TIME_UNIT_SECONDS, 10),
                                    &process_resolved_address, pc);
index 4c9e8566cb59d69740ec7d5ef14e2f9252f14527..1dc85a9039a6cd75b0eae4dac7a27529a8b50972 100644 (file)
@@ -443,11 +443,15 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
  * @param addrlen number of bytes in addr
  */
 static void
-process_address (void *cls, const struct GNUNET_PeerIdentity *peer,
-                 const char *transport, const void *addr, size_t addrlen)
+process_address (void *cls, const struct GNUNET_HELLO_Address *address)
 {
-  if ((peer != NULL) || (transport != NULL) ||
-      ((addr != NULL) && (addrlen > 0)))
+  if ((address->transport_name != NULL) ||
+      ((address->address != NULL) && (address->address_length > 0)))
+  {
+    /* 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) &&
@@ -456,6 +460,8 @@ process_address (void *cls, const struct GNUNET_PeerIdentity *peer,
                                                               NULL)) ?
              "how do i resolve the name without transport service?" :
              "<unknown>");
+#endif
+  }
 }
 
 
index 3c3f97c283745a083a624c2fbf581bf47f23f9cf..a79319163d6375cfb7fadcb0dfc9511ef75c7996 100644 (file)
@@ -47,7 +47,7 @@ struct AddressLookupCtx
   /**
    * Function to call with the human-readable address.
    */
-  GNUNET_TRANSPORT_AddressLookUpBinaryCallback cb;
+  GNUNET_TRANSPORT_AddressLookUpCallback cb;
 
   /**
    * Closure for cb.
@@ -78,17 +78,13 @@ peer_address_response_processor (void *cls,
                                  const struct GNUNET_MessageHeader *msg)
 {
   struct AddressLookupCtx *alucb = cls;
-  struct AddressIterateResponseMessage *address;
+  struct AddressIterateResponseMessage *arm;
+  struct GNUNET_HELLO_Address * address;
   uint16_t size;
-  char *transport;
-
-  //size_t transport_len;
-  //void * addr;
-  size_t addrlen;
 
   if (msg == NULL)
   {
-    alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0);
+    alucb->cb (alucb->cb_cls, NULL);
     GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
     GNUNET_free (alucb);
     return;
@@ -102,7 +98,7 @@ peer_address_response_processor (void *cls,
   if (size == sizeof (struct GNUNET_MessageHeader))
   {
     /* done! */
-    alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0);
+    alucb->cb (alucb->cb_cls, NULL);
     GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
     GNUNET_free (alucb);
     return;
@@ -111,22 +107,19 @@ peer_address_response_processor (void *cls,
   {
     /* invalid reply */
     GNUNET_break (0);
-    alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0);
+    alucb->cb (alucb->cb_cls, NULL);
     GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
     GNUNET_free (alucb);
     return;
   }
 
-  address = (struct AddressIterateResponseMessage *) &msg[1];
-
-  transport = (char *) &address[0];
-  //transport_len = ntohs(address->pluginlen);
-  addrlen = ntohs (address->addrlen);
+  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->peer, transport, NULL, addrlen);
+  alucb->cb (alucb->cb_cls, address);
 }
 
 
@@ -141,7 +134,7 @@ peer_address_response_processor (void *cls,
 void
 GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
                                   struct GNUNET_TIME_Relative timeout,
-                                  GNUNET_TRANSPORT_AddressLookUpBinaryCallback
+                                  GNUNET_TRANSPORT_AddressLookUpCallback
                                   peer_address_callback,
                                   void *peer_address_callback_cls)
 {
@@ -153,7 +146,7 @@ GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
   client = GNUNET_CLIENT_connect ("transport", cfg);
   if (client == NULL)
   {
-    peer_address_callback (peer_address_callback_cls, NULL, NULL, NULL, 0);
+    peer_address_callback (peer_address_callback_cls, NULL);
     return;
   }
   abs_timeout = GNUNET_TIME_relative_to_absolute (timeout);
index 968a4324fe188f184048cc1b28fe62fa1a5b1561..259c77152ac203bf49505238ab347484d94da183 100644 (file)
 /**
  * Context for the address lookup.
  */
-struct GNUNET_TRANSPORT_AddressLookupContext
+struct GNUNET_TRANSPORT_AddressToStringContext
 {
   /**
    * Function to call with the human-readable address.
    */
-  GNUNET_TRANSPORT_AddressLookUpCallback cb;
+  GNUNET_TRANSPORT_AddressToStringCallback cb;
 
   /**
    * Closure for cb.
@@ -64,7 +64,7 @@ struct GNUNET_TRANSPORT_AddressLookupContext
 static void
 address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
 {
-  struct GNUNET_TRANSPORT_AddressLookupContext *alucb = cls;
+  struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls;
   const char *address;
   uint16_t size;
 
@@ -117,23 +117,23 @@ address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
  * @param aluc_cls closure for aluc
  * @return handle to cancel the operation, NULL on error
  */
-struct GNUNET_TRANSPORT_AddressLookupContext *
-GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                                 const char *address, size_t addressLen,
-                                 int numeric, const char *nameTrans,
+struct GNUNET_TRANSPORT_AddressToStringContext *
+GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                                 const struct GNUNET_HELLO_Address *address,
+                                 int numeric,
                                  struct GNUNET_TIME_Relative timeout,
-                                 GNUNET_TRANSPORT_AddressLookUpCallback aluc,
+                                 GNUNET_TRANSPORT_AddressToStringCallback aluc,
                                  void *aluc_cls)
 {
-  size_t slen;
   size_t len;
+  size_t alen;
   struct AddressLookupMessage *msg;
-  struct GNUNET_TRANSPORT_AddressLookupContext *alc;
+  struct GNUNET_TRANSPORT_AddressToStringContext *alc;
   struct GNUNET_CLIENT_Connection *client;
   char *addrbuf;
 
-  slen = strlen (nameTrans) + 1;
-  len = sizeof (struct AddressLookupMessage) + addressLen + slen;
+  alen = GNUNET_HELLO_address_get_size (address);
+  len = sizeof (struct AddressLookupMessage) + alen;
   if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
   {
     GNUNET_break (0);
@@ -147,11 +147,10 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP);
   msg->numeric_only = htonl (numeric);
   msg->timeout = GNUNET_TIME_relative_hton (timeout);
-  msg->addrlen = htonl (addressLen);
+  msg->addrlen = htonl (alen);
   addrbuf = (char *) &msg[1];
-  memcpy (addrbuf, address, addressLen);
-  memcpy (&addrbuf[addressLen], nameTrans, slen);
-  alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressLookupContext));
+  memcpy (addrbuf, address, alen);
+  alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressToStringContext));
   alc->cb = aluc;
   alc->cb_cls = aluc_cls;
   alc->timeout = GNUNET_TIME_relative_to_absolute (timeout);
@@ -172,8 +171,8 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
  * @param alc handle for the request to cancel
  */
 void
-GNUNET_TRANSPORT_address_lookup_cancel (struct
-                                        GNUNET_TRANSPORT_AddressLookupContext
+GNUNET_TRANSPORT_address_to_string_cancel (struct
+                                        GNUNET_TRANSPORT_AddressToStringContext
                                         *alc)
 {
   GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO);
index 0df922085fc5b0399bf0b62c3a69507dc50aca89..66af497f5d0a0fb0da844444573ba21b05bcb280 100644 (file)
@@ -78,7 +78,7 @@ peer_address_response_processor (void *cls,
                                  const struct GNUNET_MessageHeader *msg)
 {
   struct GNUNET_TRANSPORT_PeerAddressLookupContext *alucb = cls;
-  const char *address;
+  const struct GNUNET_HELLO_Address *address;
   uint16_t size;
 
   if (msg == NULL)
@@ -94,25 +94,29 @@ peer_address_response_processor (void *cls,
   if (size == sizeof (struct GNUNET_MessageHeader))
   {
     /* done! */
-    alucb->cb (alucb->cb_cls, NULL);
+    alucb->cb (alucb->cb_cls, NULL );
     GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
     GNUNET_free (alucb);
     return;
   }
-  address = (const char *) &msg[1];
+  address = (const struct GNUNET_HELLO_Address *) &msg[1];
+#if 0
   if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
   {
     /* invalid reply */
     GNUNET_break (0);
-    alucb->cb (alucb->cb_cls, NULL);
+    alucb->cb (alucb->cb_cls, NULL );
     GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
     GNUNET_free (alucb);
     return;
   }
+#endif
   /* 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);
+
+  /* REFACTOR FIX THIS */
+  alucb->cb (alucb->cb_cls, address );
 }
 
 
@@ -127,12 +131,10 @@ peer_address_response_processor (void *cls,
  * @return handle to cancel the operation, NULL on error
  */
 struct GNUNET_TRANSPORT_PeerAddressLookupContext *
-GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle
-                                      *cfg,
+GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg,
                                       const struct GNUNET_PeerIdentity *peer,
                                       struct GNUNET_TIME_Relative timeout,
-                                      GNUNET_TRANSPORT_AddressLookUpCallback
-                                      peer_address_callback,
+                                      GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback,
                                       void *peer_address_callback_cls)
 {
   struct PeerAddressLookupMessage msg;
@@ -147,8 +149,7 @@ GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle
   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 = 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);
@@ -168,7 +169,7 @@ GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle
  * @param alc handle for the request to cancel
  */
 void
-GNUNET_TRANSPORT_peer_address_lookup_cancel (struct
+GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct
                                              GNUNET_TRANSPORT_PeerAddressLookupContext
                                              *alc)
 {