-fix ftbfs
[oweals/gnunet.git] / src / hello / gnunet-hello.c
index e4e0978ee5a30afad972b7e0dade1dfd8829a1a6..ec060a19f498bbfc9393a4831711ec2566f5e1c3 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     (C) 2012 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2012 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -35,7 +35,7 @@ struct AddContext
    * Where to add.
    */
   char *buf;
-  
+
   /**
    * Maximum number of bytes left
    */
@@ -47,6 +47,8 @@ struct AddContext
   size_t ret;
 };
 
+static int address_count;
+
 
 /**
  * Add the given address with infinit expiration to the buffer.
@@ -54,22 +56,24 @@ struct AddContext
  * @param cls closure
  * @param address address to add
  * @param expiration old expiration
- * @return GNUNET_OK keep iterating
+ * @return #GNUNET_OK keep iterating
  */
 static int
-add_to_buf (void *cls, const struct GNUNET_HELLO_Address *address,
+add_to_buf (void *cls,
+            const struct GNUNET_HELLO_Address *address,
             struct GNUNET_TIME_Absolute expiration)
 {
   struct AddContext *ac = cls;
   size_t ret;
 
-  ret = GNUNET_HELLO_add_address (address, 
+  ret = GNUNET_HELLO_add_address (address,
                                  GNUNET_TIME_UNIT_FOREVER_ABS,
                                  ac->buf,
                                  ac->max);
   ac->buf += ret;
   ac->max -= ret;
-  ac->ret += ret;  
+  ac->ret += ret;
+  address_count ++;
   return GNUNET_OK;
 }
 
@@ -82,19 +86,21 @@ add_to_buf (void *cls, const struct GNUNET_HELLO_Address *address,
  * @param buf where to add the addresses
  * @return number of bytes added, 0 to terminate
  */
-static size_t
-add_from_hello (void *cls, size_t max, void *buf)
+static ssize_t
+add_from_hello (void *cls,
+                size_t max,
+                void *buf)
 {
   struct GNUNET_HELLO_Message **orig = cls;
   struct AddContext ac;
 
   if (NULL == *orig)
-    return 0; /* already done */
+    return GNUNET_SYSERR; /* already done */
   ac.buf = buf;
   ac.max = max;
   ac.ret = 0;
   GNUNET_assert (NULL ==
-                GNUNET_HELLO_iterate_addresses (*orig, 
+                GNUNET_HELLO_iterate_addresses (*orig,
                                                 GNUNET_NO, &add_to_buf,
                                                 &ac));
   *orig = NULL;
@@ -108,8 +114,9 @@ main (int argc, char *argv[])
   struct GNUNET_DISK_FileHandle *fh;
   struct GNUNET_HELLO_Message *orig;
   struct GNUNET_HELLO_Message *result;
-  struct GNUNET_CRYPTO_EccPublicKey pk;
+  struct GNUNET_CRYPTO_EddsaPublicKey pk;
   uint64_t fsize;
+  address_count = 0;
 
   GNUNET_log_setup ("gnunet-hello", "INFO", NULL);
   if (argc != 2)
@@ -141,7 +148,7 @@ main (int argc, char *argv[])
             argv[1]);
     return 1;
   }
-  fh = GNUNET_DISK_file_open (argv[1], 
+  fh = GNUNET_DISK_file_open (argv[1],
                              GNUNET_DISK_OPEN_READ,
                              GNUNET_DISK_PERM_USER_READ);
   if (NULL == fh)
@@ -154,8 +161,8 @@ main (int argc, char *argv[])
   }
   {
     char buf[fsize] GNUNET_ALIGN;
-    
-    GNUNET_assert (fsize == 
+
+    GNUNET_assert (fsize ==
                   GNUNET_DISK_file_read (fh, buf, fsize));
     GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
     orig = (struct GNUNET_HELLO_Message *) buf;
@@ -167,10 +174,20 @@ main (int argc, char *argv[])
               argv[1]);
       return 1;
     }
-    result = GNUNET_HELLO_create (&pk, &add_from_hello, &orig,
-               GNUNET_HELLO_is_friend_only (orig));
+    {
+      char *pid;
+
+      pid = GNUNET_CRYPTO_eddsa_public_key_to_string (&pk);
+      fprintf (stdout,
+               "Processing HELLO for peer `%s'\n",
+               pid);
+      GNUNET_free (pid);
+    }
+    result = GNUNET_HELLO_create (&pk, &add_from_hello,
+                                  &orig,
+                                  GNUNET_HELLO_is_friend_only (orig));
     GNUNET_assert (NULL != result);
-     fh = GNUNET_DISK_file_open (argv[1], 
+     fh = GNUNET_DISK_file_open (argv[1],
                                 GNUNET_DISK_OPEN_WRITE,
                                 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
      if (NULL == fh)
@@ -196,6 +213,7 @@ main (int argc, char *argv[])
      }
     GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
   }
+  FPRINTF (stderr, _("Modified %u addresses \n"), address_count);
   return 0;
 }