Check that you are not present in trail twice
[oweals/gnunet.git] / src / transport / gnunet-service-transport_hello.c
index 870c083d25280fbc020e505c48036c5ddd96b2a7..49992222da31d287bc5cb8073cd06e29cca27f5e 100644 (file)
  */
 #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
@@ -69,7 +74,7 @@ struct OwnAddressList
   /**
    * Signature for a 'struct TransportPongMessage' for this address.
    */
-  struct GNUNET_CRYPTO_RsaSignature pong_signature;
+  struct GNUNET_CRYPTO_EddsaSignature pong_signature;
 
 };
 
@@ -128,17 +133,18 @@ struct GeneratorContext
  * @param cls the 'struct GeneratorContext'
  * @param max maximum number of bytes left
  * @param buf where to write the address
+ * @return bytes written or GNUNET_SYSERR to signal the
+ *         end of the iteration.
  */
-static size_t
+static ssize_t
 address_generator (void *cls, size_t max, void *buf)
 {
   struct GeneratorContext *gc = cls;
-  size_t ret;
+  ssize_t ret;
 
   if (NULL == gc->addr_pos)
-    return 0;
-  ret =
-      GNUNET_HELLO_add_address (gc->addr_pos->address, gc->expiration, buf,
+    return GNUNET_SYSERR; /* Done */
+  ret = GNUNET_HELLO_add_address (gc->addr_pos->address, gc->expiration, buf,
                                 max);
   gc->addr_pos = gc->addr_pos->next;
   return ret;
@@ -156,19 +162,23 @@ static void
 refresh_hello_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct GeneratorContext gc;
+  int friend_only;
 
   hello_task = GNUNET_SCHEDULER_NO_TASK;
   gc.addr_pos = oal_head;
-  gc.expiration =
-      GNUNET_TIME_relative_to_absolute
-      (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION);
+  gc.expiration = GNUNET_TIME_relative_to_absolute (hello_expiration);
 
+
+  friend_only = GNUNET_HELLO_is_friend_only (our_hello);
   GNUNET_free (our_hello);
-  our_hello = GNUNET_HELLO_create (&GST_my_public_key, &address_generator, &gc);
+  our_hello = GNUNET_HELLO_create (&GST_my_identity.public_key,
+                                  &address_generator,
+                                  &gc, friend_only);
   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));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Refreshed my %s `%s', new size is %d\n",
+              (GNUNET_YES == GNUNET_HELLO_is_friend_only (our_hello)) ? "friend-only" : "public",
+              "HELLO", GNUNET_HELLO_size (our_hello));
   GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# refreshed my HELLO"), 1,
                             GNUNET_NO);
   if (NULL != hello_cb)
@@ -197,15 +207,17 @@ refresh_hello ()
 /**
  * Initialize the HELLO module.
  *
+ * @param friend_only use a friend only hello
  * @param cb function to call whenever our HELLO changes
  * @param cb_cls closure for cb
  */
 void
-GST_hello_start (GST_HelloCallback cb, void *cb_cls)
+GST_hello_start (int friend_only, 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);
+  our_hello = GNUNET_HELLO_create (&GST_my_identity.public_key,
+                                  NULL, NULL, friend_only);
   GNUNET_assert (NULL != our_hello);
   refresh_hello ();
 }
@@ -277,7 +289,7 @@ GST_hello_modify_addresses (int addremove,
     GNUNET_break (0);
     return;
   }
-  al = GNUNET_malloc (sizeof (struct OwnAddressList));
+  al = GNUNET_new (struct OwnAddressList);
   GNUNET_CONTAINER_DLL_insert (oal_head, oal_tail, al);
   al->address = GNUNET_HELLO_address_copy (address);
   refresh_hello ();
@@ -296,7 +308,7 @@ GST_hello_modify_addresses (int addremove,
  */
 int
 GST_hello_test_address (const struct GNUNET_HELLO_Address *address,
-                        struct GNUNET_CRYPTO_RsaSignature **sig,
+                        struct GNUNET_CRYPTO_EddsaSignature **sig,
                         struct GNUNET_TIME_Absolute **sig_expiration)
 {
   struct OwnAddressList *al;