diff options
Diffstat (limited to 'src/service/messenger/gnunet-service-messenger.c')
-rw-r--r-- | src/service/messenger/gnunet-service-messenger.c | 324 |
1 files changed, 191 insertions, 133 deletions
diff --git a/src/service/messenger/gnunet-service-messenger.c b/src/service/messenger/gnunet-service-messenger.c index fedaa2f60..b1521f4f8 100644 --- a/src/service/messenger/gnunet-service-messenger.c +++ b/src/service/messenger/gnunet-service-messenger.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2020--2021 GNUnet e.V. | 3 | Copyright (C) 2020--2023 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 6 | under the terms of the GNU Affero General Public License as published |
@@ -27,9 +27,9 @@ | |||
27 | #include "gnunet-service-messenger.h" | 27 | #include "gnunet-service-messenger.h" |
28 | 28 | ||
29 | #include "gnunet-service-messenger_handle.h" | 29 | #include "gnunet-service-messenger_handle.h" |
30 | #include "gnunet-service-messenger_message_kind.h" | ||
31 | #include "gnunet-service-messenger_service.h" | 30 | #include "gnunet-service-messenger_service.h" |
32 | #include "messenger_api_message.h" | 31 | #include "messenger_api_message.h" |
32 | #include "messenger_api_message_kind.h" | ||
33 | 33 | ||
34 | struct GNUNET_MESSENGER_Client | 34 | struct GNUNET_MESSENGER_Client |
35 | { | 35 | { |
@@ -39,39 +39,17 @@ struct GNUNET_MESSENGER_Client | |||
39 | 39 | ||
40 | struct GNUNET_MESSENGER_Service *messenger; | 40 | struct GNUNET_MESSENGER_Service *messenger; |
41 | 41 | ||
42 | static int | ||
43 | check_create (void *cls, | ||
44 | const struct GNUNET_MESSENGER_CreateMessage *msg) | ||
45 | { | ||
46 | GNUNET_MQ_check_zero_termination (msg); | ||
47 | return GNUNET_OK; | ||
48 | } | ||
49 | |||
50 | static void | 42 | static void |
51 | handle_create (void *cls, | 43 | handle_create (void *cls, |
52 | const struct GNUNET_MESSENGER_CreateMessage *msg) | 44 | const struct GNUNET_MESSENGER_CreateMessage *msg) |
53 | { | 45 | { |
54 | struct GNUNET_MESSENGER_Client *msg_client = cls; | 46 | struct GNUNET_MESSENGER_Client *msg_client = cls; |
55 | 47 | ||
56 | const char *name = ((const char*) msg) + sizeof(*msg); | 48 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Handle created\n"); |
57 | |||
58 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Handle created with name: %s\n", name); | ||
59 | |||
60 | setup_srv_handle_name (msg_client->handle, strlen (name) > 0 ? name : NULL); | ||
61 | 49 | ||
62 | GNUNET_SERVICE_client_continue (msg_client->client); | 50 | GNUNET_SERVICE_client_continue (msg_client->client); |
63 | } | 51 | } |
64 | 52 | ||
65 | static void | ||
66 | handle_update (void *cls, | ||
67 | const struct GNUNET_MESSENGER_UpdateMessage *msg) | ||
68 | { | ||
69 | struct GNUNET_MESSENGER_Client *msg_client = cls; | ||
70 | |||
71 | update_srv_handle (msg_client->handle); | ||
72 | |||
73 | GNUNET_SERVICE_client_continue (msg_client->client); | ||
74 | } | ||
75 | 53 | ||
76 | static void | 54 | static void |
77 | handle_destroy (void *cls, | 55 | handle_destroy (void *cls, |
@@ -79,43 +57,92 @@ handle_destroy (void *cls, | |||
79 | { | 57 | { |
80 | struct GNUNET_MESSENGER_Client *msg_client = cls; | 58 | struct GNUNET_MESSENGER_Client *msg_client = cls; |
81 | 59 | ||
60 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Handle destroyed\n"); | ||
61 | |||
82 | GNUNET_SERVICE_client_drop (msg_client->client); | 62 | GNUNET_SERVICE_client_drop (msg_client->client); |
83 | } | 63 | } |
84 | 64 | ||
65 | |||
85 | static int | 66 | static int |
86 | check_set_name (void *cls, | 67 | check_room_initial_key (const struct GNUNET_MESSENGER_RoomMessage *msg) |
87 | const struct GNUNET_MESSENGER_NameMessage *msg) | ||
88 | { | 68 | { |
89 | GNUNET_MQ_check_zero_termination (msg); | 69 | const uint16_t full_length = ntohs (msg->header.size); |
90 | return GNUNET_OK; | 70 | |
71 | if (full_length < sizeof(*msg)) | ||
72 | return GNUNET_NO; | ||
73 | |||
74 | const uint16_t msg_length = full_length - sizeof(*msg); | ||
75 | const char *msg_buffer = ((const char*) msg) + sizeof(*msg); | ||
76 | |||
77 | if (0 == msg_length) | ||
78 | return GNUNET_OK; | ||
79 | |||
80 | struct GNUNET_CRYPTO_PublicKey key; | ||
81 | size_t key_len; | ||
82 | |||
83 | if (GNUNET_OK != GNUNET_CRYPTO_read_public_key_from_buffer (msg_buffer, | ||
84 | msg_length, | ||
85 | &key, &key_len)) | ||
86 | return GNUNET_NO; | ||
87 | |||
88 | return key_len == msg_length ? GNUNET_OK : GNUNET_NO; | ||
91 | } | 89 | } |
92 | 90 | ||
91 | |||
93 | static void | 92 | static void |
94 | handle_set_name (void *cls, | 93 | initialize_handle_via_key (struct GNUNET_MESSENGER_SrvHandle *handle, |
95 | const struct GNUNET_MESSENGER_NameMessage *msg) | 94 | const struct GNUNET_MESSENGER_RoomMessage *msg) |
96 | { | 95 | { |
97 | struct GNUNET_MESSENGER_Client *msg_client = cls; | 96 | GNUNET_assert (handle); |
98 | 97 | ||
99 | const char *name = ((const char*) msg) + sizeof(*msg); | 98 | const uint16_t full_length = ntohs (msg->header.size); |
99 | const uint16_t msg_length = full_length - sizeof(*msg); | ||
100 | const char *msg_buffer = ((const char*) msg) + sizeof(*msg); | ||
100 | 101 | ||
101 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Handles name is now: %s\n", name); | 102 | if (msg_length > 0) |
103 | { | ||
104 | struct GNUNET_CRYPTO_PublicKey key; | ||
105 | size_t key_len; | ||
106 | |||
107 | if (GNUNET_OK == GNUNET_CRYPTO_read_public_key_from_buffer (msg_buffer, | ||
108 | msg_length, | ||
109 | &key, | ||
110 | &key_len)) | ||
111 | set_srv_handle_key (handle, &key); | ||
112 | else | ||
113 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
114 | "Initialization failed while reading invalid key!\n"); | ||
115 | } | ||
116 | else | ||
117 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Initialization is missing key!\n"); | ||
118 | } | ||
102 | 119 | ||
103 | set_srv_handle_name (msg_client->handle, name); | ||
104 | 120 | ||
105 | GNUNET_SERVICE_client_continue (msg_client->client); | 121 | static int |
122 | check_room_open (void *cls, | ||
123 | const struct GNUNET_MESSENGER_RoomMessage *msg) | ||
124 | { | ||
125 | return check_room_initial_key (msg); | ||
106 | } | 126 | } |
107 | 127 | ||
128 | |||
108 | static void | 129 | static void |
109 | handle_room_open (void *cls, | 130 | handle_room_open (void *cls, |
110 | const struct GNUNET_MESSENGER_RoomMessage *msg) | 131 | const struct GNUNET_MESSENGER_RoomMessage *msg) |
111 | { | 132 | { |
112 | struct GNUNET_MESSENGER_Client *msg_client = cls; | 133 | struct GNUNET_MESSENGER_Client *msg_client = cls; |
113 | 134 | ||
135 | initialize_handle_via_key (msg_client->handle, msg); | ||
136 | |||
114 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opening room: %s\n", GNUNET_h2s ( | 137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opening room: %s\n", GNUNET_h2s ( |
115 | &(msg->key))); | 138 | &(msg->key))); |
116 | 139 | ||
117 | if (GNUNET_YES == open_srv_handle_room (msg_client->handle, &(msg->key))) | 140 | if (GNUNET_YES == open_srv_handle_room (msg_client->handle, &(msg->key))) |
118 | { | 141 | { |
142 | struct GNUNET_HashCode prev; | ||
143 | sync_srv_handle_messages (msg_client->handle, &(msg->key), &(msg->previous), | ||
144 | &prev); | ||
145 | |||
119 | const struct GNUNET_ShortHashCode *member_id = get_srv_handle_member_id ( | 146 | const struct GNUNET_ShortHashCode *member_id = get_srv_handle_member_id ( |
120 | msg_client->handle, &(msg->key)); | 147 | msg_client->handle, &(msg->key)); |
121 | 148 | ||
@@ -126,7 +153,8 @@ handle_room_open (void *cls, | |||
126 | struct GNUNET_MQ_Envelope *env; | 153 | struct GNUNET_MQ_Envelope *env; |
127 | 154 | ||
128 | env = GNUNET_MQ_msg (response, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN); | 155 | env = GNUNET_MQ_msg (response, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN); |
129 | GNUNET_memcpy (&(response->key), &(msg->key), sizeof(msg->key)); | 156 | GNUNET_memcpy (&(response->key), &(msg->key), sizeof(response->key)); |
157 | GNUNET_memcpy (&(response->previous), &prev, sizeof(response->previous)); | ||
130 | GNUNET_MQ_send (msg_client->handle->mq, env); | 158 | GNUNET_MQ_send (msg_client->handle->mq, env); |
131 | } | 159 | } |
132 | else | 160 | else |
@@ -136,18 +164,33 @@ handle_room_open (void *cls, | |||
136 | GNUNET_SERVICE_client_continue (msg_client->client); | 164 | GNUNET_SERVICE_client_continue (msg_client->client); |
137 | } | 165 | } |
138 | 166 | ||
167 | |||
168 | static int | ||
169 | check_room_entry (void *cls, | ||
170 | const struct GNUNET_MESSENGER_RoomMessage *msg) | ||
171 | { | ||
172 | return check_room_initial_key (msg); | ||
173 | } | ||
174 | |||
175 | |||
139 | static void | 176 | static void |
140 | handle_room_entry (void *cls, | 177 | handle_room_entry (void *cls, |
141 | const struct GNUNET_MESSENGER_RoomMessage *msg) | 178 | const struct GNUNET_MESSENGER_RoomMessage *msg) |
142 | { | 179 | { |
143 | struct GNUNET_MESSENGER_Client *msg_client = cls; | 180 | struct GNUNET_MESSENGER_Client *msg_client = cls; |
144 | 181 | ||
182 | initialize_handle_via_key (msg_client->handle, msg); | ||
183 | |||
145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Entering room: %s, %s\n", GNUNET_h2s ( | 184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Entering room: %s, %s\n", GNUNET_h2s ( |
146 | &(msg->key)), GNUNET_i2s (&(msg->door))); | 185 | &(msg->key)), GNUNET_i2s (&(msg->door))); |
147 | 186 | ||
148 | if (GNUNET_YES == entry_srv_handle_room (msg_client->handle, &(msg->door), | 187 | if (GNUNET_YES == entry_srv_handle_room (msg_client->handle, &(msg->door), |
149 | &(msg->key))) | 188 | &(msg->key))) |
150 | { | 189 | { |
190 | struct GNUNET_HashCode prev; | ||
191 | sync_srv_handle_messages (msg_client->handle, &(msg->key), &(msg->previous), | ||
192 | &prev); | ||
193 | |||
151 | const struct GNUNET_ShortHashCode *member_id = get_srv_handle_member_id ( | 194 | const struct GNUNET_ShortHashCode *member_id = get_srv_handle_member_id ( |
152 | msg_client->handle, &(msg->key)); | 195 | msg_client->handle, &(msg->key)); |
153 | 196 | ||
@@ -158,8 +201,9 @@ handle_room_entry (void *cls, | |||
158 | struct GNUNET_MQ_Envelope *env; | 201 | struct GNUNET_MQ_Envelope *env; |
159 | 202 | ||
160 | env = GNUNET_MQ_msg (response, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY); | 203 | env = GNUNET_MQ_msg (response, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY); |
161 | GNUNET_memcpy (&(response->door), &(msg->door), sizeof(msg->door)); | 204 | GNUNET_memcpy (&(response->door), &(msg->door), sizeof(response->door)); |
162 | GNUNET_memcpy (&(response->key), &(msg->key), sizeof(msg->key)); | 205 | GNUNET_memcpy (&(response->key), &(msg->key), sizeof(response->key)); |
206 | GNUNET_memcpy (&(response->previous), &prev, sizeof(response->previous)); | ||
163 | GNUNET_MQ_send (msg_client->handle->mq, env); | 207 | GNUNET_MQ_send (msg_client->handle->mq, env); |
164 | } | 208 | } |
165 | else | 209 | else |
@@ -170,6 +214,7 @@ handle_room_entry (void *cls, | |||
170 | GNUNET_SERVICE_client_continue (msg_client->client); | 214 | GNUNET_SERVICE_client_continue (msg_client->client); |
171 | } | 215 | } |
172 | 216 | ||
217 | |||
173 | static void | 218 | static void |
174 | handle_room_close (void *cls, | 219 | handle_room_close (void *cls, |
175 | const struct GNUNET_MESSENGER_RoomMessage *msg) | 220 | const struct GNUNET_MESSENGER_RoomMessage *msg) |
@@ -188,7 +233,9 @@ handle_room_close (void *cls, | |||
188 | struct GNUNET_MQ_Envelope *env; | 233 | struct GNUNET_MQ_Envelope *env; |
189 | 234 | ||
190 | env = GNUNET_MQ_msg (response, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE); | 235 | env = GNUNET_MQ_msg (response, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE); |
191 | GNUNET_memcpy (&(response->key), &(msg->key), sizeof(msg->key)); | 236 | GNUNET_memcpy (&(response->key), &(msg->key), sizeof(response->key)); |
237 | GNUNET_memcpy (&(response->previous), &(msg->previous), | ||
238 | sizeof(response->previous)); | ||
192 | GNUNET_MQ_send (msg_client->handle->mq, env); | 239 | GNUNET_MQ_send (msg_client->handle->mq, env); |
193 | } | 240 | } |
194 | else | 241 | else |
@@ -198,6 +245,32 @@ handle_room_close (void *cls, | |||
198 | GNUNET_SERVICE_client_continue (msg_client->client); | 245 | GNUNET_SERVICE_client_continue (msg_client->client); |
199 | } | 246 | } |
200 | 247 | ||
248 | |||
249 | static void | ||
250 | handle_room_sync (void *cls, | ||
251 | const struct GNUNET_MESSENGER_RoomMessage *msg) | ||
252 | { | ||
253 | struct GNUNET_MESSENGER_Client *msg_client = cls; | ||
254 | |||
255 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Syncing room: %s\n", GNUNET_h2s ( | ||
256 | &(msg->key))); | ||
257 | |||
258 | struct GNUNET_HashCode prev; | ||
259 | sync_srv_handle_messages (msg_client->handle, &(msg->key), &(msg->previous), | ||
260 | &prev); | ||
261 | |||
262 | struct GNUNET_MESSENGER_RoomMessage *response; | ||
263 | struct GNUNET_MQ_Envelope *env; | ||
264 | |||
265 | env = GNUNET_MQ_msg (response, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SYNC); | ||
266 | GNUNET_memcpy (&(response->key), &(msg->key), sizeof(response->key)); | ||
267 | GNUNET_memcpy (&(response->previous), &prev, sizeof(response->previous)); | ||
268 | GNUNET_MQ_send (msg_client->handle->mq, env); | ||
269 | |||
270 | GNUNET_SERVICE_client_continue (msg_client->client); | ||
271 | } | ||
272 | |||
273 | |||
201 | static int | 274 | static int |
202 | check_send_message (void *cls, | 275 | check_send_message (void *cls, |
203 | const struct GNUNET_MESSENGER_SendMessage *msg) | 276 | const struct GNUNET_MESSENGER_SendMessage *msg) |
@@ -207,98 +280,56 @@ check_send_message (void *cls, | |||
207 | if (full_length < sizeof(*msg)) | 280 | if (full_length < sizeof(*msg)) |
208 | return GNUNET_NO; | 281 | return GNUNET_NO; |
209 | 282 | ||
210 | const enum GNUNET_MESSENGER_MessageFlags flags = ( | 283 | const uint16_t msg_length = full_length - sizeof(*msg); |
211 | (enum GNUNET_MESSENGER_MessageFlags) (msg->flags) | 284 | const char *msg_buffer = ((const char*) msg) + sizeof(*msg); |
212 | ); | ||
213 | |||
214 | const uint16_t length = full_length - sizeof(*msg); | ||
215 | const char *buffer = ((const char*) msg) + sizeof(*msg); | ||
216 | struct GNUNET_CRYPTO_PublicKey public_key; | ||
217 | |||
218 | |||
219 | size_t key_length = 0; | ||
220 | |||
221 | if ((flags & GNUNET_MESSENGER_FLAG_PRIVATE)) | ||
222 | if (GNUNET_SYSERR == | ||
223 | GNUNET_CRYPTO_read_public_key_from_buffer (buffer, length, | ||
224 | &public_key, | ||
225 | &key_length)) | ||
226 | return GNUNET_NO; | ||
227 | |||
228 | const uint16_t msg_length = length - key_length; | ||
229 | const char *msg_buffer = buffer + key_length; | ||
230 | 285 | ||
231 | struct GNUNET_MESSENGER_Message message; | 286 | struct GNUNET_MESSENGER_Message message; |
232 | 287 | ||
233 | if (length < get_message_kind_size (GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_NO)) | 288 | if (msg_length < get_message_kind_size (GNUNET_MESSENGER_KIND_UNKNOWN, |
289 | GNUNET_YES)) | ||
234 | return GNUNET_NO; | 290 | return GNUNET_NO; |
235 | 291 | ||
236 | if (GNUNET_YES != decode_message (&message, msg_length, msg_buffer, GNUNET_NO, | 292 | if (GNUNET_YES != decode_message (&message, msg_length, msg_buffer, |
293 | GNUNET_YES, | ||
237 | NULL)) | 294 | NULL)) |
238 | return GNUNET_NO; | 295 | return GNUNET_NO; |
239 | 296 | ||
240 | const int allowed = filter_message_sending (&message); | 297 | const int allowed = filter_message_sending (&message); |
241 | 298 | ||
242 | cleanup_message (&message); | 299 | cleanup_message (&message); |
243 | return GNUNET_YES == allowed? GNUNET_OK : GNUNET_NO; | 300 | return GNUNET_SYSERR != allowed? GNUNET_OK : GNUNET_NO; |
244 | } | 301 | } |
245 | 302 | ||
303 | |||
246 | static void | 304 | static void |
247 | handle_send_message (void *cls, | 305 | handle_send_message (void *cls, |
248 | const struct GNUNET_MESSENGER_SendMessage *msg) | 306 | const struct GNUNET_MESSENGER_SendMessage *msg) |
249 | { | 307 | { |
250 | struct GNUNET_MESSENGER_Client *msg_client = cls; | 308 | struct GNUNET_MESSENGER_Client *msg_client = cls; |
251 | 309 | ||
252 | const enum GNUNET_MESSENGER_MessageFlags flags = ( | ||
253 | (enum GNUNET_MESSENGER_MessageFlags) (msg->flags) | ||
254 | ); | ||
255 | |||
256 | const struct GNUNET_HashCode *key = &(msg->key); | 310 | const struct GNUNET_HashCode *key = &(msg->key); |
257 | const char *buffer = ((const char*) msg) + sizeof(*msg); | 311 | const char *msg_buffer = ((const char*) msg) + sizeof(*msg); |
258 | 312 | const uint16_t msg_length = ntohs (msg->header.size) - sizeof(*msg); | |
259 | const uint16_t length = ntohs (msg->header.size) - sizeof(*msg); | ||
260 | size_t key_length = 0; | ||
261 | |||
262 | struct GNUNET_CRYPTO_PublicKey public_key; | ||
263 | |||
264 | if (flags & GNUNET_MESSENGER_FLAG_PRIVATE) | ||
265 | { | ||
266 | GNUNET_assert (GNUNET_SYSERR != | ||
267 | GNUNET_CRYPTO_read_public_key_from_buffer (buffer, | ||
268 | length, | ||
269 | &public_key, | ||
270 | &key_length)); | ||
271 | } | ||
272 | const uint16_t msg_length = length - key_length; | ||
273 | const char*msg_buffer = buffer + key_length; | ||
274 | 313 | ||
275 | struct GNUNET_MESSENGER_Message message; | 314 | struct GNUNET_MESSENGER_Message message; |
276 | decode_message (&message, msg_length, msg_buffer, GNUNET_NO, NULL); | 315 | decode_message (&message, msg_length, msg_buffer, GNUNET_YES, NULL); |
277 | |||
278 | if ((flags & GNUNET_MESSENGER_FLAG_PRIVATE) && | ||
279 | (GNUNET_YES != encrypt_message (&message, &public_key))) | ||
280 | { | ||
281 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
282 | "Encrypting message failed: Message got dropped!\n"); | ||
283 | 316 | ||
284 | goto end_handling; | 317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message: %s to %s (by %s)\n", |
285 | } | 318 | GNUNET_MESSENGER_name_of_kind (message.header.kind), |
286 | 319 | GNUNET_h2s (key), | |
287 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message: %s to %s\n", | 320 | GNUNET_sh2s (&(message.header.sender_id))); |
288 | GNUNET_MESSENGER_name_of_kind (message.header.kind), GNUNET_h2s ( | ||
289 | key)); | ||
290 | 321 | ||
291 | if (GNUNET_YES != send_srv_handle_message (msg_client->handle, key, &message)) | 322 | if (GNUNET_YES != send_srv_handle_message (msg_client->handle, key, &message)) |
292 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sending message failed: %s to %s\n", | 323 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sending message failed: %s to %s\n", |
293 | GNUNET_MESSENGER_name_of_kind (message.header.kind), | 324 | GNUNET_MESSENGER_name_of_kind (message.header.kind), |
294 | GNUNET_h2s (key)); | 325 | GNUNET_h2s (key)); |
295 | 326 | ||
296 | end_handling: | ||
297 | cleanup_message (&message); | 327 | cleanup_message (&message); |
298 | 328 | ||
299 | GNUNET_SERVICE_client_continue (msg_client->client); | 329 | GNUNET_SERVICE_client_continue (msg_client->client); |
300 | } | 330 | } |
301 | 331 | ||
332 | |||
302 | static void | 333 | static void |
303 | callback_found_message (void *cls, | 334 | callback_found_message (void *cls, |
304 | struct GNUNET_MESSENGER_SrvRoom *room, | 335 | struct GNUNET_MESSENGER_SrvRoom *room, |
@@ -309,30 +340,53 @@ callback_found_message (void *cls, | |||
309 | 340 | ||
310 | if (! message) | 341 | if (! message) |
311 | { | 342 | { |
312 | send_srv_room_message (room, msg_client->handle, create_message_request ( | 343 | struct GNUNET_MESSENGER_GetMessage *response; |
313 | hash)); | 344 | struct GNUNET_MQ_Envelope *env; |
345 | |||
346 | env = GNUNET_MQ_msg (response, | ||
347 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE); | ||
348 | GNUNET_memcpy (&(response->key), &(room->key), sizeof(room->key)); | ||
349 | GNUNET_memcpy (&(response->hash), hash, sizeof(*hash)); | ||
350 | GNUNET_MQ_send (msg_client->handle->mq, env); | ||
314 | return; | 351 | return; |
315 | } | 352 | } |
316 | 353 | ||
317 | struct GNUNET_MESSENGER_MemberStore *store = get_srv_room_member_store (room); | 354 | struct GNUNET_MESSENGER_SenderSession session; |
318 | 355 | ||
319 | struct GNUNET_MESSENGER_Member *member = get_store_member_of (store, message); | 356 | if (GNUNET_YES == is_peer_message (message)) |
357 | { | ||
358 | struct GNUNET_MESSENGER_PeerStore *store = get_srv_room_peer_store (room); | ||
320 | 359 | ||
321 | if (! member) | 360 | session.peer = get_store_peer_of (store, message, hash); |
361 | |||
362 | if (! session.peer) | ||
363 | return; | ||
364 | } | ||
365 | else | ||
322 | { | 366 | { |
323 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sender of message (%s) unknown!\n", | 367 | struct GNUNET_MESSENGER_MemberStore *store = get_srv_room_member_store ( |
324 | GNUNET_h2s (hash)); | 368 | room); |
325 | return; | 369 | struct GNUNET_MESSENGER_Member *member = get_store_member_of (store, |
370 | message); | ||
371 | |||
372 | if (! member) | ||
373 | { | ||
374 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sender of message (%s) unknown!\n", | ||
375 | GNUNET_h2s (hash)); | ||
376 | return; | ||
377 | } | ||
378 | |||
379 | session.member = get_member_session_of (member, message, hash); | ||
380 | |||
381 | if (! session.member) | ||
382 | return; | ||
326 | } | 383 | } |
327 | 384 | ||
328 | struct GNUNET_MESSENGER_MemberSession *session = get_member_session_of ( | 385 | notify_srv_handle_message (msg_client->handle, room, &session, message, |
329 | member, message, hash); | 386 | hash, GNUNET_NO); |
330 | |||
331 | if (session) | ||
332 | notify_srv_handle_message (msg_client->handle, room, session, message, | ||
333 | hash); | ||
334 | } | 387 | } |
335 | 388 | ||
389 | |||
336 | static void | 390 | static void |
337 | handle_get_message (void *cls, | 391 | handle_get_message (void *cls, |
338 | const struct GNUNET_MESSENGER_GetMessage *msg) | 392 | const struct GNUNET_MESSENGER_GetMessage *msg) |
@@ -369,13 +423,18 @@ handle_get_message (void *cls, | |||
369 | goto end_handling; | 423 | goto end_handling; |
370 | } | 424 | } |
371 | 425 | ||
426 | const struct GNUNET_CRYPTO_PublicKey *pubkey = get_srv_handle_key ( | ||
427 | msg_client->handle); | ||
428 | |||
429 | if (! pubkey) | ||
430 | { | ||
431 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
432 | "Handle needs to have a public key to request a message!\n"); | ||
433 | goto end_handling; | ||
434 | } | ||
435 | |||
372 | struct GNUNET_MESSENGER_MemberSession *session = get_member_session (member, | 436 | struct GNUNET_MESSENGER_MemberSession *session = get_member_session (member, |
373 | &( | 437 | pubkey); |
374 | get_srv_handle_ego ( | ||
375 | msg_client | ||
376 | -> | ||
377 | handle) | ||
378 | ->pub)); | ||
379 | 438 | ||
380 | if (! session) | 439 | if (! session) |
381 | { | 440 | { |
@@ -387,10 +446,11 @@ handle_get_message (void *cls, | |||
387 | request_srv_room_message (room, &(msg->hash), session, callback_found_message, | 446 | request_srv_room_message (room, &(msg->hash), session, callback_found_message, |
388 | msg_client); | 447 | msg_client); |
389 | 448 | ||
390 | end_handling: | 449 | end_handling: |
391 | GNUNET_SERVICE_client_continue (msg_client->client); | 450 | GNUNET_SERVICE_client_continue (msg_client->client); |
392 | } | 451 | } |
393 | 452 | ||
453 | |||
394 | static void* | 454 | static void* |
395 | callback_client_connect (void *cls, | 455 | callback_client_connect (void *cls, |
396 | struct GNUNET_SERVICE_Client *client, | 456 | struct GNUNET_SERVICE_Client *client, |
@@ -405,6 +465,7 @@ callback_client_connect (void *cls, | |||
405 | return msg_client; | 465 | return msg_client; |
406 | } | 466 | } |
407 | 467 | ||
468 | |||
408 | static void | 469 | static void |
409 | callback_client_disconnect (void *cls, | 470 | callback_client_disconnect (void *cls, |
410 | struct GNUNET_SERVICE_Client *client, | 471 | struct GNUNET_SERVICE_Client *client, |
@@ -417,6 +478,7 @@ callback_client_disconnect (void *cls, | |||
417 | GNUNET_free (msg_client); | 478 | GNUNET_free (msg_client); |
418 | } | 479 | } |
419 | 480 | ||
481 | |||
420 | /** | 482 | /** |
421 | * Setup MESSENGER internals. | 483 | * Setup MESSENGER internals. |
422 | * | 484 | * |
@@ -435,6 +497,7 @@ run (void *cls, | |||
435 | GNUNET_SCHEDULER_shutdown (); | 497 | GNUNET_SCHEDULER_shutdown (); |
436 | } | 498 | } |
437 | 499 | ||
500 | |||
438 | /** | 501 | /** |
439 | * Define "main" method using service macro. | 502 | * Define "main" method using service macro. |
440 | */ | 503 | */ |
@@ -445,25 +508,18 @@ GNUNET_SERVICE_MAIN ( | |||
445 | &callback_client_connect, | 508 | &callback_client_connect, |
446 | &callback_client_disconnect, | 509 | &callback_client_disconnect, |
447 | NULL, | 510 | NULL, |
448 | GNUNET_MQ_hd_var_size (create, | 511 | GNUNET_MQ_hd_fixed_size (create, |
449 | GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE, struct | 512 | GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE, |
450 | GNUNET_MESSENGER_CreateMessage, NULL), | ||
451 | GNUNET_MQ_hd_fixed_size (update, | ||
452 | GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_UPDATE, | ||
453 | struct | 513 | struct |
454 | GNUNET_MESSENGER_UpdateMessage, NULL), | 514 | GNUNET_MESSENGER_CreateMessage, NULL), |
455 | GNUNET_MQ_hd_fixed_size (destroy, | 515 | GNUNET_MQ_hd_fixed_size (destroy, |
456 | GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY, | 516 | GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY, |
457 | struct | 517 | struct |
458 | GNUNET_MESSENGER_DestroyMessage, NULL), | 518 | GNUNET_MESSENGER_DestroyMessage, NULL), |
459 | GNUNET_MQ_hd_var_size (set_name, | 519 | GNUNET_MQ_hd_var_size (room_open, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN, |
460 | GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_SET_NAME, | 520 | struct GNUNET_MESSENGER_RoomMessage, NULL), |
461 | struct | 521 | GNUNET_MQ_hd_var_size (room_entry, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY, |
462 | GNUNET_MESSENGER_NameMessage, NULL), | 522 | struct GNUNET_MESSENGER_RoomMessage, NULL), |
463 | GNUNET_MQ_hd_fixed_size (room_open, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN, | ||
464 | struct GNUNET_MESSENGER_RoomMessage, NULL), | ||
465 | GNUNET_MQ_hd_fixed_size (room_entry, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY, | ||
466 | struct GNUNET_MESSENGER_RoomMessage, NULL), | ||
467 | GNUNET_MQ_hd_fixed_size (room_close, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE, | 523 | GNUNET_MQ_hd_fixed_size (room_close, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE, |
468 | struct GNUNET_MESSENGER_RoomMessage, NULL), | 524 | struct GNUNET_MESSENGER_RoomMessage, NULL), |
469 | GNUNET_MQ_hd_var_size (send_message, | 525 | GNUNET_MQ_hd_var_size (send_message, |
@@ -473,4 +529,6 @@ GNUNET_SERVICE_MAIN ( | |||
473 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE, | 529 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE, |
474 | struct | 530 | struct |
475 | GNUNET_MESSENGER_GetMessage, NULL), | 531 | GNUNET_MESSENGER_GetMessage, NULL), |
532 | GNUNET_MQ_hd_fixed_size (room_sync, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SYNC, | ||
533 | struct GNUNET_MESSENGER_RoomMessage, NULL), | ||
476 | GNUNET_MQ_handler_end ()); | 534 | GNUNET_MQ_handler_end ()); |