WiP
[oweals/gnunet.git] / src / hello / hello.c
index 5b30dc167cb962cf1d052adee3c06b79a1686ba3..9affad3c13a1656d3fc5e9309d77d60263988718 100644 (file)
@@ -4,7 +4,7 @@
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
+     by the Free Software Foundation; either version 3, or (at your
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
@@ -126,7 +126,7 @@ get_hello_address_size (const char *buf, size_t max, uint16_t * ralen)
       pos++;
       slen++;
     }
-  if ('\0' != *pos)
+  if (left == 0)
     {
       /* 0-termination not found */
       GNUNET_break_op (0);
@@ -167,7 +167,7 @@ GNUNET_HELLO_create (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
                      GNUNET_HELLO_GenerateAddressListCallback addrgen,
                      void *addrgen_cls)
 {
-  char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 256 -
+  char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - 256 -
               sizeof (struct GNUNET_HELLO_Message)];
   size_t max;
   size_t used;
@@ -329,8 +329,8 @@ copy_latest (void *cls,
   ec.tname = tname;
   GNUNET_HELLO_iterate_addresses (mc->other, GNUNET_NO, &get_match_exp, &ec);
   if ( (ec.found == GNUNET_NO) ||
-       (ec.expiration.value < expiration.value) ||
-       ( (ec.expiration.value == expiration.value) &&
+       (ec.expiration.abs_value < expiration.abs_value) ||
+       ( (ec.expiration.abs_value == expiration.abs_value) &&
         (mc->take_equal == GNUNET_YES) ) )
     {
       mc->ret += GNUNET_HELLO_add_address (tname,
@@ -413,8 +413,8 @@ delta_match (void *cls,
   GNUNET_HELLO_iterate_addresses (dc->old_hello,
                                   GNUNET_NO, &get_match_exp, &ec);
   if ((ec.found == GNUNET_YES) &&
-      ((ec.expiration.value > expiration.value) ||
-       (ec.expiration.value >= dc->expiration_limit.value)))
+      ((ec.expiration.abs_value > expiration.abs_value) ||
+       (ec.expiration.abs_value >= dc->expiration_limit.abs_value)))
     return GNUNET_YES;          /* skip */
   ret = dc->it (dc->it_cls, tname, expiration, addr, addrlen);
   return ret;
@@ -560,7 +560,7 @@ find_other_matching (void *cls,
 {
   struct EqualsContext *ec = cls;
 
-  if (expiration.value < ec->expiration_limit.value)
+  if (expiration.abs_value < ec->expiration_limit.abs_value)
     return GNUNET_YES;
   if ( (addrlen == ec->addrlen) && 
        (0 == strcmp (tname,
@@ -570,11 +570,9 @@ find_other_matching (void *cls,
                     addrlen)) )
     {
       ec->found = GNUNET_YES;
-      if (expiration.value < ec->expiration.value)
-       {
-         ec->result = GNUNET_TIME_absolute_min (expiration,
-                                                ec->result);
-       }
+      if (expiration.abs_value < ec->expiration.abs_value)     
+       ec->result = GNUNET_TIME_absolute_min (expiration,
+                                              ec->result);             
       return GNUNET_SYSERR;
     }
   return GNUNET_YES;
@@ -589,7 +587,7 @@ find_matching (void *cls,
 {
   struct EqualsContext *ec = cls;
 
-  if (expiration.value < ec->expiration_limit.value)
+  if (expiration.abs_value < ec->expiration_limit.abs_value)
     return GNUNET_YES;
   ec->tname = tname;
   ec->expiration = expiration;
@@ -618,10 +616,10 @@ find_matching (void *cls,
  * @param h2 the second HELLO message
  * @param now time to use for deciding which addresses have
  *            expired and should not be considered at all
- * @return absolute time zero if the two HELLOs are 
+ * @return absolute time forever if the two HELLOs are 
  *         totally identical; smallest timestamp >= now if
  *         they only differ in timestamps; 
- *         forever if the some addresses with expirations >= now
+ *         zero if the some addresses with expirations >= now
  *         do not match at all
  */
 struct GNUNET_TIME_Absolute 
@@ -633,6 +631,10 @@ GNUNET_HELLO_equals (const struct
 {
   struct EqualsContext ec;
 
+  if (0 != memcmp (&h1->publicKey,
+                  &h2->publicKey,
+                  sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
+    return GNUNET_TIME_UNIT_ZERO_ABS;
   ec.expiration_limit = now;
   ec.result = GNUNET_TIME_UNIT_FOREVER_ABS;
   ec.h2 = h2;
@@ -640,8 +642,8 @@ GNUNET_HELLO_equals (const struct
                                   GNUNET_NO,
                                   &find_matching,
                                   &ec);
-  if (ec.result.value ==
-      GNUNET_TIME_UNIT_ZERO.value)
+  if (ec.result.abs_value ==
+      GNUNET_TIME_UNIT_ZERO.rel_value)
     return ec.result; 
   ec.h2 = h1;
   GNUNET_HELLO_iterate_addresses (h2,