gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] branch master updated: time: attempt to bring some sanity to ti


From: gnunet
Subject: [gnunet] branch master updated: time: attempt to bring some sanity to timestamps
Date: Thu, 19 Sep 2024 21:34:20 +0200

This is an automated email from the git hooks/post-receive script.

martin-schanzenbach pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new ed5620eb4 time: attempt to bring some sanity to timestamps
ed5620eb4 is described below

commit ed5620eb436c8efad01150bb0dd5453ae098db46
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Thu Sep 19 21:34:15 2024 +0200

    time: attempt to bring some sanity to timestamps
---
 src/cli/hello/gnunet-hello.c                     |  8 ++---
 src/include/gnunet_hello_uri_lib.h               |  6 ++--
 src/include/gnunet_strings_lib.h                 | 13 ++++++++
 src/include/gnunet_time_lib.h                    |  4 +--
 src/lib/hello/hello-uri.c                        | 39 +++++++++++++-----------
 src/lib/util/strings.c                           | 30 ++++++++++++++++--
 src/service/cadet/gnunet-service-cadet_dht.c     | 12 ++++----
 src/service/cadet/gnunet-service-cadet_hello.c   |  4 +--
 src/service/cadet/gnunet-service-cadet_peer.c    | 17 ++++++-----
 src/service/peerstore/gnunet-service-peerstore.c |  6 ++--
 src/service/peerstore/peerstore_api.c            | 25 +++++++++------
 src/service/topology/gnunet-daemon-topology.c    | 19 +++++++-----
 12 files changed, 119 insertions(+), 64 deletions(-)

