commit 5da873231b96928db5b1b0095471d76ac7e2fc9e
parent 963fc12054adaf60b7be87983eb676c6ac2ae66c
Author: Jacki <jacki@thejackimonster.de>
Date: Thu, 26 Sep 2024 06:53:54 +0200
Use standard types for time
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
12 files changed, 71 insertions(+), 35 deletions(-)
diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h
@@ -34,10 +34,10 @@
*/
/**@{*/
-#include <gnunet/gnunet_common.h>
-#include <gnunet/gnunet_time_lib.h>
#include <gnunet/gnunet_util_lib.h>
+
#include <stdint.h>
+#include <time.h>
/**
* @def GNUNET_CHAT_VERSION The major and minor version should be identical to
@@ -658,13 +658,13 @@ GNUNET_CHAT_get_key (const struct GNUNET_CHAT_Handle *handle);
* @param[in,out] handle Chat handle
* @param[in] name Attribute name
* @param[in] value Attribute value
- * @param[in] expires Expiration time or NULL
+ * @param[in] expires Expiration time
*/
void
GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle,
const char *name,
const char *value,
- struct GNUNET_TIME_Relative expires);
+ time_t expires);
/**
* Deletes an attribute of a chat <i>handle</i> for related communication
@@ -779,7 +779,7 @@ GNUNET_CHAT_uri_destroy (struct GNUNET_CHAT_Uri *uri);
*/
struct GNUNET_CHAT_Lobby*
GNUNET_CHAT_lobby_open (struct GNUNET_CHAT_Handle *handle,
- struct GNUNET_TIME_Relative delay,
+ unsigned int delay,
GNUNET_CHAT_LobbyCallback callback,
void *cls);
@@ -1425,7 +1425,7 @@ GNUNET_CHAT_message_get_kind (const struct GNUNET_CHAT_Message *message);
* @param[in] message Message
* @return The timestamp of message
*/
-struct GNUNET_TIME_Absolute
+time_t
GNUNET_CHAT_message_get_timestamp (const struct GNUNET_CHAT_Message *message);
/**
@@ -1592,7 +1592,8 @@ struct GNUNET_CHAT_Message*
GNUNET_CHAT_message_get_target (const struct GNUNET_CHAT_Message *message);
/**
- * Deletes a given <i>message</i> with a specific relative <i>delay</i>.
+ * Deletes a given <i>message</i> with a specific relative <i>delay</i>
+ * in seconds.
*
* @param[in,out] message Message
* @param[in] delay Relative delay
@@ -1600,7 +1601,7 @@ GNUNET_CHAT_message_get_target (const struct GNUNET_CHAT_Message *message);
*/
enum GNUNET_GenericReturnValue
GNUNET_CHAT_message_delete (struct GNUNET_CHAT_Message *message,
- struct GNUNET_TIME_Relative delay);
+ unsigned int delay);
/**
* Iterates through the tag messages in the context of a given
diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c
@@ -29,12 +29,13 @@
#include "internal/gnunet_chat_tagging.h"
-#include "gnunet_chat_contact_intern.c"
#include <gnunet/gnunet_common.h>
#include <gnunet/gnunet_messenger_service.h>
#include <gnunet/gnunet_time_lib.h>
#include <gnunet/gnunet_util_lib.h>
+#include "gnunet_chat_contact_intern.c"
+
static const unsigned int initial_map_size_of_contact = 8;
struct GNUNET_CHAT_Contact*
diff --git a/src/gnunet_chat_discourse.c b/src/gnunet_chat_discourse.c
@@ -23,6 +23,7 @@
*/
#include "gnunet_chat_discourse.h"
+
#include <gnunet/gnunet_common.h>
#include <gnunet/gnunet_scheduler_lib.h>
#include <gnunet/gnunet_time_lib.h>
diff --git a/src/gnunet_chat_discourse.h b/src/gnunet_chat_discourse.h
@@ -25,13 +25,13 @@
#ifndef GNUNET_CHAT_DISCOURSE_H_
#define GNUNET_CHAT_DISCOURSE_H_
+#include "gnunet_chat_util.h"
+
#include <gnunet/gnunet_common.h>
#include <gnunet/gnunet_messenger_service.h>
#include <gnunet/gnunet_time_lib.h>
#include <gnunet/gnunet_util_lib.h>
-#include "gnunet_chat_util.h"
-
struct GNUNET_CHAT_Contact;
struct GNUNET_CHAT_Context;
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h
@@ -25,6 +25,16 @@
#ifndef GNUNET_CHAT_HANDLE_H_
#define GNUNET_CHAT_HANDLE_H_
+#include "gnunet_chat_lib.h"
+#include "gnunet_chat_account.h"
+#include "gnunet_chat_lobby.h"
+#include "gnunet_chat_message.h"
+#include "gnunet_chat_uri.h"
+
+#include "internal/gnunet_chat_accounts.h"
+#include "internal/gnunet_chat_attribute_process.h"
+#include "internal/gnunet_chat_ticket_process.h"
+
#include <gnunet/gnunet_common.h>
#include <gnunet/gnunet_arm_service.h>
#include <gnunet/gnunet_fs_service.h>
@@ -37,16 +47,6 @@
#include <gnunet/gnunet_time_lib.h>
#include <gnunet/gnunet_util_lib.h>
-#include "gnunet_chat_lib.h"
-#include "gnunet_chat_account.h"
-#include "gnunet_chat_lobby.h"
-#include "gnunet_chat_message.h"
-#include "gnunet_chat_uri.h"
-
-#include "internal/gnunet_chat_accounts.h"
-#include "internal/gnunet_chat_attribute_process.h"
-#include "internal/gnunet_chat_ticket_process.h"
-
struct GNUNET_CHAT_Handle;
struct GNUNET_CHAT_InternalServices
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
@@ -45,6 +45,7 @@
#include <gnunet/gnunet_scheduler_lib.h>
#include <gnunet/gnunet_time_lib.h>
#include <gnunet/gnunet_util_lib.h>
+
#include <stdio.h>
#include <string.h>
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -330,7 +330,7 @@ void
GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle,
const char *name,
const char *value,
- struct GNUNET_TIME_Relative expires)
+ time_t expires)
{
GNUNET_CHAT_VERSION_ASSERT();
@@ -344,8 +344,14 @@ GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle,
if ((!key) || (!name))
return;
+ const double delay = difftime(expires, time(NULL));
+
+ struct GNUNET_TIME_Relative rel = GNUNET_TIME_relative_multiply_double(
+ GNUNET_TIME_relative_get_second_(), delay
+ );
+
struct GNUNET_CHAT_AttributeProcess *attributes;
- attributes = internal_attributes_create_store(handle, name, expires);
+ attributes = internal_attributes_create_store(handle, name, rel);
if (!attributes)
return;
@@ -624,7 +630,7 @@ GNUNET_CHAT_uri_destroy (struct GNUNET_CHAT_Uri *uri)
struct GNUNET_CHAT_Lobby*
GNUNET_CHAT_lobby_open (struct GNUNET_CHAT_Handle *handle,
- struct GNUNET_TIME_Relative delay,
+ unsigned int delay,
GNUNET_CHAT_LobbyCallback callback,
void *cls)
{
@@ -633,6 +639,10 @@ GNUNET_CHAT_lobby_open (struct GNUNET_CHAT_Handle *handle,
if ((!handle) || (handle->destruction))
return NULL;
+ struct GNUNET_TIME_Relative rel = GNUNET_TIME_relative_multiply(
+ GNUNET_TIME_relative_get_second_(), delay
+ );
+
struct GNUNET_CHAT_InternalLobbies *lobbies = GNUNET_new(
struct GNUNET_CHAT_InternalLobbies
);
@@ -645,7 +655,7 @@ GNUNET_CHAT_lobby_open (struct GNUNET_CHAT_Handle *handle,
lobbies
);
- lobby_open(lobbies->lobby, delay, callback, cls);
+ lobby_open(lobbies->lobby, rel, callback, cls);
return lobbies->lobby;
}
@@ -2073,15 +2083,23 @@ GNUNET_CHAT_message_get_kind (const struct GNUNET_CHAT_Message *message)
}
-struct GNUNET_TIME_Absolute
+time_t
GNUNET_CHAT_message_get_timestamp (const struct GNUNET_CHAT_Message *message)
{
GNUNET_CHAT_VERSION_ASSERT();
if ((!message) || (GNUNET_YES != message_has_msg(message)))
- return GNUNET_TIME_absolute_get_zero_();
+ return ((time_t) -1);
+
+ struct GNUNET_TIME_Absolute abs = GNUNET_TIME_absolute_ntoh(
+ message->msg->header.timestamp
+ );
- return GNUNET_TIME_absolute_ntoh(message->msg->header.timestamp);
+ struct GNUNET_TIME_Timestamp ts = GNUNET_TIME_absolute_to_timestamp(
+ abs
+ );
+
+ return (time_t) GNUNET_TIME_timestamp_to_s(ts);
}
@@ -2378,15 +2396,24 @@ GNUNET_CHAT_message_get_target (const struct GNUNET_CHAT_Message *message)
enum GNUNET_GenericReturnValue
GNUNET_CHAT_message_delete (struct GNUNET_CHAT_Message *message,
- struct GNUNET_TIME_Relative delay)
+ unsigned int delay)
{
GNUNET_CHAT_VERSION_ASSERT();
if ((!message) || (GNUNET_YES != message_has_msg(message)) ||
(!(message->context)))
return GNUNET_SYSERR;
+
+ struct GNUNET_TIME_Relative rel = GNUNET_TIME_relative_multiply(
+ GNUNET_TIME_relative_get_second_(), delay
+ );
+
+ GNUNET_MESSENGER_delete_message(
+ message->context->room,
+ &(message->hash),
+ rel
+ );
- GNUNET_MESSENGER_delete_message(message->context->room, &(message->hash), delay);
return GNUNET_OK;
}
diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c
@@ -30,6 +30,7 @@
#include <gnunet/gnunet_messenger_service.h>
#include <gnunet/gnunet_reclaim_lib.h>
#include <gnunet/gnunet_reclaim_service.h>
+#include <gnunet/gnunet_time_lib.h>
#include <stdlib.h>
#include <string.h>
@@ -506,8 +507,12 @@ it_message_iterate_read_receipts (void *cls,
if (!timestamp)
return GNUNET_YES;
+ struct GNUNET_TIME_Absolute abs = GNUNET_TIME_absolute_ntoh(
+ it->message->msg->header.timestamp
+ );
+
struct GNUNET_TIME_Relative delta = GNUNET_TIME_absolute_get_difference(
- *timestamp, GNUNET_CHAT_message_get_timestamp(it->message)
+ *timestamp, abs
);
int read_receipt;
diff --git a/tests/attribute/test_gnunet_chat_attribute_check.c b/tests/attribute/test_gnunet_chat_attribute_check.c
@@ -90,7 +90,7 @@ on_gnunet_chat_attribute_check_msg(void *cls,
handle,
TEST_CHECK_NAME,
TEST_CHECK_VALUE,
- GNUNET_TIME_relative_get_forever_()
+ time(NULL) + 60
);
break;
case GNUNET_CHAT_KIND_LOGOUT:
diff --git a/tests/attribute/test_gnunet_chat_attribute_share.c b/tests/attribute/test_gnunet_chat_attribute_share.c
@@ -122,7 +122,7 @@ on_gnunet_chat_attribute_share_msg(void *cls,
handle,
TEST_SHARE_NAME,
TEST_SHARE_VALUE,
- GNUNET_TIME_relative_get_forever_()
+ time(NULL) + 60
);
share_stage = 5;
diff --git a/tests/lobby/test_gnunet_chat_lobby_join.c b/tests/lobby/test_gnunet_chat_lobby_join.c
@@ -77,7 +77,7 @@ on_gnunet_chat_lobby_join_msg(void *cls,
lobby = GNUNET_CHAT_lobby_open(
handle,
- GNUNET_TIME_relative_get_second_(),
+ 1,
on_gnunet_chat_lobby_join_open,
handle
);
diff --git a/tests/lobby/test_gnunet_chat_lobby_open.c b/tests/lobby/test_gnunet_chat_lobby_open.c
@@ -64,7 +64,7 @@ on_gnunet_chat_lobby_open_msg(void *cls,
lobby = GNUNET_CHAT_lobby_open(
handle,
- GNUNET_TIME_relative_get_second_(),
+ 1,
NULL,
NULL
);