error msg
[oweals/gnunet.git] / src / transport / gnunet-service-transport_hello.c
index a2d0d966c1a11dc9c48367e1140986c05f726956..c04d2e1ddadb81f5ca8ae643adbe4503c33d0efb 100644 (file)
@@ -24,6 +24,7 @@
  * @author Christian Grothoff
  */
 #include "platform.h"
+#include "gnunet_constants.h"
 #include "gnunet_hello_lib.h"
 #include "gnunet_peerinfo_service.h"
 #include "gnunet_statistics_service.h"
  */
 #define HELLO_REFRESH_PERIOD GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 6)
 
+/**
+ * Hello address expiration
+ */
+extern struct GNUNET_TIME_Relative hello_expiration;
+
 
 /**
  * Entry in linked list of network addresses for ourselves.  Also
@@ -55,9 +61,9 @@ struct OwnAddressList
   struct OwnAddressList *prev;
 
   /**
-   * Name of the plugin.
+   * The address.
    */
-  char *plugin_name;
+  struct GNUNET_HELLO_Address *address;
 
   /**
    * How long until the current signature expires? (ZERO if the
@@ -68,12 +74,7 @@ struct OwnAddressList
   /**
    * Signature for a 'struct TransportPongMessage' for this address.
    */
-  struct GNUNET_CRYPTO_RsaSignature pong_signature;
-
-  /**
-   * Length of addr.
-   */
-  size_t addrlen;
+  struct GNUNET_CRYPTO_EccSignature pong_signature;
 
 };
 
