diff options
Diffstat (limited to 'src/service/messenger/gnunet-service-messenger_message_handle.c')
-rw-r--r-- | src/service/messenger/gnunet-service-messenger_message_handle.c | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/src/service/messenger/gnunet-service-messenger_message_handle.c b/src/service/messenger/gnunet-service-messenger_message_handle.c new file mode 100644 index 000000000..ee099d893 --- /dev/null +++ b/src/service/messenger/gnunet-service-messenger_message_handle.c | |||
@@ -0,0 +1,185 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020--2024 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_handle.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet-service-messenger_message_handle.h" | ||
27 | |||
28 | #include "gnunet-service-messenger_room.h" | ||
29 | |||
30 | static void | ||
31 | handle_member_session_switch (struct GNUNET_MESSENGER_MemberSession *session, | ||
32 | const struct GNUNET_MESSENGER_Message *message, | ||
33 | const struct GNUNET_HashCode *hash) | ||
34 | { | ||
35 | struct GNUNET_MESSENGER_MemberSession *next = switch_member_session (session, | ||
36 | message, | ||
37 | hash); | ||
38 | |||
39 | if (next != session) | ||
40 | add_member_session (next->member, next); | ||
41 | } | ||
42 | |||
43 | |||
44 | void | ||
45 | handle_message_join (struct GNUNET_MESSENGER_SrvRoom *room, | ||
46 | struct GNUNET_MESSENGER_SenderSession *session, | ||
47 | const struct GNUNET_MESSENGER_Message *message, | ||
48 | const struct GNUNET_HashCode *hash) | ||
49 | { | ||
50 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Member (%s) joins room (%s).\n", | ||
51 | GNUNET_sh2s (&(message->header.sender_id)), GNUNET_h2s ( | ||
52 | get_srv_room_key (room))); | ||
53 | |||
54 | if (GNUNET_OK != reset_member_session (session->member, hash)) | ||
55 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Resetting member session failed!\n"); | ||
56 | |||
57 | solve_srv_room_member_collisions ( | ||
58 | room, | ||
59 | &(message->body.join.key), | ||
60 | &(message->header.sender_id), | ||
61 | GNUNET_TIME_absolute_ntoh (message->header.timestamp) | ||
62 | ); | ||
63 | } | ||
64 | |||
65 | |||
66 | void | ||
67 | handle_message_leave (struct GNUNET_MESSENGER_SrvRoom *room, | ||
68 | struct GNUNET_MESSENGER_SenderSession *session, | ||
69 | const struct GNUNET_MESSENGER_Message *message, | ||
70 | const struct GNUNET_HashCode *hash) | ||
71 | { | ||
72 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Member (%s) leaves room (%s).\n", | ||
73 | GNUNET_sh2s (&(message->header.sender_id)), GNUNET_h2s ( | ||
74 | get_srv_room_key (room))); | ||
75 | |||
76 | close_member_session (session->member); | ||
77 | } | ||
78 | |||
79 | |||
80 | void | ||
81 | handle_message_key (struct GNUNET_MESSENGER_SrvRoom *room, | ||
82 | struct GNUNET_MESSENGER_SenderSession *session, | ||
83 | const struct GNUNET_MESSENGER_Message *message, | ||
84 | const struct GNUNET_HashCode *hash) | ||
85 | { | ||
86 | handle_member_session_switch (session->member, message, hash); | ||
87 | } | ||
88 | |||
89 | |||
90 | void | ||
91 | handle_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, | ||
92 | struct GNUNET_MESSENGER_SenderSession *session, | ||
93 | const struct GNUNET_MESSENGER_Message *message, | ||
94 | const struct GNUNET_HashCode *hash) | ||
95 | { | ||
96 | struct GNUNET_MESSENGER_PeerStore *store = get_srv_room_peer_store (room); | ||
97 | |||
98 | if (0 == GNUNET_memcmp (session->peer, &(message->body.peer.peer))) | ||
99 | update_store_peer (store, &(message->body.peer.peer), GNUNET_YES); | ||
100 | |||
101 | if (GNUNET_NO == contains_list_tunnels (&(room->basement), | ||
102 | &(message->body.peer.peer))) | ||
103 | add_to_list_tunnels (&(room->basement), &(message->body.peer.peer), hash); | ||
104 | |||
105 | if (room->peer_message) | ||
106 | rebuild_srv_room_basement_structure (room); | ||
107 | } | ||
108 | |||
109 | |||
110 | void | ||
111 | handle_message_id (struct GNUNET_MESSENGER_SrvRoom *room, | ||
112 | struct GNUNET_MESSENGER_SenderSession *session, | ||
113 | const struct GNUNET_MESSENGER_Message *message, | ||
114 | const struct GNUNET_HashCode *hash) | ||
115 | { | ||
116 | handle_member_session_switch (session->member, message, hash); | ||
117 | |||
118 | solve_srv_room_member_collisions ( | ||
119 | room, | ||
120 | get_member_session_public_key (session->member), | ||
121 | &(message->body.id.id), | ||
122 | GNUNET_TIME_absolute_ntoh (message->header.timestamp) | ||
123 | ); | ||
124 | } | ||
125 | |||
126 | |||
127 | void | ||
128 | handle_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, | ||
129 | struct GNUNET_MESSENGER_SenderSession *session, | ||
130 | const struct GNUNET_MESSENGER_Message *message, | ||
131 | const struct GNUNET_HashCode *hash) | ||
132 | { | ||
133 | struct GNUNET_MESSENGER_PeerStore *store = get_srv_room_peer_store (room); | ||
134 | |||
135 | if (0 == GNUNET_memcmp (session->peer, &(message->body.miss.peer))) | ||
136 | update_store_peer (store, &(message->body.miss.peer), GNUNET_NO); | ||
137 | |||
138 | struct GNUNET_MESSENGER_ListTunnel *element = find_list_tunnels ( | ||
139 | &(room->basement), &(message->body.miss.peer), NULL); | ||
140 | |||
141 | if (! element) | ||
142 | return; | ||
143 | |||
144 | remove_from_list_tunnels (&(room->basement), element); | ||
145 | |||
146 | if (room->peer_message) | ||
147 | rebuild_srv_room_basement_structure (room); | ||
148 | } | ||
149 | |||
150 | |||
151 | void | ||
152 | handle_message_delete (struct GNUNET_MESSENGER_SrvRoom *room, | ||
153 | struct GNUNET_MESSENGER_SenderSession *session, | ||
154 | const struct GNUNET_MESSENGER_Message *message, | ||
155 | const struct GNUNET_HashCode *hash) | ||
156 | { | ||
157 | struct GNUNET_TIME_Relative delay = GNUNET_TIME_relative_ntoh ( | ||
158 | message->body.deletion.delay); | ||
159 | struct GNUNET_TIME_Absolute action = GNUNET_TIME_absolute_ntoh ( | ||
160 | message->header.timestamp); | ||
161 | |||
162 | action = GNUNET_TIME_absolute_add (action, delay); | ||
163 | delay = GNUNET_TIME_absolute_get_difference (GNUNET_TIME_absolute_get (), | ||
164 | action); | ||
165 | |||
166 | delete_srv_room_message (room, session->member, | ||
167 | &(message->body.deletion.hash), delay); | ||
168 | } | ||
169 | |||
170 | |||
171 | void | ||
172 | handle_message_connection (struct GNUNET_MESSENGER_SrvRoom *room, | ||
173 | struct GNUNET_MESSENGER_SenderSession *session, | ||
174 | const struct GNUNET_MESSENGER_Message *message, | ||
175 | const struct GNUNET_HashCode *hash) | ||
176 | { | ||
177 | struct GNUNET_MESSENGER_ListTunnel *element = find_list_tunnels ( | ||
178 | &(room->basement), session->peer, NULL); | ||
179 | |||
180 | if (! element) | ||
181 | return; | ||
182 | |||
183 | memcpy (&(element->connection), &(message->body.connection), | ||
184 | sizeof (struct GNUNET_MESSENGER_MessageConnection)); | ||
185 | } | ||