diff --git a/src/cli/hello/gnunet-hello.c b/src/cli/hello/gnunet-hello.c
index 3e7375e02..1c5187481 100644
--- a/src/cli/hello/gnunet-hello.c
+++ b/src/cli/hello/gnunet-hello.c
@@ -142,7 +142,7 @@ hello_iter (void *cls, const struct GNUNET_PEERSTORE_Record 
*record,
             const char *emsg)
 {
   struct GNUNET_HELLO_Builder *hb;
-  struct GNUNET_TIME_Absolute hello_exp;
+  struct GNUNET_TIME_Timestamp hello_exp;
   const struct GNUNET_PeerIdentity *pid;
 
   if ((NULL == record) && (NULL == emsg))
@@ -161,7 +161,7 @@ hello_iter (void *cls, const struct GNUNET_PEERSTORE_Record 
*record,
     return;
   }
   hb = GNUNET_HELLO_builder_from_msg (record->value);
-  hello_exp = GNUNET_HELLO_builder_get_expiration_time (record->value);
+  hello_exp = GNUNET_HELLO_get_expiration_time_from_msg (record->value);
   pid = GNUNET_HELLO_builder_get_id (hb);
   if (export_own_hello)
   {
@@ -202,7 +202,7 @@ hello_iter (void *cls, const struct GNUNET_PEERSTORE_Record 
*record,
         }
         else
         {
-          validity_tmp = GNUNET_TIME_absolute_get_duration (hello_exp);
+          validity_tmp = GNUNET_TIME_absolute_get_duration 
(hello_exp.abs_time);
           env = GNUNET_HELLO_builder_to_env (hb,
                                              &my_private_key,
                                              validity_tmp);
@@ -221,7 +221,7 @@ hello_iter (void *cls, const struct GNUNET_PEERSTORE_Record 
*record,
   else if (print_hellos)
   {
     printf ("`%s' (expires: %s):\n", GNUNET_i2s (pid),
-            GNUNET_STRINGS_absolute_time_to_string (hello_exp));
+            GNUNET_STRINGS_timestamp_to_string (hello_exp));
     GNUNET_HELLO_builder_iterate (hb, &print_hello_addrs, NULL);
   }
   GNUNET_HELLO_builder_free (hb);
diff --git a/src/include/gnunet_hello_uri_lib.h 
b/src/include/gnunet_hello_uri_lib.h
index 0ae9e11cc..eb63f168e 100644
--- a/src/include/gnunet_hello_uri_lib.h
+++ b/src/include/gnunet_hello_uri_lib.h
@@ -123,9 +123,9 @@ GNUNET_HELLO_builder_from_url (const char *url);
  * @param  msg The hello msg.
  * @return The expiration time.
  */
-struct GNUNET_TIME_Absolute
-GNUNET_HELLO_builder_get_expiration_time (const struct
-                                          GNUNET_MessageHeader *msg);
+struct GNUNET_TIME_Timestamp
+GNUNET_HELLO_get_expiration_time_from_msg (const struct
+                                           GNUNET_MessageHeader *msg);
 
 
 /**
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h
index df70c5e8f..b229c5f75 100644
--- a/src/include/gnunet_strings_lib.h
+++ b/src/include/gnunet_strings_lib.h
@@ -279,6 +279,19 @@ GNUNET_STRINGS_buffer_tokenize (const char *buffer,
                                 unsigned int count, ...);
 
 
+/**
+ * @ingroup time
+ * Like `asctime`, except for GNUnet time.  Converts a GNUnet internal
+ * absolute time (which is in UTC) to a string in local time.
+ * Note that the returned value will be overwritten if this function
+ * is called again.
+ *
+ * @param t the timestamp to convert
+ * @return timestamp in human-readable form in local time
+ */
+const char *
+GNUNET_STRINGS_timestamp_to_string (struct GNUNET_TIME_Timestamp t);
+
 /**
  * @ingroup time
  * Like `asctime`, except for GNUnet time.  Converts a GNUnet internal
diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h
index 8385d60ea..6afd4475b 100644
--- a/src/include/gnunet_time_lib.h
+++ b/src/include/gnunet_time_lib.h
@@ -59,12 +59,12 @@ struct GNUNET_TIME_Absolute
 };
 
 /**
- * Rounded time for timestamps used by GNUnet, in seconds.
+ * Time for timestamps used by GNUnet, in microseconds rounded to seconds.
  */
 struct GNUNET_TIME_Timestamp
 {
   /**
-   * The actual value. Must be round number in seconds.
+   * The actual value. Must be a round number of seconds in microseconds.
    */
   struct GNUNET_TIME_Absolute abs_time;
 };
diff --git a/src/lib/hello/hello-uri.c b/src/lib/hello/hello-uri.c
index 071bea78d..bada9535c 100644
--- a/src/lib/hello/hello-uri.c
+++ b/src/lib/hello/hello-uri.c
@@ -237,7 +237,7 @@ struct GNUNET_HELLO_Builder
   /**
    * Expiration time parsed
    */
-  struct GNUNET_TIME_Absolute et;
+  struct GNUNET_TIME_Timestamp et;
 };
 
 /**
@@ -340,13 +340,13 @@ sign_hello (const struct GNUNET_HELLO_Builder *builder,
  */
 static enum GNUNET_GenericReturnValue
 verify_hello (const struct GNUNET_HELLO_Builder *builder,
-              struct GNUNET_TIME_Absolute et,
+              struct GNUNET_TIME_Timestamp et,
               const struct GNUNET_CRYPTO_EddsaSignature *sig)
 {
   struct HelloSignaturePurpose hsp = {
     .purpose.size = htonl (sizeof (hsp)),
     .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
-    .expiration_time = GNUNET_TIME_absolute_hton (et)
+    .expiration_time = GNUNET_TIME_absolute_hton (et.abs_time)
   };
 
   hash_addresses (builder,
@@ -360,7 +360,7 @@ verify_hello (const struct GNUNET_HELLO_Builder *builder,
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
-  if (GNUNET_TIME_absolute_is_past (et))
+  if (GNUNET_TIME_absolute_is_past (et.abs_time))
     return GNUNET_NO;
   return GNUNET_OK;
 }
@@ -466,9 +466,11 @@ GNUNET_HELLO_builder_from_block (const void *block,
   }
   {
     enum GNUNET_GenericReturnValue ret;
+    struct GNUNET_TIME_Timestamp et;
 
+    et.abs_time = GNUNET_TIME_absolute_ntoh (bh->expiration_time);
     ret = verify_hello (b,
-                        GNUNET_TIME_absolute_ntoh (bh->expiration_time),
+                        et,
                         &bh->sig);
     GNUNET_break (GNUNET_SYSERR != ret);
     if (GNUNET_OK != ret)
@@ -476,7 +478,7 @@ GNUNET_HELLO_builder_from_block (const void *block,
       GNUNET_HELLO_builder_free (b);
       return NULL;
     }
-    b->et = GNUNET_TIME_absolute_ntoh (bh->expiration_time);
+    b->et.abs_time = GNUNET_TIME_absolute_ntoh (bh->expiration_time);
     b->sig = bh->sig;
     b->signature_set = GNUNET_YES;
   }
@@ -484,26 +486,29 @@ GNUNET_HELLO_builder_from_block (const void *block,
 }
 
 
-struct GNUNET_TIME_Absolute
-GNUNET_HELLO_builder_get_expiration_time (const struct
-                                          GNUNET_MessageHeader *msg)
+struct GNUNET_TIME_Timestamp
+GNUNET_HELLO_get_expiration_time_from_msg (const struct
+                                           GNUNET_MessageHeader *msg)
 {
+  struct GNUNET_TIME_Timestamp et;
   if (GNUNET_MESSAGE_TYPE_HELLO_URI == ntohs (msg->type))
   {
     const struct HelloUriMessage *h = (struct HelloUriMessage *) msg;
     const struct BlockHeader *bh = (const struct BlockHeader *) &h[1];
 
-    return GNUNET_TIME_absolute_ntoh (bh->expiration_time);
+    et.abs_time = GNUNET_TIME_absolute_ntoh (bh->expiration_time);
+    return et;
   }
   else if (GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO == ntohs (msg->type))
   {
     const struct DhtHelloMessage *dht_hello = (struct DhtHelloMessage *) msg;
 
-    return GNUNET_TIME_absolute_ntoh (dht_hello->expiration_time);
+    et.abs_time = GNUNET_TIME_absolute_ntoh (dht_hello->expiration_time);
+    return et;
   }
   else
     GNUNET_break (0);
-  return GNUNET_TIME_UNIT_ZERO_ABS;
+  return GNUNET_TIME_UNIT_ZERO_TS;
 }
 
 
@@ -514,7 +519,7 @@ GNUNET_HELLO_builder_from_url (const char *url)
   const char *s1;
   const char *s2;
   struct GNUNET_PeerIdentity pid;
-  struct GNUNET_TIME_Absolute et;
+  struct GNUNET_TIME_Timestamp et;
   size_t len;
   struct GNUNET_HELLO_Builder *b;
   struct GNUNET_CRYPTO_EddsaSignature sig;
@@ -570,7 +575,7 @@ GNUNET_HELLO_builder_from_url (const char *url)
       GNUNET_break_op (0);
       return NULL;
     }
-    et = GNUNET_TIME_timestamp_from_s (sec).abs_time;
+    et = GNUNET_TIME_timestamp_from_s (sec);
   }
 
   b = GNUNET_HELLO_builder_new (&pid);
@@ -722,7 +727,7 @@ GNUNET_HELLO_builder_to_url2 (const struct 
GNUNET_HELLO_Builder *builder,
   else
   {
     GNUNET_assert (GNUNET_YES == builder->signature_set);
-    et = GNUNET_TIME_absolute_to_timestamp (builder->et);
+    et = builder->et;
     sig = builder->sig;
   }
   pids = GNUNET_STRINGS_data_to_string_alloc (&builder->pid,
@@ -824,7 +829,7 @@ GNUNET_HELLO_builder_to_block (const struct 
GNUNET_HELLO_Builder *builder,
   else
   {
     GNUNET_assert (GNUNET_YES == builder->signature_set);
-    bh.expiration_time = GNUNET_TIME_absolute_hton (builder->et);
+    bh.expiration_time = GNUNET_TIME_absolute_hton (builder->et.abs_time);
     bh.sig = builder->sig;
   }
   memcpy (block,
@@ -1031,7 +1036,7 @@ GNUNET_HELLO_dht_msg_to_block (const struct 
GNUNET_MessageHeader *hello,
     return GNUNET_SYSERR;
   }
   ret = verify_hello (b,
-                      *block_expiration,
+                      *(struct GNUNET_TIME_Timestamp*) block_expiration,
                       &msg->sig);
   GNUNET_HELLO_builder_free (b);
   if (GNUNET_SYSERR == ret)
diff --git a/src/lib/util/strings.c b/src/lib/util/strings.c
index 456e3afb1..a77763885 100644
--- a/src/lib/util/strings.c
+++ b/src/lib/util/strings.c
@@ -25,6 +25,8 @@
  */
 
 
+#include "gnunet_common.h"
+#include "gnunet_time_lib.h"
 #include "platform.h"
 #if HAVE_ICONV
 #include <iconv.h>
@@ -334,8 +336,18 @@ enum GNUNET_GenericReturnValue
 GNUNET_STRINGS_fancy_time_to_timestamp (const char *fancy_time,
                                         struct GNUNET_TIME_Timestamp *atime)
 {
-  return GNUNET_STRINGS_fancy_time_to_absolute (fancy_time,
-                                                &atime->abs_time);
+  enum GNUNET_GenericReturnValue ret;
+  if (GNUNET_OK !=
+      (ret = GNUNET_STRINGS_fancy_time_to_absolute (fancy_time,
+                                                    &atime->abs_time)))
+  {
+    return ret;
+  }
+  if (GNUNET_TIME_absolute_is_never (atime->abs_time))
+  {
+    atime->abs_time = GNUNET_TIME_UNIT_FOREVER_TS.abs_time;
+  }
+  return GNUNET_OK;
 }
 
 
@@ -613,6 +625,20 @@ GNUNET_STRINGS_relative_time_to_string (struct 
GNUNET_TIME_Relative delta,
 }
 
 
+const char *
+GNUNET_STRINGS_timestamp_to_string (struct GNUNET_TIME_Timestamp t)
+{
+  struct GNUNET_TIME_Absolute av;
+
+  if (t.abs_time.abs_value_us == GNUNET_TIME_UNIT_FOREVER_TS.abs_time.
+      abs_value_us)
+    return GNUNET_STRINGS_absolute_time_to_string 
(GNUNET_TIME_UNIT_FOREVER_ABS)
+    ;
+  av.abs_value_us = t.abs_time.abs_value_us;
+  return GNUNET_STRINGS_absolute_time_to_string (av);
+}
+
+
 const char *
 GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t)
 {
diff --git a/src/service/cadet/gnunet-service-cadet_dht.c 
b/src/service/cadet/gnunet-service-cadet_dht.c
index 93ce97ed8..0c90273ae 100644
--- a/src/service/cadet/gnunet-service-cadet_dht.c
+++ b/src/service/cadet/gnunet-service-cadet_dht.c
@@ -41,7 +41,7 @@
  * we wait for the first notification.
  */
 #define STARTUP_DELAY GNUNET_TIME_relative_multiply ( \
-    GNUNET_TIME_UNIT_MILLISECONDS, 500)
+          GNUNET_TIME_UNIT_MILLISECONDS, 500)
 
 /**
  * How long do we wait after we get an updated HELLO before publishing?
@@ -49,7 +49,7 @@
  * case multiple addresses changed and we got a partial update.
  */
 #define CHANGE_DELAY GNUNET_TIME_relative_multiply ( \
-    GNUNET_TIME_UNIT_MILLISECONDS, 100)
+          GNUNET_TIME_UNIT_MILLISECONDS, 100)
 
 
 #define LOG(level, ...) GNUNET_log_from (level, "cadet-dht", __VA_ARGS__)
@@ -132,12 +132,12 @@ dht_get_id_handler (void *cls, struct 
GNUNET_TIME_Absolute exp,
   struct CadetPeer *peer;
 
   peer = GCP_get (&put_path[0].pred,
-                    GNUNET_YES);
+                  GNUNET_YES);
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Got HELLO for %s\n",
        GCP_2s (peer));
   GCP_set_hello (peer,
-                   hello);
+                 hello);
   GNUNET_HELLO_builder_free (builder);
 }
 
