diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
commit | 502af2167f7c218366666ca4944bd7cc54b5b19a (patch) | |
tree | a91fec5cc9769d260640bd91c6633cb9cf395524 /src/chat | |
parent | 03af5a603b7cc53432249d5854cd412aa90dde0d (diff) | |
download | gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip |
indentation
Diffstat (limited to 'src/chat')
-rw-r--r-- | src/chat/chat.c | 564 | ||||
-rw-r--r-- | src/chat/gnunet-chat.c | 354 | ||||
-rw-r--r-- | src/chat/gnunet-service-chat.c | 1196 | ||||
-rw-r--r-- | src/chat/test_chat.c | 331 | ||||
-rw-r--r-- | src/chat/test_chat_private.c | 308 |
5 files changed, 1313 insertions, 1440 deletions
diff --git a/src/chat/chat.c b/src/chat/chat.c index 8e35d10b5..1e90a6369 100644 --- a/src/chat/chat.c +++ b/src/chat/chat.c | |||
@@ -148,8 +148,7 @@ struct GNUNET_CHAT_SendReceiptContext | |||
148 | /** | 148 | /** |
149 | * Ask client to send a join request. | 149 | * Ask client to send a join request. |
150 | */ | 150 | */ |
151 | static int | 151 | static int rejoin_room (struct GNUNET_CHAT_Room *chat_room); |
152 | rejoin_room (struct GNUNET_CHAT_Room *chat_room); | ||
153 | 152 | ||
154 | 153 | ||
155 | /** | 154 | /** |
@@ -161,9 +160,7 @@ rejoin_room (struct GNUNET_CHAT_Room *chat_room); | |||
161 | * @return number of bytes written to buf | 160 | * @return number of bytes written to buf |
162 | */ | 161 | */ |
163 | static size_t | 162 | static size_t |
164 | transmit_acknowledge_request (void *cls, | 163 | transmit_acknowledge_request (void *cls, size_t size, void *buf) |
165 | size_t size, | ||
166 | void *buf) | ||
167 | { | 164 | { |
168 | struct GNUNET_CHAT_SendReceiptContext *src = cls; | 165 | struct GNUNET_CHAT_SendReceiptContext *src = cls; |
169 | struct ConfirmationReceiptMessage *receipt; | 166 | struct ConfirmationReceiptMessage *receipt; |
@@ -172,11 +169,11 @@ transmit_acknowledge_request (void *cls, | |||
172 | size_t msg_size; | 169 | size_t msg_size; |
173 | 170 | ||
174 | if (NULL == buf) | 171 | if (NULL == buf) |
175 | { | 172 | { |
176 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 173 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
177 | _("Could not transmit confirmation receipt\n")); | 174 | _("Could not transmit confirmation receipt\n")); |
178 | return 0; | 175 | return 0; |
179 | } | 176 | } |
180 | #if DEBUG_CHAT | 177 | #if DEBUG_CHAT |
181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
182 | "Transmitting confirmation receipt to the service\n"); | 179 | "Transmitting confirmation receipt to the service\n"); |
@@ -185,8 +182,7 @@ transmit_acknowledge_request (void *cls, | |||
185 | GNUNET_assert (size >= msg_size); | 182 | GNUNET_assert (size >= msg_size); |
186 | receipt = buf; | 183 | receipt = buf; |
187 | receipt->header.size = htons (msg_size); | 184 | receipt->header.size = htons (msg_size); |
188 | receipt->header.type = | 185 | receipt->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_RECEIPT); |
189 | htons (GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_RECEIPT); | ||
190 | receipt->reserved = htonl (0); | 186 | receipt->reserved = htonl (0); |
191 | receipt->sequence_number = src->received_msg->sequence_number; | 187 | receipt->sequence_number = src->received_msg->sequence_number; |
192 | receipt->reserved2 = htonl (0); | 188 | receipt->reserved2 = htonl (0); |
@@ -196,17 +192,15 @@ transmit_acknowledge_request (void *cls, | |||
196 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 192 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
197 | &receipt->target); | 193 | &receipt->target); |
198 | receipt->author = src->received_msg->sender; | 194 | receipt->author = src->received_msg->sender; |
199 | receipt->purpose.purpose = | 195 | receipt->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT); |
200 | htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT); | ||
201 | receipt->purpose.size = | 196 | receipt->purpose.size = |
202 | htonl (msg_size - | 197 | htonl (msg_size - |
203 | sizeof (struct GNUNET_MessageHeader) - | 198 | sizeof (struct GNUNET_MessageHeader) - |
204 | sizeof (uint32_t) - | 199 | sizeof (uint32_t) - sizeof (struct GNUNET_CRYPTO_RsaSignature)); |
205 | sizeof (struct GNUNET_CRYPTO_RsaSignature)); | ||
206 | msg_len = ntohs (src->received_msg->header.size) - | 200 | msg_len = ntohs (src->received_msg->header.size) - |
207 | sizeof (struct ReceiveNotificationMessage); | 201 | sizeof (struct ReceiveNotificationMessage); |
208 | GNUNET_CRYPTO_hash (&src->received_msg[1], msg_len, &receipt->content); | 202 | GNUNET_CRYPTO_hash (&src->received_msg[1], msg_len, &receipt->content); |
209 | GNUNET_assert (GNUNET_OK == | 203 | GNUNET_assert (GNUNET_OK == |
210 | GNUNET_CRYPTO_rsa_sign (src->chat_room->my_private_key, | 204 | GNUNET_CRYPTO_rsa_sign (src->chat_room->my_private_key, |
211 | &receipt->purpose, | 205 | &receipt->purpose, |
212 | &receipt->signature)); | 206 | &receipt->signature)); |
@@ -244,187 +238,186 @@ process_result (struct GNUNET_CHAT_Room *room, | |||
244 | 238 | ||
245 | size = ntohs (reply->size); | 239 | size = ntohs (reply->size); |
246 | switch (ntohs (reply->type)) | 240 | switch (ntohs (reply->type)) |
247 | { | 241 | { |
248 | case GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION: | 242 | case GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION: |
249 | #if DEBUG_CHAT | 243 | #if DEBUG_CHAT |
250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a join notification\n"); | 244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a join notification\n"); |
251 | #endif | 245 | #endif |
252 | if (size < sizeof (struct JoinNotificationMessage)) | 246 | if (size < sizeof (struct JoinNotificationMessage)) |
253 | { | 247 | { |
254 | GNUNET_break (0); | 248 | GNUNET_break (0); |
255 | return; | 249 | return; |
256 | } | 250 | } |
257 | join_msg = (struct JoinNotificationMessage *) reply; | 251 | join_msg = (struct JoinNotificationMessage *) reply; |
258 | meta_len = size - sizeof (struct JoinNotificationMessage); | 252 | meta_len = size - sizeof (struct JoinNotificationMessage); |
259 | meta = | 253 | meta = |
260 | GNUNET_CONTAINER_meta_data_deserialize ((const char *) &join_msg[1], | 254 | GNUNET_CONTAINER_meta_data_deserialize ((const char *) &join_msg[1], |
261 | meta_len); | 255 | meta_len); |
262 | if (NULL == meta) | 256 | if (NULL == meta) |
263 | { | 257 | { |
264 | GNUNET_break (0); | 258 | GNUNET_break (0); |
265 | return; | 259 | return; |
266 | } | 260 | } |
267 | pos = GNUNET_malloc (sizeof (struct MemberList)); | 261 | pos = GNUNET_malloc (sizeof (struct MemberList)); |
268 | pos->meta = meta; | 262 | pos->meta = meta; |
269 | GNUNET_CRYPTO_hash (&join_msg->public_key, | 263 | GNUNET_CRYPTO_hash (&join_msg->public_key, |
270 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 264 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
271 | &pos->id); | 265 | &pos->id); |
272 | GNUNET_PSEUDONYM_add (room->cfg, &pos->id, meta); | 266 | GNUNET_PSEUDONYM_add (room->cfg, &pos->id, meta); |
273 | pos->next = room->members; | 267 | pos->next = room->members; |
274 | room->members = pos; | 268 | room->members = pos; |
275 | if (GNUNET_NO == room->is_joined) | 269 | if (GNUNET_NO == room->is_joined) |
276 | { | 270 | { |
277 | GNUNET_CRYPTO_rsa_key_get_public (room->my_private_key, &pkey); | 271 | GNUNET_CRYPTO_rsa_key_get_public (room->my_private_key, &pkey); |
278 | if (0 == memcmp (&join_msg->public_key, | 272 | if (0 == memcmp (&join_msg->public_key, |
279 | &pkey, | 273 | &pkey, |
280 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))) | 274 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))) |
281 | { | 275 | { |
282 | room->join_callback (room->join_callback_cls); | 276 | room->join_callback (room->join_callback_cls); |
283 | room->is_joined = GNUNET_YES; | 277 | room->is_joined = GNUNET_YES; |
284 | } | 278 | } |
285 | else | 279 | else |
286 | { | 280 | { |
287 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 281 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
288 | _("The current user must be the the first one joined\n")); | 282 | _("The current user must be the the first one joined\n")); |
289 | GNUNET_break (0); | 283 | GNUNET_break (0); |
290 | return; | 284 | return; |
291 | } | 285 | } |
292 | } | 286 | } |
293 | else | 287 | else |
294 | room->member_list_callback (room->member_list_callback_cls, | 288 | room->member_list_callback (room->member_list_callback_cls, |
295 | meta, &join_msg->public_key, | 289 | meta, &join_msg->public_key, |
296 | ntohl (join_msg->msg_options)); | 290 | ntohl (join_msg->msg_options)); |
297 | break; | 291 | break; |
298 | case GNUNET_MESSAGE_TYPE_CHAT_LEAVE_NOTIFICATION: | 292 | case GNUNET_MESSAGE_TYPE_CHAT_LEAVE_NOTIFICATION: |
299 | #if DEBUG_CHAT | 293 | #if DEBUG_CHAT |
300 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a leave notification\n"); | 294 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a leave notification\n"); |
301 | #endif | 295 | #endif |
302 | if (size < sizeof (struct LeaveNotificationMessage)) | 296 | if (size < sizeof (struct LeaveNotificationMessage)) |
303 | { | 297 | { |
304 | GNUNET_break (0); | 298 | GNUNET_break (0); |
305 | return; | 299 | return; |
306 | } | 300 | } |
307 | leave_msg = (struct LeaveNotificationMessage *) reply; | 301 | leave_msg = (struct LeaveNotificationMessage *) reply; |
308 | room->member_list_callback (room->member_list_callback_cls, | 302 | room->member_list_callback (room->member_list_callback_cls, |
309 | NULL, &leave_msg->user, | 303 | NULL, &leave_msg->user, |
310 | GNUNET_CHAT_MSG_OPTION_NONE); | 304 | GNUNET_CHAT_MSG_OPTION_NONE); |
311 | GNUNET_CRYPTO_hash (&leave_msg->user, | 305 | GNUNET_CRYPTO_hash (&leave_msg->user, |
312 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 306 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
313 | &id); | 307 | &id); |
314 | prev = NULL; | 308 | prev = NULL; |
315 | pos = room->members; | 309 | pos = room->members; |
316 | while ((NULL != pos) && | 310 | while ((NULL != pos) && |
317 | (0 != memcmp (&pos->id, &id, sizeof (GNUNET_HashCode)))) | 311 | (0 != memcmp (&pos->id, &id, sizeof (GNUNET_HashCode)))) |
318 | { | 312 | { |
319 | prev = pos; | 313 | prev = pos; |
320 | pos = pos->next; | 314 | pos = pos->next; |
321 | } | 315 | } |
322 | GNUNET_assert (NULL != pos); | 316 | GNUNET_assert (NULL != pos); |
323 | if (NULL == prev) | 317 | if (NULL == prev) |
324 | room->members = pos->next; | 318 | room->members = pos->next; |
325 | else | 319 | else |
326 | prev->next = pos->next; | 320 | prev->next = pos->next; |
327 | GNUNET_CONTAINER_meta_data_destroy (pos->meta); | 321 | GNUNET_CONTAINER_meta_data_destroy (pos->meta); |
328 | GNUNET_free (pos); | 322 | GNUNET_free (pos); |
329 | break; | 323 | break; |
330 | case GNUNET_MESSAGE_TYPE_CHAT_MESSAGE_NOTIFICATION: | 324 | case GNUNET_MESSAGE_TYPE_CHAT_MESSAGE_NOTIFICATION: |
331 | #if DEBUG_CHAT | 325 | #if DEBUG_CHAT |
332 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a message notification\n"); | 326 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a message notification\n"); |
333 | #endif | 327 | #endif |
334 | if (size <= sizeof (struct ReceiveNotificationMessage)) | 328 | if (size <= sizeof (struct ReceiveNotificationMessage)) |
335 | { | 329 | { |
336 | GNUNET_break (0); | 330 | GNUNET_break (0); |
337 | return; | 331 | return; |
338 | } | 332 | } |
339 | received_msg = (struct ReceiveNotificationMessage *) reply; | 333 | received_msg = (struct ReceiveNotificationMessage *) reply; |
340 | if (0 != | 334 | if (0 != (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_ACKNOWLEDGED)) |
341 | (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_ACKNOWLEDGED)) | 335 | { |
342 | { | 336 | src = GNUNET_malloc (sizeof (struct GNUNET_CHAT_SendReceiptContext)); |
343 | src = GNUNET_malloc (sizeof (struct GNUNET_CHAT_SendReceiptContext)); | 337 | src->chat_room = room; |
344 | src->chat_room = room; | 338 | src->received_msg = GNUNET_memdup (received_msg, size); |
345 | src->received_msg = GNUNET_memdup (received_msg, size); | 339 | GNUNET_CLIENT_notify_transmit_ready (room->client, |
346 | GNUNET_CLIENT_notify_transmit_ready (room->client, | 340 | sizeof (struct |
347 | sizeof (struct ConfirmationReceiptMessage), | 341 | ConfirmationReceiptMessage), |
348 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, | 342 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, |
349 | GNUNET_YES, | 343 | GNUNET_YES, |
350 | &transmit_acknowledge_request, | 344 | &transmit_acknowledge_request, src); |
351 | src); | 345 | } |
352 | } | 346 | msg_len = size - sizeof (struct ReceiveNotificationMessage); |
353 | msg_len = size - sizeof (struct ReceiveNotificationMessage); | 347 | if (0 != (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_PRIVATE)) |
354 | if (0 != | 348 | { |
355 | (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_PRIVATE)) | 349 | if (-1 == GNUNET_CRYPTO_rsa_decrypt (room->my_private_key, |
356 | { | 350 | &received_msg->encrypted_key, |
357 | if (-1 == GNUNET_CRYPTO_rsa_decrypt (room->my_private_key, | 351 | &key, |
358 | &received_msg->encrypted_key, | 352 | sizeof (struct |
359 | &key, | 353 | GNUNET_CRYPTO_AesSessionKey))) |
360 | sizeof (struct GNUNET_CRYPTO_AesSessionKey))) | 354 | { |
361 | { | 355 | GNUNET_break (0); |
362 | GNUNET_break (0); | 356 | return; |
363 | return; | 357 | } |
364 | } | 358 | msg_len = GNUNET_CRYPTO_aes_decrypt (&received_msg[1], |
365 | msg_len = GNUNET_CRYPTO_aes_decrypt (&received_msg[1], | 359 | msg_len, |
366 | msg_len, | 360 | &key, |
367 | &key, | 361 | (const struct |
368 | (const struct GNUNET_CRYPTO_AesInitializationVector *) INITVALUE, | 362 | GNUNET_CRYPTO_AesInitializationVector |
369 | decrypted_msg); | 363 | *) INITVALUE, decrypted_msg); |
370 | message_content = decrypted_msg; | 364 | message_content = decrypted_msg; |
371 | } | 365 | } |
372 | else | 366 | else |
373 | { | 367 | { |
374 | message_content = GNUNET_malloc (msg_len + 1); | 368 | message_content = GNUNET_malloc (msg_len + 1); |
375 | memcpy (message_content, &received_msg[1], msg_len); | 369 | memcpy (message_content, &received_msg[1], msg_len); |
376 | } | 370 | } |
377 | message_content[msg_len] = '\0'; | 371 | message_content[msg_len] = '\0'; |
378 | if (0 != (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS)) | 372 | if (0 != (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS)) |
379 | { | 373 | { |
380 | sender = NULL; | 374 | sender = NULL; |
381 | meta = NULL; | 375 | meta = NULL; |
382 | } | 376 | } |
383 | else | 377 | else |
384 | { | 378 | { |
385 | pos = room->members; | 379 | pos = room->members; |
386 | while ((NULL != pos) && | 380 | while ((NULL != pos) && |
387 | (0 != memcmp (&pos->id, | 381 | (0 != memcmp (&pos->id, |
388 | &received_msg->sender, | 382 | &received_msg->sender, sizeof (GNUNET_HashCode)))) |
389 | sizeof (GNUNET_HashCode)))) | ||
390 | pos = pos->next; | 383 | pos = pos->next; |
391 | GNUNET_assert (NULL != pos); | 384 | GNUNET_assert (NULL != pos); |
392 | sender = &received_msg->sender; | 385 | sender = &received_msg->sender; |
393 | meta = pos->meta; | 386 | meta = pos->meta; |
394 | } | 387 | } |
395 | room->message_callback (room->message_callback_cls, | 388 | room->message_callback (room->message_callback_cls, |
396 | room, | 389 | room, |
397 | sender, | 390 | sender, |
398 | meta, | 391 | meta, |
399 | message_content, | 392 | message_content, |
400 | GNUNET_TIME_absolute_ntoh (received_msg->timestamp), | 393 | GNUNET_TIME_absolute_ntoh (received_msg->timestamp), |
401 | ntohl (received_msg->msg_options)); | 394 | ntohl (received_msg->msg_options)); |
402 | if (message_content != decrypted_msg) | 395 | if (message_content != decrypted_msg) |
403 | GNUNET_free (message_content); | 396 | GNUNET_free (message_content); |
404 | break; | 397 | break; |
405 | case GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION: | 398 | case GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION: |
406 | #if DEBUG_CHAT | 399 | #if DEBUG_CHAT |
407 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a confirmation receipt\n"); | 400 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a confirmation receipt\n"); |
408 | #endif | 401 | #endif |
409 | if (size < sizeof (struct ConfirmationReceiptMessage)) | 402 | if (size < sizeof (struct ConfirmationReceiptMessage)) |
410 | { | 403 | { |
411 | GNUNET_break (0); | 404 | GNUNET_break (0); |
412 | return; | 405 | return; |
413 | } | ||
414 | receipt = (struct ConfirmationReceiptMessage *) reply; | ||
415 | if (NULL != room->confirmation_callback) | ||
416 | room->confirmation_callback (room->confirmation_cls, | ||
417 | room, | ||
418 | ntohl (receipt->sequence_number), | ||
419 | GNUNET_TIME_absolute_ntoh (receipt->timestamp), | ||
420 | &receipt->target); | ||
421 | break; | ||
422 | default: | ||
423 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
424 | _("Unknown message type: '%u'\n"), ntohs (reply->type)); | ||
425 | GNUNET_break_op (0); | ||
426 | break; | ||
427 | } | 406 | } |
407 | receipt = (struct ConfirmationReceiptMessage *) reply; | ||
408 | if (NULL != room->confirmation_callback) | ||
409 | room->confirmation_callback (room->confirmation_cls, | ||
410 | room, | ||
411 | ntohl (receipt->sequence_number), | ||
412 | GNUNET_TIME_absolute_ntoh | ||
413 | (receipt->timestamp), &receipt->target); | ||
414 | break; | ||
415 | default: | ||
416 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
417 | _("Unknown message type: '%u'\n"), ntohs (reply->type)); | ||
418 | GNUNET_break_op (0); | ||
419 | break; | ||
420 | } | ||
428 | } | 421 | } |
429 | 422 | ||
430 | 423 | ||
@@ -435,9 +428,8 @@ process_result (struct GNUNET_CHAT_Room *room, | |||
435 | * @param cls closure, pointer to the 'struct GNUNET_CHAT_Room' | 428 | * @param cls closure, pointer to the 'struct GNUNET_CHAT_Room' |
436 | * @param msg message received, NULL on timeout or fatal error | 429 | * @param msg message received, NULL on timeout or fatal error |
437 | */ | 430 | */ |
438 | static void | 431 | static void |
439 | receive_results (void *cls, | 432 | receive_results (void *cls, const struct GNUNET_MessageHeader *msg) |
440 | const struct GNUNET_MessageHeader *msg) | ||
441 | { | 433 | { |
442 | struct GNUNET_CHAT_Room *chat_room = cls; | 434 | struct GNUNET_CHAT_Room *chat_room = cls; |
443 | 435 | ||
@@ -447,19 +439,18 @@ receive_results (void *cls, | |||
447 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & GNUNET_SCHEDULER_get_reason ())) | 439 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & GNUNET_SCHEDULER_get_reason ())) |
448 | return; | 440 | return; |
449 | if (NULL == msg) | 441 | if (NULL == msg) |
450 | { | 442 | { |
451 | GNUNET_break (0); | 443 | GNUNET_break (0); |
452 | rejoin_room (chat_room); | 444 | rejoin_room (chat_room); |
453 | return; | 445 | return; |
454 | } | 446 | } |
455 | process_result (chat_room, msg); | 447 | process_result (chat_room, msg); |
456 | if (NULL == chat_room->client) | 448 | if (NULL == chat_room->client) |
457 | return; /* fatal error */ | 449 | return; /* fatal error */ |
458 | /* continue receiving */ | 450 | /* continue receiving */ |
459 | GNUNET_CLIENT_receive (chat_room->client, | 451 | GNUNET_CLIENT_receive (chat_room->client, |
460 | &receive_results, | 452 | &receive_results, |
461 | chat_room, | 453 | chat_room, GNUNET_TIME_UNIT_FOREVER_REL); |
462 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
463 | } | 454 | } |
464 | 455 | ||
465 | 456 | ||
@@ -480,30 +471,25 @@ init_private_key (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
480 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initializing private key\n"); | 471 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initializing private key\n"); |
481 | #endif | 472 | #endif |
482 | if (GNUNET_OK != | 473 | if (GNUNET_OK != |
483 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 474 | GNUNET_CONFIGURATION_get_value_filename (cfg, "chat", "HOME", &home)) |
484 | "chat", | 475 | { |
485 | "HOME", | 476 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
486 | &home)) | 477 | _("Configuration option `%s' in section `%s' missing\n"), |
487 | { | 478 | "HOME", "chat"); |
488 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 479 | return NULL; |
489 | _("Configuration option `%s' in section `%s' missing\n"), | 480 | } |
490 | "HOME", | ||
491 | "chat"); | ||
492 | return NULL; | ||
493 | } | ||
494 | GNUNET_DISK_directory_create (home); | 481 | GNUNET_DISK_directory_create (home); |
495 | if (GNUNET_OK != GNUNET_DISK_directory_test (home)) | 482 | if (GNUNET_OK != GNUNET_DISK_directory_test (home)) |
496 | { | 483 | { |
497 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 484 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
498 | _("Failed to access chat home directory `%s'\n"), | 485 | _("Failed to access chat home directory `%s'\n"), home); |
499 | home); | 486 | GNUNET_free (home); |
500 | GNUNET_free (home); | 487 | return NULL; |
501 | return NULL; | 488 | } |
502 | } | ||
503 | /* read or create private key */ | 489 | /* read or create private key */ |
504 | keyfile = | 490 | keyfile = |
505 | GNUNET_malloc (strlen (home) + strlen (NICK_IDENTITY_PREFIX) + | 491 | GNUNET_malloc (strlen (home) + strlen (NICK_IDENTITY_PREFIX) + |
506 | strlen (nick_name) + 2); | 492 | strlen (nick_name) + 2); |
507 | strcpy (keyfile, home); | 493 | strcpy (keyfile, home); |
508 | GNUNET_free (home); | 494 | GNUNET_free (home); |
509 | if (keyfile[strlen (keyfile) - 1] != DIR_SEPARATOR) | 495 | if (keyfile[strlen (keyfile) - 1] != DIR_SEPARATOR) |
@@ -512,11 +498,10 @@ init_private_key (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
512 | strcat (keyfile, nick_name); | 498 | strcat (keyfile, nick_name); |
513 | privKey = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); | 499 | privKey = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); |
514 | if (NULL == privKey) | 500 | if (NULL == privKey) |
515 | { | 501 | { |
516 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 502 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
517 | _("Failed to create/open key in file `%s'\n"), | 503 | _("Failed to create/open key in file `%s'\n"), keyfile); |
518 | keyfile); | 504 | } |
519 | } | ||
520 | GNUNET_free (keyfile); | 505 | GNUNET_free (keyfile); |
521 | return privKey; | 506 | return privKey; |
522 | } | 507 | } |
@@ -531,9 +516,7 @@ init_private_key (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
531 | * @return number of bytes written to buf | 516 | * @return number of bytes written to buf |
532 | */ | 517 | */ |
533 | static size_t | 518 | static size_t |
534 | transmit_join_request (void *cls, | 519 | transmit_join_request (void *cls, size_t size, void *buf) |
535 | size_t size, | ||
536 | void *buf) | ||
537 | { | 520 | { |
538 | struct GNUNET_CHAT_Room *chat_room = cls; | 521 | struct GNUNET_CHAT_Room *chat_room = cls; |
539 | struct JoinRequestMessage *join_msg; | 522 | struct JoinRequestMessage *join_msg; |
@@ -544,20 +527,21 @@ transmit_join_request (void *cls, | |||
544 | size_t size_of_join; | 527 | size_t size_of_join; |
545 | 528 | ||
546 | if (NULL == buf) | 529 | if (NULL == buf) |
547 | { | 530 | { |
548 | #if DEBUG_CHAT | 531 | #if DEBUG_CHAT |
549 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 532 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
550 | "Could not transmit join request, retrying...\n"); | 533 | "Could not transmit join request, retrying...\n"); |
551 | #endif | 534 | #endif |
552 | rejoin_room (chat_room); | 535 | rejoin_room (chat_room); |
553 | return 0; | 536 | return 0; |
554 | } | 537 | } |
555 | #if DEBUG_CHAT | 538 | #if DEBUG_CHAT |
556 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 539 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
557 | "Transmitting join request to the service\n"); | 540 | "Transmitting join request to the service\n"); |
558 | #endif | 541 | #endif |
559 | room_len = strlen (chat_room->room_name); | 542 | room_len = strlen (chat_room->room_name); |
560 | meta_len = GNUNET_CONTAINER_meta_data_get_serialized_size (chat_room->member_info); | 543 | meta_len = |
544 | GNUNET_CONTAINER_meta_data_get_serialized_size (chat_room->member_info); | ||
561 | size_of_join = sizeof (struct JoinRequestMessage) + meta_len + room_len; | 545 | size_of_join = sizeof (struct JoinRequestMessage) + meta_len + room_len; |
562 | GNUNET_assert (size >= size_of_join); | 546 | GNUNET_assert (size >= size_of_join); |
563 | join_msg = buf; | 547 | join_msg = buf; |
@@ -567,7 +551,8 @@ transmit_join_request (void *cls, | |||
567 | join_msg->room_name_len = htons (room_len); | 551 | join_msg->room_name_len = htons (room_len); |
568 | join_msg->reserved = htons (0); | 552 | join_msg->reserved = htons (0); |
569 | join_msg->reserved2 = htonl (0); | 553 | join_msg->reserved2 = htonl (0); |
570 | GNUNET_CRYPTO_rsa_key_get_public (chat_room->my_private_key, &join_msg->public_key); | 554 | GNUNET_CRYPTO_rsa_key_get_public (chat_room->my_private_key, |
555 | &join_msg->public_key); | ||
571 | room = (char *) &join_msg[1]; | 556 | room = (char *) &join_msg[1]; |
572 | memcpy (room, chat_room->room_name, room_len); | 557 | memcpy (room, chat_room->room_name, room_len); |
573 | meta = &room[room_len]; | 558 | meta = &room[room_len]; |
@@ -576,15 +561,13 @@ transmit_join_request (void *cls, | |||
576 | &meta, | 561 | &meta, |
577 | meta_len, | 562 | meta_len, |
578 | GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL)) | 563 | GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL)) |
579 | { | 564 | { |
580 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 565 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not serialize metadata\n")); |
581 | _("Could not serialize metadata\n")); | 566 | return 0; |
582 | return 0; | 567 | } |
583 | } | ||
584 | GNUNET_CLIENT_receive (chat_room->client, | 568 | GNUNET_CLIENT_receive (chat_room->client, |
585 | &receive_results, | 569 | &receive_results, |
586 | chat_room, | 570 | chat_room, GNUNET_TIME_UNIT_FOREVER_REL); |
587 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
588 | return size_of_join; | 571 | return size_of_join; |
589 | } | 572 | } |
590 | 573 | ||
@@ -598,15 +581,14 @@ rejoin_room (struct GNUNET_CHAT_Room *chat_room) | |||
598 | size_t size_of_join; | 581 | size_t size_of_join; |
599 | 582 | ||
600 | size_of_join = sizeof (struct JoinRequestMessage) + | 583 | size_of_join = sizeof (struct JoinRequestMessage) + |
601 | GNUNET_CONTAINER_meta_data_get_serialized_size (chat_room->member_info) + | 584 | GNUNET_CONTAINER_meta_data_get_serialized_size (chat_room->member_info) + |
602 | strlen (chat_room->room_name); | 585 | strlen (chat_room->room_name); |
603 | if (NULL == | 586 | if (NULL == |
604 | GNUNET_CLIENT_notify_transmit_ready (chat_room->client, | 587 | GNUNET_CLIENT_notify_transmit_ready (chat_room->client, |
605 | size_of_join, | 588 | size_of_join, |
606 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, | 589 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, |
607 | GNUNET_YES, | 590 | GNUNET_YES, |
608 | &transmit_join_request, | 591 | &transmit_join_request, chat_room)) |
609 | chat_room)) | ||
610 | return GNUNET_SYSERR; | 592 | return GNUNET_SYSERR; |
611 | return GNUNET_OK; | 593 | return GNUNET_OK; |
612 | } | 594 | } |
@@ -629,12 +611,12 @@ GNUNET_CHAT_leave_room (struct GNUNET_CHAT_Room *chat_room) | |||
629 | GNUNET_CONTAINER_meta_data_destroy (chat_room->member_info); | 611 | GNUNET_CONTAINER_meta_data_destroy (chat_room->member_info); |
630 | GNUNET_CRYPTO_rsa_key_free (chat_room->my_private_key); | 612 | GNUNET_CRYPTO_rsa_key_free (chat_room->my_private_key); |
631 | while (NULL != chat_room->members) | 613 | while (NULL != chat_room->members) |
632 | { | 614 | { |
633 | pos = chat_room->members; | 615 | pos = chat_room->members; |
634 | chat_room->members = pos->next; | 616 | chat_room->members = pos->next; |
635 | GNUNET_CONTAINER_meta_data_destroy (pos->meta); | 617 | GNUNET_CONTAINER_meta_data_destroy (pos->meta); |
636 | GNUNET_free (pos); | 618 | GNUNET_free (pos); |
637 | } | 619 | } |
638 | GNUNET_free (chat_room); | 620 | GNUNET_free (chat_room); |
639 | } | 621 | } |
640 | 622 | ||
@@ -675,8 +657,7 @@ GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
675 | GNUNET_CHAT_MemberListCallback memberCallback, | 657 | GNUNET_CHAT_MemberListCallback memberCallback, |
676 | void *member_cls, | 658 | void *member_cls, |
677 | GNUNET_CHAT_MessageConfirmation confirmationCallback, | 659 | GNUNET_CHAT_MessageConfirmation confirmationCallback, |
678 | void *confirmation_cls, | 660 | void *confirmation_cls, GNUNET_HashCode * me) |
679 | GNUNET_HashCode *me) | ||
680 | { | 661 | { |
681 | struct GNUNET_CHAT_Room *chat_room; | 662 | struct GNUNET_CHAT_Room *chat_room; |
682 | struct GNUNET_CRYPTO_RsaPrivateKey *priv_key; | 663 | struct GNUNET_CRYPTO_RsaPrivateKey *priv_key; |
@@ -696,29 +677,29 @@ GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
696 | GNUNET_PSEUDONYM_add (cfg, me, member_info); | 677 | GNUNET_PSEUDONYM_add (cfg, me, member_info); |
697 | client = GNUNET_CLIENT_connect ("chat", cfg); | 678 | client = GNUNET_CLIENT_connect ("chat", cfg); |
698 | if (NULL == client) | 679 | if (NULL == client) |
699 | { | 680 | { |
700 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 681 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
701 | _("Failed to connect to the chat service\n")); | 682 | _("Failed to connect to the chat service\n")); |
702 | return NULL; | 683 | return NULL; |
703 | } | 684 | } |
704 | if (NULL == joinCallback) | 685 | if (NULL == joinCallback) |
705 | { | 686 | { |
706 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 687 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
707 | _("Undefined mandatory parameter: joinCallback\n")); | 688 | _("Undefined mandatory parameter: joinCallback\n")); |
708 | return NULL; | 689 | return NULL; |
709 | } | 690 | } |
710 | if (NULL == messageCallback) | 691 | if (NULL == messageCallback) |
711 | { | 692 | { |
712 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 693 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
713 | _("Undefined mandatory parameter: messageCallback\n")); | 694 | _("Undefined mandatory parameter: messageCallback\n")); |
714 | return NULL; | 695 | return NULL; |
715 | } | 696 | } |
716 | if (NULL == memberCallback) | 697 | if (NULL == memberCallback) |
717 | { | 698 | { |
718 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 699 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
719 | _("Undefined mandatory parameter: memberCallback\n")); | 700 | _("Undefined mandatory parameter: memberCallback\n")); |
720 | return NULL; | 701 | return NULL; |
721 | } | 702 | } |
722 | chat_room = GNUNET_malloc (sizeof (struct GNUNET_CHAT_Room)); | 703 | chat_room = GNUNET_malloc (sizeof (struct GNUNET_CHAT_Room)); |
723 | chat_room->msg_options = msg_options; | 704 | chat_room->msg_options = msg_options; |
724 | chat_room->room_name = GNUNET_strdup (room_name); | 705 | chat_room->room_name = GNUNET_strdup (room_name); |
@@ -737,10 +718,10 @@ GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
737 | chat_room->client = client; | 718 | chat_room->client = client; |
738 | chat_room->members = NULL; | 719 | chat_room->members = NULL; |
739 | if (GNUNET_SYSERR == rejoin_room (chat_room)) | 720 | if (GNUNET_SYSERR == rejoin_room (chat_room)) |
740 | { | 721 | { |
741 | GNUNET_CHAT_leave_room (chat_room); | 722 | GNUNET_CHAT_leave_room (chat_room); |
742 | return NULL; | 723 | return NULL; |
743 | } | 724 | } |
744 | return chat_room; | 725 | return chat_room; |
745 | } | 726 | } |
746 | 727 | ||
@@ -754,22 +735,19 @@ GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
754 | * @return number of bytes written to buf | 735 | * @return number of bytes written to buf |
755 | */ | 736 | */ |
756 | static size_t | 737 | static size_t |
757 | transmit_send_request (void *cls, | 738 | transmit_send_request (void *cls, size_t size, void *buf) |
758 | size_t size, | ||
759 | void *buf) | ||
760 | { | 739 | { |
761 | struct GNUNET_CHAT_SendMessageContext *smc = cls; | 740 | struct GNUNET_CHAT_SendMessageContext *smc = cls; |
762 | struct TransmitRequestMessage *msg_to_send; | 741 | struct TransmitRequestMessage *msg_to_send; |
763 | size_t msg_size; | 742 | size_t msg_size; |
764 | 743 | ||
765 | if (NULL == buf) | 744 | if (NULL == buf) |
766 | { | 745 | { |
767 | #if DEBUG_CHAT | 746 | #if DEBUG_CHAT |
768 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 747 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not transmit a chat message\n"); |
769 | "Could not transmit a chat message\n"); | ||
770 | #endif | 748 | #endif |
771 | return 0; | 749 | return 0; |
772 | } | 750 | } |
773 | #if DEBUG_CHAT | 751 | #if DEBUG_CHAT |
774 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 752 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
775 | "Transmitting a chat message to the service\n"); | 753 | "Transmitting a chat message to the service\n"); |
@@ -782,7 +760,7 @@ transmit_send_request (void *cls, | |||
782 | msg_to_send->msg_options = htonl (smc->options); | 760 | msg_to_send->msg_options = htonl (smc->options); |
783 | msg_to_send->sequence_number = htonl (smc->sequence_number); | 761 | msg_to_send->sequence_number = htonl (smc->sequence_number); |
784 | msg_to_send->timestamp = | 762 | msg_to_send->timestamp = |
785 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); | 763 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); |
786 | msg_to_send->reserved = htonl (0); | 764 | msg_to_send->reserved = htonl (0); |
787 | if (NULL == smc->receiver) | 765 | if (NULL == smc->receiver) |
788 | memset (&msg_to_send->target, 0, sizeof (GNUNET_HashCode)); | 766 | memset (&msg_to_send->target, 0, sizeof (GNUNET_HashCode)); |
@@ -796,18 +774,18 @@ transmit_send_request (void *cls, | |||
796 | * stored on the service side. | 774 | * stored on the service side. |
797 | */ | 775 | */ |
798 | if (smc->options & GNUNET_CHAT_MSG_AUTHENTICATED) | 776 | if (smc->options & GNUNET_CHAT_MSG_AUTHENTICATED) |
799 | { | 777 | { |
800 | msg_to_send->purpose.purpose = | 778 | msg_to_send->purpose.purpose = |
801 | htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE); | 779 | htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE); |
802 | msg_to_send->purpose.size = | 780 | msg_to_send->purpose.size = |
803 | htonl (msg_size - | 781 | htonl (msg_size - |
804 | sizeof (struct GNUNET_MessageHeader) - | 782 | sizeof (struct GNUNET_MessageHeader) - |
805 | sizeof (struct GNUNET_CRYPTO_RsaSignature)); | 783 | sizeof (struct GNUNET_CRYPTO_RsaSignature)); |
806 | GNUNET_assert (GNUNET_OK == | 784 | GNUNET_assert (GNUNET_OK == |
807 | GNUNET_CRYPTO_rsa_sign (smc->chat_room->my_private_key, | 785 | GNUNET_CRYPTO_rsa_sign (smc->chat_room->my_private_key, |
808 | &msg_to_send->purpose, | 786 | &msg_to_send->purpose, |
809 | &msg_to_send->signature)); | 787 | &msg_to_send->signature)); |
810 | } | 788 | } |
811 | GNUNET_free (smc->message); | 789 | GNUNET_free (smc->message); |
812 | GNUNET_free (smc); | 790 | GNUNET_free (smc); |
813 | return msg_size; | 791 | return msg_size; |
@@ -827,8 +805,8 @@ void | |||
827 | GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room, | 805 | GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room, |
828 | const char *message, | 806 | const char *message, |
829 | enum GNUNET_CHAT_MsgOptions options, | 807 | enum GNUNET_CHAT_MsgOptions options, |
830 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *receiver, | 808 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded |
831 | uint32_t *sequence_number) | 809 | *receiver, uint32_t * sequence_number) |
832 | { | 810 | { |
833 | size_t msg_size; | 811 | size_t msg_size; |
834 | struct GNUNET_CHAT_SendMessageContext *smc; | 812 | struct GNUNET_CHAT_SendMessageContext *smc; |
@@ -849,9 +827,7 @@ GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room, | |||
849 | GNUNET_CLIENT_notify_transmit_ready (room->client, | 827 | GNUNET_CLIENT_notify_transmit_ready (room->client, |
850 | msg_size, | 828 | msg_size, |
851 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, | 829 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, |
852 | GNUNET_YES, | 830 | GNUNET_YES, &transmit_send_request, smc); |
853 | &transmit_send_request, | ||
854 | smc); | ||
855 | } | 831 | } |
856 | 832 | ||
857 | /* end of chat.c */ | 833 | /* end of chat.c */ |
diff --git a/src/chat/gnunet-chat.c b/src/chat/gnunet-chat.c index 85d266534..6dba4dda5 100644 --- a/src/chat/gnunet-chat.c +++ b/src/chat/gnunet-chat.c | |||
@@ -44,7 +44,8 @@ static struct GNUNET_CONTAINER_MetaData *meta; | |||
44 | 44 | ||
45 | static struct GNUNET_CHAT_Room *room; | 45 | static struct GNUNET_CHAT_Room *room; |
46 | 46 | ||
47 | static GNUNET_SCHEDULER_TaskIdentifier handle_cmd_task = GNUNET_SCHEDULER_NO_TASK; | 47 | static GNUNET_SCHEDULER_TaskIdentifier handle_cmd_task = |
48 | GNUNET_SCHEDULER_NO_TASK; | ||
48 | 49 | ||
49 | struct ChatCommand | 50 | struct ChatCommand |
50 | { | 51 | { |
@@ -66,12 +67,13 @@ static void | |||
66 | free_user_list () | 67 | free_user_list () |
67 | { | 68 | { |
68 | struct UserList *next; | 69 | struct UserList *next; |
70 | |||
69 | while (NULL != users) | 71 | while (NULL != users) |
70 | { | 72 | { |
71 | next = users->next; | 73 | next = users->next; |
72 | GNUNET_free (users); | 74 | GNUNET_free (users); |
73 | users = next; | 75 | users = next; |
74 | } | 76 | } |
75 | } | 77 | } |
76 | 78 | ||
77 | static int do_help (const char *args, const void *xtra); | 79 | static int do_help (const char *args, const void *xtra); |
@@ -107,7 +109,7 @@ join_cb (void *cls) | |||
107 | static int | 109 | static int |
108 | receive_cb (void *cls, | 110 | receive_cb (void *cls, |
109 | struct GNUNET_CHAT_Room *room, | 111 | struct GNUNET_CHAT_Room *room, |
110 | const GNUNET_HashCode *sender, | 112 | const GNUNET_HashCode * sender, |
111 | const struct GNUNET_CONTAINER_MetaData *member_info, | 113 | const struct GNUNET_CONTAINER_MetaData *member_info, |
112 | const char *message, | 114 | const char *message, |
113 | struct GNUNET_TIME_Absolute timestamp, | 115 | struct GNUNET_TIME_Absolute timestamp, |
@@ -122,43 +124,45 @@ receive_cb (void *cls, | |||
122 | else | 124 | else |
123 | nick = GNUNET_strdup (_("anonymous")); | 125 | nick = GNUNET_strdup (_("anonymous")); |
124 | fmt = NULL; | 126 | fmt = NULL; |
125 | switch ( (int) options) | 127 | switch ((int) options) |
126 | { | 128 | { |
127 | case GNUNET_CHAT_MSG_OPTION_NONE: | 129 | case GNUNET_CHAT_MSG_OPTION_NONE: |
128 | case GNUNET_CHAT_MSG_ANONYMOUS: | 130 | case GNUNET_CHAT_MSG_ANONYMOUS: |
129 | fmt = _("(%s) `%s' said: %s\n"); | 131 | fmt = _("(%s) `%s' said: %s\n"); |
130 | break; | 132 | break; |
131 | case GNUNET_CHAT_MSG_PRIVATE: | 133 | case GNUNET_CHAT_MSG_PRIVATE: |
132 | fmt = _("(%s) `%s' said to you: %s\n"); | 134 | fmt = _("(%s) `%s' said to you: %s\n"); |
133 | break; | 135 | break; |
134 | case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ANONYMOUS: | 136 | case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ANONYMOUS: |
135 | fmt = _("(%s) `%s' said to you: %s\n"); | 137 | fmt = _("(%s) `%s' said to you: %s\n"); |
136 | break; | 138 | break; |
137 | case GNUNET_CHAT_MSG_AUTHENTICATED: | 139 | case GNUNET_CHAT_MSG_AUTHENTICATED: |
138 | fmt = _("(%s) `%s' said for sure: %s\n"); | 140 | fmt = _("(%s) `%s' said for sure: %s\n"); |
139 | break; | 141 | break; |
140 | case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_AUTHENTICATED: | 142 | case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_AUTHENTICATED: |
141 | fmt = _("(%s) `%s' said to you for sure: %s\n"); | 143 | fmt = _("(%s) `%s' said to you for sure: %s\n"); |
142 | break; | 144 | break; |
143 | case GNUNET_CHAT_MSG_ACKNOWLEDGED: | 145 | case GNUNET_CHAT_MSG_ACKNOWLEDGED: |
144 | fmt = _("(%s) `%s' was confirmed that you received: %s\n"); | 146 | fmt = _("(%s) `%s' was confirmed that you received: %s\n"); |
145 | break; | 147 | break; |
146 | case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ACKNOWLEDGED: | 148 | case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ACKNOWLEDGED: |
147 | fmt = _("(%s) `%s' was confirmed that you and only you received: %s\n"); | 149 | fmt = _("(%s) `%s' was confirmed that you and only you received: %s\n"); |
148 | break; | 150 | break; |
149 | case GNUNET_CHAT_MSG_AUTHENTICATED | GNUNET_CHAT_MSG_ACKNOWLEDGED: | 151 | case GNUNET_CHAT_MSG_AUTHENTICATED | GNUNET_CHAT_MSG_ACKNOWLEDGED: |
150 | fmt = _("(%s) `%s' was confirmed that you received from him or her: %s\n"); | 152 | fmt = _("(%s) `%s' was confirmed that you received from him or her: %s\n"); |
151 | break; | 153 | break; |
152 | case GNUNET_CHAT_MSG_AUTHENTICATED | GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ACKNOWLEDGED: | 154 | case GNUNET_CHAT_MSG_AUTHENTICATED | GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ACKNOWLEDGED: |
153 | fmt = _("(%s) `%s' was confirmed that you and only you received from him or her: %s\n"); | 155 | fmt = |
154 | break; | 156 | _ |
155 | case GNUNET_CHAT_MSG_OFF_THE_RECORD: | 157 | ("(%s) `%s' was confirmed that you and only you received from him or her: %s\n"); |
156 | fmt = _("(%s) `%s' said off the record: %s\n"); | 158 | break; |
157 | break; | 159 | case GNUNET_CHAT_MSG_OFF_THE_RECORD: |
158 | default: | 160 | fmt = _("(%s) `%s' said off the record: %s\n"); |
159 | fmt = _("(%s) <%s> said using an unknown message type: %s\n"); | 161 | break; |
160 | break; | 162 | default: |
161 | } | 163 | fmt = _("(%s) <%s> said using an unknown message type: %s\n"); |
164 | break; | ||
165 | } | ||
162 | time = GNUNET_STRINGS_absolute_time_to_string (timestamp); | 166 | time = GNUNET_STRINGS_absolute_time_to_string (timestamp); |
163 | fprintf (stdout, fmt, time, nick, message); | 167 | fprintf (stdout, fmt, time, nick, message); |
164 | GNUNET_free (nick); | 168 | GNUNET_free (nick); |
@@ -183,7 +187,7 @@ confirmation_cb (void *cls, | |||
183 | struct GNUNET_CHAT_Room *room, | 187 | struct GNUNET_CHAT_Room *room, |
184 | uint32_t orig_seq_number, | 188 | uint32_t orig_seq_number, |
185 | struct GNUNET_TIME_Absolute timestamp, | 189 | struct GNUNET_TIME_Absolute timestamp, |
186 | const GNUNET_HashCode *receiver) | 190 | const GNUNET_HashCode * receiver) |
187 | { | 191 | { |
188 | char *nick; | 192 | char *nick; |
189 | 193 | ||
@@ -222,40 +226,41 @@ member_list_cb (void *cls, | |||
222 | ? _("`%s' entered the room\n") : _("`%s' left the room\n"), nick); | 226 | ? _("`%s' entered the room\n") : _("`%s' left the room\n"), nick); |
223 | GNUNET_free (nick); | 227 | GNUNET_free (nick); |
224 | if (NULL != member_info) | 228 | if (NULL != member_info) |
229 | { | ||
230 | /* user joining */ | ||
231 | pos = GNUNET_malloc (sizeof (struct UserList)); | ||
232 | pos->next = users; | ||
233 | pos->pkey = *member_id; | ||
234 | pos->ignored = GNUNET_NO; | ||
235 | users = pos; | ||
236 | } | ||
237 | else | ||
238 | { | ||
239 | /* user leaving */ | ||
240 | prev = NULL; | ||
241 | pos = users; | ||
242 | while ((NULL != pos) && | ||
243 | (0 != memcmp (&pos->pkey, | ||
244 | member_id, | ||
245 | sizeof (struct | ||
246 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))) | ||
225 | { | 247 | { |
226 | /* user joining */ | 248 | prev = pos; |
227 | pos = GNUNET_malloc (sizeof (struct UserList)); | 249 | pos = pos->next; |
228 | pos->next = users; | ||
229 | pos->pkey = *member_id; | ||
230 | pos->ignored = GNUNET_NO; | ||
231 | users = pos; | ||
232 | } | 250 | } |
233 | else | 251 | if (NULL == pos) |
234 | { | 252 | { |
235 | /* user leaving */ | 253 | GNUNET_break (0); |
236 | prev = NULL; | 254 | } |
237 | pos = users; | 255 | else |
238 | while ((NULL != pos) && | 256 | { |
239 | (0 != memcmp (&pos->pkey, | 257 | if (NULL == prev) |
240 | member_id, | 258 | users = pos->next; |
241 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))) | ||
242 | { | ||
243 | prev = pos; | ||
244 | pos = pos->next; | ||
245 | } | ||
246 | if (NULL == pos) | ||
247 | { | ||
248 | GNUNET_break (0); | ||
249 | } | ||
250 | else | 259 | else |
251 | { | 260 | prev->next = pos->next; |
252 | if (NULL == prev) | 261 | GNUNET_free (pos); |
253 | users = pos->next; | ||
254 | else | ||
255 | prev->next = pos->next; | ||
256 | GNUNET_free (pos); | ||
257 | } | ||
258 | } | 262 | } |
263 | } | ||
259 | return GNUNET_OK; | 264 | return GNUNET_OK; |
260 | } | 265 | } |
261 | 266 | ||
@@ -282,12 +287,13 @@ do_join (const char *arg, const void *xtra) | |||
282 | &member_list_cb, NULL, | 287 | &member_list_cb, NULL, |
283 | &confirmation_cb, NULL, &me); | 288 | &confirmation_cb, NULL, &me); |
284 | if (NULL == room) | 289 | if (NULL == room) |
285 | { | 290 | { |
286 | fprintf (stdout, _("Could not change username\n")); | 291 | fprintf (stdout, _("Could not change username\n")); |
287 | return GNUNET_SYSERR; | 292 | return GNUNET_SYSERR; |
288 | } | 293 | } |
289 | my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me); | 294 | my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me); |
290 | fprintf (stdout, _("Joining room `%s' as user `%s'...\n"), room_name, my_name); | 295 | fprintf (stdout, _("Joining room `%s' as user `%s'...\n"), room_name, |
296 | my_name); | ||
291 | GNUNET_free (my_name); | 297 | GNUNET_free (my_name); |
292 | return GNUNET_OK; | 298 | return GNUNET_OK; |
293 | } | 299 | } |
@@ -310,8 +316,7 @@ do_nick (const char *msg, const void *xtra) | |||
310 | EXTRACTOR_METATYPE_TITLE, | 316 | EXTRACTOR_METATYPE_TITLE, |
311 | EXTRACTOR_METAFORMAT_UTF8, | 317 | EXTRACTOR_METAFORMAT_UTF8, |
312 | "text/plain", | 318 | "text/plain", |
313 | nickname, | 319 | nickname, strlen (nickname) + 1); |
314 | strlen(nickname)+1); | ||
315 | room = GNUNET_CHAT_join_room (cfg, | 320 | room = GNUNET_CHAT_join_room (cfg, |
316 | nickname, | 321 | nickname, |
317 | meta, | 322 | meta, |
@@ -322,10 +327,10 @@ do_nick (const char *msg, const void *xtra) | |||
322 | &member_list_cb, NULL, | 327 | &member_list_cb, NULL, |
323 | &confirmation_cb, NULL, &me); | 328 | &confirmation_cb, NULL, &me); |
324 | if (NULL == room) | 329 | if (NULL == room) |
325 | { | 330 | { |
326 | fprintf (stdout, _("Could not change username\n")); | 331 | fprintf (stdout, _("Could not change username\n")); |
327 | return GNUNET_SYSERR; | 332 | return GNUNET_SYSERR; |
328 | } | 333 | } |
329 | my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me); | 334 | my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me); |
330 | fprintf (stdout, _("Changed username to `%s'\n"), my_name); | 335 | fprintf (stdout, _("Changed username to `%s'\n"), my_name); |
331 | GNUNET_free (my_name); | 336 | GNUNET_free (my_name); |
@@ -343,15 +348,15 @@ do_names (const char *msg, const void *xtra) | |||
343 | fprintf (stdout, _("Users in room `%s': "), room_name); | 348 | fprintf (stdout, _("Users in room `%s': "), room_name); |
344 | pos = users; | 349 | pos = users; |
345 | while (NULL != pos) | 350 | while (NULL != pos) |
346 | { | 351 | { |
347 | GNUNET_CRYPTO_hash (&pos->pkey, | 352 | GNUNET_CRYPTO_hash (&pos->pkey, |
348 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 353 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
349 | &pid); | 354 | &pid); |
350 | name = GNUNET_PSEUDONYM_id_to_name (cfg, &pid); | 355 | name = GNUNET_PSEUDONYM_id_to_name (cfg, &pid); |
351 | fprintf (stdout, "`%s' ", name); | 356 | fprintf (stdout, "`%s' ", name); |
352 | GNUNET_free (name); | 357 | GNUNET_free (name); |
353 | pos = pos->next; | 358 | pos = pos->next; |
354 | } | 359 | } |
355 | fprintf (stdout, "\n"); | 360 | fprintf (stdout, "\n"); |
356 | return GNUNET_OK; | 361 | return GNUNET_OK; |
357 | } | 362 | } |
@@ -361,10 +366,8 @@ static int | |||
361 | do_send (const char *msg, const void *xtra) | 366 | do_send (const char *msg, const void *xtra) |
362 | { | 367 | { |
363 | uint32_t seq; | 368 | uint32_t seq; |
364 | GNUNET_CHAT_send_message (room, | 369 | |
365 | msg, | 370 | GNUNET_CHAT_send_message (room, msg, GNUNET_CHAT_MSG_OPTION_NONE, NULL, &seq); |
366 | GNUNET_CHAT_MSG_OPTION_NONE, | ||
367 | NULL, &seq); | ||
368 | return GNUNET_OK; | 371 | return GNUNET_OK; |
369 | } | 372 | } |
370 | 373 | ||
@@ -379,40 +382,37 @@ do_send_pm (const char *msg, const void *xtra) | |||
379 | struct UserList *pos; | 382 | struct UserList *pos; |
380 | 383 | ||
381 | if (NULL == strstr (msg, " ")) | 384 | if (NULL == strstr (msg, " ")) |
382 | { | 385 | { |
383 | fprintf (stderr, _("Syntax: /msg USERNAME MESSAGE")); | 386 | fprintf (stderr, _("Syntax: /msg USERNAME MESSAGE")); |
384 | return GNUNET_OK; | 387 | return GNUNET_OK; |
385 | } | 388 | } |
386 | user = GNUNET_strdup (msg); | 389 | user = GNUNET_strdup (msg); |
387 | strstr (user, " ")[0] = '\0'; | 390 | strstr (user, " ")[0] = '\0'; |
388 | msg += strlen (user) + 1; | 391 | msg += strlen (user) + 1; |
389 | if (GNUNET_OK != GNUNET_PSEUDONYM_name_to_id (cfg, user, &uid)) | 392 | if (GNUNET_OK != GNUNET_PSEUDONYM_name_to_id (cfg, user, &uid)) |
390 | { | 393 | { |
391 | fprintf (stderr, _("Unknown user `%s'\n"), user); | 394 | fprintf (stderr, _("Unknown user `%s'\n"), user); |
392 | GNUNET_free (user); | 395 | GNUNET_free (user); |
393 | return GNUNET_OK; | 396 | return GNUNET_OK; |
394 | } | 397 | } |
395 | pos = users; | 398 | pos = users; |
396 | while (NULL != pos) | 399 | while (NULL != pos) |
397 | { | 400 | { |
398 | GNUNET_CRYPTO_hash (&pos->pkey, | 401 | GNUNET_CRYPTO_hash (&pos->pkey, |
399 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 402 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
400 | &pid); | 403 | &pid); |
401 | if (0 == memcmp (&pid, &uid, sizeof (GNUNET_HashCode))) | 404 | if (0 == memcmp (&pid, &uid, sizeof (GNUNET_HashCode))) |
402 | break; | 405 | break; |
403 | pos = pos->next; | 406 | pos = pos->next; |
404 | } | 407 | } |
405 | if (NULL == pos) | 408 | if (NULL == pos) |
406 | { | 409 | { |
407 | fprintf (stderr, _("User `%s' is currently not in the room!\n"), user); | 410 | fprintf (stderr, _("User `%s' is currently not in the room!\n"), user); |
408 | GNUNET_free (user); | 411 | GNUNET_free (user); |
409 | return GNUNET_OK; | 412 | return GNUNET_OK; |
410 | } | 413 | } |
411 | GNUNET_CHAT_send_message (room, | 414 | GNUNET_CHAT_send_message (room, |
412 | msg, | 415 | msg, GNUNET_CHAT_MSG_PRIVATE, &pos->pkey, &seq); |
413 | GNUNET_CHAT_MSG_PRIVATE, | ||
414 | &pos->pkey, | ||
415 | &seq); | ||
416 | GNUNET_free (user); | 416 | GNUNET_free (user); |
417 | return GNUNET_OK; | 417 | return GNUNET_OK; |
418 | } | 418 | } |
@@ -422,10 +422,9 @@ static int | |||
422 | do_send_sig (const char *msg, const void *xtra) | 422 | do_send_sig (const char *msg, const void *xtra) |
423 | { | 423 | { |
424 | uint32_t seq; | 424 | uint32_t seq; |
425 | |||
425 | GNUNET_CHAT_send_message (room, | 426 | GNUNET_CHAT_send_message (room, |
426 | msg, | 427 | msg, GNUNET_CHAT_MSG_AUTHENTICATED, NULL, &seq); |
427 | GNUNET_CHAT_MSG_AUTHENTICATED, | ||
428 | NULL, &seq); | ||
429 | return GNUNET_OK; | 428 | return GNUNET_OK; |
430 | } | 429 | } |
431 | 430 | ||
@@ -434,10 +433,9 @@ static int | |||
434 | do_send_ack (const char *msg, const void *xtra) | 433 | do_send_ack (const char *msg, const void *xtra) |
435 | { | 434 | { |
436 | uint32_t seq; | 435 | uint32_t seq; |
436 | |||
437 | GNUNET_CHAT_send_message (room, | 437 | GNUNET_CHAT_send_message (room, |
438 | msg, | 438 | msg, GNUNET_CHAT_MSG_ACKNOWLEDGED, NULL, &seq); |
439 | GNUNET_CHAT_MSG_ACKNOWLEDGED, | ||
440 | NULL, &seq); | ||
441 | return GNUNET_OK; | 439 | return GNUNET_OK; |
442 | } | 440 | } |
443 | 441 | ||
@@ -446,10 +444,8 @@ static int | |||
446 | do_send_anonymous (const char *msg, const void *xtra) | 444 | do_send_anonymous (const char *msg, const void *xtra) |
447 | { | 445 | { |
448 | uint32_t seq; | 446 | uint32_t seq; |
449 | GNUNET_CHAT_send_message (room, | 447 | |
450 | msg, | 448 | GNUNET_CHAT_send_message (room, msg, GNUNET_CHAT_MSG_ANONYMOUS, NULL, &seq); |
451 | GNUNET_CHAT_MSG_ANONYMOUS, | ||
452 | NULL, &seq); | ||
453 | return GNUNET_OK; | 449 | return GNUNET_OK; |
454 | } | 450 | } |
455 | 451 | ||
@@ -509,8 +505,8 @@ static struct ChatCommand commands[] = { | |||
509 | {"/help", &do_help, | 505 | {"/help", &do_help, |
510 | gettext_noop ("Use `/help command' to get help for a specific command")}, | 506 | gettext_noop ("Use `/help command' to get help for a specific command")}, |
511 | /* Add standard commands: | 507 | /* Add standard commands: |
512 | /whois (print metadata), | 508 | * /whois (print metadata), |
513 | /ignore (set flag, check on receive!) */ | 509 | * /ignore (set flag, check on receive!) */ |
514 | /* the following three commands must be last! */ | 510 | /* the following three commands must be last! */ |
515 | {"/", &do_unknown, NULL}, | 511 | {"/", &do_unknown, NULL}, |
516 | {"", &do_send, NULL}, | 512 | {"", &do_send, NULL}, |
@@ -522,41 +518,40 @@ static int | |||
522 | do_help (const char *args, const void *xtra) | 518 | do_help (const char *args, const void *xtra) |
523 | { | 519 | { |
524 | int i; | 520 | int i; |
521 | |||
525 | i = 0; | 522 | i = 0; |
526 | while ((NULL != args) && | 523 | while ((NULL != args) && |
527 | (0 != strlen (args)) && (commands[i].Action != &do_help)) | 524 | (0 != strlen (args)) && (commands[i].Action != &do_help)) |
525 | { | ||
526 | if (0 == strncasecmp (&args[1], &commands[i].command[1], strlen (args) - 1)) | ||
528 | { | 527 | { |
529 | if (0 == | 528 | fprintf (stdout, "%s\n", gettext (commands[i].helptext)); |
530 | strncasecmp (&args[1], &commands[i].command[1], strlen (args) - 1)) | 529 | return GNUNET_OK; |
531 | { | ||
532 | fprintf (stdout, "%s\n", gettext (commands[i].helptext)); | ||
533 | return GNUNET_OK; | ||
534 | } | ||
535 | i++; | ||
536 | } | 530 | } |
531 | i++; | ||
532 | } | ||
537 | i = 0; | 533 | i = 0; |
538 | fprintf (stdout, "Available commands:"); | 534 | fprintf (stdout, "Available commands:"); |
539 | while (commands[i].Action != &do_help) | 535 | while (commands[i].Action != &do_help) |
540 | { | 536 | { |
541 | fprintf (stdout, " %s", gettext (commands[i].command)); | 537 | fprintf (stdout, " %s", gettext (commands[i].command)); |
542 | i++; | 538 | i++; |
543 | } | 539 | } |
544 | fprintf (stdout, "\n"); | 540 | fprintf (stdout, "\n"); |
545 | fprintf (stdout, "%s\n", gettext (commands[i].helptext)); | 541 | fprintf (stdout, "%s\n", gettext (commands[i].helptext)); |
546 | return GNUNET_OK; | 542 | return GNUNET_OK; |
547 | } | 543 | } |
548 | 544 | ||
549 | 545 | ||
550 | static void | 546 | static void |
551 | do_stop_task (void *cls, | 547 | do_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
552 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
553 | { | 548 | { |
554 | GNUNET_CHAT_leave_room (room); | 549 | GNUNET_CHAT_leave_room (room); |
555 | if (handle_cmd_task != GNUNET_SCHEDULER_NO_TASK) | 550 | if (handle_cmd_task != GNUNET_SCHEDULER_NO_TASK) |
556 | { | 551 | { |
557 | GNUNET_SCHEDULER_cancel (handle_cmd_task); | 552 | GNUNET_SCHEDULER_cancel (handle_cmd_task); |
558 | handle_cmd_task = GNUNET_SCHEDULER_NO_TASK; | 553 | handle_cmd_task = GNUNET_SCHEDULER_NO_TASK; |
559 | } | 554 | } |
560 | free_user_list (); | 555 | free_user_list (); |
561 | GNUNET_CONTAINER_meta_data_destroy (meta); | 556 | GNUNET_CONTAINER_meta_data_destroy (meta); |
562 | GNUNET_free (room_name); | 557 | GNUNET_free (room_name); |
@@ -591,10 +586,9 @@ handle_command (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
591 | 586 | ||
592 | next: | 587 | next: |
593 | handle_cmd_task = | 588 | handle_cmd_task = |
594 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 589 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
595 | 100), | 590 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
596 | &handle_command, | 591 | &handle_command, NULL); |
597 | NULL); | ||
598 | return; | 592 | return; |
599 | 593 | ||
600 | out: | 594 | out: |
@@ -614,8 +608,7 @@ out: | |||
614 | static void | 608 | static void |
615 | run (void *cls, | 609 | run (void *cls, |
616 | char *const *args, | 610 | char *const *args, |
617 | const char *cfgfile, | 611 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
618 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
619 | { | 612 | { |
620 | GNUNET_HashCode me; | 613 | GNUNET_HashCode me; |
621 | char *my_name; | 614 | char *my_name; |
@@ -623,11 +616,11 @@ run (void *cls, | |||
623 | cfg = c; | 616 | cfg = c; |
624 | /* check arguments */ | 617 | /* check arguments */ |
625 | if (NULL == nickname) | 618 | if (NULL == nickname) |
626 | { | 619 | { |
627 | fprintf (stderr, _("You must specify a nickname\n")); | 620 | fprintf (stderr, _("You must specify a nickname\n")); |
628 | ret = -1; | 621 | ret = -1; |
629 | return; | 622 | return; |
630 | } | 623 | } |
631 | if (NULL == room_name) | 624 | if (NULL == room_name) |
632 | room_name = GNUNET_strdup ("gnunet"); | 625 | room_name = GNUNET_strdup ("gnunet"); |
633 | meta = GNUNET_CONTAINER_meta_data_create (); | 626 | meta = GNUNET_CONTAINER_meta_data_create (); |
@@ -636,8 +629,7 @@ run (void *cls, | |||
636 | EXTRACTOR_METATYPE_TITLE, | 629 | EXTRACTOR_METATYPE_TITLE, |
637 | EXTRACTOR_METAFORMAT_UTF8, | 630 | EXTRACTOR_METAFORMAT_UTF8, |
638 | "text/plain", | 631 | "text/plain", |
639 | nickname, | 632 | nickname, strlen (nickname) + 1); |
640 | strlen(nickname)+1); | ||
641 | room = GNUNET_CHAT_join_room (cfg, | 633 | room = GNUNET_CHAT_join_room (cfg, |
642 | nickname, | 634 | nickname, |
643 | meta, | 635 | meta, |
@@ -648,24 +640,23 @@ run (void *cls, | |||
648 | &member_list_cb, NULL, | 640 | &member_list_cb, NULL, |
649 | &confirmation_cb, NULL, &me); | 641 | &confirmation_cb, NULL, &me); |
650 | if (NULL == room) | 642 | if (NULL == room) |
651 | { | 643 | { |
652 | fprintf (stderr, _("Failed to join room `%s'\n"), room_name); | 644 | fprintf (stderr, _("Failed to join room `%s'\n"), room_name); |
653 | GNUNET_free (room_name); | 645 | GNUNET_free (room_name); |
654 | GNUNET_free (nickname); | 646 | GNUNET_free (nickname); |
655 | GNUNET_CONTAINER_meta_data_destroy (meta); | 647 | GNUNET_CONTAINER_meta_data_destroy (meta); |
656 | ret = -1; | 648 | ret = -1; |
657 | return; | 649 | return; |
658 | } | 650 | } |
659 | my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me); | 651 | my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me); |
660 | fprintf (stdout, _("Joining room `%s' as user `%s'...\n"), room_name, my_name); | 652 | fprintf (stdout, _("Joining room `%s' as user `%s'...\n"), room_name, |
653 | my_name); | ||
661 | GNUNET_free (my_name); | 654 | GNUNET_free (my_name); |
662 | handle_cmd_task = | 655 | handle_cmd_task = |
663 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, | 656 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, |
664 | &handle_command, | 657 | &handle_command, NULL); |
665 | NULL); | ||
666 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 658 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
667 | &do_stop_task, | 659 | &do_stop_task, NULL); |
668 | NULL); | ||
669 | } | 660 | } |
670 | 661 | ||
671 | 662 | ||
@@ -680,6 +671,7 @@ int | |||
680 | main (int argc, char *const *argv) | 671 | main (int argc, char *const *argv) |
681 | { | 672 | { |
682 | int flags; | 673 | int flags; |
674 | |||
683 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 675 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
684 | {'n', "nick", "NAME", | 676 | {'n', "nick", "NAME", |
685 | gettext_noop ("set the nickname to use (required)"), | 677 | gettext_noop ("set the nickname to use (required)"), |
diff --git a/src/chat/gnunet-service-chat.c b/src/chat/gnunet-service-chat.c index 470b4ad0b..7afa18d68 100644 --- a/src/chat/gnunet-service-chat.c +++ b/src/chat/gnunet-service-chat.c | |||
@@ -105,7 +105,7 @@ struct ConnectedPeer | |||
105 | /** | 105 | /** |
106 | * The peer's identity. | 106 | * The peer's identity. |
107 | */ | 107 | */ |
108 | GNUNET_PEER_Id pid; | 108 | GNUNET_PEER_Id pid; |
109 | }; | 109 | }; |
110 | 110 | ||
111 | /** | 111 | /** |
@@ -157,10 +157,11 @@ static struct AnonymousMessage *anonymous_list_head = NULL; | |||
157 | * Map of peer identifiers to "struct ConnectedPeer" (for that peer). | 157 | * Map of peer identifiers to "struct ConnectedPeer" (for that peer). |
158 | */ | 158 | */ |
159 | static struct GNUNET_CONTAINER_MultiHashMap *connected_peers; | 159 | static struct GNUNET_CONTAINER_MultiHashMap *connected_peers; |
160 | 160 | ||
161 | 161 | ||
162 | static void | 162 | static void |
163 | remember_anonymous_message (const struct P2PReceiveNotificationMessage *p2p_rnmsg) | 163 | remember_anonymous_message (const struct P2PReceiveNotificationMessage |
164 | *p2p_rnmsg) | ||
164 | { | 165 | { |
165 | static GNUNET_HashCode hash; | 166 | static GNUNET_HashCode hash; |
166 | struct AnonymousMessage *anon_msg; | 167 | struct AnonymousMessage *anon_msg; |
@@ -175,17 +176,17 @@ remember_anonymous_message (const struct P2PReceiveNotificationMessage *p2p_rnms | |||
175 | anon_list_len = 1; | 176 | anon_list_len = 1; |
176 | prev = NULL; | 177 | prev = NULL; |
177 | while ((NULL != anon_msg->next)) | 178 | while ((NULL != anon_msg->next)) |
178 | { | 179 | { |
179 | prev = anon_msg; | 180 | prev = anon_msg; |
180 | anon_msg = anon_msg->next; | 181 | anon_msg = anon_msg->next; |
181 | anon_list_len++; | 182 | anon_list_len++; |
182 | } | 183 | } |
183 | if (anon_list_len == MAX_ANONYMOUS_MSG_LIST_LENGTH) | 184 | if (anon_list_len == MAX_ANONYMOUS_MSG_LIST_LENGTH) |
184 | { | 185 | { |
185 | GNUNET_free (anon_msg); | 186 | GNUNET_free (anon_msg); |
186 | if (NULL != prev) | 187 | if (NULL != prev) |
187 | prev->next = NULL; | 188 | prev->next = NULL; |
188 | } | 189 | } |
189 | } | 190 | } |
190 | 191 | ||
191 | 192 | ||
@@ -213,9 +214,7 @@ lookup_anonymous_message (const struct P2PReceiveNotificationMessage *p2p_rnmsg) | |||
213 | * @return number of bytes written to buf | 214 | * @return number of bytes written to buf |
214 | */ | 215 | */ |
215 | static size_t | 216 | static size_t |
216 | transmit_message_notification_to_peer (void *cls, | 217 | transmit_message_notification_to_peer (void *cls, size_t size, void *buf) |
217 | size_t size, | ||
218 | void *buf) | ||
219 | { | 218 | { |
220 | struct P2PReceiveNotificationMessage *my_msg = cls; | 219 | struct P2PReceiveNotificationMessage *my_msg = cls; |
221 | struct P2PReceiveNotificationMessage *m = buf; | 220 | struct P2PReceiveNotificationMessage *m = buf; |
@@ -226,14 +225,14 @@ transmit_message_notification_to_peer (void *cls, | |||
226 | "Transmitting P2P message notification\n"); | 225 | "Transmitting P2P message notification\n"); |
227 | #endif | 226 | #endif |
228 | if (buf == NULL) | 227 | if (buf == NULL) |
229 | { | 228 | { |
230 | /* client disconnected */ | 229 | /* client disconnected */ |
231 | #if DEBUG_CHAT_SERVICE | 230 | #if DEBUG_CHAT_SERVICE |
232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 231 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
233 | "Buffer is NULL, dropping the message\n"); | 232 | "Buffer is NULL, dropping the message\n"); |
234 | #endif | 233 | #endif |
235 | return 0; | 234 | return 0; |
236 | } | 235 | } |
237 | msg_size = ntohs (my_msg->header.size); | 236 | msg_size = ntohs (my_msg->header.size); |
238 | GNUNET_assert (size >= msg_size); | 237 | GNUNET_assert (size >= msg_size); |
239 | memcpy (m, my_msg, msg_size); | 238 | memcpy (m, my_msg, msg_size); |
@@ -246,9 +245,7 @@ transmit_message_notification_to_peer (void *cls, | |||
246 | * Ask to send a message notification to the peer. | 245 | * Ask to send a message notification to the peer. |
247 | */ | 246 | */ |
248 | static int | 247 | static int |
249 | send_message_noficiation (void *cls, | 248 | send_message_noficiation (void *cls, const GNUNET_HashCode * key, void *value) |
250 | const GNUNET_HashCode *key, | ||
251 | void *value) | ||
252 | { | 249 | { |
253 | struct P2PReceiveNotificationMessage *msg = cls; | 250 | struct P2PReceiveNotificationMessage *msg = cls; |
254 | struct ConnectedPeer *cp = value; | 251 | struct ConnectedPeer *cp = value; |
@@ -262,7 +259,7 @@ send_message_noficiation (void *cls, | |||
262 | #endif | 259 | #endif |
263 | my_msg = GNUNET_memdup (msg, ntohs (msg->header.size)); | 260 | my_msg = GNUNET_memdup (msg, ntohs (msg->header.size)); |
264 | if (NULL == GNUNET_CORE_notify_transmit_ready (core, | 261 | if (NULL == GNUNET_CORE_notify_transmit_ready (core, |
265 | GNUNET_NO, | 262 | GNUNET_NO, |
266 | 1, | 263 | 1, |
267 | MAX_TRANSMIT_DELAY, | 264 | MAX_TRANSMIT_DELAY, |
268 | &pid, | 265 | &pid, |
@@ -304,35 +301,36 @@ handle_transmit_request (void *cls, | |||
304 | 301 | ||
305 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Client sent a chat message\n"); | 302 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Client sent a chat message\n"); |
306 | if (ntohs (message->size) <= sizeof (struct TransmitRequestMessage)) | 303 | if (ntohs (message->size) <= sizeof (struct TransmitRequestMessage)) |
307 | { | 304 | { |
308 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n"); | 305 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n"); |
309 | GNUNET_break (0); | 306 | GNUNET_break (0); |
310 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 307 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
311 | return; | 308 | return; |
312 | } | 309 | } |
313 | trmsg = (const struct TransmitRequestMessage *) message; | 310 | trmsg = (const struct TransmitRequestMessage *) message; |
314 | msg_len = ntohs (trmsg->header.size) - sizeof (struct TransmitRequestMessage); | 311 | msg_len = ntohs (trmsg->header.size) - sizeof (struct TransmitRequestMessage); |
315 | is_priv = (0 != (ntohl (trmsg->msg_options) & GNUNET_CHAT_MSG_PRIVATE)); | 312 | is_priv = (0 != (ntohl (trmsg->msg_options) & GNUNET_CHAT_MSG_PRIVATE)); |
316 | if (is_priv) | 313 | if (is_priv) |
317 | { | 314 | { |
318 | #if DEBUG_CHAT_SERVICE | 315 | #if DEBUG_CHAT_SERVICE |
319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting the message text\n"); | 316 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting the message text\n"); |
320 | #endif | 317 | #endif |
321 | GNUNET_CRYPTO_aes_create_session_key (&key); | 318 | GNUNET_CRYPTO_aes_create_session_key (&key); |
322 | msg_len = GNUNET_CRYPTO_aes_encrypt (&trmsg[1], | 319 | msg_len = GNUNET_CRYPTO_aes_encrypt (&trmsg[1], |
323 | msg_len, | 320 | msg_len, |
324 | &key, | 321 | &key, |
325 | (const struct GNUNET_CRYPTO_AesInitializationVector *) INITVALUE, | 322 | (const struct |
326 | encrypted_msg); | 323 | GNUNET_CRYPTO_AesInitializationVector |
327 | if (-1 == msg_len) | 324 | *) INITVALUE, encrypted_msg); |
328 | { | 325 | if (-1 == msg_len) |
329 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 326 | { |
330 | "Could not encrypt the message text\n"); | 327 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
331 | GNUNET_break (0); | 328 | "Could not encrypt the message text\n"); |
332 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 329 | GNUNET_break (0); |
333 | return; | 330 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
334 | } | 331 | return; |
335 | } | 332 | } |
333 | } | ||
336 | rnmsg = GNUNET_malloc (sizeof (struct ReceiveNotificationMessage) + msg_len); | 334 | rnmsg = GNUNET_malloc (sizeof (struct ReceiveNotificationMessage) + msg_len); |
337 | rnmsg->header.size = htons (sizeof (struct ReceiveNotificationMessage) + | 335 | rnmsg->header.size = htons (sizeof (struct ReceiveNotificationMessage) + |
338 | msg_len); | 336 | msg_len); |
@@ -343,134 +341,134 @@ handle_transmit_request (void *cls, | |||
343 | while ((NULL != pos) && (pos->client != client)) | 341 | while ((NULL != pos) && (pos->client != client)) |
344 | pos = pos->next; | 342 | pos = pos->next; |
345 | if (NULL == pos) | 343 | if (NULL == pos) |
346 | { | 344 | { |
347 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 345 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
348 | "The client is not a member of a chat room. Client has to " | 346 | "The client is not a member of a chat room. Client has to " |
349 | "join a chat room first\n"); | 347 | "join a chat room first\n"); |
350 | GNUNET_break (0); | 348 | GNUNET_break (0); |
351 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 349 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
352 | GNUNET_free (rnmsg); | 350 | GNUNET_free (rnmsg); |
353 | return; | 351 | return; |
354 | } | 352 | } |
355 | room = pos->room; | 353 | room = pos->room; |
356 | pos->msg_sequence_number = ntohl (trmsg->sequence_number); | 354 | pos->msg_sequence_number = ntohl (trmsg->sequence_number); |
357 | is_anon = (0 != (ntohl (trmsg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS)); | 355 | is_anon = (0 != (ntohl (trmsg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS)); |
358 | if (is_anon) | 356 | if (is_anon) |
359 | { | 357 | { |
360 | memset (&rnmsg->sender, 0, sizeof (GNUNET_HashCode)); | 358 | memset (&rnmsg->sender, 0, sizeof (GNUNET_HashCode)); |
361 | rnmsg->sequence_number = 0; | 359 | rnmsg->sequence_number = 0; |
362 | } | 360 | } |
363 | else | 361 | else |
364 | { | 362 | { |
365 | rnmsg->sender = pos->id; | 363 | rnmsg->sender = pos->id; |
366 | rnmsg->sequence_number = trmsg->sequence_number; | 364 | rnmsg->sequence_number = trmsg->sequence_number; |
367 | } | 365 | } |
368 | if (is_priv) | 366 | if (is_priv) |
369 | { | 367 | { |
370 | #if DEBUG_CHAT_SERVICE | 368 | #if DEBUG_CHAT_SERVICE |
371 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 369 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
372 | "Encrypting the session key using the public key of '%s'\n", | 370 | "Encrypting the session key using the public key of '%s'\n", |
373 | GNUNET_h2s (&trmsg->target)); | 371 | GNUNET_h2s (&trmsg->target)); |
374 | #endif | 372 | #endif |
375 | if (0 == memcmp (&all_zeros, &trmsg->target, sizeof (GNUNET_HashCode))) | 373 | if (0 == memcmp (&all_zeros, &trmsg->target, sizeof (GNUNET_HashCode))) |
376 | { | 374 | { |
377 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 375 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
378 | "Malformed message: private, but no target\n"); | 376 | "Malformed message: private, but no target\n"); |
379 | GNUNET_break (0); | 377 | GNUNET_break (0); |
380 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 378 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
381 | GNUNET_free (rnmsg); | 379 | GNUNET_free (rnmsg); |
382 | return; | 380 | return; |
383 | } | ||
384 | memcpy (&rnmsg[1], encrypted_msg, msg_len); | ||
385 | target = client_list_head; | ||
386 | while ((NULL != target) && | ||
387 | (0 != memcmp (&target->id, | ||
388 | &trmsg->target, | ||
389 | sizeof (GNUNET_HashCode)))) | ||
390 | target = target->next; | ||
391 | if (NULL == target) | ||
392 | { | ||
393 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
394 | "Unknown target of the private message\n"); | ||
395 | GNUNET_break (0); | ||
396 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
397 | GNUNET_free (rnmsg); | ||
398 | return; | ||
399 | } | ||
400 | if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (&key, | ||
401 | sizeof (struct GNUNET_CRYPTO_AesSessionKey), | ||
402 | &target->public_key, | ||
403 | &rnmsg->encrypted_key)) | ||
404 | { | ||
405 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
406 | "Could not encrypt the session key\n"); | ||
407 | GNUNET_break (0); | ||
408 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
409 | GNUNET_free (rnmsg); | ||
410 | return; | ||
411 | } | ||
412 | } | 381 | } |
413 | else | 382 | memcpy (&rnmsg[1], encrypted_msg, msg_len); |
383 | target = client_list_head; | ||
384 | while ((NULL != target) && | ||
385 | (0 != memcmp (&target->id, | ||
386 | &trmsg->target, sizeof (GNUNET_HashCode)))) | ||
387 | target = target->next; | ||
388 | if (NULL == target) | ||
414 | { | 389 | { |
415 | memcpy (&rnmsg[1], &trmsg[1], msg_len); | 390 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
391 | "Unknown target of the private message\n"); | ||
392 | GNUNET_break (0); | ||
393 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
394 | GNUNET_free (rnmsg); | ||
395 | return; | ||
416 | } | 396 | } |
397 | if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (&key, | ||
398 | sizeof (struct | ||
399 | GNUNET_CRYPTO_AesSessionKey), | ||
400 | &target->public_key, | ||
401 | &rnmsg->encrypted_key)) | ||
402 | { | ||
403 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
404 | "Could not encrypt the session key\n"); | ||
405 | GNUNET_break (0); | ||
406 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
407 | GNUNET_free (rnmsg); | ||
408 | return; | ||
409 | } | ||
410 | } | ||
411 | else | ||
412 | { | ||
413 | memcpy (&rnmsg[1], &trmsg[1], msg_len); | ||
414 | } | ||
417 | pos = client_list_head; | 415 | pos = client_list_head; |
418 | #if DEBUG_CHAT_SERVICE | 416 | #if DEBUG_CHAT_SERVICE |
419 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message to local room members\n"); | 417 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
418 | "Sending message to local room members\n"); | ||
420 | #endif | 419 | #endif |
421 | while (NULL != pos) | 420 | while (NULL != pos) |
421 | { | ||
422 | if ((0 == strcmp (room, pos->room)) && | ||
423 | (NULL != pos->client) && (pos->client != client)) | ||
422 | { | 424 | { |
423 | if ((0 == strcmp (room, pos->room)) && | 425 | if (((!is_priv) || |
424 | (NULL != pos->client) && | 426 | (0 == memcmp (&trmsg->target, |
425 | (pos->client != client)) | 427 | &pos->id, |
426 | { | 428 | sizeof (GNUNET_HashCode)))) && |
427 | if (((!is_priv) || | 429 | (0 == (ntohl (trmsg->msg_options) & (~pos->msg_options)))) |
428 | (0 == memcmp (&trmsg->target, | 430 | { |
429 | &pos->id, | 431 | GNUNET_SERVER_notification_context_unicast (nc, |
430 | sizeof (GNUNET_HashCode)))) && | 432 | pos->client, |
431 | (0 == (ntohl (trmsg->msg_options) & (~pos->msg_options)))) | 433 | &rnmsg->header, GNUNET_NO); |
432 | { | 434 | } |
433 | GNUNET_SERVER_notification_context_unicast (nc, | ||
434 | pos->client, | ||
435 | &rnmsg->header, | ||
436 | GNUNET_NO); | ||
437 | } | ||
438 | } | ||
439 | pos = pos->next; | ||
440 | } | 435 | } |
436 | pos = pos->next; | ||
437 | } | ||
441 | #if DEBUG_CHAT_SERVICE | 438 | #if DEBUG_CHAT_SERVICE |
442 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 439 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
443 | "Broadcasting message to neighbour peers\n"); | 440 | "Broadcasting message to neighbour peers\n"); |
444 | #endif | 441 | #endif |
445 | if (is_anon) | 442 | if (is_anon) |
446 | { | 443 | { |
447 | room_len = strlen (room); | 444 | room_len = strlen (room); |
448 | p2p_rnmsg = GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) + | 445 | p2p_rnmsg = GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) + |
449 | msg_len + room_len); | 446 | msg_len + room_len); |
450 | p2p_rnmsg->header.size = | 447 | p2p_rnmsg->header.size = |
451 | htons (sizeof (struct P2PReceiveNotificationMessage) + msg_len + | 448 | htons (sizeof (struct P2PReceiveNotificationMessage) + msg_len + |
452 | room_len); | 449 | room_len); |
453 | p2p_rnmsg->room_name_len = htons (room_len); | 450 | p2p_rnmsg->room_name_len = htons (room_len); |
454 | memcpy ((char *) &p2p_rnmsg[1], room, room_len); | 451 | memcpy ((char *) &p2p_rnmsg[1], room, room_len); |
455 | memcpy ((char *) &p2p_rnmsg[1] + room_len, &trmsg[1], msg_len); | 452 | memcpy ((char *) &p2p_rnmsg[1] + room_len, &trmsg[1], msg_len); |
456 | } | 453 | } |
457 | else | 454 | else |
458 | { | 455 | { |
459 | p2p_rnmsg = GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) + | 456 | p2p_rnmsg = GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) + |
460 | msg_len); | 457 | msg_len); |
461 | p2p_rnmsg->header.size = | 458 | p2p_rnmsg->header.size = |
462 | htons (sizeof (struct P2PReceiveNotificationMessage) + msg_len); | 459 | htons (sizeof (struct P2PReceiveNotificationMessage) + msg_len); |
463 | if (is_priv) | 460 | if (is_priv) |
464 | { | 461 | { |
465 | memcpy (&p2p_rnmsg[1], encrypted_msg, msg_len); | 462 | memcpy (&p2p_rnmsg[1], encrypted_msg, msg_len); |
466 | memcpy (&p2p_rnmsg->encrypted_key, | 463 | memcpy (&p2p_rnmsg->encrypted_key, |
467 | &rnmsg->encrypted_key, | 464 | &rnmsg->encrypted_key, |
468 | sizeof (struct GNUNET_CRYPTO_RsaEncryptedData)); | 465 | sizeof (struct GNUNET_CRYPTO_RsaEncryptedData)); |
469 | } | 466 | } |
470 | else | 467 | else |
471 | memcpy (&p2p_rnmsg[1], &trmsg[1], msg_len); | 468 | memcpy (&p2p_rnmsg[1], &trmsg[1], msg_len); |
472 | } | 469 | } |
473 | p2p_rnmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_P2P_MESSAGE_NOTIFICATION); | 470 | p2p_rnmsg->header.type = |
471 | htons (GNUNET_MESSAGE_TYPE_CHAT_P2P_MESSAGE_NOTIFICATION); | ||
474 | p2p_rnmsg->msg_options = trmsg->msg_options; | 472 | p2p_rnmsg->msg_options = trmsg->msg_options; |
475 | p2p_rnmsg->sequence_number = trmsg->sequence_number; | 473 | p2p_rnmsg->sequence_number = trmsg->sequence_number; |
476 | p2p_rnmsg->timestamp = trmsg->timestamp; | 474 | p2p_rnmsg->timestamp = trmsg->timestamp; |
@@ -480,8 +478,7 @@ handle_transmit_request (void *cls, | |||
480 | if (is_anon) | 478 | if (is_anon) |
481 | remember_anonymous_message (p2p_rnmsg); | 479 | remember_anonymous_message (p2p_rnmsg); |
482 | GNUNET_CONTAINER_multihashmap_iterate (connected_peers, | 480 | GNUNET_CONTAINER_multihashmap_iterate (connected_peers, |
483 | &send_message_noficiation, | 481 | &send_message_noficiation, p2p_rnmsg); |
484 | p2p_rnmsg); | ||
485 | GNUNET_free (p2p_rnmsg); | 482 | GNUNET_free (p2p_rnmsg); |
486 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 483 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
487 | GNUNET_free (rnmsg); | 484 | GNUNET_free (rnmsg); |
@@ -497,9 +494,7 @@ handle_transmit_request (void *cls, | |||
497 | * @return number of bytes written to buf | 494 | * @return number of bytes written to buf |
498 | */ | 495 | */ |
499 | static size_t | 496 | static size_t |
500 | transmit_join_notification_to_peer (void *cls, | 497 | transmit_join_notification_to_peer (void *cls, size_t size, void *buf) |
501 | size_t size, | ||
502 | void *buf) | ||
503 | { | 498 | { |
504 | struct ChatClient *entry = cls; | 499 | struct ChatClient *entry = cls; |
505 | struct P2PJoinNotificationMessage *m = buf; | 500 | struct P2PJoinNotificationMessage *m = buf; |
@@ -509,8 +504,7 @@ transmit_join_notification_to_peer (void *cls, | |||
509 | char *roomptr; | 504 | char *roomptr; |
510 | 505 | ||
511 | #if DEBUG_CHAT_SERVICE | 506 | #if DEBUG_CHAT_SERVICE |
512 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 507 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting P2P join notification\n"); |
513 | "Transmitting P2P join notification\n"); | ||
514 | #endif | 508 | #endif |
515 | room_len = strlen (entry->room); | 509 | room_len = strlen (entry->room); |
516 | meta_len = entry->meta_len; | 510 | meta_len = entry->meta_len; |
@@ -537,9 +531,7 @@ transmit_join_notification_to_peer (void *cls, | |||
537 | * Ask to send a join notification to the peer. | 531 | * Ask to send a join notification to the peer. |
538 | */ | 532 | */ |
539 | static int | 533 | static int |
540 | send_join_noficiation (void *cls, | 534 | send_join_noficiation (void *cls, const GNUNET_HashCode * key, void *value) |
541 | const GNUNET_HashCode *key, | ||
542 | void *value) | ||
543 | { | 535 | { |
544 | struct ChatClient *entry = cls; | 536 | struct ChatClient *entry = cls; |
545 | struct ConnectedPeer *cp = value; | 537 | struct ConnectedPeer *cp = value; |
@@ -552,10 +544,9 @@ send_join_noficiation (void *cls, | |||
552 | "Sending join notification to `%s'\n", GNUNET_i2s (&pid)); | 544 | "Sending join notification to `%s'\n", GNUNET_i2s (&pid)); |
553 | #endif | 545 | #endif |
554 | msg_size = sizeof (struct P2PJoinNotificationMessage) + | 546 | msg_size = sizeof (struct P2PJoinNotificationMessage) + |
555 | strlen (entry->room) + | 547 | strlen (entry->room) + entry->meta_len; |
556 | entry->meta_len; | ||
557 | if (NULL == GNUNET_CORE_notify_transmit_ready (core, | 548 | if (NULL == GNUNET_CORE_notify_transmit_ready (core, |
558 | GNUNET_NO, | 549 | GNUNET_NO, |
559 | 1, | 550 | 1, |
560 | MAX_TRANSMIT_DELAY, | 551 | MAX_TRANSMIT_DELAY, |
561 | &pid, | 552 | &pid, |
@@ -594,26 +585,24 @@ handle_join_request (void *cls, | |||
594 | 585 | ||
595 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Client sent a join request\n"); | 586 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Client sent a join request\n"); |
596 | if (ntohs (message->size) <= sizeof (struct JoinRequestMessage)) | 587 | if (ntohs (message->size) <= sizeof (struct JoinRequestMessage)) |
597 | { | 588 | { |
598 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n"); | 589 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n"); |
599 | GNUNET_break (0); | 590 | GNUNET_break (0); |
600 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 591 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
601 | return; | 592 | return; |
602 | } | 593 | } |
603 | jrmsg = (const struct JoinRequestMessage *) message; | 594 | jrmsg = (const struct JoinRequestMessage *) message; |
604 | header_size = ntohs (jrmsg->header.size); | 595 | header_size = ntohs (jrmsg->header.size); |
605 | room_name_len = ntohs (jrmsg->room_name_len); | 596 | room_name_len = ntohs (jrmsg->room_name_len); |
606 | if (header_size - sizeof (struct JoinRequestMessage) <= | 597 | if (header_size - sizeof (struct JoinRequestMessage) <= room_name_len) |
607 | room_name_len) | 598 | { |
608 | { | 599 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
609 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 600 | "Malformed message: wrong length of the room name\n"); |
610 | "Malformed message: wrong length of the room name\n"); | 601 | GNUNET_break (0); |
611 | GNUNET_break (0); | 602 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
612 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 603 | return; |
613 | return; | 604 | } |
614 | } | 605 | meta_len = header_size - sizeof (struct JoinRequestMessage) - room_name_len; |
615 | meta_len = | ||
616 | header_size - sizeof (struct JoinRequestMessage) - room_name_len; | ||
617 | roomptr = (const char *) &jrmsg[1]; | 606 | roomptr = (const char *) &jrmsg[1]; |
618 | room_name = GNUNET_malloc (room_name_len + 1); | 607 | room_name = GNUNET_malloc (room_name_len + 1); |
619 | memcpy (room_name, roomptr, room_name_len); | 608 | memcpy (room_name, roomptr, room_name_len); |
@@ -625,10 +614,10 @@ handle_join_request (void *cls, | |||
625 | new_entry->public_key = jrmsg->public_key; | 614 | new_entry->public_key = jrmsg->public_key; |
626 | new_entry->meta_len = meta_len; | 615 | new_entry->meta_len = meta_len; |
627 | if (meta_len > 0) | 616 | if (meta_len > 0) |
628 | { | 617 | { |
629 | new_entry->member_info = GNUNET_malloc (meta_len); | 618 | new_entry->member_info = GNUNET_malloc (meta_len); |
630 | memcpy (new_entry->member_info, &roomptr[room_name_len], meta_len); | 619 | memcpy (new_entry->member_info, &roomptr[room_name_len], meta_len); |
631 | } | 620 | } |
632 | else | 621 | else |
633 | new_entry->member_info = NULL; | 622 | new_entry->member_info = NULL; |
634 | GNUNET_CRYPTO_hash (&new_entry->public_key, | 623 | GNUNET_CRYPTO_hash (&new_entry->public_key, |
@@ -644,50 +633,47 @@ handle_join_request (void *cls, | |||
644 | jnmsg = GNUNET_malloc (sizeof (struct JoinNotificationMessage) + meta_len); | 633 | jnmsg = GNUNET_malloc (sizeof (struct JoinNotificationMessage) + meta_len); |
645 | jnmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION); | 634 | jnmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION); |
646 | jnmsg->header.size = | 635 | jnmsg->header.size = |
647 | htons (sizeof (struct JoinNotificationMessage) + meta_len); | 636 | htons (sizeof (struct JoinNotificationMessage) + meta_len); |
648 | jnmsg->msg_options = jrmsg->msg_options; | 637 | jnmsg->msg_options = jrmsg->msg_options; |
649 | jnmsg->public_key = new_entry->public_key; | 638 | jnmsg->public_key = new_entry->public_key; |
650 | memcpy (&jnmsg[1], &roomptr[room_name_len], meta_len); | 639 | memcpy (&jnmsg[1], &roomptr[room_name_len], meta_len); |
651 | GNUNET_SERVER_notification_context_add (nc, client); | 640 | GNUNET_SERVER_notification_context_add (nc, client); |
652 | entry = client_list_head; | 641 | entry = client_list_head; |
653 | while (NULL != entry) | 642 | while (NULL != entry) |
643 | { | ||
644 | if (0 == strcmp (room_name, entry->room)) | ||
654 | { | 645 | { |
655 | if (0 == strcmp (room_name, entry->room)) | 646 | if (NULL != entry->client) |
656 | { | 647 | GNUNET_SERVER_notification_context_unicast (nc, |
657 | if (NULL != entry->client) | 648 | entry->client, |
658 | GNUNET_SERVER_notification_context_unicast (nc, | 649 | &jnmsg->header, GNUNET_NO); |
659 | entry->client, | 650 | if (entry->client != client) |
660 | &jnmsg->header, | 651 | { |
661 | GNUNET_NO); | 652 | entry_jnmsg = |
662 | if (entry->client != client) | 653 | GNUNET_malloc (sizeof (struct JoinNotificationMessage) + |
663 | { | 654 | entry->meta_len); |
664 | entry_jnmsg = | 655 | entry_jnmsg->header.type = |
665 | GNUNET_malloc (sizeof (struct JoinNotificationMessage) + | 656 | htons (GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION); |
666 | entry->meta_len); | 657 | entry_jnmsg->header.size = |
667 | entry_jnmsg->header.type = | 658 | htons (sizeof (struct JoinNotificationMessage) + entry->meta_len); |
668 | htons (GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION); | 659 | entry_jnmsg->msg_options = entry->msg_options; |
669 | entry_jnmsg->header.size = | 660 | entry_jnmsg->public_key = entry->public_key; |
670 | htons (sizeof (struct JoinNotificationMessage) + | 661 | memcpy (&entry_jnmsg[1], entry->member_info, entry->meta_len); |
671 | entry->meta_len); | 662 | GNUNET_SERVER_notification_context_unicast (nc, |
672 | entry_jnmsg->msg_options = entry->msg_options; | 663 | client, |
673 | entry_jnmsg->public_key = entry->public_key; | 664 | &entry_jnmsg->header, |
674 | memcpy (&entry_jnmsg[1], entry->member_info, entry->meta_len); | 665 | GNUNET_NO); |
675 | GNUNET_SERVER_notification_context_unicast (nc, | 666 | GNUNET_free (entry_jnmsg); |
676 | client, | 667 | } |
677 | &entry_jnmsg->header, | ||
678 | GNUNET_NO); | ||
679 | GNUNET_free (entry_jnmsg); | ||
680 | } | ||
681 | } | ||
682 | entry = entry->next; | ||
683 | } | 668 | } |
669 | entry = entry->next; | ||
670 | } | ||
684 | #if DEBUG_CHAT_SERVICE | 671 | #if DEBUG_CHAT_SERVICE |
685 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 672 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
686 | "Broadcasting join notification to neighbour peers\n"); | 673 | "Broadcasting join notification to neighbour peers\n"); |
687 | #endif | 674 | #endif |
688 | GNUNET_CONTAINER_multihashmap_iterate (connected_peers, | 675 | GNUNET_CONTAINER_multihashmap_iterate (connected_peers, |
689 | &send_join_noficiation, | 676 | &send_join_noficiation, new_entry); |
690 | new_entry); | ||
691 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 677 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
692 | GNUNET_free (jnmsg); | 678 | GNUNET_free (jnmsg); |
693 | } | 679 | } |
@@ -701,9 +687,7 @@ handle_join_request (void *cls, | |||
701 | * @return number of bytes written to buf | 687 | * @return number of bytes written to buf |
702 | */ | 688 | */ |
703 | static size_t | 689 | static size_t |
704 | transmit_confirmation_receipt_to_peer (void *cls, | 690 | transmit_confirmation_receipt_to_peer (void *cls, size_t size, void *buf) |
705 | size_t size, | ||
706 | void *buf) | ||
707 | { | 691 | { |
708 | struct P2PConfirmationReceiptMessage *receipt = cls; | 692 | struct P2PConfirmationReceiptMessage *receipt = cls; |
709 | size_t msg_size; | 693 | size_t msg_size; |
@@ -714,14 +698,14 @@ transmit_confirmation_receipt_to_peer (void *cls, | |||
714 | GNUNET_h2s (&receipt->target)); | 698 | GNUNET_h2s (&receipt->target)); |
715 | #endif | 699 | #endif |
716 | if (buf == NULL) | 700 | if (buf == NULL) |
717 | { | 701 | { |
718 | /* client disconnected */ | 702 | /* client disconnected */ |
719 | #if DEBUG_CHAT_SERVICE | 703 | #if DEBUG_CHAT_SERVICE |
720 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 704 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
721 | "Buffer is NULL, dropping the message\n"); | 705 | "Buffer is NULL, dropping the message\n"); |
722 | #endif | 706 | #endif |
723 | return 0; | 707 | return 0; |
724 | } | 708 | } |
725 | msg_size = sizeof (struct P2PConfirmationReceiptMessage); | 709 | msg_size = sizeof (struct P2PConfirmationReceiptMessage); |
726 | GNUNET_assert (size >= msg_size); | 710 | GNUNET_assert (size >= msg_size); |
727 | memcpy (buf, receipt, msg_size); | 711 | memcpy (buf, receipt, msg_size); |
@@ -734,9 +718,7 @@ transmit_confirmation_receipt_to_peer (void *cls, | |||
734 | * Ask to send a confirmation receipt to the peer. | 718 | * Ask to send a confirmation receipt to the peer. |
735 | */ | 719 | */ |
736 | static int | 720 | static int |
737 | send_confirmation_receipt (void *cls, | 721 | send_confirmation_receipt (void *cls, const GNUNET_HashCode * key, void *value) |
738 | const GNUNET_HashCode *key, | ||
739 | void *value) | ||
740 | { | 722 | { |
741 | struct P2PConfirmationReceiptMessage *receipt = cls; | 723 | struct P2PConfirmationReceiptMessage *receipt = cls; |
742 | struct ConnectedPeer *cp = value; | 724 | struct ConnectedPeer *cp = value; |
@@ -753,7 +735,7 @@ send_confirmation_receipt (void *cls, | |||
753 | my_receipt = GNUNET_memdup (receipt, | 735 | my_receipt = GNUNET_memdup (receipt, |
754 | sizeof (struct P2PConfirmationReceiptMessage)); | 736 | sizeof (struct P2PConfirmationReceiptMessage)); |
755 | if (NULL == GNUNET_CORE_notify_transmit_ready (core, | 737 | if (NULL == GNUNET_CORE_notify_transmit_ready (core, |
756 | GNUNET_YES, | 738 | GNUNET_YES, |
757 | 1, | 739 | 1, |
758 | MAX_TRANSMIT_DELAY, | 740 | MAX_TRANSMIT_DELAY, |
759 | &pid, | 741 | &pid, |
@@ -791,86 +773,84 @@ handle_acknowledge_request (void *cls, | |||
791 | author = client_list_head; | 773 | author = client_list_head; |
792 | while ((NULL != author) && | 774 | while ((NULL != author) && |
793 | (0 != memcmp (&receipt->author, | 775 | (0 != memcmp (&receipt->author, |
794 | &author->id, | 776 | &author->id, sizeof (GNUNET_HashCode)))) |
795 | sizeof (GNUNET_HashCode)))) | ||
796 | author = author->next; | 777 | author = author->next; |
797 | if (NULL == author) | 778 | if (NULL == author) |
798 | { | 779 | { |
799 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 780 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
800 | "Unknown author of the original message\n"); | 781 | "Unknown author of the original message\n"); |
801 | GNUNET_break (0); | 782 | GNUNET_break (0); |
802 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 783 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
803 | return; | 784 | return; |
804 | } | 785 | } |
805 | target = client_list_head; | 786 | target = client_list_head; |
806 | while ((NULL != target) && | 787 | while ((NULL != target) && |
807 | (0 != memcmp (&receipt->target, | 788 | (0 != memcmp (&receipt->target, |
808 | &target->id, | 789 | &target->id, sizeof (GNUNET_HashCode)))) |
809 | sizeof (GNUNET_HashCode)))) | ||
810 | target = target->next; | 790 | target = target->next; |
811 | if (NULL == target) | 791 | if (NULL == target) |
812 | { | 792 | { |
813 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 793 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
814 | "Unknown target of the confirmation receipt\n"); | 794 | "Unknown target of the confirmation receipt\n"); |
815 | GNUNET_break (0); | 795 | GNUNET_break (0); |
816 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 796 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
817 | return; | 797 | return; |
818 | } | 798 | } |
819 | if (NULL == author->client) | 799 | if (NULL == author->client) |
820 | { | 800 | { |
821 | target->rcpt_sequence_number++; | 801 | target->rcpt_sequence_number++; |
822 | #if DEBUG_CHAT_SERVICE | 802 | #if DEBUG_CHAT_SERVICE |
823 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 803 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
824 | "Broadcasting %s's receipt #%u to neighbour peers\n", | 804 | "Broadcasting %s's receipt #%u to neighbour peers\n", |
825 | GNUNET_h2s (&target->id), target->rcpt_sequence_number); | 805 | GNUNET_h2s (&target->id), target->rcpt_sequence_number); |
826 | #endif | 806 | #endif |
827 | p2p_crmsg = GNUNET_malloc (sizeof (struct P2PConfirmationReceiptMessage)); | 807 | p2p_crmsg = GNUNET_malloc (sizeof (struct P2PConfirmationReceiptMessage)); |
828 | p2p_crmsg->header.size = htons (sizeof (struct P2PConfirmationReceiptMessage)); | 808 | p2p_crmsg->header.size = |
829 | p2p_crmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_P2P_CONFIRMATION_RECEIPT); | 809 | htons (sizeof (struct P2PConfirmationReceiptMessage)); |
830 | p2p_crmsg->reserved = htonl (0); | 810 | p2p_crmsg->header.type = |
831 | p2p_crmsg->signature = receipt->signature; | 811 | htons (GNUNET_MESSAGE_TYPE_CHAT_P2P_CONFIRMATION_RECEIPT); |
832 | p2p_crmsg->purpose = receipt->purpose; | 812 | p2p_crmsg->reserved = htonl (0); |
833 | p2p_crmsg->msg_sequence_number = receipt->sequence_number; | 813 | p2p_crmsg->signature = receipt->signature; |
834 | p2p_crmsg->timestamp = receipt->timestamp; | 814 | p2p_crmsg->purpose = receipt->purpose; |
835 | p2p_crmsg->target = receipt->target; | 815 | p2p_crmsg->msg_sequence_number = receipt->sequence_number; |
836 | p2p_crmsg->author = receipt->author; | 816 | p2p_crmsg->timestamp = receipt->timestamp; |
837 | p2p_crmsg->content = receipt->content; | 817 | p2p_crmsg->target = receipt->target; |
838 | p2p_crmsg->sequence_number = htonl (target->rcpt_sequence_number); | 818 | p2p_crmsg->author = receipt->author; |
839 | GNUNET_CONTAINER_multihashmap_iterate (connected_peers, | 819 | p2p_crmsg->content = receipt->content; |
840 | &send_confirmation_receipt, | 820 | p2p_crmsg->sequence_number = htonl (target->rcpt_sequence_number); |
841 | p2p_crmsg); | 821 | GNUNET_CONTAINER_multihashmap_iterate (connected_peers, |
842 | GNUNET_free (p2p_crmsg); | 822 | &send_confirmation_receipt, |
843 | } | 823 | p2p_crmsg); |
824 | GNUNET_free (p2p_crmsg); | ||
825 | } | ||
844 | else | 826 | else |
845 | { | 827 | { |
846 | #if DEBUG_CHAT_SERVICE | 828 | #if DEBUG_CHAT_SERVICE |
847 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 829 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
848 | "Verifying signature of the receipt\n"); | 830 | "Verifying signature of the receipt\n"); |
849 | #endif | 831 | #endif |
850 | if (GNUNET_OK != | 832 | if (GNUNET_OK != |
851 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT, | 833 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT, |
852 | &receipt->purpose, | 834 | &receipt->purpose, |
853 | &receipt->signature, | 835 | &receipt->signature, &target->public_key)) |
854 | &target->public_key)) | 836 | { |
855 | { | 837 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
856 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 838 | "Invalid signature of the receipt\n"); |
857 | "Invalid signature of the receipt\n"); | 839 | GNUNET_break (0); |
858 | GNUNET_break (0); | 840 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
859 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 841 | return; |
860 | return; | 842 | } |
861 | } | ||
862 | #if DEBUG_CHAT_SERVICE | 843 | #if DEBUG_CHAT_SERVICE |
863 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 844 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
864 | "Sending receipt to the client which sent the original message\n"); | 845 | "Sending receipt to the client which sent the original message\n"); |
865 | #endif | 846 | #endif |
866 | crmsg = GNUNET_memdup (receipt, sizeof (struct ConfirmationReceiptMessage)); | 847 | crmsg = GNUNET_memdup (receipt, sizeof (struct ConfirmationReceiptMessage)); |
867 | crmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION); | 848 | crmsg->header.type = |
868 | GNUNET_SERVER_notification_context_unicast (nc, | 849 | htons (GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION); |
869 | author->client, | 850 | GNUNET_SERVER_notification_context_unicast (nc, author->client, |
870 | &crmsg->header, | 851 | &crmsg->header, GNUNET_NO); |
871 | GNUNET_NO); | 852 | GNUNET_free (crmsg); |
872 | GNUNET_free (crmsg); | 853 | } |
873 | } | ||
874 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 854 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
875 | } | 855 | } |
876 | 856 | ||
@@ -885,27 +865,24 @@ handle_acknowledge_request (void *cls, | |||
885 | * @return number of bytes written to buf | 865 | * @return number of bytes written to buf |
886 | */ | 866 | */ |
887 | static size_t | 867 | static size_t |
888 | transmit_leave_notification_to_peer (void *cls, | 868 | transmit_leave_notification_to_peer (void *cls, size_t size, void *buf) |
889 | size_t size, | ||
890 | void *buf) | ||
891 | { | 869 | { |
892 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key = cls; | 870 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key = cls; |
893 | struct P2PLeaveNotificationMessage *m = buf; | 871 | struct P2PLeaveNotificationMessage *m = buf; |
894 | size_t msg_size; | 872 | size_t msg_size; |
895 | 873 | ||
896 | #if DEBUG_CHAT_SERVICE | 874 | #if DEBUG_CHAT_SERVICE |
897 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 875 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting P2P leave notification\n"); |
898 | "Transmitting P2P leave notification\n"); | ||
899 | #endif | 876 | #endif |
900 | if (buf == NULL) | 877 | if (buf == NULL) |
901 | { | 878 | { |
902 | /* client disconnected */ | 879 | /* client disconnected */ |
903 | #if DEBUG_CHAT_SERVICE | 880 | #if DEBUG_CHAT_SERVICE |
904 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 881 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
905 | "Buffer is NULL, dropping the message\n"); | 882 | "Buffer is NULL, dropping the message\n"); |
906 | #endif | 883 | #endif |
907 | return 0; | 884 | return 0; |
908 | } | 885 | } |
909 | msg_size = sizeof (struct P2PLeaveNotificationMessage); | 886 | msg_size = sizeof (struct P2PLeaveNotificationMessage); |
910 | GNUNET_assert (size >= msg_size); | 887 | GNUNET_assert (size >= msg_size); |
911 | m = buf; | 888 | m = buf; |
@@ -922,9 +899,7 @@ transmit_leave_notification_to_peer (void *cls, | |||
922 | * Ask to send a leave notification to the peer. | 899 | * Ask to send a leave notification to the peer. |
923 | */ | 900 | */ |
924 | static int | 901 | static int |
925 | send_leave_noficiation (void *cls, | 902 | send_leave_noficiation (void *cls, const GNUNET_HashCode * key, void *value) |
926 | const GNUNET_HashCode *key, | ||
927 | void *value) | ||
928 | { | 903 | { |
929 | struct ChatClient *entry = cls; | 904 | struct ChatClient *entry = cls; |
930 | struct ConnectedPeer *cp = value; | 905 | struct ConnectedPeer *cp = value; |
@@ -939,15 +914,13 @@ send_leave_noficiation (void *cls, | |||
939 | #endif | 914 | #endif |
940 | msg_size = sizeof (struct P2PLeaveNotificationMessage); | 915 | msg_size = sizeof (struct P2PLeaveNotificationMessage); |
941 | public_key = GNUNET_memdup (&entry->public_key, | 916 | public_key = GNUNET_memdup (&entry->public_key, |
942 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | 917 | sizeof (struct |
943 | if (NULL == GNUNET_CORE_notify_transmit_ready (core, | 918 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); |
944 | GNUNET_YES, | 919 | if (NULL == |
945 | 1, | 920 | GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES, 1, |
946 | MAX_TRANSMIT_DELAY, | 921 | MAX_TRANSMIT_DELAY, &pid, msg_size, |
947 | &pid, | 922 | &transmit_leave_notification_to_peer, |
948 | msg_size, | 923 | public_key)) |
949 | &transmit_leave_notification_to_peer, | ||
950 | public_key)) | ||
951 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 924 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
952 | _("Failed to queue a leave notification\n")); | 925 | _("Failed to queue a leave notification\n")); |
953 | return GNUNET_YES; | 926 | return GNUNET_YES; |
@@ -962,8 +935,7 @@ send_leave_noficiation (void *cls, | |||
962 | * @param client identification of the client | 935 | * @param client identification of the client |
963 | */ | 936 | */ |
964 | static void | 937 | static void |
965 | handle_client_disconnect (void *cls, | 938 | handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) |
966 | struct GNUNET_SERVER_Client *client) | ||
967 | { | 939 | { |
968 | struct ChatClient *entry; | 940 | struct ChatClient *entry; |
969 | struct ChatClient *pos; | 941 | struct ChatClient *pos; |
@@ -974,18 +946,18 @@ handle_client_disconnect (void *cls, | |||
974 | pos = client_list_head; | 946 | pos = client_list_head; |
975 | prev = NULL; | 947 | prev = NULL; |
976 | while ((NULL != pos) && (pos->client != client)) | 948 | while ((NULL != pos) && (pos->client != client)) |
977 | { | 949 | { |
978 | prev = pos; | 950 | prev = pos; |
979 | pos = pos->next; | 951 | pos = pos->next; |
980 | } | 952 | } |
981 | if (NULL == pos) | 953 | if (NULL == pos) |
982 | { | 954 | { |
983 | #if DEBUG_CHAT_SERVICE | 955 | #if DEBUG_CHAT_SERVICE |
984 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 956 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
985 | "No such client. There is nothing to do\n"); | 957 | "No such client. There is nothing to do\n"); |
986 | #endif | 958 | #endif |
987 | return; | 959 | return; |
988 | } | 960 | } |
989 | if (NULL == prev) | 961 | if (NULL == prev) |
990 | client_list_head = pos->next; | 962 | client_list_head = pos->next; |
991 | else | 963 | else |
@@ -1000,24 +972,21 @@ handle_client_disconnect (void *cls, | |||
1000 | lnmsg.reserved = htonl (0); | 972 | lnmsg.reserved = htonl (0); |
1001 | lnmsg.user = pos->public_key; | 973 | lnmsg.user = pos->public_key; |
1002 | while (NULL != entry) | 974 | while (NULL != entry) |
975 | { | ||
976 | if ((0 == strcmp (pos->room, entry->room)) && (NULL != entry->client)) | ||
1003 | { | 977 | { |
1004 | if ((0 == strcmp (pos->room, entry->room)) && | 978 | GNUNET_SERVER_notification_context_unicast (nc, |
1005 | (NULL != entry->client)) | 979 | entry->client, |
1006 | { | 980 | &lnmsg.header, GNUNET_NO); |
1007 | GNUNET_SERVER_notification_context_unicast (nc, | ||
1008 | entry->client, | ||
1009 | &lnmsg.header, | ||
1010 | GNUNET_NO); | ||
1011 | } | ||
1012 | entry = entry->next; | ||
1013 | } | 981 | } |
982 | entry = entry->next; | ||
983 | } | ||
1014 | #if DEBUG_CHAT_SERVICE | 984 | #if DEBUG_CHAT_SERVICE |
1015 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 985 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1016 | "Broadcasting leave notification to neighbour peers\n"); | 986 | "Broadcasting leave notification to neighbour peers\n"); |
1017 | #endif | 987 | #endif |
1018 | GNUNET_CONTAINER_multihashmap_iterate (connected_peers, | 988 | GNUNET_CONTAINER_multihashmap_iterate (connected_peers, |
1019 | &send_leave_noficiation, | 989 | &send_leave_noficiation, pos); |
1020 | pos); | ||
1021 | GNUNET_free (pos->room); | 990 | GNUNET_free (pos->room); |
1022 | GNUNET_free_non_null (pos->member_info); | 991 | GNUNET_free_non_null (pos->member_info); |
1023 | GNUNET_free (pos); | 992 | GNUNET_free (pos); |
@@ -1038,7 +1007,8 @@ static int | |||
1038 | handle_p2p_join_notification (void *cls, | 1007 | handle_p2p_join_notification (void *cls, |
1039 | const struct GNUNET_PeerIdentity *other, | 1008 | const struct GNUNET_PeerIdentity *other, |
1040 | const struct GNUNET_MessageHeader *message, | 1009 | const struct GNUNET_MessageHeader *message, |
1041 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 1010 | const struct GNUNET_TRANSPORT_ATS_Information |
1011 | *atsi) | ||
1042 | { | 1012 | { |
1043 | const struct P2PJoinNotificationMessage *p2p_jnmsg; | 1013 | const struct P2PJoinNotificationMessage *p2p_jnmsg; |
1044 | char *room_name; | 1014 | char *room_name; |
@@ -1053,40 +1023,39 @@ handle_p2p_join_notification (void *cls, | |||
1053 | 1023 | ||
1054 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got P2P join notification\n"); | 1024 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got P2P join notification\n"); |
1055 | if (ntohs (message->size) <= sizeof (struct P2PJoinNotificationMessage)) | 1025 | if (ntohs (message->size) <= sizeof (struct P2PJoinNotificationMessage)) |
1056 | { | 1026 | { |
1057 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n"); | 1027 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n"); |
1058 | GNUNET_break_op (0); | 1028 | GNUNET_break_op (0); |
1059 | return GNUNET_SYSERR; | 1029 | return GNUNET_SYSERR; |
1060 | } | 1030 | } |
1061 | p2p_jnmsg = (const struct P2PJoinNotificationMessage *) message; | 1031 | p2p_jnmsg = (const struct P2PJoinNotificationMessage *) message; |
1062 | header_size = ntohs (p2p_jnmsg->header.size); | 1032 | header_size = ntohs (p2p_jnmsg->header.size); |
1063 | room_name_len = ntohs (p2p_jnmsg->room_name_len); | 1033 | room_name_len = ntohs (p2p_jnmsg->room_name_len); |
1064 | if (header_size - sizeof (struct P2PJoinNotificationMessage) <= | 1034 | if (header_size - sizeof (struct P2PJoinNotificationMessage) <= room_name_len) |
1065 | room_name_len) | 1035 | { |
1066 | { | 1036 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1067 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1037 | "Malformed message: wrong length of the room name\n"); |
1068 | "Malformed message: wrong length of the room name\n"); | 1038 | GNUNET_break_op (0); |
1069 | GNUNET_break_op (0); | 1039 | return GNUNET_SYSERR; |
1070 | return GNUNET_SYSERR; | 1040 | } |
1071 | } | ||
1072 | GNUNET_CRYPTO_hash (&p2p_jnmsg->public_key, | 1041 | GNUNET_CRYPTO_hash (&p2p_jnmsg->public_key, |
1073 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 1042 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
1074 | &id); | 1043 | &id); |
1075 | entry = client_list_head; | 1044 | entry = client_list_head; |
1076 | while (NULL != entry) | 1045 | while (NULL != entry) |
1046 | { | ||
1047 | if (0 == memcmp (&entry->id, &id, sizeof (GNUNET_HashCode))) | ||
1077 | { | 1048 | { |
1078 | if (0 == memcmp (&entry->id, &id, sizeof (GNUNET_HashCode))) | ||
1079 | { | ||
1080 | #if DEBUG_CHAT_SERVICE | 1049 | #if DEBUG_CHAT_SERVICE |
1081 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1050 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1082 | "The client has already joined. There is nothing to do\n"); | 1051 | "The client has already joined. There is nothing to do\n"); |
1083 | #endif | 1052 | #endif |
1084 | return GNUNET_OK; | 1053 | return GNUNET_OK; |
1085 | } | ||
1086 | entry = entry->next; | ||
1087 | } | 1054 | } |
1055 | entry = entry->next; | ||
1056 | } | ||
1088 | meta_len = | 1057 | meta_len = |
1089 | header_size - sizeof (struct P2PJoinNotificationMessage) - room_name_len; | 1058 | header_size - sizeof (struct P2PJoinNotificationMessage) - room_name_len; |
1090 | roomptr = (const char *) &p2p_jnmsg[1]; | 1059 | roomptr = (const char *) &p2p_jnmsg[1]; |
1091 | room_name = GNUNET_malloc (room_name_len + 1); | 1060 | room_name = GNUNET_malloc (room_name_len + 1); |
1092 | memcpy (room_name, roomptr, room_name_len); | 1061 | memcpy (room_name, roomptr, room_name_len); |
@@ -1099,10 +1068,10 @@ handle_p2p_join_notification (void *cls, | |||
1099 | new_entry->public_key = p2p_jnmsg->public_key; | 1068 | new_entry->public_key = p2p_jnmsg->public_key; |
1100 | new_entry->meta_len = meta_len; | 1069 | new_entry->meta_len = meta_len; |
1101 | if (meta_len > 0) | 1070 | if (meta_len > 0) |
1102 | { | 1071 | { |
1103 | new_entry->member_info = GNUNET_malloc (meta_len); | 1072 | new_entry->member_info = GNUNET_malloc (meta_len); |
1104 | memcpy (new_entry->member_info, &roomptr[room_name_len], meta_len); | 1073 | memcpy (new_entry->member_info, &roomptr[room_name_len], meta_len); |
1105 | } | 1074 | } |
1106 | else | 1075 | else |
1107 | new_entry->member_info = NULL; | 1076 | new_entry->member_info = NULL; |
1108 | new_entry->msg_options = ntohl (p2p_jnmsg->msg_options); | 1077 | new_entry->msg_options = ntohl (p2p_jnmsg->msg_options); |
@@ -1115,30 +1084,27 @@ handle_p2p_join_notification (void *cls, | |||
1115 | jnmsg = GNUNET_malloc (sizeof (struct JoinNotificationMessage) + meta_len); | 1084 | jnmsg = GNUNET_malloc (sizeof (struct JoinNotificationMessage) + meta_len); |
1116 | jnmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION); | 1085 | jnmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION); |
1117 | jnmsg->header.size = | 1086 | jnmsg->header.size = |
1118 | htons (sizeof (struct JoinNotificationMessage) + meta_len); | 1087 | htons (sizeof (struct JoinNotificationMessage) + meta_len); |
1119 | jnmsg->msg_options = p2p_jnmsg->msg_options; | 1088 | jnmsg->msg_options = p2p_jnmsg->msg_options; |
1120 | jnmsg->public_key = new_entry->public_key; | 1089 | jnmsg->public_key = new_entry->public_key; |
1121 | memcpy (&jnmsg[1], &roomptr[room_name_len], meta_len); | 1090 | memcpy (&jnmsg[1], &roomptr[room_name_len], meta_len); |
1122 | entry = client_list_head; | 1091 | entry = client_list_head; |
1123 | while (NULL != entry) | 1092 | while (NULL != entry) |
1093 | { | ||
1094 | if ((0 == strcmp (room_name, entry->room)) && (NULL != entry->client)) | ||
1124 | { | 1095 | { |
1125 | if ((0 == strcmp (room_name, entry->room)) && | 1096 | GNUNET_SERVER_notification_context_unicast (nc, |
1126 | (NULL != entry->client)) | 1097 | entry->client, |
1127 | { | 1098 | &jnmsg->header, GNUNET_NO); |
1128 | GNUNET_SERVER_notification_context_unicast (nc, | ||
1129 | entry->client, | ||
1130 | &jnmsg->header, | ||
1131 | GNUNET_NO); | ||
1132 | } | ||
1133 | entry = entry->next; | ||
1134 | } | 1099 | } |
1100 | entry = entry->next; | ||
1101 | } | ||
1135 | #if DEBUG_CHAT_SERVICE | 1102 | #if DEBUG_CHAT_SERVICE |
1136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1137 | "Broadcasting join notification to neighbour peers\n"); | 1104 | "Broadcasting join notification to neighbour peers\n"); |
1138 | #endif | 1105 | #endif |
1139 | GNUNET_CONTAINER_multihashmap_iterate (connected_peers, | 1106 | GNUNET_CONTAINER_multihashmap_iterate (connected_peers, |
1140 | &send_join_noficiation, | 1107 | &send_join_noficiation, new_entry); |
1141 | new_entry); | ||
1142 | GNUNET_free (jnmsg); | 1108 | GNUNET_free (jnmsg); |
1143 | return GNUNET_OK; | 1109 | return GNUNET_OK; |
1144 | } | 1110 | } |
@@ -1158,7 +1124,8 @@ static int | |||
1158 | handle_p2p_leave_notification (void *cls, | 1124 | handle_p2p_leave_notification (void *cls, |
1159 | const struct GNUNET_PeerIdentity *other, | 1125 | const struct GNUNET_PeerIdentity *other, |
1160 | const struct GNUNET_MessageHeader *message, | 1126 | const struct GNUNET_MessageHeader *message, |
1161 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 1127 | const struct GNUNET_TRANSPORT_ATS_Information |
1128 | *atsi) | ||
1162 | { | 1129 | { |
1163 | const struct P2PLeaveNotificationMessage *p2p_lnmsg; | 1130 | const struct P2PLeaveNotificationMessage *p2p_lnmsg; |
1164 | GNUNET_HashCode id; | 1131 | GNUNET_HashCode id; |
@@ -1175,20 +1142,20 @@ handle_p2p_leave_notification (void *cls, | |||
1175 | pos = client_list_head; | 1142 | pos = client_list_head; |
1176 | prev = NULL; | 1143 | prev = NULL; |
1177 | while (NULL != pos) | 1144 | while (NULL != pos) |
1178 | { | 1145 | { |
1179 | if (0 == memcmp (&pos->id, &id, sizeof (GNUNET_HashCode))) | 1146 | if (0 == memcmp (&pos->id, &id, sizeof (GNUNET_HashCode))) |
1180 | break; | 1147 | break; |
1181 | prev = pos; | 1148 | prev = pos; |
1182 | pos = pos->next; | 1149 | pos = pos->next; |
1183 | } | 1150 | } |
1184 | if (NULL == pos) | 1151 | if (NULL == pos) |
1185 | { | 1152 | { |
1186 | #if DEBUG_CHAT_SERVICE | 1153 | #if DEBUG_CHAT_SERVICE |
1187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1188 | "No such client. There is nothing to do\n"); | 1155 | "No such client. There is nothing to do\n"); |
1189 | #endif | 1156 | #endif |
1190 | return GNUNET_OK; | 1157 | return GNUNET_OK; |
1191 | } | 1158 | } |
1192 | if (NULL == prev) | 1159 | if (NULL == prev) |
1193 | client_list_head = pos->next; | 1160 | client_list_head = pos->next; |
1194 | else | 1161 | else |
@@ -1203,24 +1170,21 @@ handle_p2p_leave_notification (void *cls, | |||
1203 | lnmsg.user = pos->public_key; | 1170 | lnmsg.user = pos->public_key; |
1204 | entry = client_list_head; | 1171 | entry = client_list_head; |
1205 | while (NULL != entry) | 1172 | while (NULL != entry) |
1173 | { | ||
1174 | if (0 == strcmp (pos->room, entry->room) && (NULL != entry->client)) | ||
1206 | { | 1175 | { |
1207 | if (0 == strcmp (pos->room, entry->room) && | 1176 | GNUNET_SERVER_notification_context_unicast (nc, |
1208 | (NULL != entry->client)) | 1177 | entry->client, |
1209 | { | 1178 | &lnmsg.header, GNUNET_NO); |
1210 | GNUNET_SERVER_notification_context_unicast (nc, | ||
1211 | entry->client, | ||
1212 | &lnmsg.header, | ||
1213 | GNUNET_NO); | ||
1214 | } | ||
1215 | entry = entry->next; | ||
1216 | } | 1179 | } |
1180 | entry = entry->next; | ||
1181 | } | ||
1217 | #if DEBUG_CHAT_SERVICE | 1182 | #if DEBUG_CHAT_SERVICE |
1218 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1183 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1219 | "Broadcasting leave notification to neighbour peers\n"); | 1184 | "Broadcasting leave notification to neighbour peers\n"); |
1220 | #endif | 1185 | #endif |
1221 | GNUNET_CONTAINER_multihashmap_iterate (connected_peers, | 1186 | GNUNET_CONTAINER_multihashmap_iterate (connected_peers, |
1222 | &send_leave_noficiation, | 1187 | &send_leave_noficiation, pos); |
1223 | pos); | ||
1224 | GNUNET_free (pos->room); | 1188 | GNUNET_free (pos->room); |
1225 | GNUNET_free_non_null (pos->member_info); | 1189 | GNUNET_free_non_null (pos->member_info); |
1226 | GNUNET_free (pos); | 1190 | GNUNET_free (pos); |
@@ -1242,7 +1206,8 @@ static int | |||
1242 | handle_p2p_message_notification (void *cls, | 1206 | handle_p2p_message_notification (void *cls, |
1243 | const struct GNUNET_PeerIdentity *other, | 1207 | const struct GNUNET_PeerIdentity *other, |
1244 | const struct GNUNET_MessageHeader *message, | 1208 | const struct GNUNET_MessageHeader *message, |
1245 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 1209 | const struct GNUNET_TRANSPORT_ATS_Information |
1210 | *atsi) | ||
1246 | { | 1211 | { |
1247 | const struct P2PReceiveNotificationMessage *p2p_rnmsg; | 1212 | const struct P2PReceiveNotificationMessage *p2p_rnmsg; |
1248 | struct P2PReceiveNotificationMessage *my_p2p_rnmsg; | 1213 | struct P2PReceiveNotificationMessage *my_p2p_rnmsg; |
@@ -1259,74 +1224,73 @@ handle_p2p_message_notification (void *cls, | |||
1259 | 1224 | ||
1260 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got P2P message notification\n"); | 1225 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got P2P message notification\n"); |
1261 | if (ntohs (message->size) <= sizeof (struct P2PReceiveNotificationMessage)) | 1226 | if (ntohs (message->size) <= sizeof (struct P2PReceiveNotificationMessage)) |
1262 | { | 1227 | { |
1263 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n"); | 1228 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n"); |
1264 | GNUNET_break_op (0); | 1229 | GNUNET_break_op (0); |
1265 | return GNUNET_SYSERR; | 1230 | return GNUNET_SYSERR; |
1266 | } | 1231 | } |
1267 | p2p_rnmsg = (const struct P2PReceiveNotificationMessage *) message; | 1232 | p2p_rnmsg = (const struct P2PReceiveNotificationMessage *) message; |
1268 | msg_len = ntohs (p2p_rnmsg->header.size) - | 1233 | msg_len = ntohs (p2p_rnmsg->header.size) - |
1269 | sizeof (struct P2PReceiveNotificationMessage); | 1234 | sizeof (struct P2PReceiveNotificationMessage); |
1270 | 1235 | ||
1271 | is_anon = (0 != (ntohl (p2p_rnmsg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS)); | 1236 | is_anon = (0 != (ntohl (p2p_rnmsg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS)); |
1272 | if (is_anon) | 1237 | if (is_anon) |
1238 | { | ||
1239 | room_name_len = ntohs (p2p_rnmsg->room_name_len); | ||
1240 | if (msg_len <= room_name_len) | ||
1241 | { | ||
1242 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1243 | "Malformed message: wrong length of the room name\n"); | ||
1244 | GNUNET_break_op (0); | ||
1245 | return GNUNET_SYSERR; | ||
1246 | } | ||
1247 | msg_len -= room_name_len; | ||
1248 | if (lookup_anonymous_message (p2p_rnmsg)) | ||
1273 | { | 1249 | { |
1274 | room_name_len = ntohs (p2p_rnmsg->room_name_len); | ||
1275 | if (msg_len <= room_name_len) | ||
1276 | { | ||
1277 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1278 | "Malformed message: wrong length of the room name\n"); | ||
1279 | GNUNET_break_op (0); | ||
1280 | return GNUNET_SYSERR; | ||
1281 | } | ||
1282 | msg_len -= room_name_len; | ||
1283 | if (lookup_anonymous_message (p2p_rnmsg)) | ||
1284 | { | ||
1285 | #if DEBUG_CHAT_SERVICE | 1250 | #if DEBUG_CHAT_SERVICE |
1286 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1287 | "This anonymous message has already been handled."); | 1252 | "This anonymous message has already been handled."); |
1288 | #endif | 1253 | #endif |
1289 | return GNUNET_OK; | 1254 | return GNUNET_OK; |
1290 | } | ||
1291 | remember_anonymous_message (p2p_rnmsg); | ||
1292 | room_name = GNUNET_malloc (room_name_len + 1); | ||
1293 | memcpy (room_name, (char *) &p2p_rnmsg[1], room_name_len); | ||
1294 | room_name[room_name_len] = '\0'; | ||
1295 | text = (char *) &p2p_rnmsg[1] + room_name_len; | ||
1296 | } | 1255 | } |
1256 | remember_anonymous_message (p2p_rnmsg); | ||
1257 | room_name = GNUNET_malloc (room_name_len + 1); | ||
1258 | memcpy (room_name, (char *) &p2p_rnmsg[1], room_name_len); | ||
1259 | room_name[room_name_len] = '\0'; | ||
1260 | text = (char *) &p2p_rnmsg[1] + room_name_len; | ||
1261 | } | ||
1297 | else | 1262 | else |
1263 | { | ||
1264 | sender = client_list_head; | ||
1265 | while ((NULL != sender) && | ||
1266 | (0 != memcmp (&sender->id, | ||
1267 | &p2p_rnmsg->sender, sizeof (GNUNET_HashCode)))) | ||
1268 | sender = sender->next; | ||
1269 | if (NULL == sender) | ||
1298 | { | 1270 | { |
1299 | sender = client_list_head; | 1271 | /* not an error since the sender may have left before we got the |
1300 | while ((NULL != sender) && | 1272 | * message */ |
1301 | (0 != memcmp (&sender->id, | ||
1302 | &p2p_rnmsg->sender, | ||
1303 | sizeof (GNUNET_HashCode)))) | ||
1304 | sender = sender->next; | ||
1305 | if (NULL == sender) | ||
1306 | { | ||
1307 | /* not an error since the sender may have left before we got the | ||
1308 | message */ | ||
1309 | #if DEBUG_CHAT_SERVICE | 1273 | #if DEBUG_CHAT_SERVICE |
1310 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1311 | "Unknown source. Rejecting the message\n"); | 1275 | "Unknown source. Rejecting the message\n"); |
1312 | #endif | 1276 | #endif |
1313 | return GNUNET_OK; | 1277 | return GNUNET_OK; |
1314 | } | 1278 | } |
1315 | if (sender->msg_sequence_number >= ntohl (p2p_rnmsg->sequence_number)) | 1279 | if (sender->msg_sequence_number >= ntohl (p2p_rnmsg->sequence_number)) |
1316 | { | 1280 | { |
1317 | #if DEBUG_CHAT_SERVICE | 1281 | #if DEBUG_CHAT_SERVICE |
1318 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1282 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1319 | "This message has already been handled." | 1283 | "This message has already been handled." |
1320 | " Sequence numbers (msg/sender): %u/%u\n", | 1284 | " Sequence numbers (msg/sender): %u/%u\n", |
1321 | ntohl (p2p_rnmsg->sequence_number), | 1285 | ntohl (p2p_rnmsg->sequence_number), |
1322 | sender->msg_sequence_number); | 1286 | sender->msg_sequence_number); |
1323 | #endif | 1287 | #endif |
1324 | return GNUNET_OK; | 1288 | return GNUNET_OK; |
1325 | } | 1289 | } |
1326 | sender->msg_sequence_number = ntohl (p2p_rnmsg->sequence_number); | 1290 | sender->msg_sequence_number = ntohl (p2p_rnmsg->sequence_number); |
1327 | room_name = sender->room; | 1291 | room_name = sender->room; |
1328 | text = (char *) &p2p_rnmsg[1]; | 1292 | text = (char *) &p2p_rnmsg[1]; |
1329 | } | 1293 | } |
1330 | 1294 | ||
1331 | #if DEBUG_CHAT_SERVICE | 1295 | #if DEBUG_CHAT_SERVICE |
1332 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1341,7 +1305,7 @@ handle_p2p_message_notification (void *cls, | |||
1341 | rnmsg->reserved = htonl (0); | 1305 | rnmsg->reserved = htonl (0); |
1342 | rnmsg->timestamp = p2p_rnmsg->timestamp; | 1306 | rnmsg->timestamp = p2p_rnmsg->timestamp; |
1343 | is_priv = (0 != memcmp (&all_zeros, | 1307 | is_priv = (0 != memcmp (&all_zeros, |
1344 | &p2p_rnmsg->target, sizeof (GNUNET_HashCode))); | 1308 | &p2p_rnmsg->target, sizeof (GNUNET_HashCode))); |
1345 | if (is_priv) | 1309 | if (is_priv) |
1346 | memcpy (&rnmsg->encrypted_key, | 1310 | memcpy (&rnmsg->encrypted_key, |
1347 | &p2p_rnmsg->encrypted_key, | 1311 | &p2p_rnmsg->encrypted_key, |
@@ -1350,24 +1314,22 @@ handle_p2p_message_notification (void *cls, | |||
1350 | memcpy (&rnmsg[1], text, msg_len); | 1314 | memcpy (&rnmsg[1], text, msg_len); |
1351 | pos = client_list_head; | 1315 | pos = client_list_head; |
1352 | while (NULL != pos) | 1316 | while (NULL != pos) |
1317 | { | ||
1318 | if ((0 == strcmp (room_name, pos->room)) && (NULL != pos->client)) | ||
1353 | { | 1319 | { |
1354 | if ((0 == strcmp (room_name, pos->room)) && | 1320 | if (((!is_priv) || |
1355 | (NULL != pos->client)) | 1321 | (0 == memcmp (&p2p_rnmsg->target, |
1356 | { | 1322 | &pos->id, |
1357 | if (((!is_priv) || | 1323 | sizeof (GNUNET_HashCode)))) && |
1358 | (0 == memcmp (&p2p_rnmsg->target, | 1324 | (0 == (ntohl (p2p_rnmsg->msg_options) & (~pos->msg_options)))) |
1359 | &pos->id, | 1325 | { |
1360 | sizeof (GNUNET_HashCode)))) && | 1326 | GNUNET_SERVER_notification_context_unicast (nc, |
1361 | (0 == (ntohl (p2p_rnmsg->msg_options) & (~pos->msg_options)))) | 1327 | pos->client, |
1362 | { | 1328 | &rnmsg->header, GNUNET_NO); |
1363 | GNUNET_SERVER_notification_context_unicast (nc, | 1329 | } |
1364 | pos->client, | ||
1365 | &rnmsg->header, | ||
1366 | GNUNET_NO); | ||
1367 | } | ||
1368 | } | ||
1369 | pos = pos->next; | ||
1370 | } | 1330 | } |
1331 | pos = pos->next; | ||
1332 | } | ||
1371 | if (is_anon) | 1333 | if (is_anon) |
1372 | GNUNET_free (room_name); | 1334 | GNUNET_free (room_name); |
1373 | #if DEBUG_CHAT_SERVICE | 1335 | #if DEBUG_CHAT_SERVICE |
@@ -1410,21 +1372,20 @@ handle_p2p_sync_request (void *cls, | |||
1410 | #endif | 1372 | #endif |
1411 | entry = client_list_head; | 1373 | entry = client_list_head; |
1412 | while (NULL != entry) | 1374 | while (NULL != entry) |
1413 | { | 1375 | { |
1414 | msg_size = sizeof (struct P2PJoinNotificationMessage) + | 1376 | msg_size = sizeof (struct P2PJoinNotificationMessage) + |
1415 | strlen (entry->room) + | 1377 | strlen (entry->room) + entry->meta_len; |
1416 | entry->meta_len; | 1378 | th = GNUNET_CORE_notify_transmit_ready (core, |
1417 | th = GNUNET_CORE_notify_transmit_ready (core, | 1379 | GNUNET_NO, |
1418 | GNUNET_NO, | 1380 | 1, |
1419 | 1, | 1381 | MAX_TRANSMIT_DELAY, |
1420 | MAX_TRANSMIT_DELAY, | 1382 | other, |
1421 | other, | 1383 | msg_size, |
1422 | msg_size, | 1384 | &transmit_join_notification_to_peer, |
1423 | &transmit_join_notification_to_peer, | 1385 | entry); |
1424 | entry); | 1386 | GNUNET_assert (NULL != th); |
1425 | GNUNET_assert (NULL != th); | 1387 | entry = entry->next; |
1426 | entry = entry->next; | 1388 | } |
1427 | } | ||
1428 | return GNUNET_OK; | 1389 | return GNUNET_OK; |
1429 | } | 1390 | } |
1430 | 1391 | ||
@@ -1443,7 +1404,8 @@ static int | |||
1443 | handle_p2p_confirmation_receipt (void *cls, | 1404 | handle_p2p_confirmation_receipt (void *cls, |
1444 | const struct GNUNET_PeerIdentity *other, | 1405 | const struct GNUNET_PeerIdentity *other, |
1445 | const struct GNUNET_MessageHeader *message, | 1406 | const struct GNUNET_MessageHeader *message, |
1446 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 1407 | const struct GNUNET_TRANSPORT_ATS_Information |
1408 | *atsi) | ||
1447 | { | 1409 | { |
1448 | const struct P2PConfirmationReceiptMessage *p2p_crmsg; | 1410 | const struct P2PConfirmationReceiptMessage *p2p_crmsg; |
1449 | struct P2PConfirmationReceiptMessage *my_p2p_crmsg; | 1411 | struct P2PConfirmationReceiptMessage *my_p2p_crmsg; |
@@ -1456,94 +1418,94 @@ handle_p2p_confirmation_receipt (void *cls, | |||
1456 | target = client_list_head; | 1418 | target = client_list_head; |
1457 | while ((NULL != target) && | 1419 | while ((NULL != target) && |
1458 | (0 != memcmp (&target->id, | 1420 | (0 != memcmp (&target->id, |
1459 | &p2p_crmsg->target, | 1421 | &p2p_crmsg->target, sizeof (GNUNET_HashCode)))) |
1460 | sizeof (GNUNET_HashCode)))) | ||
1461 | target = target->next; | 1422 | target = target->next; |
1462 | if (NULL == target) | 1423 | if (NULL == target) |
1463 | { | 1424 | { |
1464 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1425 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1465 | "Unknown source of the receipt. Rejecting the message\n"); | 1426 | "Unknown source of the receipt. Rejecting the message\n"); |
1466 | GNUNET_break_op (0); | 1427 | GNUNET_break_op (0); |
1467 | return GNUNET_SYSERR; | 1428 | return GNUNET_SYSERR; |
1468 | } | 1429 | } |
1469 | if (target->rcpt_sequence_number >= ntohl (p2p_crmsg->sequence_number)) | 1430 | if (target->rcpt_sequence_number >= ntohl (p2p_crmsg->sequence_number)) |
1470 | { | 1431 | { |
1471 | #if DEBUG_CHAT_SERVICE | 1432 | #if DEBUG_CHAT_SERVICE |
1472 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1473 | "This receipt has already been handled." | 1434 | "This receipt has already been handled." |
1474 | " Sequence numbers (msg/sender): %u/%u\n", | 1435 | " Sequence numbers (msg/sender): %u/%u\n", |
1475 | ntohl (p2p_crmsg->sequence_number), target->rcpt_sequence_number); | 1436 | ntohl (p2p_crmsg->sequence_number), |
1437 | target->rcpt_sequence_number); | ||
1476 | #endif | 1438 | #endif |
1477 | return GNUNET_OK; | 1439 | return GNUNET_OK; |
1478 | } | 1440 | } |
1479 | target->rcpt_sequence_number = ntohl (p2p_crmsg->sequence_number); | 1441 | target->rcpt_sequence_number = ntohl (p2p_crmsg->sequence_number); |
1480 | author = client_list_head; | 1442 | author = client_list_head; |
1481 | while ((NULL != author) && | 1443 | while ((NULL != author) && |
1482 | (0 != memcmp (&author->id, | 1444 | (0 != memcmp (&author->id, |
1483 | &p2p_crmsg->author, | 1445 | &p2p_crmsg->author, sizeof (GNUNET_HashCode)))) |
1484 | sizeof (GNUNET_HashCode)))) | ||
1485 | author = author->next; | 1446 | author = author->next; |
1486 | if (NULL == author) | 1447 | if (NULL == author) |
1487 | { | 1448 | { |
1488 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1449 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1489 | "Unknown addressee. Rejecting the receipt\n"); | 1450 | "Unknown addressee. Rejecting the receipt\n"); |
1490 | GNUNET_break_op (0); | 1451 | GNUNET_break_op (0); |
1491 | return GNUNET_SYSERR; | 1452 | return GNUNET_SYSERR; |
1492 | } | 1453 | } |
1493 | 1454 | ||
1494 | if (NULL == author->client) | 1455 | if (NULL == author->client) |
1495 | { | 1456 | { |
1496 | #if DEBUG_CHAT_SERVICE | 1457 | #if DEBUG_CHAT_SERVICE |
1497 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1458 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1498 | "The author of the original message is not a local client." | 1459 | "The author of the original message is not a local client." |
1499 | " Broadcasting receipt to neighbour peers\n"); | 1460 | " Broadcasting receipt to neighbour peers\n"); |
1500 | #endif | 1461 | #endif |
1501 | my_p2p_crmsg = GNUNET_memdup (p2p_crmsg, sizeof (struct P2PConfirmationReceiptMessage)); | 1462 | my_p2p_crmsg = |
1502 | GNUNET_CONTAINER_multihashmap_iterate (connected_peers, | 1463 | GNUNET_memdup (p2p_crmsg, |
1503 | &send_confirmation_receipt, | 1464 | sizeof (struct P2PConfirmationReceiptMessage)); |
1504 | my_p2p_crmsg); | 1465 | GNUNET_CONTAINER_multihashmap_iterate (connected_peers, |
1505 | GNUNET_free (my_p2p_crmsg); | 1466 | &send_confirmation_receipt, |
1506 | } | 1467 | my_p2p_crmsg); |
1468 | GNUNET_free (my_p2p_crmsg); | ||
1469 | } | ||
1507 | else | 1470 | else |
1508 | { | 1471 | { |
1509 | #if DEBUG_CHAT_SERVICE | 1472 | #if DEBUG_CHAT_SERVICE |
1510 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1473 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1511 | "The author of the original message is a local client." | 1474 | "The author of the original message is a local client." |
1512 | " Verifying signature of the receipt\n"); | 1475 | " Verifying signature of the receipt\n"); |
1513 | #endif | 1476 | #endif |
1514 | crmsg = GNUNET_malloc (sizeof (struct ConfirmationReceiptMessage)); | 1477 | crmsg = GNUNET_malloc (sizeof (struct ConfirmationReceiptMessage)); |
1515 | crmsg->header.size = htons (sizeof (struct ConfirmationReceiptMessage)); | 1478 | crmsg->header.size = htons (sizeof (struct ConfirmationReceiptMessage)); |
1516 | crmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION); | 1479 | crmsg->header.type = |
1517 | crmsg->signature = p2p_crmsg->signature; | 1480 | htons (GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION); |
1518 | crmsg->purpose = p2p_crmsg->purpose; | 1481 | crmsg->signature = p2p_crmsg->signature; |
1519 | crmsg->sequence_number = p2p_crmsg->msg_sequence_number; | 1482 | crmsg->purpose = p2p_crmsg->purpose; |
1520 | crmsg->reserved2 = 0; | 1483 | crmsg->sequence_number = p2p_crmsg->msg_sequence_number; |
1521 | crmsg->timestamp = p2p_crmsg->timestamp; | 1484 | crmsg->reserved2 = 0; |
1522 | crmsg->target = p2p_crmsg->target; | 1485 | crmsg->timestamp = p2p_crmsg->timestamp; |
1523 | crmsg->author = p2p_crmsg->author; | 1486 | crmsg->target = p2p_crmsg->target; |
1524 | crmsg->content = p2p_crmsg->content; | 1487 | crmsg->author = p2p_crmsg->author; |
1525 | if (GNUNET_OK != | 1488 | crmsg->content = p2p_crmsg->content; |
1526 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT, | 1489 | if (GNUNET_OK != |
1527 | &crmsg->purpose, | 1490 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT, |
1528 | &crmsg->signature, | 1491 | &crmsg->purpose, |
1529 | &target->public_key)) | 1492 | &crmsg->signature, &target->public_key)) |
1530 | { | 1493 | { |
1531 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1494 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1532 | "Invalid signature of the receipt\n"); | 1495 | "Invalid signature of the receipt\n"); |
1533 | GNUNET_break_op (0); | 1496 | GNUNET_break_op (0); |
1534 | return GNUNET_SYSERR; | 1497 | return GNUNET_SYSERR; |
1535 | } | 1498 | } |
1536 | #if DEBUG_CHAT_SERVICE | 1499 | #if DEBUG_CHAT_SERVICE |
1537 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1500 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1538 | "The author of the original message is a local client." | 1501 | "The author of the original message is a local client." |
1539 | " Sending receipt to the client\n"); | 1502 | " Sending receipt to the client\n"); |
1540 | #endif | 1503 | #endif |
1541 | GNUNET_SERVER_notification_context_unicast (nc, | 1504 | GNUNET_SERVER_notification_context_unicast (nc, |
1542 | author->client, | 1505 | author->client, |
1543 | &crmsg->header, | 1506 | &crmsg->header, GNUNET_NO); |
1544 | GNUNET_NO); | 1507 | GNUNET_free (crmsg); |
1545 | GNUNET_free (crmsg); | 1508 | } |
1546 | } | ||
1547 | return GNUNET_OK; | 1509 | return GNUNET_OK; |
1548 | } | 1510 | } |
1549 | 1511 | ||
@@ -1557,9 +1519,7 @@ handle_p2p_confirmation_receipt (void *cls, | |||
1557 | * @return number of bytes written to buf | 1519 | * @return number of bytes written to buf |
1558 | */ | 1520 | */ |
1559 | static size_t | 1521 | static size_t |
1560 | transmit_sync_request_to_peer (void *cls, | 1522 | transmit_sync_request_to_peer (void *cls, size_t size, void *buf) |
1561 | size_t size, | ||
1562 | void *buf) | ||
1563 | { | 1523 | { |
1564 | struct GNUNET_MessageHeader *m = buf; | 1524 | struct GNUNET_MessageHeader *m = buf; |
1565 | size_t msg_size; | 1525 | size_t msg_size; |
@@ -1584,7 +1544,7 @@ transmit_sync_request_to_peer (void *cls, | |||
1584 | * @param peer peer identity this notification is about | 1544 | * @param peer peer identity this notification is about |
1585 | * @param atsi performance data | 1545 | * @param atsi performance data |
1586 | */ | 1546 | */ |
1587 | static void | 1547 | static void |
1588 | peer_connect_handler (void *cls, | 1548 | peer_connect_handler (void *cls, |
1589 | const struct GNUNET_PeerIdentity *peer, | 1549 | const struct GNUNET_PeerIdentity *peer, |
1590 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 1550 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
@@ -1597,21 +1557,19 @@ peer_connect_handler (void *cls, | |||
1597 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1557 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1598 | "Peer connected: %s\n", GNUNET_i2s (peer)); | 1558 | "Peer connected: %s\n", GNUNET_i2s (peer)); |
1599 | th = GNUNET_CORE_notify_transmit_ready (core, | 1559 | th = GNUNET_CORE_notify_transmit_ready (core, |
1600 | GNUNET_YES, | 1560 | GNUNET_YES, |
1601 | 1, | 1561 | 1, |
1602 | MAX_TRANSMIT_DELAY, | 1562 | MAX_TRANSMIT_DELAY, |
1603 | peer, | 1563 | peer, |
1604 | sizeof (struct GNUNET_MessageHeader), | 1564 | sizeof (struct GNUNET_MessageHeader), |
1605 | &transmit_sync_request_to_peer, | 1565 | &transmit_sync_request_to_peer, NULL); |
1606 | NULL); | ||
1607 | GNUNET_assert (NULL != th); | 1566 | GNUNET_assert (NULL != th); |
1608 | cp = GNUNET_CONTAINER_multihashmap_get (connected_peers, | 1567 | cp = GNUNET_CONTAINER_multihashmap_get (connected_peers, &peer->hashPubKey); |
1609 | &peer->hashPubKey); | ||
1610 | if (NULL != cp) | 1568 | if (NULL != cp) |
1611 | { | 1569 | { |
1612 | GNUNET_break (0); | 1570 | GNUNET_break (0); |
1613 | return; | 1571 | return; |
1614 | } | 1572 | } |
1615 | cp = GNUNET_malloc (sizeof (struct ConnectedPeer)); | 1573 | cp = GNUNET_malloc (sizeof (struct ConnectedPeer)); |
1616 | cp->pid = GNUNET_PEER_intern (peer); | 1574 | cp->pid = GNUNET_PEER_intern (peer); |
1617 | GNUNET_break (GNUNET_OK == | 1575 | GNUNET_break (GNUNET_OK == |
@@ -1630,22 +1588,19 @@ peer_connect_handler (void *cls, | |||
1630 | * @param value value in the hash map (peer entry) | 1588 | * @param value value in the hash map (peer entry) |
1631 | * @return GNUNET_YES (we should continue to iterate) | 1589 | * @return GNUNET_YES (we should continue to iterate) |
1632 | */ | 1590 | */ |
1633 | static int | 1591 | static int |
1634 | clean_peer (void *cls, | 1592 | clean_peer (void *cls, const GNUNET_HashCode * key, void *value) |
1635 | const GNUNET_HashCode * key, | ||
1636 | void *value) | ||
1637 | { | 1593 | { |
1638 | struct ConnectedPeer *cp; | 1594 | struct ConnectedPeer *cp; |
1639 | const struct GNUNET_PeerIdentity *peer = (const struct GNUNET_PeerIdentity *) key; | 1595 | const struct GNUNET_PeerIdentity *peer = |
1596 | (const struct GNUNET_PeerIdentity *) key; | ||
1640 | 1597 | ||
1641 | cp = GNUNET_CONTAINER_multihashmap_get (connected_peers, | 1598 | cp = GNUNET_CONTAINER_multihashmap_get (connected_peers, &peer->hashPubKey); |
1642 | &peer->hashPubKey); | ||
1643 | if (cp == NULL) | 1599 | if (cp == NULL) |
1644 | return GNUNET_YES; | 1600 | return GNUNET_YES; |
1645 | GNUNET_break (GNUNET_YES == | 1601 | GNUNET_break (GNUNET_YES == |
1646 | GNUNET_CONTAINER_multihashmap_remove (connected_peers, | 1602 | GNUNET_CONTAINER_multihashmap_remove (connected_peers, |
1647 | &peer->hashPubKey, | 1603 | &peer->hashPubKey, cp)); |
1648 | cp)); | ||
1649 | GNUNET_PEER_change_rc (cp->pid, -1); | 1604 | GNUNET_PEER_change_rc (cp->pid, -1); |
1650 | GNUNET_free (cp); | 1605 | GNUNET_free (cp); |
1651 | return GNUNET_YES; | 1606 | return GNUNET_YES; |
@@ -1659,8 +1614,7 @@ clean_peer (void *cls, | |||
1659 | * @param peer peer identity this notification is about | 1614 | * @param peer peer identity this notification is about |
1660 | */ | 1615 | */ |
1661 | static void | 1616 | static void |
1662 | peer_disconnect_handler (void *cls, | 1617 | peer_disconnect_handler (void *cls, const struct GNUNET_PeerIdentity *peer) |
1663 | const struct GNUNET_PeerIdentity *peer) | ||
1664 | { | 1618 | { |
1665 | 1619 | ||
1666 | if (0 == memcmp (peer, me, sizeof (struct GNUNET_PeerIdentity))) | 1620 | if (0 == memcmp (peer, me, sizeof (struct GNUNET_PeerIdentity))) |
@@ -1678,40 +1632,37 @@ peer_disconnect_handler (void *cls, | |||
1678 | * @param tc unused | 1632 | * @param tc unused |
1679 | */ | 1633 | */ |
1680 | static void | 1634 | static void |
1681 | cleanup_task (void *cls, | 1635 | cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1682 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1683 | { | 1636 | { |
1684 | struct AnonymousMessage *next_msg; | 1637 | struct AnonymousMessage *next_msg; |
1685 | struct ChatClient *next_client; | 1638 | struct ChatClient *next_client; |
1686 | 1639 | ||
1687 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Cleaning up\n"); | 1640 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Cleaning up\n"); |
1688 | if (NULL != core) | 1641 | if (NULL != core) |
1689 | { | 1642 | { |
1690 | GNUNET_CORE_disconnect (core); | 1643 | GNUNET_CORE_disconnect (core); |
1691 | core = NULL; | 1644 | core = NULL; |
1692 | } | 1645 | } |
1693 | if (NULL != nc) | 1646 | if (NULL != nc) |
1694 | { | 1647 | { |
1695 | GNUNET_SERVER_notification_context_destroy (nc); | 1648 | GNUNET_SERVER_notification_context_destroy (nc); |
1696 | nc = NULL; | 1649 | nc = NULL; |
1697 | } | 1650 | } |
1698 | while (NULL != client_list_head) | 1651 | while (NULL != client_list_head) |
1699 | { | 1652 | { |
1700 | next_client = client_list_head->next; | 1653 | next_client = client_list_head->next; |
1701 | GNUNET_free (client_list_head->room); | 1654 | GNUNET_free (client_list_head->room); |
1702 | GNUNET_free_non_null (client_list_head->member_info); | 1655 | GNUNET_free_non_null (client_list_head->member_info); |
1703 | GNUNET_free (client_list_head); | 1656 | GNUNET_free (client_list_head); |
1704 | client_list_head = next_client; | 1657 | client_list_head = next_client; |
1705 | } | 1658 | } |
1706 | while (NULL != anonymous_list_head) | 1659 | while (NULL != anonymous_list_head) |
1707 | { | 1660 | { |
1708 | next_msg = anonymous_list_head->next; | 1661 | next_msg = anonymous_list_head->next; |
1709 | GNUNET_free (anonymous_list_head); | 1662 | GNUNET_free (anonymous_list_head); |
1710 | anonymous_list_head = next_msg; | 1663 | anonymous_list_head = next_msg; |
1711 | } | 1664 | } |
1712 | GNUNET_CONTAINER_multihashmap_iterate (connected_peers, | 1665 | GNUNET_CONTAINER_multihashmap_iterate (connected_peers, &clean_peer, NULL); |
1713 | &clean_peer, | ||
1714 | NULL); | ||
1715 | GNUNET_CONTAINER_multihashmap_destroy (connected_peers); | 1666 | GNUNET_CONTAINER_multihashmap_destroy (connected_peers); |
1716 | connected_peers = NULL; | 1667 | connected_peers = NULL; |
1717 | } | 1668 | } |
@@ -1748,34 +1699,32 @@ run (void *cls, | |||
1748 | struct GNUNET_SERVER_Handle *server, | 1699 | struct GNUNET_SERVER_Handle *server, |
1749 | const struct GNUNET_CONFIGURATION_Handle *c) | 1700 | const struct GNUNET_CONFIGURATION_Handle *c) |
1750 | { | 1701 | { |
1751 | static const struct GNUNET_SERVER_MessageHandler handlers[] = | 1702 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
1752 | { | 1703 | {&handle_join_request, NULL, |
1753 | { &handle_join_request, NULL, | 1704 | GNUNET_MESSAGE_TYPE_CHAT_JOIN_REQUEST, 0}, |
1754 | GNUNET_MESSAGE_TYPE_CHAT_JOIN_REQUEST, 0 }, | 1705 | {&handle_transmit_request, NULL, |
1755 | { &handle_transmit_request, NULL, | 1706 | GNUNET_MESSAGE_TYPE_CHAT_TRANSMIT_REQUEST, 0}, |
1756 | GNUNET_MESSAGE_TYPE_CHAT_TRANSMIT_REQUEST, 0 }, | 1707 | {&handle_acknowledge_request, NULL, |
1757 | { &handle_acknowledge_request, NULL, | 1708 | GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_RECEIPT, |
1758 | GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_RECEIPT, | 1709 | sizeof (struct ConfirmationReceiptMessage)}, |
1759 | sizeof (struct ConfirmationReceiptMessage) }, | 1710 | {NULL, NULL, 0, 0} |
1760 | { NULL, NULL, 0, 0 } | 1711 | }; |
1761 | }; | 1712 | static const struct GNUNET_CORE_MessageHandler p2p_handlers[] = { |
1762 | static const struct GNUNET_CORE_MessageHandler p2p_handlers[] = | 1713 | {&handle_p2p_join_notification, |
1763 | { | 1714 | GNUNET_MESSAGE_TYPE_CHAT_P2P_JOIN_NOTIFICATION, 0}, |
1764 | { &handle_p2p_join_notification, | 1715 | {&handle_p2p_leave_notification, |
1765 | GNUNET_MESSAGE_TYPE_CHAT_P2P_JOIN_NOTIFICATION, 0 }, | 1716 | GNUNET_MESSAGE_TYPE_CHAT_P2P_LEAVE_NOTIFICATION, |
1766 | { &handle_p2p_leave_notification, | 1717 | sizeof (struct P2PLeaveNotificationMessage)}, |
1767 | GNUNET_MESSAGE_TYPE_CHAT_P2P_LEAVE_NOTIFICATION, | 1718 | {&handle_p2p_message_notification, |
1768 | sizeof (struct P2PLeaveNotificationMessage) }, | 1719 | GNUNET_MESSAGE_TYPE_CHAT_P2P_MESSAGE_NOTIFICATION, 0}, |
1769 | { &handle_p2p_message_notification, | 1720 | {&handle_p2p_sync_request, |
1770 | GNUNET_MESSAGE_TYPE_CHAT_P2P_MESSAGE_NOTIFICATION, 0 }, | 1721 | GNUNET_MESSAGE_TYPE_CHAT_P2P_SYNC_REQUEST, |
1771 | { &handle_p2p_sync_request, | 1722 | sizeof (struct GNUNET_MessageHeader)}, |
1772 | GNUNET_MESSAGE_TYPE_CHAT_P2P_SYNC_REQUEST, | 1723 | {&handle_p2p_confirmation_receipt, |
1773 | sizeof (struct GNUNET_MessageHeader) }, | 1724 | GNUNET_MESSAGE_TYPE_CHAT_P2P_CONFIRMATION_RECEIPT, |
1774 | { &handle_p2p_confirmation_receipt, | 1725 | sizeof (struct P2PConfirmationReceiptMessage)}, |
1775 | GNUNET_MESSAGE_TYPE_CHAT_P2P_CONFIRMATION_RECEIPT, | 1726 | {NULL, 0, 0} |
1776 | sizeof (struct P2PConfirmationReceiptMessage) }, | 1727 | }; |
1777 | { NULL, 0, 0 } | ||
1778 | }; | ||
1779 | 1728 | ||
1780 | GNUNET_log_setup ("gnunet-service-chat", | 1729 | GNUNET_log_setup ("gnunet-service-chat", |
1781 | #if DEBUG_CHAT_SERVICE | 1730 | #if DEBUG_CHAT_SERVICE |
@@ -1786,7 +1735,8 @@ run (void *cls, | |||
1786 | NULL); | 1735 | NULL); |
1787 | cfg = c; | 1736 | cfg = c; |
1788 | nc = GNUNET_SERVER_notification_context_create (server, 16); | 1737 | nc = GNUNET_SERVER_notification_context_create (server, 16); |
1789 | connected_peers = GNUNET_CONTAINER_multihashmap_create (EXPECTED_NEIGHBOUR_COUNT); | 1738 | connected_peers = |
1739 | GNUNET_CONTAINER_multihashmap_create (EXPECTED_NEIGHBOUR_COUNT); | ||
1790 | GNUNET_SERVER_add_handlers (server, handlers); | 1740 | GNUNET_SERVER_add_handlers (server, handlers); |
1791 | core = GNUNET_CORE_connect (cfg, | 1741 | core = GNUNET_CORE_connect (cfg, |
1792 | QUEUE_SIZE, | 1742 | QUEUE_SIZE, |
@@ -1795,15 +1745,10 @@ run (void *cls, | |||
1795 | &peer_connect_handler, | 1745 | &peer_connect_handler, |
1796 | &peer_disconnect_handler, | 1746 | &peer_disconnect_handler, |
1797 | NULL, | 1747 | NULL, |
1798 | NULL, GNUNET_NO, | 1748 | NULL, GNUNET_NO, NULL, GNUNET_NO, p2p_handlers); |
1799 | NULL, GNUNET_NO, | 1749 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); |
1800 | p2p_handlers); | ||
1801 | GNUNET_SERVER_disconnect_notify (server, | ||
1802 | &handle_client_disconnect, | ||
1803 | NULL); | ||
1804 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 1750 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
1805 | &cleanup_task, | 1751 | &cleanup_task, NULL); |
1806 | NULL); | ||
1807 | } | 1752 | } |
1808 | 1753 | ||
1809 | 1754 | ||
@@ -1821,8 +1766,7 @@ main (int argc, char *const *argv) | |||
1821 | GNUNET_SERVICE_run (argc, | 1766 | GNUNET_SERVICE_run (argc, |
1822 | argv, | 1767 | argv, |
1823 | "chat", | 1768 | "chat", |
1824 | GNUNET_SERVICE_OPTION_NONE, | 1769 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; |
1825 | &run, NULL)) ? 0 : 1; | ||
1826 | } | 1770 | } |
1827 | 1771 | ||
1828 | /* end of gnunet-service-chat.c */ | 1772 | /* end of gnunet-service-chat.c */ |
diff --git a/src/chat/test_chat.c b/src/chat/test_chat.c index 7a20c0331..0953a895b 100644 --- a/src/chat/test_chat.c +++ b/src/chat/test_chat.c | |||
@@ -119,11 +119,11 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
119 | p->cfg = GNUNET_CONFIGURATION_create (); | 119 | p->cfg = GNUNET_CONFIGURATION_create (); |
120 | #if START_ARM | 120 | #if START_ARM |
121 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 121 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
122 | "gnunet-service-arm", | 122 | "gnunet-service-arm", |
123 | #if VERBOSE | 123 | #if VERBOSE |
124 | "-L", "DEBUG", | 124 | "-L", "DEBUG", |
125 | #endif | 125 | #endif |
126 | "-c", cfgname, NULL); | 126 | "-c", cfgname, NULL); |
127 | #endif | 127 | #endif |
128 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 128 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
129 | } | 129 | } |
@@ -135,10 +135,11 @@ stop_arm (struct PeerContext *p) | |||
135 | #if START_ARM | 135 | #if START_ARM |
136 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | 136 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) |
137 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 137 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
138 | if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) | 138 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) |
139 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 139 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
141 | "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); | 141 | "ARM process %u stopped\n", |
142 | GNUNET_OS_process_get_pid (p->arm_proc)); | ||
142 | GNUNET_OS_process_close (p->arm_proc); | 143 | GNUNET_OS_process_close (p->arm_proc); |
143 | p->arm_proc = NULL; | 144 | p->arm_proc = NULL; |
144 | #endif | 145 | #endif |
@@ -147,36 +148,34 @@ stop_arm (struct PeerContext *p) | |||
147 | 148 | ||
148 | 149 | ||
149 | static void | 150 | static void |
150 | abort_test (void *cls, | 151 | abort_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
151 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
152 | { | 152 | { |
153 | if (alice_room != NULL) | 153 | if (alice_room != NULL) |
154 | { | 154 | { |
155 | GNUNET_CHAT_leave_room (alice_room); | 155 | GNUNET_CHAT_leave_room (alice_room); |
156 | alice_room = NULL; | 156 | alice_room = NULL; |
157 | } | 157 | } |
158 | if (bob_room != NULL) | 158 | if (bob_room != NULL) |
159 | { | 159 | { |
160 | GNUNET_CHAT_leave_room (bob_room); | 160 | GNUNET_CHAT_leave_room (bob_room); |
161 | bob_room = NULL; | 161 | bob_room = NULL; |
162 | } | 162 | } |
163 | err = 1; | 163 | err = 1; |
164 | } | 164 | } |
165 | 165 | ||
166 | 166 | ||
167 | static void | 167 | static void |
168 | timeout_kill (void *cls, | 168 | timeout_kill (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
169 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
170 | { | 169 | { |
171 | #if VERBOSE | 170 | #if VERBOSE |
172 | printf ("Timed out, stopping the test.\n"); | 171 | printf ("Timed out, stopping the test.\n"); |
173 | #endif | 172 | #endif |
174 | kill_task = GNUNET_SCHEDULER_NO_TASK; | 173 | kill_task = GNUNET_SCHEDULER_NO_TASK; |
175 | if (wait_task != GNUNET_SCHEDULER_NO_TASK) | 174 | if (wait_task != GNUNET_SCHEDULER_NO_TASK) |
176 | { | 175 | { |
177 | GNUNET_SCHEDULER_cancel (wait_task); | 176 | GNUNET_SCHEDULER_cancel (wait_task); |
178 | wait_task = GNUNET_SCHEDULER_NO_TASK; | 177 | wait_task = GNUNET_SCHEDULER_NO_TASK; |
179 | } | 178 | } |
180 | GNUNET_SCHEDULER_add_continuation (&abort_test, NULL, | 179 | GNUNET_SCHEDULER_add_continuation (&abort_test, NULL, |
181 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 180 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
182 | } | 181 | } |
@@ -207,11 +206,11 @@ member_list_cb (void *cls, | |||
207 | 206 | ||
208 | #if VERBOSE | 207 | #if VERBOSE |
209 | printf ("%s - told that %s has %s\n", | 208 | printf ("%s - told that %s has %s\n", |
210 | want->me, | 209 | want->me, |
211 | member_info == NULL ? NULL | 210 | member_info == NULL ? NULL |
212 | : GNUNET_CONTAINER_meta_data_get_by_type (member_info, | 211 | : GNUNET_CONTAINER_meta_data_get_by_type (member_info, |
213 | EXTRACTOR_METATYPE_TITLE), | 212 | EXTRACTOR_METATYPE_TITLE), |
214 | member_info == NULL ? "left" : "joined"); | 213 | member_info == NULL ? "left" : "joined"); |
215 | #endif | 214 | #endif |
216 | GNUNET_CRYPTO_hash (member_id, | 215 | GNUNET_CRYPTO_hash (member_id, |
217 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 216 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
@@ -225,16 +224,16 @@ member_list_cb (void *cls, | |||
225 | (GNUNET_CONTAINER_meta_data_test_equal (member_info, | 224 | (GNUNET_CONTAINER_meta_data_test_equal (member_info, |
226 | want->meta)))) && | 225 | want->meta)))) && |
227 | (options == want->opt)) | 226 | (options == want->opt)) |
228 | { | 227 | { |
229 | if (NULL != want->next_task) | 228 | if (NULL != want->next_task) |
230 | GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls); | 229 | GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls); |
231 | } | 230 | } |
232 | else | 231 | else |
233 | { | 232 | { |
234 | GNUNET_SCHEDULER_cancel (kill_task); | 233 | GNUNET_SCHEDULER_cancel (kill_task); |
235 | kill_task = GNUNET_SCHEDULER_NO_TASK; | 234 | kill_task = GNUNET_SCHEDULER_NO_TASK; |
236 | GNUNET_SCHEDULER_add_now (&abort_test, NULL); | 235 | GNUNET_SCHEDULER_add_now (&abort_test, NULL); |
237 | } | 236 | } |
238 | return GNUNET_OK; | 237 | return GNUNET_OK; |
239 | } | 238 | } |
240 | 239 | ||
@@ -242,7 +241,7 @@ member_list_cb (void *cls, | |||
242 | static int | 241 | static int |
243 | receive_cb (void *cls, | 242 | receive_cb (void *cls, |
244 | struct GNUNET_CHAT_Room *room, | 243 | struct GNUNET_CHAT_Room *room, |
245 | const GNUNET_HashCode *sender, | 244 | const GNUNET_HashCode * sender, |
246 | const struct GNUNET_CONTAINER_MetaData *meta, | 245 | const struct GNUNET_CONTAINER_MetaData *meta, |
247 | const char *message, | 246 | const char *message, |
248 | struct GNUNET_TIME_Absolute timestamp, | 247 | struct GNUNET_TIME_Absolute timestamp, |
@@ -269,16 +268,16 @@ receive_cb (void *cls, | |||
269 | * slightly greater | 268 | * slightly greater |
270 | */ | 269 | */ |
271 | (timestamp.abs_value >= want->timestamp.abs_value)) | 270 | (timestamp.abs_value >= want->timestamp.abs_value)) |
272 | { | 271 | { |
273 | if (NULL != want->next_task) | 272 | if (NULL != want->next_task) |
274 | GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls); | 273 | GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls); |
275 | } | 274 | } |
276 | else | 275 | else |
277 | { | 276 | { |
278 | GNUNET_SCHEDULER_cancel (kill_task); | 277 | GNUNET_SCHEDULER_cancel (kill_task); |
279 | kill_task = GNUNET_SCHEDULER_NO_TASK; | 278 | kill_task = GNUNET_SCHEDULER_NO_TASK; |
280 | GNUNET_SCHEDULER_add_now (&abort_test, NULL); | 279 | GNUNET_SCHEDULER_add_now (&abort_test, NULL); |
281 | } | 280 | } |
282 | return GNUNET_OK; | 281 | return GNUNET_OK; |
283 | } | 282 | } |
284 | 283 | ||
@@ -288,7 +287,7 @@ confirmation_cb (void *cls, | |||
288 | struct GNUNET_CHAT_Room *room, | 287 | struct GNUNET_CHAT_Room *room, |
289 | uint32_t orig_seq_number, | 288 | uint32_t orig_seq_number, |
290 | struct GNUNET_TIME_Absolute timestamp, | 289 | struct GNUNET_TIME_Absolute timestamp, |
291 | const GNUNET_HashCode *receiver) | 290 | const GNUNET_HashCode * receiver) |
292 | { | 291 | { |
293 | struct Wanted *want = cls; | 292 | struct Wanted *want = cls; |
294 | 293 | ||
@@ -303,23 +302,22 @@ confirmation_cb (void *cls, | |||
303 | sizeof (GNUNET_HashCode))) && | 302 | sizeof (GNUNET_HashCode))) && |
304 | (orig_seq_number == want->sequence_number) && | 303 | (orig_seq_number == want->sequence_number) && |
305 | (timestamp.abs_value >= want->timestamp.abs_value)) | 304 | (timestamp.abs_value >= want->timestamp.abs_value)) |
306 | { | 305 | { |
307 | if (NULL != want->next_task) | 306 | if (NULL != want->next_task) |
308 | GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls); | 307 | GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls); |
309 | } | 308 | } |
310 | else | 309 | else |
311 | { | 310 | { |
312 | GNUNET_SCHEDULER_cancel (kill_task); | 311 | GNUNET_SCHEDULER_cancel (kill_task); |
313 | kill_task = GNUNET_SCHEDULER_NO_TASK; | 312 | kill_task = GNUNET_SCHEDULER_NO_TASK; |
314 | GNUNET_SCHEDULER_add_now (&abort_test, NULL); | 313 | GNUNET_SCHEDULER_add_now (&abort_test, NULL); |
315 | } | 314 | } |
316 | return GNUNET_OK; | 315 | return GNUNET_OK; |
317 | } | 316 | } |
318 | 317 | ||
319 | 318 | ||
320 | static void | 319 | static void |
321 | wait_until_ready (void *cls, | 320 | wait_until_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
322 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
323 | { | 321 | { |
324 | GNUNET_SCHEDULER_Task task = cls; | 322 | GNUNET_SCHEDULER_Task task = cls; |
325 | 323 | ||
@@ -327,22 +325,20 @@ wait_until_ready (void *cls, | |||
327 | printf ("Waiting...\n"); | 325 | printf ("Waiting...\n"); |
328 | #endif | 326 | #endif |
329 | if (is_ready) | 327 | if (is_ready) |
330 | { | 328 | { |
331 | wait_task = GNUNET_SCHEDULER_NO_TASK; | 329 | wait_task = GNUNET_SCHEDULER_NO_TASK; |
332 | GNUNET_SCHEDULER_add_now (task, NULL); | 330 | GNUNET_SCHEDULER_add_now (task, NULL); |
333 | } | 331 | } |
334 | else | 332 | else |
335 | wait_task = | 333 | wait_task = |
336 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 334 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
337 | 50), | 335 | (GNUNET_TIME_UNIT_MILLISECONDS, 50), |
338 | &wait_until_ready, | 336 | &wait_until_ready, task); |
339 | task); | ||
340 | } | 337 | } |
341 | 338 | ||
342 | 339 | ||
343 | static void | 340 | static void |
344 | disconnect_alice (void *cls, | 341 | disconnect_alice (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
345 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
346 | { | 342 | { |
347 | #if VERBOSE | 343 | #if VERBOSE |
348 | printf ("Alice is leaving.\n"); | 344 | printf ("Alice is leaving.\n"); |
@@ -357,8 +353,7 @@ disconnect_alice (void *cls, | |||
357 | 353 | ||
358 | 354 | ||
359 | static void | 355 | static void |
360 | disconnect_bob (void *cls, | 356 | disconnect_bob (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
361 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
362 | { | 357 | { |
363 | #if VERBOSE | 358 | #if VERBOSE |
364 | printf ("Bod is leaving.\n"); | 359 | printf ("Bod is leaving.\n"); |
@@ -375,16 +370,14 @@ disconnect_bob (void *cls, | |||
375 | 370 | ||
376 | 371 | ||
377 | static void | 372 | static void |
378 | set_ready (void *cls, | 373 | set_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
379 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
380 | { | 374 | { |
381 | is_ready = GNUNET_YES; | 375 | is_ready = GNUNET_YES; |
382 | } | 376 | } |
383 | 377 | ||
384 | 378 | ||
385 | static void | 379 | static void |
386 | send_to_alice (void *cls, | 380 | send_to_alice (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
387 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
388 | { | 381 | { |
389 | #if VERBOSE | 382 | #if VERBOSE |
390 | printf ("Bob says 'Hi!'\n"); | 383 | printf ("Bob says 'Hi!'\n"); |
@@ -399,15 +392,12 @@ send_to_alice (void *cls, | |||
399 | alice_wanted.next_task_cls = NULL; | 392 | alice_wanted.next_task_cls = NULL; |
400 | GNUNET_CHAT_send_message (bob_room, | 393 | GNUNET_CHAT_send_message (bob_room, |
401 | "Hi Alice!", | 394 | "Hi Alice!", |
402 | GNUNET_CHAT_MSG_OPTION_NONE, | 395 | GNUNET_CHAT_MSG_OPTION_NONE, NULL, NULL); |
403 | NULL, | ||
404 | NULL); | ||
405 | } | 396 | } |
406 | 397 | ||
407 | 398 | ||
408 | static void | 399 | static void |
409 | send_to_bob (void *cls, | 400 | send_to_bob (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
410 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
411 | { | 401 | { |
412 | enum GNUNET_CHAT_MsgOptions options; | 402 | enum GNUNET_CHAT_MsgOptions options; |
413 | uint32_t *seq = NULL; | 403 | uint32_t *seq = NULL; |
@@ -416,39 +406,39 @@ send_to_bob (void *cls, | |||
416 | printf ("Alice says 'Hi!'\n"); | 406 | printf ("Alice says 'Hi!'\n"); |
417 | #endif | 407 | #endif |
418 | if (is_ackn) | 408 | if (is_ackn) |
419 | { | 409 | { |
420 | options = GNUNET_CHAT_MSG_ACKNOWLEDGED; | 410 | options = GNUNET_CHAT_MSG_ACKNOWLEDGED; |
421 | alice_wanted.meta = bob_meta; | 411 | alice_wanted.meta = bob_meta; |
422 | alice_wanted.sender = &bob; | 412 | alice_wanted.sender = &bob; |
423 | alice_wanted.timestamp = GNUNET_TIME_absolute_get (); | 413 | alice_wanted.timestamp = GNUNET_TIME_absolute_get (); |
424 | alice_wanted.next_task = &disconnect_bob; | 414 | alice_wanted.next_task = &disconnect_bob; |
425 | alice_wanted.next_task_cls = NULL; | 415 | alice_wanted.next_task_cls = NULL; |
426 | bob_wanted.meta = alice_meta; | 416 | bob_wanted.meta = alice_meta; |
427 | bob_wanted.sender = &alice; | 417 | bob_wanted.sender = &alice; |
428 | bob_wanted.next_task = NULL; | 418 | bob_wanted.next_task = NULL; |
429 | seq = &(alice_wanted.sequence_number); | 419 | seq = &(alice_wanted.sequence_number); |
430 | } | 420 | } |
431 | else if (is_anon) | 421 | else if (is_anon) |
432 | { | 422 | { |
433 | options = GNUNET_CHAT_MSG_ANONYMOUS; | 423 | options = GNUNET_CHAT_MSG_ANONYMOUS; |
434 | bob_wanted.meta = NULL; | 424 | bob_wanted.meta = NULL; |
435 | bob_wanted.sender = NULL; | 425 | bob_wanted.sender = NULL; |
436 | bob_wanted.next_task = &disconnect_bob; | 426 | bob_wanted.next_task = &disconnect_bob; |
437 | } | 427 | } |
438 | else if (is_auth) | 428 | else if (is_auth) |
439 | { | 429 | { |
440 | options = GNUNET_CHAT_MSG_AUTHENTICATED; | 430 | options = GNUNET_CHAT_MSG_AUTHENTICATED; |
441 | bob_wanted.meta = alice_meta; | 431 | bob_wanted.meta = alice_meta; |
442 | bob_wanted.sender = &alice; | 432 | bob_wanted.sender = &alice; |
443 | bob_wanted.next_task = &disconnect_bob; | 433 | bob_wanted.next_task = &disconnect_bob; |
444 | } | 434 | } |
445 | else | 435 | else |
446 | { | 436 | { |
447 | options = GNUNET_CHAT_MSG_OPTION_NONE; | 437 | options = GNUNET_CHAT_MSG_OPTION_NONE; |
448 | bob_wanted.meta = alice_meta; | 438 | bob_wanted.meta = alice_meta; |
449 | bob_wanted.sender = &alice; | 439 | bob_wanted.sender = &alice; |
450 | bob_wanted.next_task = &send_to_alice; | 440 | bob_wanted.next_task = &send_to_alice; |
451 | } | 441 | } |
452 | bob_wanted.msg = "Hi Bob!"; | 442 | bob_wanted.msg = "Hi Bob!"; |
453 | bob_wanted.opt = options; | 443 | bob_wanted.opt = options; |
454 | bob_wanted.timestamp = GNUNET_TIME_absolute_get (); | 444 | bob_wanted.timestamp = GNUNET_TIME_absolute_get (); |
@@ -471,8 +461,7 @@ prepare_for_alice_task (void *cls, | |||
471 | 461 | ||
472 | 462 | ||
473 | static void | 463 | static void |
474 | join_bob_task (void *cls, | 464 | join_bob_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
475 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
476 | { | 465 | { |
477 | #if VERBOSE | 466 | #if VERBOSE |
478 | printf ("Bob joining\n"); | 467 | printf ("Bob joining\n"); |
@@ -487,27 +476,25 @@ join_bob_task (void *cls, | |||
487 | bob_wanted.next_task_cls = NULL; | 476 | bob_wanted.next_task_cls = NULL; |
488 | is_ready = GNUNET_NO; | 477 | is_ready = GNUNET_NO; |
489 | bob_room = | 478 | bob_room = |
490 | GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta, | 479 | GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta, |
491 | "test", -1, | 480 | "test", -1, |
492 | &join_cb, &bob_wanted, | 481 | &join_cb, &bob_wanted, |
493 | &receive_cb, &bob_wanted, | 482 | &receive_cb, &bob_wanted, |
494 | &member_list_cb, &bob_wanted, | 483 | &member_list_cb, &bob_wanted, |
495 | &confirmation_cb, &bob_wanted, | 484 | &confirmation_cb, &bob_wanted, &bob); |
496 | &bob); | ||
497 | if (NULL == bob_room) | 485 | if (NULL == bob_room) |
498 | { | 486 | { |
499 | GNUNET_SCHEDULER_cancel (kill_task); | 487 | GNUNET_SCHEDULER_cancel (kill_task); |
500 | kill_task = GNUNET_SCHEDULER_NO_TASK; | 488 | kill_task = GNUNET_SCHEDULER_NO_TASK; |
501 | GNUNET_CHAT_leave_room (alice_room); | 489 | GNUNET_CHAT_leave_room (alice_room); |
502 | alice_room = NULL; | 490 | alice_room = NULL; |
503 | err = 1; | 491 | err = 1; |
504 | } | 492 | } |
505 | } | 493 | } |
506 | 494 | ||
507 | 495 | ||
508 | static void | 496 | static void |
509 | join_alice_task (void *cls, | 497 | join_alice_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
510 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
511 | { | 498 | { |
512 | #if VERBOSE | 499 | #if VERBOSE |
513 | printf ("Alice joining\n"); | 500 | printf ("Alice joining\n"); |
@@ -515,33 +502,31 @@ join_alice_task (void *cls, | |||
515 | alice_wanted.next_task = &join_bob_task; | 502 | alice_wanted.next_task = &join_bob_task; |
516 | alice_wanted.next_task_cls = NULL; | 503 | alice_wanted.next_task_cls = NULL; |
517 | alice_room = | 504 | alice_room = |
518 | GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta, | 505 | GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta, |
519 | "test", -1, | 506 | "test", -1, |
520 | &join_cb, &alice_wanted, | 507 | &join_cb, &alice_wanted, |
521 | &receive_cb, &alice_wanted, | 508 | &receive_cb, &alice_wanted, |
522 | &member_list_cb, &alice_wanted, | 509 | &member_list_cb, &alice_wanted, |
523 | &confirmation_cb, &alice_wanted, | 510 | &confirmation_cb, &alice_wanted, &alice); |
524 | &alice); | ||
525 | if (NULL == alice_room) | 511 | if (NULL == alice_room) |
526 | { | 512 | { |
527 | GNUNET_SCHEDULER_cancel (kill_task); | 513 | GNUNET_SCHEDULER_cancel (kill_task); |
528 | kill_task = GNUNET_SCHEDULER_NO_TASK; | 514 | kill_task = GNUNET_SCHEDULER_NO_TASK; |
529 | err = 1; | 515 | err = 1; |
530 | } | 516 | } |
531 | } | 517 | } |
532 | 518 | ||
533 | 519 | ||
534 | static void | 520 | static void |
535 | run (void *cls, | 521 | run (void *cls, |
536 | char *const *args, | 522 | char *const *args, |
537 | const char *cfgfile, | 523 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
538 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
539 | { | 524 | { |
540 | if (is_p2p) | 525 | if (is_p2p) |
541 | { | 526 | { |
542 | setup_peer (&p1, "test_chat_peer1.conf"); | 527 | setup_peer (&p1, "test_chat_peer1.conf"); |
543 | setup_peer (&p2, "test_chat_peer2.conf"); | 528 | setup_peer (&p2, "test_chat_peer2.conf"); |
544 | } | 529 | } |
545 | else | 530 | else |
546 | setup_peer (&p1, "test_chat_data.conf"); | 531 | setup_peer (&p1, "test_chat_data.conf"); |
547 | 532 | ||
@@ -555,19 +540,14 @@ run (void *cls, | |||
555 | EXTRACTOR_METATYPE_TITLE, | 540 | EXTRACTOR_METATYPE_TITLE, |
556 | EXTRACTOR_METAFORMAT_UTF8, | 541 | EXTRACTOR_METAFORMAT_UTF8, |
557 | "text/plain", | 542 | "text/plain", |
558 | "Alice", | 543 | "Alice", strlen ("Alice") + 1); |
559 | strlen("Alice")+1); | ||
560 | bob_meta = GNUNET_CONTAINER_meta_data_create (); | 544 | bob_meta = GNUNET_CONTAINER_meta_data_create (); |
561 | GNUNET_CONTAINER_meta_data_insert (bob_meta, | 545 | GNUNET_CONTAINER_meta_data_insert (bob_meta, |
562 | "<gnunet>", | 546 | "<gnunet>", |
563 | EXTRACTOR_METATYPE_TITLE, | 547 | EXTRACTOR_METATYPE_TITLE, |
564 | EXTRACTOR_METAFORMAT_UTF8, | 548 | EXTRACTOR_METAFORMAT_UTF8, |
565 | "text/plain", | 549 | "text/plain", "Bob", strlen ("Bob") + 1); |
566 | "Bob", | 550 | kill_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_kill, NULL); |
567 | strlen("Bob")+1); | ||
568 | kill_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
569 | &timeout_kill, | ||
570 | NULL); | ||
571 | GNUNET_SCHEDULER_add_now (&join_alice_task, NULL); | 551 | GNUNET_SCHEDULER_add_now (&join_alice_task, NULL); |
572 | } | 552 | } |
573 | 553 | ||
@@ -575,7 +555,7 @@ run (void *cls, | |||
575 | int | 555 | int |
576 | main (int argc, char *argv[]) | 556 | main (int argc, char *argv[]) |
577 | { | 557 | { |
578 | char *const argvx[] = { | 558 | char *const argvx[] = { |
579 | "test-chat", | 559 | "test-chat", |
580 | "-c", | 560 | "-c", |
581 | "test_chat_data.conf", | 561 | "test_chat_data.conf", |
@@ -588,40 +568,39 @@ main (int argc, char *argv[]) | |||
588 | GNUNET_GETOPT_OPTION_END | 568 | GNUNET_GETOPT_OPTION_END |
589 | }; | 569 | }; |
590 | 570 | ||
591 | GNUNET_log_setup ("test_chat", | 571 | GNUNET_log_setup ("test_chat", |
592 | #if VERBOSE | 572 | #if VERBOSE |
593 | "DEBUG", | 573 | "DEBUG", |
594 | #else | 574 | #else |
595 | "WARNING", | 575 | "WARNING", |
596 | #endif | 576 | #endif |
597 | NULL); | 577 | NULL); |
598 | if (strstr(argv[0], "p2p") != NULL) | 578 | if (strstr (argv[0], "p2p") != NULL) |
599 | { | 579 | { |
600 | is_p2p = GNUNET_YES; | 580 | is_p2p = GNUNET_YES; |
601 | } | 581 | } |
602 | if (strstr(argv[0], "acknowledgment") != NULL) | 582 | if (strstr (argv[0], "acknowledgment") != NULL) |
603 | { | 583 | { |
604 | is_ackn = GNUNET_YES; | 584 | is_ackn = GNUNET_YES; |
605 | } | 585 | } |
606 | else if (strstr(argv[0], "anonymous") != NULL) | 586 | else if (strstr (argv[0], "anonymous") != NULL) |
607 | { | 587 | { |
608 | is_anon = GNUNET_YES; | 588 | is_anon = GNUNET_YES; |
609 | } | 589 | } |
610 | else if (strstr(argv[0], "authentication") != NULL) | 590 | else if (strstr (argv[0], "authentication") != NULL) |
611 | { | 591 | { |
612 | is_auth = GNUNET_YES; | 592 | is_auth = GNUNET_YES; |
613 | } | 593 | } |
614 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, | 594 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, |
615 | argvx, "test-chat", | 595 | argvx, "test-chat", "nohelp", options, &run, NULL); |
616 | "nohelp", options, &run, NULL); | ||
617 | stop_arm (&p1); | 596 | stop_arm (&p1); |
618 | GNUNET_CONTAINER_meta_data_destroy (alice_meta); | 597 | GNUNET_CONTAINER_meta_data_destroy (alice_meta); |
619 | GNUNET_CONTAINER_meta_data_destroy (bob_meta); | 598 | GNUNET_CONTAINER_meta_data_destroy (bob_meta); |
620 | if (is_p2p) | 599 | if (is_p2p) |
621 | { | 600 | { |
622 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-1/"); | 601 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-1/"); |
623 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-2/"); | 602 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-2/"); |
624 | } | 603 | } |
625 | else | 604 | else |
626 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat/"); | 605 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat/"); |
627 | return err; | 606 | return err; |
diff --git a/src/chat/test_chat_private.c b/src/chat/test_chat_private.c index c14de0a88..507e333c9 100644 --- a/src/chat/test_chat_private.c +++ b/src/chat/test_chat_private.c | |||
@@ -133,11 +133,11 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
133 | p->cfg = GNUNET_CONFIGURATION_create (); | 133 | p->cfg = GNUNET_CONFIGURATION_create (); |
134 | #if START_ARM | 134 | #if START_ARM |
135 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 135 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
136 | "gnunet-service-arm", | 136 | "gnunet-service-arm", |
137 | #if VERBOSE | 137 | #if VERBOSE |
138 | "-L", "DEBUG", | 138 | "-L", "DEBUG", |
139 | #endif | 139 | #endif |
140 | "-c", cfgname, NULL); | 140 | "-c", cfgname, NULL); |
141 | #endif | 141 | #endif |
142 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 142 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
143 | } | 143 | } |
@@ -149,10 +149,11 @@ stop_arm (struct PeerContext *p) | |||
149 | #if START_ARM | 149 | #if START_ARM |
150 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | 150 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) |
151 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 151 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
152 | if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) | 152 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) |
153 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 153 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
155 | "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); | 155 | "ARM process %u stopped\n", |
156 | GNUNET_OS_process_get_pid (p->arm_proc)); | ||
156 | GNUNET_OS_process_close (p->arm_proc); | 157 | GNUNET_OS_process_close (p->arm_proc); |
157 | p->arm_proc = NULL; | 158 | p->arm_proc = NULL; |
158 | #endif | 159 | #endif |
@@ -161,41 +162,39 @@ stop_arm (struct PeerContext *p) | |||
161 | 162 | ||
162 | 163 | ||
163 | static void | 164 | static void |
164 | abort_test (void *cls, | 165 | abort_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
165 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
166 | { | 166 | { |
167 | if (alice_room != NULL) | 167 | if (alice_room != NULL) |
168 | { | 168 | { |
169 | GNUNET_CHAT_leave_room (alice_room); | 169 | GNUNET_CHAT_leave_room (alice_room); |
170 | alice_room = NULL; | 170 | alice_room = NULL; |
171 | } | 171 | } |
172 | if (bob_room != NULL) | 172 | if (bob_room != NULL) |
173 | { | 173 | { |
174 | GNUNET_CHAT_leave_room (bob_room); | 174 | GNUNET_CHAT_leave_room (bob_room); |
175 | bob_room = NULL; | 175 | bob_room = NULL; |
176 | } | 176 | } |
177 | if (carol_room != NULL) | 177 | if (carol_room != NULL) |
178 | { | 178 | { |
179 | GNUNET_CHAT_leave_room (carol_room); | 179 | GNUNET_CHAT_leave_room (carol_room); |
180 | carol_room = NULL; | 180 | carol_room = NULL; |
181 | } | 181 | } |
182 | err = 1; | 182 | err = 1; |
183 | } | 183 | } |
184 | 184 | ||
185 | 185 | ||
186 | static void | 186 | static void |
187 | timeout_kill (void *cls, | 187 | timeout_kill (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
188 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
189 | { | 188 | { |
190 | #if VERBOSE | 189 | #if VERBOSE |
191 | printf ("Timed out, stopping the test.\n"); | 190 | printf ("Timed out, stopping the test.\n"); |
192 | #endif | 191 | #endif |
193 | kill_task = GNUNET_SCHEDULER_NO_TASK; | 192 | kill_task = GNUNET_SCHEDULER_NO_TASK; |
194 | if (wait_task != GNUNET_SCHEDULER_NO_TASK) | 193 | if (wait_task != GNUNET_SCHEDULER_NO_TASK) |
195 | { | 194 | { |
196 | GNUNET_SCHEDULER_cancel (wait_task); | 195 | GNUNET_SCHEDULER_cancel (wait_task); |
197 | wait_task = GNUNET_SCHEDULER_NO_TASK; | 196 | wait_task = GNUNET_SCHEDULER_NO_TASK; |
198 | } | 197 | } |
199 | GNUNET_SCHEDULER_add_continuation (&abort_test, NULL, | 198 | GNUNET_SCHEDULER_add_continuation (&abort_test, NULL, |
200 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 199 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
201 | } | 200 | } |
@@ -226,11 +225,11 @@ member_list_cb (void *cls, | |||
226 | 225 | ||
227 | #if VERBOSE | 226 | #if VERBOSE |
228 | printf ("%s - told that %s has %s\n", | 227 | printf ("%s - told that %s has %s\n", |
229 | want->me, | 228 | want->me, |
230 | member_info == NULL ? NULL | 229 | member_info == NULL ? NULL |
231 | : GNUNET_CONTAINER_meta_data_get_by_type (member_info, | 230 | : GNUNET_CONTAINER_meta_data_get_by_type (member_info, |
232 | EXTRACTOR_METATYPE_TITLE), | 231 | EXTRACTOR_METATYPE_TITLE), |
233 | member_info == NULL ? "left" : "joined"); | 232 | member_info == NULL ? "left" : "joined"); |
234 | #endif | 233 | #endif |
235 | GNUNET_CRYPTO_hash (member_id, | 234 | GNUNET_CRYPTO_hash (member_id, |
236 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 235 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
@@ -248,34 +247,34 @@ member_list_cb (void *cls, | |||
248 | GNUNET_CONTAINER_meta_data_test_equal (member_info, | 247 | GNUNET_CONTAINER_meta_data_test_equal (member_info, |
249 | want->meta2))))) && | 248 | want->meta2))))) && |
250 | (options == want->opt)) | 249 | (options == want->opt)) |
251 | { | 250 | { |
252 | /* remember Bob's public key, we need it to send private message */ | 251 | /* remember Bob's public key, we need it to send private message */ |
253 | if (NULL == bob_public_key && | 252 | if (NULL == bob_public_key && |
254 | (0 == memcmp (&bob, want->sender, sizeof (GNUNET_HashCode)))) | 253 | (0 == memcmp (&bob, want->sender, sizeof (GNUNET_HashCode)))) |
255 | bob_public_key = | 254 | bob_public_key = |
256 | GNUNET_memdup (member_id, | 255 | GNUNET_memdup (member_id, |
257 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | 256 | sizeof (struct |
258 | if (want->sender2 != NULL) | 257 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); |
259 | { | 258 | if (want->sender2 != NULL) |
260 | /* flush alternative sender */ | ||
261 | if (0 == memcmp (&sender, want->sender, sizeof (GNUNET_HashCode))) | ||
262 | { | ||
263 | want->sender = want->sender2; | ||
264 | want->meta = want->meta2; | ||
265 | } | ||
266 | want->sender2 = NULL; | ||
267 | want->meta2 = NULL; | ||
268 | } | ||
269 | else | ||
270 | if (NULL != want->next_task) | ||
271 | GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls); | ||
272 | } | ||
273 | else | ||
274 | { | 259 | { |
275 | GNUNET_SCHEDULER_cancel (kill_task); | 260 | /* flush alternative sender */ |
276 | kill_task = GNUNET_SCHEDULER_NO_TASK; | 261 | if (0 == memcmp (&sender, want->sender, sizeof (GNUNET_HashCode))) |
277 | GNUNET_SCHEDULER_add_now (&abort_test, NULL); | 262 | { |
263 | want->sender = want->sender2; | ||
264 | want->meta = want->meta2; | ||
265 | } | ||
266 | want->sender2 = NULL; | ||
267 | want->meta2 = NULL; | ||
278 | } | 268 | } |
269 | else if (NULL != want->next_task) | ||
270 | GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls); | ||
271 | } | ||
272 | else | ||
273 | { | ||
274 | GNUNET_SCHEDULER_cancel (kill_task); | ||
275 | kill_task = GNUNET_SCHEDULER_NO_TASK; | ||
276 | GNUNET_SCHEDULER_add_now (&abort_test, NULL); | ||
277 | } | ||
279 | return GNUNET_OK; | 278 | return GNUNET_OK; |
280 | } | 279 | } |
281 | 280 | ||
@@ -283,7 +282,7 @@ member_list_cb (void *cls, | |||
283 | static int | 282 | static int |
284 | receive_cb (void *cls, | 283 | receive_cb (void *cls, |
285 | struct GNUNET_CHAT_Room *room, | 284 | struct GNUNET_CHAT_Room *room, |
286 | const GNUNET_HashCode *sender, | 285 | const GNUNET_HashCode * sender, |
287 | const struct GNUNET_CONTAINER_MetaData *meta, | 286 | const struct GNUNET_CONTAINER_MetaData *meta, |
288 | const char *message, | 287 | const char *message, |
289 | struct GNUNET_TIME_Absolute timestamp, | 288 | struct GNUNET_TIME_Absolute timestamp, |
@@ -311,25 +310,24 @@ receive_cb (void *cls, | |||
311 | * slightly greater | 310 | * slightly greater |
312 | */ | 311 | */ |
313 | (timestamp.abs_value >= want->timestamp.abs_value)) | 312 | (timestamp.abs_value >= want->timestamp.abs_value)) |
314 | { | 313 | { |
315 | if (NULL != want->next_task) | 314 | if (NULL != want->next_task) |
316 | GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls); | 315 | GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls); |
317 | } | 316 | } |
318 | else | 317 | else |
319 | { | 318 | { |
320 | GNUNET_SCHEDULER_cancel (kill_task); | 319 | GNUNET_SCHEDULER_cancel (kill_task); |
321 | kill_task = GNUNET_SCHEDULER_NO_TASK; | 320 | kill_task = GNUNET_SCHEDULER_NO_TASK; |
322 | GNUNET_SCHEDULER_cancel (finish_task); | 321 | GNUNET_SCHEDULER_cancel (finish_task); |
323 | finish_task = GNUNET_SCHEDULER_NO_TASK; | 322 | finish_task = GNUNET_SCHEDULER_NO_TASK; |
324 | GNUNET_SCHEDULER_add_now (&abort_test, NULL); | 323 | GNUNET_SCHEDULER_add_now (&abort_test, NULL); |
325 | } | 324 | } |
326 | return GNUNET_OK; | 325 | return GNUNET_OK; |
327 | } | 326 | } |
328 | 327 | ||
329 | 328 | ||
330 | static void | 329 | static void |
331 | wait_until_all_ready (void *cls, | 330 | wait_until_all_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
332 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
333 | { | 331 | { |
334 | GNUNET_SCHEDULER_Task task = cls; | 332 | GNUNET_SCHEDULER_Task task = cls; |
335 | 333 | ||
@@ -337,38 +335,34 @@ wait_until_all_ready (void *cls, | |||
337 | printf ("Waiting...\n"); | 335 | printf ("Waiting...\n"); |
338 | #endif | 336 | #endif |
339 | if (alice_ready && bob_ready) | 337 | if (alice_ready && bob_ready) |
340 | { | 338 | { |
341 | wait_task = GNUNET_SCHEDULER_NO_TASK; | 339 | wait_task = GNUNET_SCHEDULER_NO_TASK; |
342 | GNUNET_SCHEDULER_add_now (task, NULL); | 340 | GNUNET_SCHEDULER_add_now (task, NULL); |
343 | } | 341 | } |
344 | else | 342 | else |
345 | wait_task = | 343 | wait_task = |
346 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 344 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
347 | 5000), | 345 | (GNUNET_TIME_UNIT_MILLISECONDS, 5000), |
348 | &wait_until_all_ready, | 346 | &wait_until_all_ready, task); |
349 | task); | ||
350 | } | 347 | } |
351 | 348 | ||
352 | 349 | ||
353 | static void | 350 | static void |
354 | set_alice_ready (void *cls, | 351 | set_alice_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
355 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
356 | { | 352 | { |
357 | alice_ready = GNUNET_YES; | 353 | alice_ready = GNUNET_YES; |
358 | } | 354 | } |
359 | 355 | ||
360 | 356 | ||
361 | static void | 357 | static void |
362 | set_bob_ready (void *cls, | 358 | set_bob_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
363 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
364 | { | 359 | { |
365 | bob_ready = GNUNET_YES; | 360 | bob_ready = GNUNET_YES; |
366 | } | 361 | } |
367 | 362 | ||
368 | 363 | ||
369 | static void | 364 | static void |
370 | disconnect_alice (void *cls, | 365 | disconnect_alice (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
371 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
372 | { | 366 | { |
373 | #if VERBOSE | 367 | #if VERBOSE |
374 | printf ("Alice is leaving.\n"); | 368 | printf ("Alice is leaving.\n"); |
@@ -383,8 +377,7 @@ disconnect_alice (void *cls, | |||
383 | 377 | ||
384 | 378 | ||
385 | static void | 379 | static void |
386 | disconnect_bob (void *cls, | 380 | disconnect_bob (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
387 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
388 | { | 381 | { |
389 | #if VERBOSE | 382 | #if VERBOSE |
390 | printf ("Bod is leaving.\n"); | 383 | printf ("Bod is leaving.\n"); |
@@ -403,8 +396,7 @@ disconnect_bob (void *cls, | |||
403 | 396 | ||
404 | 397 | ||
405 | static void | 398 | static void |
406 | disconnect_carol (void *cls, | 399 | disconnect_carol (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
407 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
408 | { | 400 | { |
409 | #if VERBOSE | 401 | #if VERBOSE |
410 | printf ("Carol is leaving.\n"); | 402 | printf ("Carol is leaving.\n"); |
@@ -454,8 +446,7 @@ send_from_alice_to_bob (void *cls, | |||
454 | carol_wanted.next_task_cls = NULL; | 446 | carol_wanted.next_task_cls = NULL; |
455 | GNUNET_CHAT_send_message (alice_room, | 447 | GNUNET_CHAT_send_message (alice_room, |
456 | "Hi Bob!", | 448 | "Hi Bob!", |
457 | GNUNET_CHAT_MSG_PRIVATE, | 449 | GNUNET_CHAT_MSG_PRIVATE, bob_public_key, &seq); |
458 | bob_public_key, &seq); | ||
459 | finish_task = GNUNET_SCHEDULER_add_delayed (PM_TIMEOUT, | 450 | finish_task = GNUNET_SCHEDULER_add_delayed (PM_TIMEOUT, |
460 | &wait_until_all_ready, | 451 | &wait_until_all_ready, |
461 | &disconnect_carol); | 452 | &disconnect_carol); |
@@ -477,12 +468,13 @@ prepare_bob_for_alice_task (void *cls, | |||
477 | 468 | ||
478 | static void | 469 | static void |
479 | prepare_carol_for_alice_and_bob_task (void *cls, | 470 | prepare_carol_for_alice_and_bob_task (void *cls, |
480 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 471 | const struct GNUNET_SCHEDULER_TaskContext |
472 | *tc) | ||
481 | { | 473 | { |
482 | carol_wanted.meta = alice_meta; | 474 | carol_wanted.meta = alice_meta; |
483 | carol_wanted.sender = &alice; | 475 | carol_wanted.sender = &alice; |
484 | /* set alternative meta/sender since we don't know from which peer | 476 | /* set alternative meta/sender since we don't know from which peer |
485 | notification will come first */ | 477 | * notification will come first */ |
486 | carol_wanted.meta2 = bob_meta; | 478 | carol_wanted.meta2 = bob_meta; |
487 | carol_wanted.sender2 = &bob; | 479 | carol_wanted.sender2 = &bob; |
488 | carol_wanted.msg = NULL; | 480 | carol_wanted.msg = NULL; |
@@ -493,8 +485,7 @@ prepare_carol_for_alice_and_bob_task (void *cls, | |||
493 | 485 | ||
494 | 486 | ||
495 | static void | 487 | static void |
496 | join_carol_task (void *cls, | 488 | join_carol_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
497 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
498 | { | 489 | { |
499 | #if VERBOSE | 490 | #if VERBOSE |
500 | printf ("Carol joining\n"); | 491 | printf ("Carol joining\n"); |
@@ -516,28 +507,27 @@ join_carol_task (void *cls, | |||
516 | carol_wanted.next_task = &prepare_carol_for_alice_and_bob_task; | 507 | carol_wanted.next_task = &prepare_carol_for_alice_and_bob_task; |
517 | carol_wanted.next_task_cls = NULL; | 508 | carol_wanted.next_task_cls = NULL; |
518 | carol_room = | 509 | carol_room = |
519 | GNUNET_CHAT_join_room (is_p2p ? p3.cfg : p1.cfg, "carol", carol_meta, | 510 | GNUNET_CHAT_join_room (is_p2p ? p3.cfg : p1.cfg, "carol", carol_meta, |
520 | "test", -1, | 511 | "test", -1, |
521 | &join_cb, &carol_wanted, | 512 | &join_cb, &carol_wanted, |
522 | &receive_cb, &carol_wanted, | 513 | &receive_cb, &carol_wanted, |
523 | &member_list_cb, &carol_wanted, | 514 | &member_list_cb, &carol_wanted, |
524 | NULL, NULL, &carol); | 515 | NULL, NULL, &carol); |
525 | if (NULL == carol_room) | 516 | if (NULL == carol_room) |
526 | { | 517 | { |
527 | GNUNET_SCHEDULER_cancel (kill_task); | 518 | GNUNET_SCHEDULER_cancel (kill_task); |
528 | kill_task = GNUNET_SCHEDULER_NO_TASK; | 519 | kill_task = GNUNET_SCHEDULER_NO_TASK; |
529 | GNUNET_CHAT_leave_room (alice_room); | 520 | GNUNET_CHAT_leave_room (alice_room); |
530 | alice_room = NULL; | 521 | alice_room = NULL; |
531 | GNUNET_CHAT_leave_room (bob_room); | 522 | GNUNET_CHAT_leave_room (bob_room); |
532 | bob_room = NULL; | 523 | bob_room = NULL; |
533 | err = 1; | 524 | err = 1; |
534 | } | 525 | } |
535 | } | 526 | } |
536 | 527 | ||
537 | 528 | ||
538 | static void | 529 | static void |
539 | join_bob_task (void *cls, | 530 | join_bob_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
540 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
541 | { | 531 | { |
542 | #if VERBOSE | 532 | #if VERBOSE |
543 | printf ("Bob joining\n"); | 533 | printf ("Bob joining\n"); |
@@ -553,26 +543,24 @@ join_bob_task (void *cls, | |||
553 | bob_wanted.next_task_cls = NULL; | 543 | bob_wanted.next_task_cls = NULL; |
554 | bob_ready = GNUNET_NO; | 544 | bob_ready = GNUNET_NO; |
555 | bob_room = | 545 | bob_room = |
556 | GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta, | 546 | GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta, |
557 | "test", -1, | 547 | "test", -1, |
558 | &join_cb, &bob_wanted, | 548 | &join_cb, &bob_wanted, |
559 | &receive_cb, &bob_wanted, | 549 | &receive_cb, &bob_wanted, |
560 | &member_list_cb, &bob_wanted, | 550 | &member_list_cb, &bob_wanted, NULL, NULL, &bob); |
561 | NULL, NULL, &bob); | ||
562 | if (NULL == bob_room) | 551 | if (NULL == bob_room) |
563 | { | 552 | { |
564 | GNUNET_SCHEDULER_cancel (kill_task); | 553 | GNUNET_SCHEDULER_cancel (kill_task); |
565 | kill_task = GNUNET_SCHEDULER_NO_TASK; | 554 | kill_task = GNUNET_SCHEDULER_NO_TASK; |
566 | GNUNET_CHAT_leave_room (alice_room); | 555 | GNUNET_CHAT_leave_room (alice_room); |
567 | alice_room = NULL; | 556 | alice_room = NULL; |
568 | err = 1; | 557 | err = 1; |
569 | } | 558 | } |
570 | } | 559 | } |
571 | 560 | ||
572 | 561 | ||
573 | static void | 562 | static void |
574 | join_alice_task (void *cls, | 563 | join_alice_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
575 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
576 | { | 564 | { |
577 | #if VERBOSE | 565 | #if VERBOSE |
578 | printf ("Alice joining\n"); | 566 | printf ("Alice joining\n"); |
@@ -580,33 +568,32 @@ join_alice_task (void *cls, | |||
580 | alice_wanted.next_task = &join_bob_task; | 568 | alice_wanted.next_task = &join_bob_task; |
581 | alice_wanted.next_task_cls = NULL; | 569 | alice_wanted.next_task_cls = NULL; |
582 | alice_room = | 570 | alice_room = |
583 | GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta, | 571 | GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta, |
584 | "test", -1, | 572 | "test", -1, |
585 | &join_cb, &alice_wanted, | 573 | &join_cb, &alice_wanted, |
586 | &receive_cb, &alice_wanted, | 574 | &receive_cb, &alice_wanted, |
587 | &member_list_cb, &alice_wanted, | 575 | &member_list_cb, &alice_wanted, |
588 | NULL, NULL, &alice); | 576 | NULL, NULL, &alice); |
589 | if (NULL == alice_room) | 577 | if (NULL == alice_room) |
590 | { | 578 | { |
591 | GNUNET_SCHEDULER_cancel (kill_task); | 579 | GNUNET_SCHEDULER_cancel (kill_task); |
592 | kill_task = GNUNET_SCHEDULER_NO_TASK; | 580 | kill_task = GNUNET_SCHEDULER_NO_TASK; |
593 | err = 1; | 581 | err = 1; |
594 | } | 582 | } |
595 | } | 583 | } |
596 | 584 | ||
597 | 585 | ||
598 | static void | 586 | static void |
599 | run (void *cls, | 587 | run (void *cls, |
600 | char *const *args, | 588 | char *const *args, |
601 | const char *cfgfile, | 589 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
602 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
603 | { | 590 | { |
604 | if (is_p2p) | 591 | if (is_p2p) |
605 | { | 592 | { |
606 | setup_peer (&p1, "test_chat_peer1.conf"); | 593 | setup_peer (&p1, "test_chat_peer1.conf"); |
607 | setup_peer (&p2, "test_chat_peer2.conf"); | 594 | setup_peer (&p2, "test_chat_peer2.conf"); |
608 | setup_peer (&p3, "test_chat_peer3.conf"); | 595 | setup_peer (&p3, "test_chat_peer3.conf"); |
609 | } | 596 | } |
610 | else | 597 | else |
611 | setup_peer (&p1, "test_chat_data.conf"); | 598 | setup_peer (&p1, "test_chat_data.conf"); |
612 | 599 | ||
@@ -622,24 +609,20 @@ run (void *cls, | |||
622 | EXTRACTOR_METATYPE_TITLE, | 609 | EXTRACTOR_METATYPE_TITLE, |
623 | EXTRACTOR_METAFORMAT_UTF8, | 610 | EXTRACTOR_METAFORMAT_UTF8, |
624 | "text/plain", | 611 | "text/plain", |
625 | "Alice", | 612 | "Alice", strlen ("Alice") + 1); |
626 | strlen("Alice")+1); | ||
627 | bob_meta = GNUNET_CONTAINER_meta_data_create (); | 613 | bob_meta = GNUNET_CONTAINER_meta_data_create (); |
628 | GNUNET_CONTAINER_meta_data_insert (bob_meta, | 614 | GNUNET_CONTAINER_meta_data_insert (bob_meta, |
629 | "<gnunet>", | 615 | "<gnunet>", |
630 | EXTRACTOR_METATYPE_TITLE, | 616 | EXTRACTOR_METATYPE_TITLE, |
631 | EXTRACTOR_METAFORMAT_UTF8, | 617 | EXTRACTOR_METAFORMAT_UTF8, |
632 | "text/plain", | 618 | "text/plain", "Bob", strlen ("Bob") + 1); |
633 | "Bob", | ||
634 | strlen("Bob")+1); | ||
635 | carol_meta = GNUNET_CONTAINER_meta_data_create (); | 619 | carol_meta = GNUNET_CONTAINER_meta_data_create (); |
636 | GNUNET_CONTAINER_meta_data_insert (carol_meta, | 620 | GNUNET_CONTAINER_meta_data_insert (carol_meta, |
637 | "<gnunet>", | 621 | "<gnunet>", |
638 | EXTRACTOR_METATYPE_TITLE, | 622 | EXTRACTOR_METATYPE_TITLE, |
639 | EXTRACTOR_METAFORMAT_UTF8, | 623 | EXTRACTOR_METAFORMAT_UTF8, |
640 | "text/plain", | 624 | "text/plain", |
641 | "Carol", | 625 | "Carol", strlen ("Carol") + 1); |
642 | strlen("Carol")+1); | ||
643 | kill_task = GNUNET_SCHEDULER_add_delayed (KILL_TIMEOUT, &timeout_kill, NULL); | 626 | kill_task = GNUNET_SCHEDULER_add_delayed (KILL_TIMEOUT, &timeout_kill, NULL); |
644 | GNUNET_SCHEDULER_add_now (&join_alice_task, NULL); | 627 | GNUNET_SCHEDULER_add_now (&join_alice_task, NULL); |
645 | } | 628 | } |
@@ -648,7 +631,7 @@ run (void *cls, | |||
648 | int | 631 | int |
649 | main (int argc, char *argv[]) | 632 | main (int argc, char *argv[]) |
650 | { | 633 | { |
651 | char *const argvx[] = { | 634 | char *const argvx[] = { |
652 | "test-chat", | 635 | "test-chat", |
653 | "-c", | 636 | "-c", |
654 | "test_chat_data.conf", | 637 | "test_chat_data.conf", |
@@ -661,30 +644,29 @@ main (int argc, char *argv[]) | |||
661 | GNUNET_GETOPT_OPTION_END | 644 | GNUNET_GETOPT_OPTION_END |
662 | }; | 645 | }; |
663 | 646 | ||
664 | GNUNET_log_setup ("test_chat", | 647 | GNUNET_log_setup ("test_chat", |
665 | #if VERBOSE | 648 | #if VERBOSE |
666 | "DEBUG", | 649 | "DEBUG", |
667 | #else | 650 | #else |
668 | "WARNING", | 651 | "WARNING", |
669 | #endif | 652 | #endif |
670 | NULL); | 653 | NULL); |
671 | if (strstr(argv[0], "p2p") != NULL) | 654 | if (strstr (argv[0], "p2p") != NULL) |
672 | { | 655 | { |
673 | is_p2p = GNUNET_YES; | 656 | is_p2p = GNUNET_YES; |
674 | } | 657 | } |
675 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, | 658 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, |
676 | argvx, "test-chat", | 659 | argvx, "test-chat", "nohelp", options, &run, NULL); |
677 | "nohelp", options, &run, NULL); | ||
678 | stop_arm (&p1); | 660 | stop_arm (&p1); |
679 | GNUNET_CONTAINER_meta_data_destroy (alice_meta); | 661 | GNUNET_CONTAINER_meta_data_destroy (alice_meta); |
680 | GNUNET_CONTAINER_meta_data_destroy (bob_meta); | 662 | GNUNET_CONTAINER_meta_data_destroy (bob_meta); |
681 | GNUNET_CONTAINER_meta_data_destroy (carol_meta); | 663 | GNUNET_CONTAINER_meta_data_destroy (carol_meta); |
682 | if (is_p2p) | 664 | if (is_p2p) |
683 | { | 665 | { |
684 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-1/"); | 666 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-1/"); |
685 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-2/"); | 667 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-2/"); |
686 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-3/"); | 668 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-3/"); |
687 | } | 669 | } |
688 | else | 670 | else |
689 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat/"); | 671 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat/"); |
690 | return err; | 672 | return err; |