@@ -128,7 +129,7 @@ struct GeneratorContext
 
 /**
  * Add an address from the 'OwnAddressList' to the buffer.
- * 
+ *
  * @param cls the 'struct GeneratorContext'
  * @param max maximum number of bytes left
  * @param buf where to write the address
@@ -141,10 +142,9 @@ address_generator (void *cls, size_t max, void *buf)
 
   if (NULL == gc->addr_pos)
     return 0;
-  ret = GNUNET_HELLO_add_address (gc->addr_pos->plugin_name,
-                                  gc->expiration,
-                                  &gc->addr_pos[1],
-                                  gc->addr_pos->addrlen, buf, max);
+  ret =
+      GNUNET_HELLO_add_address (gc->addr_pos->address, gc->expiration, buf,
+                                max);
   gc->addr_pos = gc->addr_pos->next;
   return ret;
 }
@@ -164,24 +164,22 @@ refresh_hello_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
   hello_task = GNUNET_SCHEDULER_NO_TASK;
   gc.addr_pos = oal_head;
-  gc.expiration =
-      GNUNET_TIME_relative_to_absolute (GST_HELLO_ADDRESS_EXPIRATION);
+  gc.expiration = GNUNET_TIME_relative_to_absolute (hello_expiration);
+
   GNUNET_free (our_hello);
   our_hello = GNUNET_HELLO_create (&GST_my_public_key, &address_generator, &gc);
-#if DEBUG_TRANSPORT
+  GNUNET_assert (NULL != our_hello);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
               "Refreshed my `%s', new size is %d\n", "HELLO",
               GNUNET_HELLO_size (our_hello));
-#endif
-  GNUNET_STATISTICS_update (GST_stats,
-                            gettext_noop ("# refreshed my HELLO"),
-                            1, GNUNET_NO);
+  GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# refreshed my HELLO"), 1,
+                            GNUNET_NO);
   if (NULL != hello_cb)
     hello_cb (hello_cb_cls, GST_hello_get ());
-  GNUNET_PEERINFO_add_peer (GST_peerinfo, our_hello);
-  hello_task
-      = GNUNET_SCHEDULER_add_delayed (HELLO_REFRESH_PERIOD,
-                                      &refresh_hello_task, NULL);
+  GNUNET_PEERINFO_add_peer (GST_peerinfo, our_hello, NULL, NULL);
+  hello_task =
+      GNUNET_SCHEDULER_add_delayed (HELLO_REFRESH_PERIOD, &refresh_hello_task,
+                                    NULL);
 
 }
 
@@ -211,6 +209,7 @@ GST_hello_start (GST_HelloCallback cb, void *cb_cls)
   hello_cb = cb;
   hello_cb_cls = cb_cls;
   our_hello = GNUNET_HELLO_create (&GST_my_public_key, NULL, NULL);
+  GNUNET_assert (NULL != our_hello);
   refresh_hello ();
 }
 
@@ -252,35 +251,27 @@ GST_hello_get ()
  * Add or remove an address from this peer's HELLO message.
  *
  * @param addremove GNUNET_YES to add, GNUNET_NO to remove
- * @param plugin_name name of the plugin for which this is an address
- * @param plugin_address address in a plugin-specific format
- * @param plugin_address_len number of bytes in plugin_address
+ * @param address address to add or remove
  */
 void
 GST_hello_modify_addresses (int addremove,
-                            const char *plugin_name,
-                            const void *plugin_address,
-                            size_t plugin_address_len)
+                            const struct GNUNET_HELLO_Address *address)
 {
   struct OwnAddressList *al;
 
-#if DEBUG_TRANSPORT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              (add_remove == GNUNET_YES)
-              ? "Adding `%s':%s to the set of our addresses\n"
-              : "Removing `%s':%s from the set of our addresses\n",
-              GST_plugins_a2s (plugin_name, addr, addrlen), p->short_name);
-#endif
-  GNUNET_assert (plugin_address != NULL);
+              (addremove ==
+               GNUNET_YES) ? "Adding `%s' to the set of our addresses\n" :
+              "Removing `%s' from the set of our addresses\n",
+              GST_plugins_a2s (address));
+  GNUNET_assert (address != NULL);
   if (GNUNET_NO == addremove)
   {
     for (al = oal_head; al != NULL; al = al->next)
-      if ((plugin_address_len == al->addrlen) &&
-          (0 == strcmp (al->plugin_name, plugin_name)) &&
-          (0 == memcmp (plugin_address, &al[1], plugin_address_len)))
+      if (0 == GNUNET_HELLO_address_cmp (address, al->address))
       {
         GNUNET_CONTAINER_DLL_remove (oal_head, oal_tail, al);
-        GNUNET_free (al->plugin_name);
+        GNUNET_HELLO_address_free (al->address);
         GNUNET_free (al);
         refresh_hello ();
         return;
@@ -289,11 +280,9 @@ GST_hello_modify_addresses (int addremove,
     GNUNET_break (0);
     return;
   }
-  al = GNUNET_malloc (sizeof (struct OwnAddressList) + plugin_address_len);
+  al = GNUNET_malloc (sizeof (struct OwnAddressList));
   GNUNET_CONTAINER_DLL_insert (oal_head, oal_tail, al);
-  al->plugin_name = GNUNET_strdup (plugin_name);
-  al->addrlen = plugin_address_len;
-  memcpy (&al[1], plugin_address, plugin_address_len);
+  al->address = GNUNET_HELLO_address_copy (address);
   refresh_hello ();
 }
 
@@ -301,9 +290,7 @@ GST_hello_modify_addresses (int addremove,
 /**
  * Test if a particular address is one of ours.
  *
- * @param plugin_name name of the plugin for which this is an address
- * @param plugin_address address in a plugin-specific format
- * @param plugin_address_len number of bytes in plugin_address
+ * @param address address to test
  * @param sig location where to cache PONG signatures for this address [set]
  * @param sig_expiration how long until the current 'sig' expires?
  *            (ZERO if sig was never created) [set]
@@ -311,18 +298,14 @@ GST_hello_modify_addresses (int addremove,
  *         GNUNET_NO if not
  */
 int
-GST_hello_test_address (const char *plugin_name,
-                        const void *plugin_address,
-                        size_t plugin_address_len,
-                        struct GNUNET_CRYPTO_RsaSignature **sig,
+GST_hello_test_address (const struct GNUNET_HELLO_Address *address,
+                        struct GNUNET_CRYPTO_EccSignature **sig,
                         struct GNUNET_TIME_Absolute **sig_expiration)
 {
   struct OwnAddressList *al;
 
   for (al = oal_head; al != NULL; al = al->next)
-    if ((plugin_address_len == al->addrlen) &&
-        (0 == strcmp (al->plugin_name, plugin_name)) &&
-        (0 == memcmp (plugin_address, &al[1], plugin_address_len)))
+    if (0 == GNUNET_HELLO_address_cmp (address, al->address))
     {
       *sig = &al->pong_signature;
       *sig_expiration = &al->pong_sig_expires;