libgnunetchat

library for GNUnet Messenger
Log | Files | Refs | README | LICENSE

commit 1a43f468dada34bcbfaa102a9fe37aec7122af16
parent 5da873231b96928db5b1b0095471d76ac7e2fc9e
Author: Jacki <jacki@thejackimonster.de>
Date:   Thu, 26 Sep 2024 07:13:20 +0200

Revert "Use standard types for time"

This reverts commit 5da873231b96928db5b1b0095471d76ac7e2fc9e.

Diffstat:
Minclude/gnunet/gnunet_chat_lib.h | 17++++++++---------
Msrc/gnunet_chat_contact.c | 3+--
Msrc/gnunet_chat_discourse.c | 1-
Msrc/gnunet_chat_discourse.h | 4++--
Msrc/gnunet_chat_handle.h | 20++++++++++----------
Msrc/gnunet_chat_handle_intern.c | 1-
Msrc/gnunet_chat_lib.c | 45+++++++++------------------------------------
Msrc/gnunet_chat_lib_intern.c | 7+------
Mtests/attribute/test_gnunet_chat_attribute_check.c | 2+-
Mtests/attribute/test_gnunet_chat_attribute_share.c | 2+-
Mtests/lobby/test_gnunet_chat_lobby_join.c | 2+-
Mtests/lobby/test_gnunet_chat_lobby_open.c | 2+-
12 files changed, 35 insertions(+), 71 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 + * @param[in] expires Expiration time or NULL */ void GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle, const char *name, const char *value, - time_t expires); + struct GNUNET_TIME_Relative 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, - unsigned int delay, + struct GNUNET_TIME_Relative 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 */ -time_t +struct GNUNET_TIME_Absolute GNUNET_CHAT_message_get_timestamp (const struct GNUNET_CHAT_Message *message); /** @@ -1592,8 +1592,7 @@ 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> - * in seconds. + * Deletes a given <i>message</i> with a specific relative <i>delay</i>. * * @param[in,out] message Message * @param[in] delay Relative delay @@ -1601,7 +1600,7 @@ GNUNET_CHAT_message_get_target (const struct GNUNET_CHAT_Message *message); */ enum GNUNET_GenericReturnValue GNUNET_CHAT_message_delete (struct GNUNET_CHAT_Message *message, - unsigned int delay); + struct GNUNET_TIME_Relative 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,13 +29,12 @@ #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,7 +23,6 @@ */ #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,16 +25,6 @@ #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> @@ -47,6 +37,16 @@ #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,7 +45,6 @@ #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, - time_t expires) + struct GNUNET_TIME_Relative expires) { GNUNET_CHAT_VERSION_ASSERT(); @@ -344,14 +344,8 @@ 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, rel); + attributes = internal_attributes_create_store(handle, name, expires); if (!attributes) return; @@ -630,7 +624,7 @@ GNUNET_CHAT_uri_destroy (struct GNUNET_CHAT_Uri *uri) struct GNUNET_CHAT_Lobby* GNUNET_CHAT_lobby_open (struct GNUNET_CHAT_Handle *handle, - unsigned int delay, + struct GNUNET_TIME_Relative delay, GNUNET_CHAT_LobbyCallback callback, void *cls) { @@ -639,10 +633,6 @@ 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 ); @@ -655,7 +645,7 @@ GNUNET_CHAT_lobby_open (struct GNUNET_CHAT_Handle *handle, lobbies ); - lobby_open(lobbies->lobby, rel, callback, cls); + lobby_open(lobbies->lobby, delay, callback, cls); return lobbies->lobby; } @@ -2083,23 +2073,15 @@ GNUNET_CHAT_message_get_kind (const struct GNUNET_CHAT_Message *message) } -time_t +struct GNUNET_TIME_Absolute GNUNET_CHAT_message_get_timestamp (const struct GNUNET_CHAT_Message *message) { GNUNET_CHAT_VERSION_ASSERT(); if ((!message) || (GNUNET_YES != message_has_msg(message))) - return ((time_t) -1); - - struct GNUNET_TIME_Absolute abs = GNUNET_TIME_absolute_ntoh( - message->msg->header.timestamp - ); + return GNUNET_TIME_absolute_get_zero_(); - struct GNUNET_TIME_Timestamp ts = GNUNET_TIME_absolute_to_timestamp( - abs - ); - - return (time_t) GNUNET_TIME_timestamp_to_s(ts); + return GNUNET_TIME_absolute_ntoh(message->msg->header.timestamp); } @@ -2396,24 +2378,15 @@ GNUNET_CHAT_message_get_target (const struct GNUNET_CHAT_Message *message) enum GNUNET_GenericReturnValue GNUNET_CHAT_message_delete (struct GNUNET_CHAT_Message *message, - unsigned int delay) + struct GNUNET_TIME_Relative 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,7 +30,6 @@ #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> @@ -507,12 +506,8 @@ 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, abs + *timestamp, GNUNET_CHAT_message_get_timestamp(it->message) ); 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, - time(NULL) + 60 + GNUNET_TIME_relative_get_forever_() ); 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, - time(NULL) + 60 + GNUNET_TIME_relative_get_forever_() ); 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, - 1, + GNUNET_TIME_relative_get_second_(), 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, - 1, + GNUNET_TIME_relative_get_second_(), NULL, NULL );