@@ -159,7 +159,7 @@ announce_id (void *cls)
   struct GNUNET_TIME_Relative next_put;
 
   hello = GCH_get_mine ();
-  size = (NULL != hello) ? ntohs(hello->size) : 0;
+  size = (NULL != hello) ? ntohs (hello->size) : 0;
   if (0 == size)
   {
     expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
@@ -168,7 +168,7 @@ announce_id (void *cls)
   }
   else
   {
-    expiration = GNUNET_HELLO_builder_get_expiration_time (hello);
+    expiration = GNUNET_HELLO_get_expiration_time_from_msg (hello).abs_time;
     announce_delay = GNUNET_TIME_UNIT_SECONDS;
   }
 
diff --git a/src/service/cadet/gnunet-service-cadet_hello.c 
b/src/service/cadet/gnunet-service-cadet_hello.c
index 889f3d588..0a8e8e6ae 100644
--- a/src/service/cadet/gnunet-service-cadet_hello.c
+++ b/src/service/cadet/gnunet-service-cadet_hello.c
@@ -94,8 +94,8 @@ got_hello (void *cls,
        "Hello for %s (%d bytes), expires on %s\n",
        GNUNET_i2s (&record->peer),
        ntohs (hello->size),
-       GNUNET_STRINGS_absolute_time_to_string (
-         GNUNET_HELLO_builder_get_expiration_time (hello)));
+       GNUNET_STRINGS_timestamp_to_string (
+         GNUNET_HELLO_get_expiration_time_from_msg (hello)));
   peer = GCP_get (&record->peer,
                   GNUNET_YES);
   GCP_set_hello (peer,
diff --git a/src/service/cadet/gnunet-service-cadet_peer.c 
b/src/service/cadet/gnunet-service-cadet_peer.c
index 2b05f353f..6dc1c7a75 100644
--- a/src/service/cadet/gnunet-service-cadet_peer.c
+++ b/src/service/cadet/gnunet-service-cadet_peer.c
@@ -53,13 +53,13 @@
  * How long do we wait until tearing down an idle peer?
  */
 #define IDLE_PEER_TIMEOUT GNUNET_TIME_relative_multiply ( \
-    GNUNET_TIME_UNIT_MINUTES, 5)
+          GNUNET_TIME_UNIT_MINUTES, 5)
 
 /**
  * How long do we keep paths around if we no longer care about the peer?
  */
 #define IDLE_PATH_TIMEOUT GNUNET_TIME_relative_multiply ( \
