gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r18368 - in gnunet/src: core hello include peerinfo-tool tr


From: gnunet
Subject: [GNUnet-SVN] r18368 - in gnunet/src: core hello include peerinfo-tool transport
Date: Tue, 29 Nov 2011 10:37:54 +0100

Author: wachs
Date: 2011-11-29 10:37:54 +0100 (Tue, 29 Nov 2011)
New Revision: 18368

Modified:
   gnunet/src/core/gnunet-core-list-connections.c
   gnunet/src/hello/address.c
   gnunet/src/include/gnunet_hello_lib.h
   gnunet/src/include/gnunet_transport_service.h
   gnunet/src/peerinfo-tool/gnunet-peerinfo.c
   gnunet/src/transport/gnunet-transport.c
   gnunet/src/transport/transport_api_address_iterate.c
   gnunet/src/transport/transport_api_address_lookup.c
   gnunet/src/transport/transport_api_peer_address_lookup.c
Log:
first steps to transport_api cleanup
compiles but no guarante to work!


Modified: gnunet/src/core/gnunet-core-list-connections.c
===================================================================
--- gnunet/src/core/gnunet-core-list-connections.c      2011-11-29 08:32:22 UTC 
(rev 18367)
+++ gnunet/src/core/gnunet-core-list-connections.c      2011-11-29 09:37:54 UTC 
(rev 18368)
@@ -97,7 +97,7 @@
  * @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 @@
 #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 @@
 #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

Modified: gnunet/src/hello/address.c
===================================================================
--- gnunet/src/hello/address.c  2011-11-29 08:32:22 UTC (rev 18367)
+++ gnunet/src/hello/address.c  2011-11-29 09:37:54 UTC (rev 18368)
@@ -63,6 +63,21 @@
 
 
 /**
+ * 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.
  *
  * @param address address to copy

Modified: gnunet/src/include/gnunet_hello_lib.h
===================================================================
--- gnunet/src/include/gnunet_hello_lib.h       2011-11-29 08:32:22 UTC (rev 
18367)
+++ gnunet/src/include/gnunet_hello_lib.h       2011-11-29 09:37:54 UTC (rev 
18368)
@@ -111,6 +111,14 @@
                          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.

Modified: gnunet/src/include/gnunet_transport_service.h
===================================================================
--- gnunet/src/include/gnunet_transport_service.h       2011-11-29 08:32:22 UTC 
(rev 18367)
+++ gnunet/src/include/gnunet_transport_service.h       2011-11-29 09:37:54 UTC 
(rev 18368)
@@ -104,8 +104,7 @@
  * @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 @@
  * @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 @@
 /**
  * Handle to cancel a pending address lookup.
  */
-struct GNUNET_TRANSPORT_AddressLookupContext;
+struct GNUNET_TRANSPORT_AddressToStringContext;
 
 
 /**
@@ -297,14 +289,12 @@
  * @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,18 +304,12 @@
  * @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!
  * CHANGE: Returns the address(es) that we are currently using for this
@@ -342,17 +326,12 @@
  * @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 @@
  * @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 @@
 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);
 

Modified: gnunet/src/peerinfo-tool/gnunet-peerinfo.c
===================================================================
--- gnunet/src/peerinfo-tool/gnunet-peerinfo.c  2011-11-29 08:32:22 UTC (rev 
18367)
+++ gnunet/src/peerinfo-tool/gnunet-peerinfo.c  2011-11-29 09:37:54 UTC (rev 
18368)
@@ -126,11 +126,9 @@
                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);

Modified: gnunet/src/transport/gnunet-transport.c
===================================================================
--- gnunet/src/transport/gnunet-transport.c     2011-11-29 08:32:22 UTC (rev 
18367)
+++ gnunet/src/transport/gnunet-transport.c     2011-11-29 09:37:54 UTC (rev 
18368)
@@ -443,11 +443,15 @@
  * @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 @@
                                                               NULL)) ?
              "how do i resolve the name without transport service?" :
              "<unknown>");
+#endif
+  }
 }
 
 

Modified: gnunet/src/transport/transport_api_address_iterate.c
===================================================================
--- gnunet/src/transport/transport_api_address_iterate.c        2011-11-29 
08:32:22 UTC (rev 18367)
+++ gnunet/src/transport/transport_api_address_iterate.c        2011-11-29 
09:37:54 UTC (rev 18368)
@@ -47,7 +47,7 @@
   /**
    * Function to call with the human-readable address.
    */
-  GNUNET_TRANSPORT_AddressLookUpBinaryCallback cb;
+  GNUNET_TRANSPORT_AddressLookUpCallback cb;
 
   /**
    * Closure for cb.
@@ -78,17 +78,13 @@
                                  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 @@
   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 @@
   {
     /* 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];
+  arm = (struct AddressIterateResponseMessage *) &msg[1];
+  address = (struct GNUNET_HELLO_Address *) &arm[1];
 
-  transport = (char *) &address[0];
-  //transport_len = ntohs(address->pluginlen);
-  addrlen = ntohs (address->addrlen);
-
   /* 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 @@
 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 @@
   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);

Modified: gnunet/src/transport/transport_api_address_lookup.c
===================================================================
--- gnunet/src/transport/transport_api_address_lookup.c 2011-11-29 08:32:22 UTC 
(rev 18367)
+++ gnunet/src/transport/transport_api_address_lookup.c 2011-11-29 09:37:54 UTC 
(rev 18368)
@@ -30,12 +30,12 @@
 /**
  * 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 @@
 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 @@
  * @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 @@
   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 @@
  * @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);

Modified: gnunet/src/transport/transport_api_peer_address_lookup.c
===================================================================
--- gnunet/src/transport/transport_api_peer_address_lookup.c    2011-11-29 
08:32:22 UTC (rev 18367)
+++ gnunet/src/transport/transport_api_peer_address_lookup.c    2011-11-29 
09:37:54 UTC (rev 18368)
@@ -78,7 +78,7 @@
                                  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 @@
   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 @@
  * @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 @@
   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 @@
  * @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)
 {




reply via email to

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