diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2021-03-20 13:53:23 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-04-04 17:58:11 +0200 |
commit | ac3aa3cc3a617bc54ed8beb2b5a30c0b95483525 (patch) | |
tree | 6e0444e568722f18501746665a07dfa3434c7ad6 /src/messenger/gnunet-service-messenger_message_state.c | |
parent | 2413977f917534aa24ef562a28da193a2cdaa343 (diff) | |
download | gnunet-ac3aa3cc3a617bc54ed8beb2b5a30c0b95483525.tar.gz gnunet-ac3aa3cc3a617bc54ed8beb2b5a30c0b95483525.zip |
-multiple fixes and correction regarding messenger service
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-added message states to tunnels
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-fixed requests for deleted messages returning previous ones
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-added automatic solving of member id collissions
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-added light timestamp verification
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-fixed decoding asserts and member session forwarding
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-added permission check for member sessions during local join
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat (limited to 'src/messenger/gnunet-service-messenger_message_state.c')
-rw-r--r-- | src/messenger/gnunet-service-messenger_message_state.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/messenger/gnunet-service-messenger_message_state.c b/src/messenger/gnunet-service-messenger_message_state.c new file mode 100644 index 000000000..cdd2d9712 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_message_state.c | |||
@@ -0,0 +1,109 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020--2021 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 | */ | ||
20 | /** | ||
21 | * @author Tobias Frisch | ||
22 | * @file src/messenger/gnunet-service-messenger_message_state.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet-service-messenger_message_state.h" | ||
27 | |||
28 | void | ||
29 | init_message_state (struct GNUNET_MESSENGER_MessageState *state) | ||
30 | { | ||
31 | GNUNET_assert(state); | ||
32 | |||
33 | init_list_messages (&(state->last_messages)); | ||
34 | } | ||
35 | |||
36 | void | ||
37 | clear_message_state (struct GNUNET_MESSENGER_MessageState *state) | ||
38 | { | ||
39 | GNUNET_assert(state); | ||
40 | |||
41 | clear_list_messages (&(state->last_messages)); | ||
42 | } | ||
43 | |||
44 | void | ||
45 | get_message_state_chain_hash (const struct GNUNET_MESSENGER_MessageState *state, | ||
46 | struct GNUNET_HashCode *hash) | ||
47 | { | ||
48 | GNUNET_assert((state) && (hash)); | ||
49 | |||
50 | if (state->last_messages.head) | ||
51 | GNUNET_memcpy(hash, &(state->last_messages.head->hash), sizeof(*hash)); | ||
52 | else | ||
53 | memset (hash, 0, sizeof(*hash)); | ||
54 | } | ||
55 | |||
56 | const struct GNUNET_HashCode* | ||
57 | get_message_state_merge_hash (const struct GNUNET_MESSENGER_MessageState *state) | ||
58 | { | ||
59 | GNUNET_assert(state); | ||
60 | |||
61 | if (state->last_messages.head == state->last_messages.tail) | ||
62 | return NULL; | ||
63 | |||
64 | return &(state->last_messages.tail->hash); | ||
65 | } | ||
66 | |||
67 | void | ||
68 | update_message_state (struct GNUNET_MESSENGER_MessageState *state, int requested, | ||
69 | const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
70 | { | ||
71 | GNUNET_assert((state) && (message) && (hash)); | ||
72 | |||
73 | if ((GNUNET_YES == requested) || | ||
74 | (GNUNET_MESSENGER_KIND_INFO == message->header.kind) || | ||
75 | (GNUNET_MESSENGER_KIND_REQUEST == message->header.kind)) | ||
76 | return; | ||
77 | |||
78 | if (GNUNET_MESSENGER_KIND_MERGE == message->header.kind) | ||
79 | remove_from_list_messages(&(state->last_messages), &(message->body.merge.previous)); | ||
80 | remove_from_list_messages(&(state->last_messages), &(message->header.previous)); | ||
81 | |||
82 | add_to_list_messages (&(state->last_messages), hash); | ||
83 | } | ||
84 | |||
85 | void | ||
86 | load_message_state (struct GNUNET_MESSENGER_MessageState *state, const char *path) | ||
87 | { | ||
88 | GNUNET_assert((state) && (path)); | ||
89 | |||
90 | char *last_messages_file; | ||
91 | GNUNET_asprintf (&last_messages_file, "%s%s", path, "last_messages.list"); | ||
92 | |||
93 | load_list_messages(&(state->last_messages), last_messages_file); | ||
94 | GNUNET_free(last_messages_file); | ||
95 | } | ||
96 | |||
97 | void | ||
98 | save_message_state (const struct GNUNET_MESSENGER_MessageState *state, const char *path) | ||
99 | { | ||
100 | GNUNET_assert((state) && (path)); | ||
101 | |||
102 | char *last_messages_file; | ||
103 | GNUNET_asprintf (&last_messages_file, "%s%s", path, "last_messages.list"); | ||
104 | |||
105 | save_list_messages(&(state->last_messages), last_messages_file); | ||
106 | GNUNET_free(last_messages_file); | ||
107 | } | ||
108 | |||
109 | |||