-    GNUNET_TIME_UNIT_MINUTES, 2)
+          GNUNET_TIME_UNIT_MINUTES, 2)
 
 /**
  * Queue size when we start dropping OOO messages.
@@ -490,8 +490,8 @@ consider_peer_destroy (struct CadetPeer *cp)
   {
     /* relevant only until HELLO expires */
     exp = GNUNET_TIME_absolute_get_remaining (
-      GNUNET_HELLO_builder_get_expiration_time (cp
-                                                ->hello));
+      GNUNET_HELLO_get_expiration_time_from_msg (cp
+                                                 ->hello).abs_time);
     cp->destroy_task = GNUNET_SCHEDULER_add_delayed (exp,
                                                      &destroy_peer,
                                                      cp);
@@ -1044,7 +1044,8 @@ GCP_add_connection (struct CadetPeer *cp,
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_CONTAINER_multishortmap_put (cp->connections,
                                                      &GCC_get_id (
-                                                       
cc)->connection_of_tunnel,
+                                                       
cc)->connection_of_tunnel
+                                                     ,
                                                      cc,
                                                      
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
   if (NULL != cp->destroy_task)
@@ -1319,10 +1320,10 @@ GCP_set_hello (struct CadetPeer *cp,
     struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
 
     struct GNUNET_TIME_Absolute new_hello_exp =
-      GNUNET_HELLO_builder_get_expiration_time (hello);
+      GNUNET_HELLO_get_expiration_time_from_msg (hello).abs_time;
     struct GNUNET_TIME_Absolute old_hello_exp =
-      GNUNET_HELLO_builder_get_expiration_time (cp
-                                                ->hello);
+      GNUNET_HELLO_get_expiration_time_from_msg (cp
+                                                 ->hello).abs_time;
 
     if (GNUNET_TIME_absolute_cmp (new_hello_exp, >, now) &&
         GNUNET_TIME_absolute_cmp (new_hello_exp, >, old_hello_exp))
diff --git a/src/service/peerstore/gnunet-service-peerstore.c 
b/src/service/peerstore/gnunet-service-peerstore.c
index 2c966f159..d55b9ed6b 100644
--- a/src/service/peerstore/gnunet-service-peerstore.c
+++ b/src/service/peerstore/gnunet-service-peerstore.c
@@ -23,6 +23,7 @@
  * @brief peerstore service implementation
  * @author Omar Tarabai
  */
+#include "gnunet_time_lib.h"
 #include "platform.h"
 #include "gnunet_peerstore_service.h"
 #include "gnunet_protocols.h"
@@ -1134,6 +1135,7 @@ hosts_directory_scan_callback (void *cls, const char 
*fullname)
   const struct GNUNET_MessageHeader *hello;
   struct GNUNET_HELLO_Builder *builder;
   const struct GNUNET_PeerIdentity *pid;
+  struct GNUNET_TIME_Timestamp et;
   (void) cls;
 
   if (GNUNET_YES != GNUNET_DISK_file_test (fullname))
@@ -1162,7 +1164,7 @@ hosts_directory_scan_callback (void *cls, const char 
*fullname)
     return GNUNET_OK;
   }
   pid = GNUNET_HELLO_builder_get_id (builder);
-
+  et = GNUNET_HELLO_get_expiration_time_from_msg (hello);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "store contrib hello for peer %s\n",
               GNUNET_i2s (pid));
