GNUnet 0.21.2
gnunet-service-messenger_message_state.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020--2023 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
27
29
30void
32{
34
35 init_list_messages (&(state->last_messages));
36}
37
38
39void
41{
43
44 clear_list_messages (&(state->last_messages));
45}
46
47
48void
50 struct GNUNET_HashCode *hash)
51{
52 GNUNET_assert ((state) && (hash));
53
54 if (state->last_messages.head)
55 GNUNET_memcpy (hash, &(state->last_messages.head->hash), sizeof(*hash));
56 else
57 memset (hash, 0, sizeof(*hash));
58}
59
60
61const struct GNUNET_HashCode*
63{
65
66 if (state->last_messages.head == state->last_messages.tail)
67 return NULL;
68
69 return &(state->last_messages.tail->hash);
70}
71
72
73void
75 enum GNUNET_GenericReturnValue requested,
76 const struct GNUNET_MESSENGER_Message *message,
77 const struct GNUNET_HashCode *hash)
78{
79 GNUNET_assert ((state) && (message) && (hash));
80
81 if ((GNUNET_YES == requested) ||
84 (get_message_discourse (message)))
85 return;
86
88 remove_from_list_messages (&(state->last_messages),
89 &(message->body.merge.previous));
90 remove_from_list_messages (&(state->last_messages),
91 &(message->header.previous));
92
93 add_to_list_messages (&(state->last_messages), hash);
94}
95
96
97void
99 const char *path)
100{
101 GNUNET_assert ((state) && (path));
102
103 char *last_messages_file;
104 GNUNET_asprintf (&last_messages_file, "%s%s", path, "last_messages.list");
105
106 load_list_messages (&(state->last_messages), last_messages_file);
107 GNUNET_free (last_messages_file);
108}
109
110
111void
113 const char *path)
114{
115 GNUNET_assert ((state) && (path));
116
117 char *last_messages_file;
118 GNUNET_asprintf (&last_messages_file, "%s%s", path, "last_messages.list");
119
120 save_list_messages (&(state->last_messages), last_messages_file);
121 GNUNET_free (last_messages_file);
122}
enum State state
current state of profiling
void remove_from_list_messages(struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash)
Removes the first entry with a matching hash from the list.
void clear_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Clears the list of message hashes.
void load_list_messages(struct GNUNET_MESSENGER_ListMessages *messages, const char *path)
Loads the list of message hashes from a file under a given path.
void init_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Initializes list of message hashes as empty list.
void save_list_messages(const struct GNUNET_MESSENGER_ListMessages *messages, const char *path)
Saves the list of message hashes to a file under a given path.
void add_to_list_messages(struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash)
Adds a specific hash from a message to the end of the list.
const struct GNUNET_HashCode * get_message_state_merge_hash(const struct GNUNET_MESSENGER_MessageState *state)
void save_message_state(const struct GNUNET_MESSENGER_MessageState *state, const char *path)
void clear_message_state(struct GNUNET_MESSENGER_MessageState *state)
void get_message_state_chain_hash(const struct GNUNET_MESSENGER_MessageState *state, struct GNUNET_HashCode *hash)
void init_message_state(struct GNUNET_MESSENGER_MessageState *state)
void update_message_state(struct GNUNET_MESSENGER_MessageState *state, enum GNUNET_GenericReturnValue requested, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
void load_message_state(struct GNUNET_MESSENGER_MessageState *state, const char *path)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_YES
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_free(ptr)
Wrapper around free.
@ GNUNET_MESSENGER_KIND_INFO
The info kind.
@ GNUNET_MESSENGER_KIND_REQUEST
The request kind.
@ GNUNET_MESSENGER_KIND_MERGE
The merge kind.
const struct GNUNET_ShortHashCode * get_message_discourse(const struct GNUNET_MESSENGER_Message *message)
Returns the discourse hash of a message depending on its kind.
A 512-bit hashcode.
struct GNUNET_MESSENGER_MessageMerge merge
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_HashCode previous
The hash of a second previous message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageBody body
Body.