@@ -1173,7 +1175,7 @@ hosts_directory_scan_callback (void *cls, const char 
*fullname)
                                      GNUNET_PEERSTORE_HELLO_KEY,
                                      hello,
                                      size_total,
-                                     GNUNET_TIME_UNIT_FOREVER_ABS,
+                                     et.abs_time,
                                      GNUNET_PEERSTORE_STOREOPTION_MULTIPLE,
                                      &store_hello_continuation,
                                      NULL))
diff --git a/src/service/peerstore/peerstore_api.c 
b/src/service/peerstore/peerstore_api.c
index 45f347b6a..28233c415 100644
--- a/src/service/peerstore/peerstore_api.c
+++ b/src/service/peerstore/peerstore_api.c
@@ -873,8 +873,10 @@ hello_add_iter (void *cls, const struct 
GNUNET_PEERSTORE_Record *record,
                 const char *emsg)
 {
   struct GNUNET_PEERSTORE_StoreHelloContext *huc = cls;
-  struct GNUNET_TIME_Absolute hello_exp =
-    GNUNET_HELLO_builder_get_expiration_time (huc->hello);
+  struct GNUNET_TIME_Timestamp hello_exp =
+    GNUNET_HELLO_get_expiration_time_from_msg (huc->hello);
+  struct GNUNET_TIME_Timestamp hello_record_exp;
+
   if ((NULL == record) && (NULL == emsg))
   {
     /** If we ever get here, we are newer than the existing record
@@ -886,7 +888,7 @@ hello_add_iter (void *cls, const struct 
GNUNET_PEERSTORE_Record *record,
                                       GNUNET_PEERSTORE_HELLO_KEY,
                                       huc->hello,
                                       ntohs (huc->hello->size),
-                                      hello_exp,
+                                      hello_exp.abs_time,
                                       GNUNET_PEERSTORE_STOREOPTION_REPLACE,
                                       &hello_store_success,
                                       huc);
@@ -898,11 +900,14 @@ hello_add_iter (void *cls, const struct 
GNUNET_PEERSTORE_Record *record,
     GNUNET_PEERSTORE_iteration_next (huc->ic, 1);
     return;
   }
-  if (GNUNET_TIME_absolute_cmp (record->expiry, >, hello_exp))
+  hello_record_exp = GNUNET_HELLO_get_expiration_time_from_msg (record->value);
+  if (GNUNET_TIME_absolute_cmp (hello_record_exp.abs_time, >, 
hello_exp.abs_time))
   {
     LOG (GNUNET_ERROR_TYPE_WARNING,
-         "Not storing hello for %s since we seem to have a newer version on 
record.\n",
-         GNUNET_i2s (&huc->pid));
+         "Not storing hello for %s since we seem to have a newer version on 
record expiring `%s' and after `%s'.\n",
+         GNUNET_i2s (&huc->pid),
+         GNUNET_STRINGS_timestamp_to_string (hello_record_exp),
+         GNUNET_STRINGS_timestamp_to_string (hello_exp));
     huc->cont (huc->cont_cls, GNUNET_OK);
     GNUNET_PEERSTORE_iteration_stop (huc->ic);
     GNUNET_free (huc->hello);
@@ -923,14 +928,14 @@ GNUNET_PEERSTORE_hello_add (struct 
GNUNET_PEERSTORE_Handle *h,
   struct GNUNET_PEERSTORE_StoreHelloContext *huc;
   const struct GNUNET_PeerIdentity *pid;
   struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
-  struct GNUNET_TIME_Absolute hello_exp =
-    GNUNET_HELLO_builder_get_expiration_time (msg);
+  struct GNUNET_TIME_Timestamp hello_exp =
+    GNUNET_HELLO_get_expiration_time_from_msg (msg);
   struct GNUNET_TIME_Absolute huc_exp;
   uint16_t size_msg = ntohs (msg->size);
 
   if (NULL == builder)
     return NULL;
-  if (GNUNET_TIME_absolute_cmp (hello_exp, <, now))
+  if (GNUNET_TIME_absolute_cmp (hello_exp.abs_time, <, now))
     return NULL;
 
   huc = GNUNET_new (struct GNUNET_PEERSTORE_StoreHelloContext);
@@ -940,7 +945,7 @@ GNUNET_PEERSTORE_hello_add (struct GNUNET_PEERSTORE_Handle 
*h,
   huc->hello = GNUNET_malloc (size_msg);
   GNUNET_memcpy (huc->hello, msg, size_msg);
   huc_exp =
-    GNUNET_HELLO_builder_get_expiration_time (huc->hello);
+    GNUNET_HELLO_get_expiration_time_from_msg (huc->hello).abs_time;
   pid = GNUNET_HELLO_builder_get_id (builder);
   huc->pid = *pid;
   LOG (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/service/topology/gnunet-daemon-topology.c 
b/src/service/topology/gnunet-daemon-topology.c
index 0aa5988cd..e5cc7c62b 100644
--- a/src/service/topology/gnunet-daemon-topology.c
+++ b/src/service/topology/gnunet-daemon-topology.c
@@ -27,6 +27,7 @@
  * - gossping HELLOs
  *
  */
+#include "gnunet_time_lib.h"
 #include "platform.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_hello_uri_lib.h"
@@ -479,7 +480,8 @@ schedule_next_hello (void *cls)
   pl->next_hello_allowed =
     GNUNET_TIME_relative_to_absolute (HELLO_ADVERTISEMENT_MIN_FREQUENCY);
   delay = GNUNET_TIME_absolute_get_remaining (pl->next_hello_allowed);
-  pl->hello_delay_task = GNUNET_SCHEDULER_add_delayed (delay, 
&schedule_next_hello, pl);
+  pl->hello_delay_task = GNUNET_SCHEDULER_add_delayed (delay, &
+                                                       schedule_next_hello, 
pl);
 }
 
 
@@ -498,8 +500,8 @@ reschedule_hellos (void *cls,
                    const struct GNUNET_PeerIdentity *pid,
                    void *value)
 {
-  (void) cls;
   struct Peer *peer = value;
+  (void) cls;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Reschedule for `%s'\n",
@@ -689,10 +691,10 @@ consider_for_advertising (const struct 
GNUNET_MessageHeader *hello)
   else if (NULL != peer->hello)
   {
     struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
-    struct GNUNET_TIME_Absolute new_hello_exp =
-      GNUNET_HELLO_builder_get_expiration_time (hello);
-    struct GNUNET_TIME_Absolute old_hello_exp =
-      GNUNET_HELLO_builder_get_expiration_time (peer->hello);
+    struct GNUNET_TIME_Timestamp new_hello_exp =
+      GNUNET_HELLO_get_expiration_time_from_msg (hello);
+    struct GNUNET_TIME_Timestamp old_hello_exp =
+      GNUNET_HELLO_get_expiration_time_from_msg (peer->hello);
     struct GNUNET_HELLO_Builder *builder_old = GNUNET_HELLO_builder_from_msg (
       peer->hello);
 
@@ -700,8 +702,9 @@ consider_for_advertising (const struct GNUNET_MessageHeader 
*hello)
                                   &address_iterator,
                                   &num_addresses_old);
     GNUNET_HELLO_builder_free (builder_old);
-    if (GNUNET_TIME_absolute_cmp (new_hello_exp, >, now) &&
-        (GNUNET_TIME_absolute_cmp (new_hello_exp, >, old_hello_exp) ||
+    if (GNUNET_TIME_absolute_cmp (new_hello_exp.abs_time, >, now) &&
+        (GNUNET_TIME_absolute_cmp (new_hello_exp.abs_time, >, old_hello_exp.
+                                   abs_time) ||
          num_addresses_old < num_addresses_new))
     {
       GNUNET_free (peer->hello);

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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