aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cadet/gnunet-service-cadet_tunnels.c4
-rw-r--r--src/conversation/gnunet-helper-audio-playback-gst.c5
-rw-r--r--src/conversation/gnunet-helper-audio-playback.c5
-rw-r--r--src/conversation/gnunet_gst.c5
-rw-r--r--src/conversation/microphone.c4
-rw-r--r--src/core/gnunet-service-core.c3
-rw-r--r--src/core/gnunet-service-core_kx.c3
-rw-r--r--src/fs/fs_dirmetascan.c3
-rw-r--r--src/include/gnunet_mst_lib.h4
-rw-r--r--src/include/gnunet_protocols.h30
-rw-r--r--src/include/gnunet_service_lib.h7
-rw-r--r--src/multicast/gnunet-service-multicast.c248
-rw-r--r--src/multicast/multicast_api.c51
-rw-r--r--src/multicast/test_multicast_multipeer.c312
-rw-r--r--src/psyc/gnunet-service-psyc.c131
-rw-r--r--src/psyc/psyc_api.c103
-rw-r--r--src/psyc/test_psyc.c28
-rw-r--r--src/psyc/test_psyc.conf16
-rw-r--r--src/psycstore/psycstore_api.c10
-rw-r--r--src/social/gnunet-service-social.c774
-rw-r--r--src/social/gnunet-social.c26
-rw-r--r--src/social/social_api.c292
-rw-r--r--src/social/test_social.c268
-rw-r--r--src/social/test_social.conf19
-rw-r--r--src/statistics/gnunet-service-statistics.c4
-rw-r--r--src/testbed/gnunet-helper-testbed.c7
-rw-r--r--src/transport/gnunet-helper-transport-wlan-dummy.c6
-rw-r--r--src/transport/plugin_transport_http_server.c2
-rw-r--r--src/util/client.c41
-rw-r--r--src/util/mq.c22
-rw-r--r--src/util/mst.c27
-rw-r--r--src/util/scheduler.c4
-rw-r--r--src/util/service.c31
-rw-r--r--src/vpn/gnunet-service-vpn.c3
34 files changed, 1500 insertions, 998 deletions
diff --git a/src/cadet/gnunet-service-cadet_tunnels.c b/src/cadet/gnunet-service-cadet_tunnels.c
index 22e19ef70..fb91a4a6a 100644
--- a/src/cadet/gnunet-service-cadet_tunnels.c
+++ b/src/cadet/gnunet-service-cadet_tunnels.c
@@ -2856,7 +2856,9 @@ handle_plaintext_channel_destroy (void *cls,
2856 * 2856 *
2857 * @param cls the `struct CadetTunnel` that got the message 2857 * @param cls the `struct CadetTunnel` that got the message
2858 * @param msg the message 2858 * @param msg the message
2859 * @return #GNUNET_OK (continue to process) 2859 * @return #GNUNET_OK on success (always)
2860 * #GNUNET_NO to stop further processing (no error)
2861 * #GNUNET_SYSERR to stop further processing with error
2860 */ 2862 */
2861static int 2863static int
2862handle_decrypted (void *cls, 2864handle_decrypted (void *cls,
diff --git a/src/conversation/gnunet-helper-audio-playback-gst.c b/src/conversation/gnunet-helper-audio-playback-gst.c
index 264b14e76..002fed6c7 100644
--- a/src/conversation/gnunet-helper-audio-playback-gst.c
+++ b/src/conversation/gnunet-helper-audio-playback-gst.c
@@ -221,6 +221,11 @@ feed_buffer_to_gst (const char *audio, size_t b_len)
221 221
222/** 222/**
223 * Message callback 223 * Message callback
224 *
225 * @param msg message we received.
226 * @return #GNUNET_OK on success,
227 * #GNUNET_NO to stop further processing due to disconnect (no error)
228 * #GNUNET_SYSERR to stop further processing due to error
224 */ 229 */
225static int 230static int
226stdin_receiver (void *cls, 231stdin_receiver (void *cls,
diff --git a/src/conversation/gnunet-helper-audio-playback.c b/src/conversation/gnunet-helper-audio-playback.c
index 4344e1d41..18f63ad18 100644
--- a/src/conversation/gnunet-helper-audio-playback.c
+++ b/src/conversation/gnunet-helper-audio-playback.c
@@ -546,6 +546,11 @@ ogg_demux_and_decode ()
546 546
547/** 547/**
548 * Message callback 548 * Message callback
549 *
550 * @param msg message we received.
551 * @return #GNUNET_OK on success,
552 * #GNUNET_NO to stop further processing due to disconnect (no error)
553 * #GNUNET_SYSERR to stop further processing due to error
549 */ 554 */
550static int 555static int
551stdin_receiver (void *cls, 556stdin_receiver (void *cls,
diff --git a/src/conversation/gnunet_gst.c b/src/conversation/gnunet_gst.c
index 52cb2ccbc..828b35077 100644
--- a/src/conversation/gnunet_gst.c
+++ b/src/conversation/gnunet_gst.c
@@ -649,6 +649,11 @@ gnunet_read (GNUNET_gstData * d)
649 649
650/** 650/**
651 * Message callback 651 * Message callback
652 *
653 * @param msg message we received.
654 * @return #GNUNET_OK on success,
655 * #GNUNET_NO to stop further processing due to disconnect (no error)
656 * #GNUNET_SYSERR to stop further processing due to error
652 */ 657 */
653static int 658static int
654stdin_receiver (void *cls, 659stdin_receiver (void *cls,
diff --git a/src/conversation/microphone.c b/src/conversation/microphone.c
index 7871433a3..11468fc59 100644
--- a/src/conversation/microphone.c
+++ b/src/conversation/microphone.c
@@ -65,7 +65,9 @@ struct Microphone
65 * 65 *
66 * @param cls clsoure with our `struct Microphone` 66 * @param cls clsoure with our `struct Microphone`
67 * @param msg the message from the helper 67 * @param msg the message from the helper
68 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 68 * @return #GNUNET_OK on success,
69 * #GNUNET_NO to stop further processing (no error)
70 * #GNUNET_SYSERR to stop further processing with error
69 */ 71 */
70static int 72static int
71process_record_messages (void *cls, 73process_record_messages (void *cls,
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c
index 625bf9655..214f72904 100644
--- a/src/core/gnunet-service-core.c
+++ b/src/core/gnunet-service-core.c
@@ -426,6 +426,9 @@ struct TokenizerContext
426 * 426 *
427 * @param cls reservation request (`struct TokenizerContext`) 427 * @param cls reservation request (`struct TokenizerContext`)
428 * @param message the actual message 428 * @param message the actual message
429 * @return #GNUNET_OK on success,
430 * #GNUNET_NO to stop further processing (no error)
431 * #GNUNET_SYSERR to stop further processing with error
429 */ 432 */
430static int 433static int
431tokenized_cb (void *cls, 434tokenized_cb (void *cls,
diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c
index c80fbb322..944d1e692 100644
--- a/src/core/gnunet-service-core_kx.c
+++ b/src/core/gnunet-service-core_kx.c
@@ -708,6 +708,9 @@ setup_fresh_ping (struct GSC_KeyExchangeInfo *kx)
708 * 708 *
709 * @param cls the `struct GSC_KeyExchangeInfo` 709 * @param cls the `struct GSC_KeyExchangeInfo`
710 * @param m the message 710 * @param m the message
711 * @return #GNUNET_OK on success,
712 * #GNUNET_NO to stop further processing (no error)
713 * #GNUNET_SYSERR to stop further processing with error
711 */ 714 */
712static int 715static int
713deliver_message (void *cls, 716deliver_message (void *cls,
diff --git a/src/fs/fs_dirmetascan.c b/src/fs/fs_dirmetascan.c
index 7b9f178fd..8a3e37b49 100644
--- a/src/fs/fs_dirmetascan.c
+++ b/src/fs/fs_dirmetascan.c
@@ -246,6 +246,9 @@ finish_scan (void *cls)
246 * 246 *
247 * @param cls the closure (directory scanner object) 247 * @param cls the closure (directory scanner object)
248 * @param msg message from the helper process 248 * @param msg message from the helper process
249 * @return #GNUNET_OK on success,
250 * #GNUNET_NO to stop further processing (no error)
251 * #GNUNET_SYSERR to stop further processing with error
249 */ 252 */
250static int 253static int
251process_helper_msgs (void *cls, 254process_helper_msgs (void *cls,
diff --git a/src/include/gnunet_mst_lib.h b/src/include/gnunet_mst_lib.h
index 7a1ca7a55..fe6524eb3 100644
--- a/src/include/gnunet_mst_lib.h
+++ b/src/include/gnunet_mst_lib.h
@@ -61,7 +61,9 @@ struct GNUNET_MessageStreamTokenizer;
61 * 61 *
62 * @param cls closure 62 * @param cls closure
63 * @param message the actual message 63 * @param message the actual message
64 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing 64 * @return #GNUNET_OK on success,
65 * #GNUNET_NO to stop further processing due to disconnect (no error)
66 * #GNUNET_SYSERR to stop further processing due to error
65 */ 67 */
66typedef int 68typedef int
67(*GNUNET_MessageTokenizerCallback) (void *cls, 69(*GNUNET_MessageTokenizerCallback) (void *cls,
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 72054913f..9cfd00e39 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -2067,7 +2067,11 @@ extern "C"
2067/** S->C: slave join acknowledgement */ 2067/** S->C: slave join acknowledgement */
2068#define GNUNET_MESSAGE_TYPE_PSYC_SLAVE_JOIN_ACK 684 2068#define GNUNET_MESSAGE_TYPE_PSYC_SLAVE_JOIN_ACK 684
2069 2069
2070/* 685-686 */ 2070/** C->S: request to part from a channel */
2071#define GNUNET_MESSAGE_TYPE_PSYC_PART_REQUEST 685
2072
2073/** S->C: acknowledgement that a slave of master parted from a channel */
2074#define GNUNET_MESSAGE_TYPE_PSYC_PART_ACK 686
2071 2075
2072/** M->S->C: incoming join request from multicast */ 2076/** M->S->C: incoming join request from multicast */
2073#define GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST 687 2077#define GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST 687
@@ -2258,6 +2262,7 @@ extern "C"
2258 */ 2262 */
2259#define GNUNET_MESSAGE_TYPE_MULTICAST_PART_ACK 755 2263#define GNUNET_MESSAGE_TYPE_MULTICAST_PART_ACK 755
2260 2264
2265// FIXME: this is never used!
2261/** 2266/**
2262 * Group terminated. 2267 * Group terminated.
2263 */ 2268 */
@@ -2398,35 +2403,38 @@ extern "C"
2398/** C->S: request to leave a place */ 2403/** C->S: request to leave a place */
2399#define GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE 848 2404#define GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE 848
2400 2405
2406/** S->C: place leave acknowledgement */
2407#define GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE_ACK 849
2408
2401/** C->S: add place to GNS zone */ 2409/** C->S: add place to GNS zone */
2402#define GNUNET_MESSAGE_TYPE_SOCIAL_ZONE_ADD_PLACE 849 2410#define GNUNET_MESSAGE_TYPE_SOCIAL_ZONE_ADD_PLACE 850
2403 2411
2404/** C->S: add nym to GNS zone */ 2412/** C->S: add nym to GNS zone */
2405#define GNUNET_MESSAGE_TYPE_SOCIAL_ZONE_ADD_NYM 850 2413#define GNUNET_MESSAGE_TYPE_SOCIAL_ZONE_ADD_NYM 851
2406 2414
2407/** C->S: connect application */ 2415/** C->S: connect application */
2408#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_CONNECT 851 2416#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_CONNECT 852
2409 2417
2410/** C->S: detach a place from application */ 2418/** C->S: detach a place from application */
2411#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_DETACH 852 2419#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_DETACH 853
2412 2420
2413/** S->C: notify about an existing ego */ 2421/** S->C: notify about an existing ego */
2414#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO 853 2422#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO 854
2415 2423
2416/** S->C: end of ego list */ 2424/** S->C: end of ego list */
2417#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO_END 854 2425#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO_END 855
2418 2426
2419/** S->C: notify about an existing place */ 2427/** S->C: notify about an existing place */
2420#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE 855 2428#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE 856
2421 2429
2422/** S->C: end of place list */ 2430/** S->C: end of place list */
2423#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE_END 856 2431#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE_END 857
2424 2432
2425/** C->S: set message processing flags */ 2433/** C->S: set message processing flags */
2426#define GNUNET_MESSAGE_TYPE_SOCIAL_MSG_PROC_SET 860 2434#define GNUNET_MESSAGE_TYPE_SOCIAL_MSG_PROC_SET 858
2427 2435
2428/** C->S: clear message processing flags */ 2436/** C->S: clear message processing flags */
2429#define GNUNET_MESSAGE_TYPE_SOCIAL_MSG_PROC_CLEAR 861 2437#define GNUNET_MESSAGE_TYPE_SOCIAL_MSG_PROC_CLEAR 859
2430 2438
2431/******************************************************************************* 2439/*******************************************************************************
2432 * X-VINE DHT messages 2440 * X-VINE DHT messages
diff --git a/src/include/gnunet_service_lib.h b/src/include/gnunet_service_lib.h
index aacafe956..dda827c95 100644
--- a/src/include/gnunet_service_lib.h
+++ b/src/include/gnunet_service_lib.h
@@ -366,11 +366,16 @@ GNUNET_SERVICE_client_disable_continue_warning (struct GNUNET_SERVICE_Client *c)
366/** 366/**
367 * Ask the server to disconnect from the given client. This is the 367 * Ask the server to disconnect from the given client. This is the
368 * same as returning #GNUNET_SYSERR within the check procedure when 368 * same as returning #GNUNET_SYSERR within the check procedure when
369 * handling a message, wexcept that it allows dropping of a client even 369 * handling a message, except that it allows dropping of a client even
370 * when not handling a message from that client. The `disconnect_cb` 370 * when not handling a message from that client. The `disconnect_cb`
371 * will be called on @a c even if the application closes the connection 371 * will be called on @a c even if the application closes the connection
372 * using this function. 372 * using this function.
373 * 373 *
374 * This function should be called (outside of util's internal logic)
375 * if (and usually only if) the client has violated the
376 * protocol. Otherwise, we should leave it to the client to disconnect
377 * from the service.
378 *
374 * @param c client to disconnect now 379 * @param c client to disconnect now
375 */ 380 */
376void 381void
diff --git a/src/multicast/gnunet-service-multicast.c b/src/multicast/gnunet-service-multicast.c
index 2f4dc8a14..ba1086cc5 100644
--- a/src/multicast/gnunet-service-multicast.c
+++ b/src/multicast/gnunet-service-multicast.c
@@ -137,6 +137,7 @@ struct Channel
137 */ 137 */
138 struct GNUNET_CADET_Channel *channel; 138 struct GNUNET_CADET_Channel *channel;
139 139
140 // FIXME: not used
140 /** 141 /**
141 * CADET transmission handle. 142 * CADET transmission handle.
142 */ 143 */
@@ -228,7 +229,7 @@ struct Group
228 /** 229 /**
229 * Is the client disconnected? #GNUNET_YES or #GNUNET_NO 230 * Is the client disconnected? #GNUNET_YES or #GNUNET_NO
230 */ 231 */
231 uint8_t disconnected; 232 uint8_t is_disconnected;
232 233
233 /** 234 /**
234 * Is this an origin (#GNUNET_YES), or member (#GNUNET_NO)? 235 * Is this an origin (#GNUNET_YES), or member (#GNUNET_NO)?
@@ -365,6 +366,8 @@ client_send_join_decision (struct Member *mem,
365static void 366static void
366shutdown_task (void *cls) 367shutdown_task (void *cls)
367{ 368{
369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
370 "shutting down\n");
368 if (NULL != cadet) 371 if (NULL != cadet)
369 { 372 {
370 GNUNET_CADET_disconnect (cadet); 373 GNUNET_CADET_disconnect (cadet);
@@ -420,6 +423,11 @@ cleanup_member (struct Member *mem)
420 GNUNET_free (mem->join_dcsn); 423 GNUNET_free (mem->join_dcsn);
421 mem->join_dcsn = NULL; 424 mem->join_dcsn = NULL;
422 } 425 }
426 if (NULL != mem->origin_channel)
427 {
428 GNUNET_CADET_channel_destroy (mem->origin_channel->channel);
429 mem->origin_channel = NULL;
430 }
423 GNUNET_CONTAINER_multihashmap_remove (members, &grp->pub_key_hash, mem); 431 GNUNET_CONTAINER_multihashmap_remove (members, &grp->pub_key_hash, mem);
424 GNUNET_free (mem); 432 GNUNET_free (mem);
425} 433}
@@ -553,36 +561,47 @@ client_send (struct GNUNET_SERVICE_Client *client,
553 * Send message to all clients connected to the group. 561 * Send message to all clients connected to the group.
554 */ 562 */
555static void 563static void
556client_send_group (const struct Group *grp, 564client_send_group_keep_envelope (const struct Group *grp,
557 const struct GNUNET_MessageHeader *msg) 565 struct GNUNET_MQ_Envelope *env)
558{ 566{
559 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 567 struct ClientList *cli = grp->clients_head;
560 "%p Sending message to all clients of the group.\n", grp);
561 568
562 struct ClientList *cl = grp->clients_head; 569 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
563 while (NULL != cl) 570 "%p Sending message to all clients of the group.\n",
571 grp);
572 while (NULL != cli)
564 { 573 {
565 struct GNUNET_MQ_Envelope * 574 GNUNET_MQ_send_copy (GNUNET_SERVICE_client_get_mq (cli->client),
566 env = GNUNET_MQ_msg_copy (msg); 575 env);
567 576 cli = cli->next;
568 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cl->client),
569 env);
570 cl = cl->next;
571 } 577 }
572} 578}
573 579
574 580
575/** 581/**
582 * Send message to all clients connected to the group and
583 * takes care of freeing @env.
584 */
585static void
586client_send_group (const struct Group *grp,
587 struct GNUNET_MQ_Envelope *env)
588{
589 client_send_group_keep_envelope (grp, env);
590 GNUNET_MQ_discard (env);
591}
592
593
594/**
576 * Iterator callback for sending a message to origin clients. 595 * Iterator callback for sending a message to origin clients.
577 */ 596 */
578static int 597static int
579client_send_origin_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash, 598client_send_origin_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash,
580 void *origin) 599 void *origin)
581{ 600{
582 const struct GNUNET_MessageHeader *msg = cls; 601 struct GNUNET_MQ_Envelope *env = cls;
583 struct Member *orig = origin; 602 struct Member *orig = origin;
584 603
585 client_send_group (&orig->group, msg); 604 client_send_group_keep_envelope (&orig->group, env);
586 return GNUNET_YES; 605 return GNUNET_YES;
587} 606}
588 607
@@ -594,12 +613,12 @@ static int
594client_send_member_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash, 613client_send_member_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash,
595 void *member) 614 void *member)
596{ 615{
597 const struct GNUNET_MessageHeader *msg = cls; 616 struct GNUNET_MQ_Envelope *env = cls;
598 struct Member *mem = member; 617 struct Member *mem = member;
599 618
600 if (NULL != mem->join_dcsn) 619 if (NULL != mem->join_dcsn)
601 { /* Only send message to admitted members */ 620 { /* Only send message to admitted members */
602 client_send_group (&mem->group, msg); 621 client_send_group_keep_envelope (&mem->group, env);
603 } 622 }
604 return GNUNET_YES; 623 return GNUNET_YES;
605} 624}
@@ -615,15 +634,16 @@ client_send_member_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash,
615 */ 634 */
616static int 635static int
617client_send_all (struct GNUNET_HashCode *pub_key_hash, 636client_send_all (struct GNUNET_HashCode *pub_key_hash,
618 const struct GNUNET_MessageHeader *msg) 637 struct GNUNET_MQ_Envelope *env)
619{ 638{
620 int n = 0; 639 int n = 0;
621 n += GNUNET_CONTAINER_multihashmap_get_multiple (origins, pub_key_hash, 640 n += GNUNET_CONTAINER_multihashmap_get_multiple (origins, pub_key_hash,
622 client_send_origin_cb, 641 client_send_origin_cb,
623 (void *) msg); 642 (void *) env);
624 n += GNUNET_CONTAINER_multihashmap_get_multiple (members, pub_key_hash, 643 n += GNUNET_CONTAINER_multihashmap_get_multiple (members, pub_key_hash,
625 client_send_member_cb, 644 client_send_member_cb,
626 (void *) msg); 645 (void *) env);
646 GNUNET_MQ_discard (env);
627 return n; 647 return n;
628} 648}
629 649
@@ -636,14 +656,14 @@ client_send_all (struct GNUNET_HashCode *pub_key_hash,
636 */ 656 */
637static int 657static int
638client_send_random (struct GNUNET_HashCode *pub_key_hash, 658client_send_random (struct GNUNET_HashCode *pub_key_hash,
639 const struct GNUNET_MessageHeader *msg) 659 struct GNUNET_MQ_Envelope *env)
640{ 660{
641 int n = 0; 661 int n = 0;
642 n = GNUNET_CONTAINER_multihashmap_get_random (origins, client_send_origin_cb, 662 n = GNUNET_CONTAINER_multihashmap_get_random (origins, client_send_origin_cb,
643 (void *) msg); 663 (void *) env);
644 if (n <= 0) 664 if (n <= 0)
645 n = GNUNET_CONTAINER_multihashmap_get_random (members, client_send_member_cb, 665 n = GNUNET_CONTAINER_multihashmap_get_random (members, client_send_member_cb,
646 (void *) msg); 666 (void *) env);
647 return n; 667 return n;
648} 668}
649 669
@@ -658,12 +678,12 @@ client_send_random (struct GNUNET_HashCode *pub_key_hash,
658 */ 678 */
659static int 679static int
660client_send_origin (struct GNUNET_HashCode *pub_key_hash, 680client_send_origin (struct GNUNET_HashCode *pub_key_hash,
661 const struct GNUNET_MessageHeader *msg) 681 struct GNUNET_MQ_Envelope *env)
662{ 682{
663 int n = 0; 683 int n = 0;
664 n += GNUNET_CONTAINER_multihashmap_get_multiple (origins, pub_key_hash, 684 n += GNUNET_CONTAINER_multihashmap_get_multiple (origins, pub_key_hash,
665 client_send_origin_cb, 685 client_send_origin_cb,
666 (void *) msg); 686 (void *) env);
667 return n; 687 return n;
668} 688}
669 689
@@ -677,17 +697,12 @@ client_send_origin (struct GNUNET_HashCode *pub_key_hash,
677static void 697static void
678client_send_ack (struct GNUNET_HashCode *pub_key_hash) 698client_send_ack (struct GNUNET_HashCode *pub_key_hash)
679{ 699{
700 struct GNUNET_MQ_Envelope *env;
701
680 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 702 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
681 "Sending message ACK to client.\n"); 703 "Sending message ACK to client.\n");
682 704 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_MULTICAST_FRAGMENT_ACK);
683 static struct GNUNET_MessageHeader *msg = NULL; 705 client_send_all (pub_key_hash, env);
684 if (NULL == msg)
685 {
686 msg = GNUNET_malloc (sizeof (*msg));
687 msg->type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_FRAGMENT_ACK);
688 msg->size = htons (sizeof (*msg));
689 }
690 client_send_all (pub_key_hash, msg);
691} 706}
692 707
693 708
@@ -983,7 +998,8 @@ handle_cadet_join_request (void *cls,
983 chn->peer = req->peer; 998 chn->peer = req->peer;
984 chn->join_status = JOIN_WAITING; 999 chn->join_status = JOIN_WAITING;
985 1000
986 client_send_all (&group_pub_hash, &req->header); 1001 client_send_all (&group_pub_hash,
1002 GNUNET_MQ_msg_copy (&req->header));
987} 1003}
988 1004
989 1005
@@ -1102,7 +1118,8 @@ handle_cadet_message (void *cls,
1102{ 1118{
1103 struct Channel *chn = cls; 1119 struct Channel *chn = cls;
1104 GNUNET_CADET_receive_done (chn->channel); 1120 GNUNET_CADET_receive_done (chn->channel);
1105 client_send_all (&chn->group_pub_hash, &msg->header); 1121 client_send_all (&chn->group_pub_hash,
1122 GNUNET_MQ_msg_copy (&msg->header));
1106} 1123}
1107 1124
1108 1125
@@ -1153,30 +1170,32 @@ handle_cadet_request (void *cls,
1153{ 1170{
1154 struct Channel *chn = cls; 1171 struct Channel *chn = cls;
1155 GNUNET_CADET_receive_done (chn->channel); 1172 GNUNET_CADET_receive_done (chn->channel);
1156 client_send_origin (&chn->group_pub_hash, &req->header); 1173 client_send_origin (&chn->group_pub_hash,
1174 GNUNET_MQ_msg_copy (&req->header));
1157} 1175}
1158 1176
1159 1177
1160static int 1178// FIXME: do checks in handle_cadet_replay_request
1161check_cadet_replay_request (void *cls, 1179//static int
1162 const struct MulticastReplayRequestMessage *req) 1180//check_cadet_replay_request (void *cls,
1163{ 1181// const struct MulticastReplayRequestMessage *req)
1164 uint16_t size = ntohs (req->header.size); 1182//{
1165 if (size < sizeof (*req)) 1183// uint16_t size = ntohs (req->header.size);
1166 { 1184// if (size < sizeof (*req))
1167 GNUNET_break_op (0); 1185// {
1168 return GNUNET_SYSERR; 1186// GNUNET_break_op (0);
1169 } 1187// return GNUNET_SYSERR;
1170 1188// }
1171 struct Channel *chn = cls; 1189//
1172 if (NULL == chn) 1190// struct Channel *chn = cls;
1173 { 1191// if (NULL == chn)
1174 GNUNET_break_op (0); 1192// {
1175 return GNUNET_SYSERR; 1193// GNUNET_break_op (0);
1176 } 1194// return GNUNET_SYSERR;
1177 1195// }
1178 return GNUNET_OK; 1196//
1179} 1197// return GNUNET_OK;
1198//}
1180 1199
1181 1200
1182/** 1201/**
@@ -1187,6 +1206,7 @@ handle_cadet_replay_request (void *cls,
1187 const struct MulticastReplayRequestMessage *req) 1206 const struct MulticastReplayRequestMessage *req)
1188{ 1207{
1189 struct Channel *chn = cls; 1208 struct Channel *chn = cls;
1209
1190 GNUNET_CADET_receive_done (chn->channel); 1210 GNUNET_CADET_receive_done (chn->channel);
1191 1211
1192 struct MulticastReplayRequestMessage rep = *req; 1212 struct MulticastReplayRequestMessage rep = *req;
@@ -1203,12 +1223,16 @@ handle_cadet_replay_request (void *cls,
1203 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 1223 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1204 } 1224 }
1205 struct GNUNET_HashCode key_hash; 1225 struct GNUNET_HashCode key_hash;
1206 replay_key_hash (rep.fragment_id, rep.message_id, rep.fragment_offset, 1226 replay_key_hash (rep.fragment_id,
1207 rep.flags, &key_hash); 1227 rep.message_id,
1228 rep.fragment_offset,
1229 rep.flags,
1230 &key_hash);
1208 GNUNET_CONTAINER_multihashmap_put (grp_replay_req, &key_hash, chn, 1231 GNUNET_CONTAINER_multihashmap_put (grp_replay_req, &key_hash, chn,
1209 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1232 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1210 1233
1211 client_send_random (&chn->group_pub_hash, &rep.header); 1234 client_send_random (&chn->group_pub_hash,
1235 GNUNET_MQ_msg_copy (&rep.header));
1212} 1236}
1213 1237
1214 1238
@@ -1290,10 +1314,10 @@ cadet_channel_create (struct Group *grp, struct GNUNET_PeerIdentity *peer)
1290 struct MulticastJoinDecisionMessageHeader, 1314 struct MulticastJoinDecisionMessageHeader,
1291 chn), 1315 chn),
1292 1316
1293 GNUNET_MQ_hd_var_size (cadet_replay_request, 1317 GNUNET_MQ_hd_fixed_size (cadet_replay_request,
1294 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST, 1318 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST,
1295 struct MulticastReplayRequestMessage, 1319 struct MulticastReplayRequestMessage,
1296 chn), 1320 chn),
1297 1321
1298 GNUNET_MQ_hd_var_size (cadet_replay_response, 1322 GNUNET_MQ_hd_var_size (cadet_replay_response,
1299 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_RESPONSE, 1323 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_RESPONSE,
@@ -1357,6 +1381,7 @@ handle_client_origin_start (void *cls,
1357 grp->is_origin = GNUNET_YES; 1381 grp->is_origin = GNUNET_YES;
1358 grp->pub_key = pub_key; 1382 grp->pub_key = pub_key;
1359 grp->pub_key_hash = pub_key_hash; 1383 grp->pub_key_hash = pub_key_hash;
1384 grp->is_disconnected = GNUNET_NO;
1360 1385
1361 GNUNET_CONTAINER_multihashmap_put (origins, &grp->pub_key_hash, orig, 1386 GNUNET_CONTAINER_multihashmap_put (origins, &grp->pub_key_hash, orig,
1362 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 1387 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
@@ -1379,10 +1404,10 @@ handle_client_origin_start (void *cls,
1379 struct MulticastJoinRequestMessage, 1404 struct MulticastJoinRequestMessage,
1380 grp), 1405 grp),
1381 1406
1382 GNUNET_MQ_hd_var_size (cadet_replay_request, 1407 GNUNET_MQ_hd_fixed_size (cadet_replay_request,
1383 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST, 1408 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST,
1384 struct MulticastReplayRequestMessage, 1409 struct MulticastReplayRequestMessage,
1385 grp), 1410 grp),
1386 1411
1387 GNUNET_MQ_hd_var_size (cadet_replay_response, 1412 GNUNET_MQ_hd_var_size (cadet_replay_response,
1388 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_RESPONSE, 1413 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_RESPONSE,
@@ -1484,6 +1509,7 @@ handle_client_member_join (void *cls,
1484 grp->is_origin = GNUNET_NO; 1509 grp->is_origin = GNUNET_NO;
1485 grp->pub_key = msg->group_pub_key; 1510 grp->pub_key = msg->group_pub_key;
1486 grp->pub_key_hash = pub_key_hash; 1511 grp->pub_key_hash = pub_key_hash;
1512 grp->is_disconnected = GNUNET_NO;
1487 group_set_cadet_port_hash (grp); 1513 group_set_cadet_port_hash (grp);
1488 1514
1489 if (NULL == grp_mem) 1515 if (NULL == grp_mem)
@@ -1494,7 +1520,8 @@ handle_client_member_join (void *cls,
1494 } 1520 }
1495 GNUNET_CONTAINER_multihashmap_put (grp_mem, &mem->pub_key_hash, mem, 1521 GNUNET_CONTAINER_multihashmap_put (grp_mem, &mem->pub_key_hash, mem,
1496 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 1522 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1497 1523
1524 // FIXME: should the members hash map have option UNIQUE_FAST?
1498 GNUNET_CONTAINER_multihashmap_put (members, &grp->pub_key_hash, mem, 1525 GNUNET_CONTAINER_multihashmap_put (members, &grp->pub_key_hash, mem,
1499 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1526 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1500 } 1527 }
@@ -1509,10 +1536,11 @@ handle_client_member_join (void *cls,
1509 1536
1510 char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&mem->pub_key); 1537 char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&mem->pub_key);
1511 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1512 "Client connected to group %s as member %s (%s).\n", 1539 "Client connected to group %s as member %s (%s). size = %d\n",
1513 GNUNET_h2s (&grp->pub_key_hash), 1540 GNUNET_h2s (&grp->pub_key_hash),
1514 GNUNET_h2s2 (&mem->pub_key_hash), 1541 GNUNET_h2s2 (&mem->pub_key_hash),
1515 str); 1542 str,
1543 GNUNET_CONTAINER_multihashmap_size (members));
1516 GNUNET_free (str); 1544 GNUNET_free (str);
1517 1545
1518 if (NULL != mem->join_dcsn) 1546 if (NULL != mem->join_dcsn)
@@ -1567,7 +1595,9 @@ handle_client_member_join (void *cls,
1567 GNUNET_free (mem->join_req); 1595 GNUNET_free (mem->join_req);
1568 mem->join_req = req; 1596 mem->join_req = req;
1569 1597
1570 if (0 == client_send_origin (&grp->pub_key_hash, &mem->join_req->header)) 1598 if (0 ==
1599 client_send_origin (&grp->pub_key_hash,
1600 GNUNET_MQ_msg_copy (&mem->join_req->header)))
1571 { /* No local origins, send to remote origin */ 1601 { /* No local origins, send to remote origin */
1572 cadet_send_join_request (mem); 1602 cadet_send_join_request (mem);
1573 } 1603 }
@@ -1580,7 +1610,7 @@ static void
1580client_send_join_decision (struct Member *mem, 1610client_send_join_decision (struct Member *mem,
1581 const struct MulticastJoinDecisionMessageHeader *hdcsn) 1611 const struct MulticastJoinDecisionMessageHeader *hdcsn)
1582{ 1612{
1583 client_send_group (&mem->group, &hdcsn->header); 1613 client_send_group (&mem->group, GNUNET_MQ_msg_copy (&hdcsn->header));
1584 1614
1585 const struct MulticastJoinDecisionMessage * 1615 const struct MulticastJoinDecisionMessage *
1586 dcsn = (const struct MulticastJoinDecisionMessage *) &hdcsn[1]; 1616 dcsn = (const struct MulticastJoinDecisionMessage *) &hdcsn[1];
@@ -1621,8 +1651,9 @@ handle_client_join_decision (void *cls,
1621 GNUNET_SERVICE_client_drop (client); 1651 GNUNET_SERVICE_client_drop (client);
1622 return; 1652 return;
1623 } 1653 }
1654 GNUNET_assert (GNUNET_NO == grp->is_disconnected);
1624 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1655 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1625 "%p Got join decision from client for group %s..\n", 1656 "%p got join decision from client for group %s..\n",
1626 grp, GNUNET_h2s (&grp->pub_key_hash)); 1657 grp, GNUNET_h2s (&grp->pub_key_hash));
1627 1658
1628 struct GNUNET_CONTAINER_MultiHashMap * 1659 struct GNUNET_CONTAINER_MultiHashMap *
@@ -1652,6 +1683,32 @@ handle_client_join_decision (void *cls,
1652} 1683}
1653 1684
1654 1685
1686static void
1687handle_client_part_request (void *cls,
1688 const struct GNUNET_MessageHeader *msg)
1689{
1690 struct Client *c = cls;
1691 struct GNUNET_SERVICE_Client *client = c->client;
1692 struct Group *grp = c->group;
1693 struct GNUNET_MQ_Envelope *env;
1694
1695 if (NULL == grp)
1696 {
1697 GNUNET_break (0);
1698 GNUNET_SERVICE_client_drop (client);
1699 return;
1700 }
1701 GNUNET_assert (GNUNET_NO == grp->is_disconnected);
1702 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1703 "%p got part request from client for group %s.\n",
1704 grp, GNUNET_h2s (&grp->pub_key_hash));
1705 grp->is_disconnected = GNUNET_YES;
1706 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_MULTICAST_PART_ACK);
1707 client_send_group (grp, env);
1708 GNUNET_SERVICE_client_continue (client);
1709}
1710
1711
1655static int 1712static int
1656check_client_multicast_message (void *cls, 1713check_client_multicast_message (void *cls,
1657 const struct GNUNET_MULTICAST_MessageHeader *msg) 1714 const struct GNUNET_MULTICAST_MessageHeader *msg)
@@ -1667,6 +1724,7 @@ static void
1667handle_client_multicast_message (void *cls, 1724handle_client_multicast_message (void *cls,
1668 const struct GNUNET_MULTICAST_MessageHeader *msg) 1725 const struct GNUNET_MULTICAST_MessageHeader *msg)
1669{ 1726{
1727 // FIXME: what if GNUNET_YES == grp->is_disconnected? Do we allow sending messages?
1670 struct Client *c = cls; 1728 struct Client *c = cls;
1671 struct GNUNET_SERVICE_Client *client = c->client; 1729 struct GNUNET_SERVICE_Client *client = c->client;
1672 struct Group *grp = c->group; 1730 struct Group *grp = c->group;
@@ -1680,6 +1738,7 @@ handle_client_multicast_message (void *cls,
1680 GNUNET_assert (GNUNET_YES == grp->is_origin); 1738 GNUNET_assert (GNUNET_YES == grp->is_origin);
1681 struct Origin *orig = grp->origin; 1739 struct Origin *orig = grp->origin;
1682 1740
1741 // FIXME: use GNUNET_MQ_msg_copy
1683 /* FIXME: yucky, should use separate message structs for P2P and CS! */ 1742 /* FIXME: yucky, should use separate message structs for P2P and CS! */
1684 struct GNUNET_MULTICAST_MessageHeader * 1743 struct GNUNET_MULTICAST_MessageHeader *
1685 out = (struct GNUNET_MULTICAST_MessageHeader *) GNUNET_copy_message (&msg->header); 1744 out = (struct GNUNET_MULTICAST_MessageHeader *) GNUNET_copy_message (&msg->header);
@@ -1696,7 +1755,7 @@ handle_client_multicast_message (void *cls,
1696 GNUNET_assert (0); 1755 GNUNET_assert (0);
1697 } 1756 }
1698 1757
1699 client_send_all (&grp->pub_key_hash, &out->header); 1758 client_send_all (&grp->pub_key_hash, GNUNET_MQ_msg_copy (&out->header));
1700 cadet_send_children (&grp->pub_key_hash, &out->header); 1759 cadet_send_children (&grp->pub_key_hash, &out->header);
1701 client_send_ack (&grp->pub_key_hash); 1760 client_send_ack (&grp->pub_key_hash);
1702 GNUNET_free (out); 1761 GNUNET_free (out);
@@ -1730,6 +1789,7 @@ handle_client_multicast_request (void *cls,
1730 GNUNET_SERVICE_client_drop (client); 1789 GNUNET_SERVICE_client_drop (client);
1731 return; 1790 return;
1732 } 1791 }
1792 GNUNET_assert (GNUNET_NO == grp->is_disconnected);
1733 GNUNET_assert (GNUNET_NO == grp->is_origin); 1793 GNUNET_assert (GNUNET_NO == grp->is_origin);
1734 struct Member *mem = grp->member; 1794 struct Member *mem = grp->member;
1735 1795
@@ -1751,7 +1811,9 @@ handle_client_multicast_request (void *cls,
1751 } 1811 }
1752 1812
1753 uint8_t send_ack = GNUNET_YES; 1813 uint8_t send_ack = GNUNET_YES;
1754 if (0 == client_send_origin (&grp->pub_key_hash, &out->header)) 1814 if (0 ==
1815 client_send_origin (&grp->pub_key_hash,
1816 GNUNET_MQ_msg_copy (&out->header)))
1755 { /* No local origins, send to remote origin */ 1817 { /* No local origins, send to remote origin */
1756 if (NULL != mem->origin_channel) 1818 if (NULL != mem->origin_channel)
1757 { 1819 {
@@ -1792,6 +1854,7 @@ handle_client_replay_request (void *cls,
1792 GNUNET_SERVICE_client_drop (client); 1854 GNUNET_SERVICE_client_drop (client);
1793 return; 1855 return;
1794 } 1856 }
1857 GNUNET_assert (GNUNET_NO == grp->is_disconnected);
1795 GNUNET_assert (GNUNET_NO == grp->is_origin); 1858 GNUNET_assert (GNUNET_NO == grp->is_origin);
1796 struct Member *mem = grp->member; 1859 struct Member *mem = grp->member;
1797 1860
@@ -1812,7 +1875,9 @@ handle_client_replay_request (void *cls,
1812 GNUNET_CONTAINER_multihashmap_put (grp_replay_req, &key_hash, client, 1875 GNUNET_CONTAINER_multihashmap_put (grp_replay_req, &key_hash, client,
1813 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1876 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1814 1877
1815 if (0 == client_send_origin (&grp->pub_key_hash, &rep->header)) 1878 if (0 ==
1879 client_send_origin (&grp->pub_key_hash,
1880 GNUNET_MQ_msg_copy (&rep->header)))
1816 { /* No local origin, replay from remote members / origin. */ 1881 { /* No local origin, replay from remote members / origin. */
1817 if (NULL != mem->origin_channel) 1882 if (NULL != mem->origin_channel)
1818 { 1883 {
@@ -1821,6 +1886,7 @@ handle_client_replay_request (void *cls,
1821 else 1886 else
1822 { 1887 {
1823 /* FIXME: not yet connected to origin */ 1888 /* FIXME: not yet connected to origin */
1889 GNUNET_assert (0);
1824 GNUNET_SERVICE_client_drop (client); 1890 GNUNET_SERVICE_client_drop (client);
1825 return; 1891 return;
1826 } 1892 }
@@ -1880,6 +1946,7 @@ handle_client_replay_response_end (void *cls,
1880 GNUNET_SERVICE_client_drop (client); 1946 GNUNET_SERVICE_client_drop (client);
1881 return; 1947 return;
1882 } 1948 }
1949 GNUNET_assert (GNUNET_NO == grp->is_disconnected);
1883 1950
1884 struct GNUNET_HashCode key_hash; 1951 struct GNUNET_HashCode key_hash;
1885 replay_key_hash (res->fragment_id, res->message_id, res->fragment_offset, 1952 replay_key_hash (res->fragment_id, res->message_id, res->fragment_offset,
@@ -1939,6 +2006,7 @@ handle_client_replay_response (void *cls,
1939 GNUNET_SERVICE_client_drop (client); 2006 GNUNET_SERVICE_client_drop (client);
1940 return; 2007 return;
1941 } 2008 }
2009 GNUNET_assert (GNUNET_NO == grp->is_disconnected);
1942 2010
1943 const struct GNUNET_MessageHeader *msg = &res->header; 2011 const struct GNUNET_MessageHeader *msg = &res->header;
1944 if (GNUNET_MULTICAST_REC_OK == res->error_code) 2012 if (GNUNET_MULTICAST_REC_OK == res->error_code)
@@ -2033,9 +2101,14 @@ client_notify_disconnect (void *cls,
2033 grp, (GNUNET_YES == grp->is_origin) ? "origin" : "member", 2101 grp, (GNUNET_YES == grp->is_origin) ? "origin" : "member",
2034 GNUNET_h2s (&grp->pub_key_hash)); 2102 GNUNET_h2s (&grp->pub_key_hash));
2035 2103
2104 // FIXME (due to protocol change): here we must not remove all clients,
2105 // only the one we were notified about!
2036 struct ClientList *cl = grp->clients_head; 2106 struct ClientList *cl = grp->clients_head;
2037 while (NULL != cl) 2107 while (NULL != cl)
2038 { 2108 {
2109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2110 "iterating clients for group %p\n",
2111 grp);
2039 if (cl->client == client) 2112 if (cl->client == client)
2040 { 2113 {
2041 GNUNET_CONTAINER_DLL_remove (grp->clients_head, grp->clients_tail, cl); 2114 GNUNET_CONTAINER_DLL_remove (grp->clients_head, grp->clients_tail, cl);
@@ -2049,16 +2122,7 @@ client_notify_disconnect (void *cls,
2049 2122
2050 if (NULL == grp->clients_head) 2123 if (NULL == grp->clients_head)
2051 { /* Last client disconnected. */ 2124 { /* Last client disconnected. */
2052#if FIXME 2125 cleanup_group (grp);
2053 if (NULL != grp->tmit_head)
2054 { /* Send pending messages via CADET before cleanup. */
2055 transmit_message (grp);
2056 }
2057 else
2058#endif
2059 {
2060 cleanup_group (grp);
2061 }
2062 } 2126 }
2063} 2127}
2064 2128
@@ -2103,9 +2167,9 @@ run (void *cls,
2103GNUNET_SERVICE_MAIN 2167GNUNET_SERVICE_MAIN
2104("multicast", 2168("multicast",
2105 GNUNET_SERVICE_OPTION_NONE, 2169 GNUNET_SERVICE_OPTION_NONE,
2106 run, 2170 &run,
2107 client_notify_connect, 2171 &client_notify_connect,
2108 client_notify_disconnect, 2172 &client_notify_disconnect,
2109 NULL, 2173 NULL,
2110 GNUNET_MQ_hd_fixed_size (client_origin_start, 2174 GNUNET_MQ_hd_fixed_size (client_origin_start,
2111 GNUNET_MESSAGE_TYPE_MULTICAST_ORIGIN_START, 2175 GNUNET_MESSAGE_TYPE_MULTICAST_ORIGIN_START,
@@ -2119,6 +2183,10 @@ GNUNET_SERVICE_MAIN
2119 GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION, 2183 GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION,
2120 struct MulticastJoinDecisionMessageHeader, 2184 struct MulticastJoinDecisionMessageHeader,
2121 NULL), 2185 NULL),
2186 GNUNET_MQ_hd_fixed_size (client_part_request,
2187 GNUNET_MESSAGE_TYPE_MULTICAST_PART_REQUEST,
2188 struct GNUNET_MessageHeader,
2189 NULL),
2122 GNUNET_MQ_hd_var_size (client_multicast_message, 2190 GNUNET_MQ_hd_var_size (client_multicast_message,
2123 GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE, 2191 GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE,
2124 struct GNUNET_MULTICAST_MessageHeader, 2192 struct GNUNET_MULTICAST_MessageHeader,
diff --git a/src/multicast/multicast_api.c b/src/multicast/multicast_api.c
index a8b1dee40..3c911f48a 100644
--- a/src/multicast/multicast_api.c
+++ b/src/multicast/multicast_api.c
@@ -542,31 +542,12 @@ group_cleanup (struct GNUNET_MULTICAST_Group *grp)
542 542
543 543
544static void 544static void
545group_disconnect (struct GNUNET_MULTICAST_Group *grp, 545handle_group_part_ack (void *cls,
546 GNUNET_ContinuationCallback cb, 546 const struct GNUNET_MessageHeader *msg)
547 void *cls)
548{ 547{
549 grp->is_disconnecting = GNUNET_YES; 548 struct GNUNET_MULTICAST_Group *grp = cls;
550 grp->disconnect_cb = cb;
551 grp->disconnect_cls = cls;
552 549
553 if (NULL != grp->mq) 550 group_cleanup (grp);
554 {
555 struct GNUNET_MQ_Envelope *last = GNUNET_MQ_get_last_envelope (grp->mq);
556 if (NULL != last)
557 {
558 GNUNET_MQ_notify_sent (last,
559 (GNUNET_SCHEDULER_TaskCallback) group_cleanup, grp);
560 }
561 else
562 {
563 group_cleanup (grp);
564 }
565 }
566 else
567 {
568 group_cleanup (grp);
569 }
570} 551}
571 552
572 553
@@ -779,6 +760,10 @@ origin_connect (struct GNUNET_MULTICAST_Origin *orig)
779 GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST, 760 GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST,
780 struct MulticastJoinRequestMessage, 761 struct MulticastJoinRequestMessage,
781 grp), 762 grp),
763 GNUNET_MQ_hd_fixed_size (group_part_ack,
764 GNUNET_MESSAGE_TYPE_MULTICAST_PART_ACK,
765 struct GNUNET_MessageHeader,
766 grp),
782 GNUNET_MQ_hd_fixed_size (group_replay_request, 767 GNUNET_MQ_hd_fixed_size (group_replay_request,
783 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST, 768 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST,
784 struct MulticastReplayRequestMessage, 769 struct MulticastReplayRequestMessage,
@@ -879,8 +864,13 @@ GNUNET_MULTICAST_origin_stop (struct GNUNET_MULTICAST_Origin *orig,
879 void *stop_cls) 864 void *stop_cls)
880{ 865{
881 struct GNUNET_MULTICAST_Group *grp = &orig->grp; 866 struct GNUNET_MULTICAST_Group *grp = &orig->grp;
867 struct GNUNET_MQ_Envelope *env;
882 868
883 group_disconnect (grp, stop_cb, stop_cls); 869 grp->is_disconnecting = GNUNET_YES;
870 grp->disconnect_cb = stop_cb;
871 grp->disconnect_cls = stop_cls;
872 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_MULTICAST_PART_REQUEST);
873 GNUNET_MQ_send (grp->mq, env);
884} 874}
885 875
886 876
@@ -1065,6 +1055,10 @@ member_connect (struct GNUNET_MULTICAST_Member *mem)
1065 GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION, 1055 GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION,
1066 struct MulticastJoinDecisionMessageHeader, 1056 struct MulticastJoinDecisionMessageHeader,
1067 mem), 1057 mem),
1058 GNUNET_MQ_hd_fixed_size (group_part_ack,
1059 GNUNET_MESSAGE_TYPE_MULTICAST_PART_ACK,
1060 struct GNUNET_MessageHeader,
1061 grp),
1068 GNUNET_MQ_hd_fixed_size (group_replay_request, 1062 GNUNET_MQ_hd_fixed_size (group_replay_request,
1069 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST, 1063 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST,
1070 struct MulticastReplayRequestMessage, 1064 struct MulticastReplayRequestMessage,
@@ -1198,16 +1192,19 @@ GNUNET_MULTICAST_member_part (struct GNUNET_MULTICAST_Member *mem,
1198 GNUNET_ContinuationCallback part_cb, 1192 GNUNET_ContinuationCallback part_cb,
1199 void *part_cls) 1193 void *part_cls)
1200{ 1194{
1201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%p Member parting.\n", mem);
1202 struct GNUNET_MULTICAST_Group *grp = &mem->grp; 1195 struct GNUNET_MULTICAST_Group *grp = &mem->grp;
1196 struct GNUNET_MQ_Envelope *env;
1203 1197
1204 mem->join_dcsn_cb = NULL; 1198 mem->join_dcsn_cb = NULL;
1205 grp->join_req_cb = NULL; 1199 grp->join_req_cb = NULL;
1206 grp->message_cb = NULL; 1200 grp->message_cb = NULL;
1207 grp->replay_msg_cb = NULL; 1201 grp->replay_msg_cb = NULL;
1208 grp->replay_frag_cb = NULL; 1202 grp->replay_frag_cb = NULL;
1209 1203 grp->is_disconnecting = GNUNET_YES;
1210 group_disconnect (grp, part_cb, part_cls); 1204 grp->disconnect_cb = part_cb;
1205 grp->disconnect_cls = part_cls;
1206 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_MULTICAST_PART_REQUEST);
1207 GNUNET_MQ_send (grp->mq, env);
1211} 1208}
1212 1209
1213 1210
diff --git a/src/multicast/test_multicast_multipeer.c b/src/multicast/test_multicast_multipeer.c
index 5f4493993..7df1a8213 100644
--- a/src/multicast/test_multicast_multipeer.c
+++ b/src/multicast/test_multicast_multipeer.c
@@ -35,9 +35,10 @@
35 35
36#define PEERS_REQUESTED 12 36#define PEERS_REQUESTED 12
37 37
38struct multicast_peer 38struct MulticastPeerContext
39{ 39{
40 int peer; /* peer number */ 40 int peer; /* peer number */
41 struct GNUNET_CRYPTO_EcdsaPrivateKey *key;
41 const struct GNUNET_PeerIdentity *id; 42 const struct GNUNET_PeerIdentity *id;
42 struct GNUNET_TESTBED_Operation *op; /* not yet in use */ 43 struct GNUNET_TESTBED_Operation *op; /* not yet in use */
43 struct GNUNET_TESTBED_Operation *pi_op; /* not yet in use */ 44 struct GNUNET_TESTBED_Operation *pi_op; /* not yet in use */
@@ -61,7 +62,7 @@ static void service_connect (void *cls,
61 void *ca_result, 62 void *ca_result,
62 const char *emsg); 63 const char *emsg);
63 64
64static struct multicast_peer **mc_peers; 65static struct MulticastPeerContext **multicast_peers;
65static struct GNUNET_TESTBED_Peer **peers; 66static struct GNUNET_TESTBED_Peer **peers;
66 67
67// FIXME: refactor 68// FIXME: refactor
@@ -69,18 +70,14 @@ static struct GNUNET_TESTBED_Operation *op[PEERS_REQUESTED];
69static struct GNUNET_TESTBED_Operation *pi_op[PEERS_REQUESTED]; 70static struct GNUNET_TESTBED_Operation *pi_op[PEERS_REQUESTED];
70 71
71static struct GNUNET_MULTICAST_Origin *origin; 72static struct GNUNET_MULTICAST_Origin *origin;
72static struct GNUNET_MULTICAST_Member *member[PEERS_REQUESTED]; /* first element always empty */ 73static struct GNUNET_MULTICAST_Member *members[PEERS_REQUESTED]; /* first element always empty */
73 74
74static struct GNUNET_SCHEDULER_Task *timeout_tid; 75static struct GNUNET_SCHEDULER_Task *timeout_tid;
75 76
76static struct GNUNET_CRYPTO_EddsaPrivateKey group_key; 77//static struct GNUNET_CRYPTO_EddsaPrivateKey *group_key;
77static struct GNUNET_CRYPTO_EddsaPublicKey group_pub_key; 78static struct GNUNET_CRYPTO_EddsaPublicKey group_pub_key;
78static struct GNUNET_HashCode group_pub_key_hash; 79static struct GNUNET_HashCode group_pub_key_hash;
79 80
80static struct GNUNET_CRYPTO_EcdsaPrivateKey *member_key[PEERS_REQUESTED];
81static struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key[PEERS_REQUESTED];
82
83
84/** 81/**
85 * Global result for testcase. 82 * Global result for testcase.
86 */ 83 */
@@ -93,6 +90,8 @@ static int result;
93static void 90static void
94shutdown_task (void *cls) 91shutdown_task (void *cls)
95{ 92{
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
94 "shutdown_task!\n");
96 for (int i=0;i<PEERS_REQUESTED;i++) 95 for (int i=0;i<PEERS_REQUESTED;i++)
97 { 96 {
98 if (NULL != op[i]) 97 if (NULL != op[i])
@@ -107,14 +106,16 @@ shutdown_task (void *cls)
107 } 106 }
108 } 107 }
109 108
110 if (NULL != mc_peers) 109 if (NULL != multicast_peers)
111 { 110 {
112 for (int i=0; i < PEERS_REQUESTED; i++) 111 for (int i=0; i < PEERS_REQUESTED; i++)
113 { 112 {
114 GNUNET_free (mc_peers[i]); 113 GNUNET_free (multicast_peers[i]->key);
115 mc_peers[i] = NULL; 114 GNUNET_free (multicast_peers[i]);
115 multicast_peers[i] = NULL;
116 } 116 }
117 GNUNET_free (mc_peers); 117 GNUNET_free (multicast_peers);
118 multicast_peers = NULL;
118 } 119 }
119 120
120 if (NULL != timeout_tid) 121 if (NULL != timeout_tid)
@@ -141,11 +142,11 @@ member_join_request (void *cls,
141 const struct GNUNET_MessageHeader *join_msg, 142 const struct GNUNET_MessageHeader *join_msg,
142 struct GNUNET_MULTICAST_JoinHandle *jh) 143 struct GNUNET_MULTICAST_JoinHandle *jh)
143{ 144{
144 struct multicast_peer *mc_peer = (struct multicast_peer*)cls; 145 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
145 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 146 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
146 "Peer #%u (%s) sent a join request.\n", 147 "Peer #%u (%s) sent a join request.\n",
147 mc_peer->peer, 148 mc_peer->peer,
148 GNUNET_i2s (mc_peers[mc_peer->peer]->id)); 149 GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
149} 150}
150 151
151 152
@@ -154,7 +155,7 @@ notify (void *cls,
154 size_t *data_size, 155 size_t *data_size,
155 void *data) 156 void *data)
156{ 157{
157 struct multicast_peer *mc_peer = (struct multicast_peer*)cls; 158 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
158 159
159 struct pingpong_msg *pp_msg = GNUNET_new (struct pingpong_msg); 160 struct pingpong_msg *pp_msg = GNUNET_new (struct pingpong_msg);
160 pp_msg->peer = mc_peer->peer; 161 pp_msg->peer = mc_peer->peer;
@@ -178,18 +179,18 @@ member_join_decision (void *cls,
178 const struct GNUNET_PeerIdentity *relays, 179 const struct GNUNET_PeerIdentity *relays,
179 const struct GNUNET_MessageHeader *join_msg) 180 const struct GNUNET_MessageHeader *join_msg)
180{ 181{
181 struct multicast_peer *mc_peer = (struct multicast_peer*)cls; 182 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
182 struct GNUNET_MULTICAST_MemberTransmitHandle *req; 183 struct GNUNET_MULTICAST_MemberTransmitHandle *req;
183 184
184 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 185 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
185 "Peer #%u (%s) received a decision from origin: %s\n", 186 "Peer #%u (%s) received a decision from origin: %s\n",
186 mc_peer->peer, 187 mc_peer->peer,
187 GNUNET_i2s (mc_peers[mc_peer->peer]->id), 188 GNUNET_i2s (multicast_peers[mc_peer->peer]->id),
188 (GNUNET_YES == is_admitted)?"accepted":"rejected"); 189 (GNUNET_YES == is_admitted)?"accepted":"rejected");
189 190
190 if (GNUNET_YES == is_admitted) 191 if (GNUNET_YES == is_admitted)
191 { 192 {
192 req = GNUNET_MULTICAST_member_to_origin (member[mc_peer->peer], 193 req = GNUNET_MULTICAST_member_to_origin (members[mc_peer->peer],
193 0, 194 0,
194 notify, 195 notify,
195 cls); 196 cls);
@@ -215,10 +216,32 @@ member_replay_msg ()
215 216
216 217
217static void 218static void
219origin_disconnected_cb (void *cls)
220{
221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
222 "Origin disconnected. Shutting down.\n");
223 result = GNUNET_YES;
224 GNUNET_SCHEDULER_shutdown ();
225}
226
227
228static void
229member_disconnected_cb (void *cls)
230{
231 for (int i = 1; i < PEERS_REQUESTED; ++i)
232 if (GNUNET_NO == multicast_peers[i]->test_ok)
233 return;
234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
235 "All member disconnected. Stopping origin.\n");
236 GNUNET_MULTICAST_origin_stop (origin, origin_disconnected_cb, cls);
237}
238
239
240static void
218member_message (void *cls, 241member_message (void *cls,
219 const struct GNUNET_MULTICAST_MessageHeader *msg) 242 const struct GNUNET_MULTICAST_MessageHeader *msg)
220{ 243{
221 struct multicast_peer *mc_peer = (struct multicast_peer*)cls; 244 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
222 struct pingpong_msg *pp_msg = (struct pingpong_msg*) &(msg[1]); 245 struct pingpong_msg *pp_msg = (struct pingpong_msg*) &(msg[1]);
223 246
224 if (PONG == pp_msg->msg && mc_peer->peer == pp_msg->peer) 247 if (PONG == pp_msg->msg && mc_peer->peer == pp_msg->peer)
@@ -226,18 +249,15 @@ member_message (void *cls,
226 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 249 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
227 "peer #%i (%s) receives a pong\n", 250 "peer #%i (%s) receives a pong\n",
228 mc_peer->peer, 251 mc_peer->peer,
229 GNUNET_i2s (mc_peers[mc_peer->peer]->id)); 252 GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
230
231 mc_peer->test_ok = GNUNET_OK; 253 mc_peer->test_ok = GNUNET_OK;
232 } 254 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
233 255 "peer #%u (%s) parting from multicast group\n",
234 // Test for completeness of received PONGs 256 mc_peer->peer,
235 for (int i=1; i<PEERS_REQUESTED; i++) 257 GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
236 if (GNUNET_NO == mc_peers[i]->test_ok)
237 return;
238 258
239 result = GNUNET_YES; 259 GNUNET_MULTICAST_member_part (members[mc_peer->peer], member_disconnected_cb, cls);
240 GNUNET_SCHEDULER_shutdown(); 260 }
241} 261}
242 262
243 263
@@ -349,81 +369,53 @@ origin_message (void *cls,
349 369
350 370
351static void 371static void
352multicast_da (void *cls, 372multicast_disconnect (void *cls,
353 void *op_result) 373 void *op_result)
354{ 374{
355 struct multicast_peer *mc_peer = (struct multicast_peer*)cls;
356 375
357 if (0 == mc_peer->peer)
358 {
359 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
360 "Origin closes multicast group\n");
361
362 GNUNET_MULTICAST_origin_stop (origin, NULL, cls);
363 }
364 else
365 {
366 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
367 "peer #%u (%s) parting from multicast group\n",
368 mc_peer->peer,
369 GNUNET_i2s (mc_peers[mc_peer->peer]->id));
370
371 GNUNET_MULTICAST_member_part (member[mc_peer->peer], NULL, cls);
372 }
373} 376}
374 377
375 378
376static void * 379static void *
377multicast_ca (void *cls, 380multicast_connect (void *cls,
378 const struct GNUNET_CONFIGURATION_Handle *cfg) 381 const struct GNUNET_CONFIGURATION_Handle *cfg)
379{ 382{
380 struct multicast_peer *mc_peer = (struct multicast_peer*)cls; 383 struct MulticastPeerContext *multicast_peer = cls;
381 struct GNUNET_MessageHeader *join_msg; 384 struct GNUNET_MessageHeader *join_msg;
382 char data[64]; 385 char data[64];
383 386
384 if (0 == mc_peer->peer) 387 multicast_peer->key = GNUNET_CRYPTO_ecdsa_key_create ();
388 if (0 == multicast_peer->peer)
385 { 389 {
386 struct GNUNET_CRYPTO_EddsaPrivateKey *key = GNUNET_CRYPTO_eddsa_key_create (); 390 GNUNET_CRYPTO_eddsa_key_get_public (multicast_peer->key, &group_pub_key);
387 GNUNET_CRYPTO_eddsa_key_get_public (key, &group_pub_key);
388 GNUNET_CRYPTO_hash (&group_pub_key, sizeof (group_pub_key), &group_pub_key_hash); 391 GNUNET_CRYPTO_hash (&group_pub_key, sizeof (group_pub_key), &group_pub_key_hash);
389
390 group_key = *key;
391
392 origin = GNUNET_MULTICAST_origin_start (cfg, 392 origin = GNUNET_MULTICAST_origin_start (cfg,
393 &group_key, 393 multicast_peer->key,
394 0, 394 0,
395 origin_join_request, 395 origin_join_request,
396 origin_replay_frag, 396 origin_replay_frag,
397 origin_replay_msg, 397 origin_replay_msg,
398 origin_request, 398 origin_request,
399 origin_message, 399 origin_message,
400 cls); 400 cls);
401 401 if (NULL == origin)
402 if (NULL == origin) { 402 {
403 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 403 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
404 "Peer #%u could not create a multicast group", 404 "Peer #%u could not create a multicast group",
405 mc_peer->peer); 405 multicast_peer->peer);
406 return NULL; 406 return NULL;
407 } 407 }
408
409 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 408 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
410 "Peer #%u connected as origin to group %s\n", 409 "Peer #%u connected as origin to group %s\n",
411 mc_peer->peer, 410 multicast_peer->peer,
412 GNUNET_h2s (&group_pub_key_hash)); 411 GNUNET_h2s (&group_pub_key_hash));
413
414 return origin; 412 return origin;
415 } 413 }
416 else 414 else
417 { 415 {
418 // Get members keys
419 member_pub_key[mc_peer->peer] = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
420 member_key[mc_peer->peer] = GNUNET_CRYPTO_ecdsa_key_create ();
421 GNUNET_CRYPTO_ecdsa_key_get_public (member_key[mc_peer->peer],
422 member_pub_key[mc_peer->peer]);
423
424 sprintf(data, "Hi, I am peer #%u (%s). Can I enter?", 416 sprintf(data, "Hi, I am peer #%u (%s). Can I enter?",
425 mc_peer->peer, 417 multicast_peer->peer,
426 GNUNET_i2s (mc_peers[mc_peer->peer]->id)); 418 GNUNET_i2s (multicast_peers[multicast_peer->peer]->id));
427 uint8_t data_size = strlen (data) + 1; 419 uint8_t data_size = strlen (data) + 1;
428 join_msg = GNUNET_malloc (sizeof (join_msg) + data_size); 420 join_msg = GNUNET_malloc (sizeof (join_msg) + data_size);
429 join_msg->size = htons (sizeof (join_msg) + data_size); 421 join_msg->size = htons (sizeof (join_msg) + data_size);
@@ -432,24 +424,25 @@ multicast_ca (void *cls,
432 424
433 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 425 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
434 "Peer #%u (%s) tries to join multicast group %s\n", 426 "Peer #%u (%s) tries to join multicast group %s\n",
435 mc_peer->peer, 427 multicast_peer->peer,
436 GNUNET_i2s (mc_peers[mc_peer->peer]->id), 428 GNUNET_i2s (multicast_peers[multicast_peer->peer]->id),
437 GNUNET_h2s (&group_pub_key_hash)); 429 GNUNET_h2s (&group_pub_key_hash));
438 430
439 member[mc_peer->peer] = GNUNET_MULTICAST_member_join (cfg, 431 members[multicast_peer->peer] =
440 &group_pub_key, 432 GNUNET_MULTICAST_member_join (cfg,
441 member_key[mc_peer->peer], 433 &group_pub_key,
442 mc_peers[0]->id, 434 multicast_peer->key,
443 0, 435 multicast_peers[0]->id,
444 NULL, 436 0,
445 join_msg, /* join message */ 437 NULL,
446 member_join_request, 438 join_msg, /* join message */
447 member_join_decision, 439 member_join_request,
448 member_replay_frag, 440 member_join_decision,
449 member_replay_msg, 441 member_replay_frag,
450 member_message, 442 member_replay_msg,
451 cls); 443 member_message,
452 return member[mc_peer->peer]; 444 cls);
445 return members[multicast_peer->peer];
453 } 446 }
454} 447}
455 448
@@ -460,7 +453,7 @@ peer_information_cb (void *cls,
460 const struct GNUNET_TESTBED_PeerInformation *pinfo, 453 const struct GNUNET_TESTBED_PeerInformation *pinfo,
461 const char *emsg) 454 const char *emsg)
462{ 455{
463 struct multicast_peer *mc_peer = (struct multicast_peer*)cls; 456 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
464 457
465 if (NULL == pinfo) { 458 if (NULL == pinfo) {
466 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "got no peer information\n"); 459 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "got no peer information\n");
@@ -468,7 +461,7 @@ peer_information_cb (void *cls,
468 GNUNET_SCHEDULER_shutdown (); 461 GNUNET_SCHEDULER_shutdown ();
469 } 462 }
470 463
471 mc_peers[mc_peer->peer]->id = pinfo->result.id; 464 multicast_peers[mc_peer->peer]->id = pinfo->result.id;
472 465
473 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 466 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
474 "Got peer information of %s (%s)\n", 467 "Got peer information of %s (%s)\n",
@@ -478,22 +471,28 @@ peer_information_cb (void *cls,
478 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 471 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
479 "Create peer #%u (%s)\n", 472 "Create peer #%u (%s)\n",
480 mc_peer->peer, 473 mc_peer->peer,
481 GNUNET_i2s (mc_peers[mc_peer->peer]->id)); 474 GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
482 475
483 if (0 != mc_peer->peer) 476 if (0 != mc_peer->peer)
484 { 477 {
485 /* connect to multicast service of members */ 478 /* connect to multicast service of members */
486 op[mc_peer->peer] = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */ 479 op[mc_peer->peer] =
487 peers[mc_peer->peer], /* The peer whose service to connect to */ 480 GNUNET_TESTBED_service_connect (/* Closure for operation */
488 "multicast", /* The name of the service */ 481 NULL,
489 service_connect, /* callback to call after a handle to service 482 /* The peer whose service to connect to */
490 is opened */ 483 peers[mc_peer->peer],
491 cls, /* closure for the above callback */ 484 /* The name of the service */
492 multicast_ca, /* callback to call with peer's configuration; 485 "multicast",
493 this should open the needed service connection */ 486 /* called after a handle to service is opened */
494 multicast_da, /* callback to be called when closing the 487 service_connect,
495 opened service connection */ 488 /* closure for the above callback */
496 cls); /* closure for the above two callbacks */ 489 cls,
490 /* called when opening the service connection */
491 multicast_connect,
492 /* called when closing the service connection */
493 multicast_disconnect,
494 /* closure for the above two callbacks */
495 cls);
497 } 496 }
498} 497}
499 498
@@ -504,14 +503,14 @@ service_connect (void *cls,
504 void *ca_result, 503 void *ca_result,
505 const char *emsg) 504 const char *emsg)
506{ 505{
507 struct multicast_peer *mc_peer = (struct multicast_peer*)cls; 506 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
508 507
509 if (NULL == ca_result) 508 if (NULL == ca_result)
510 { 509 {
511 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 510 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
512 "Connection adapter not created for peer #%u (%s)\n", 511 "Connection adapter not created for peer #%u (%s)\n",
513 mc_peer->peer, 512 mc_peer->peer,
514 GNUNET_i2s (mc_peers[mc_peer->peer]->id)); 513 GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
515 514
516 result = GNUNET_SYSERR; 515 result = GNUNET_SYSERR;
517 GNUNET_SCHEDULER_shutdown(); 516 GNUNET_SCHEDULER_shutdown();
@@ -525,7 +524,7 @@ service_connect (void *cls,
525 pi_op[i] = GNUNET_TESTBED_peer_get_information (peers[i], 524 pi_op[i] = GNUNET_TESTBED_peer_get_information (peers[i],
526 GNUNET_TESTBED_PIT_IDENTITY, 525 GNUNET_TESTBED_PIT_IDENTITY,
527 peer_information_cb, 526 peer_information_cb,
528 mc_peers[i]); 527 multicast_peers[i]);
529 } 528 }
530 } 529 }
531} 530}
@@ -549,50 +548,51 @@ service_connect (void *cls,
549 * @param links_failed number of links testbed was unable to establish 548 * @param links_failed number of links testbed was unable to establish
550 */ static void 549 */ static void
551testbed_master (void *cls, 550testbed_master (void *cls,
552 struct GNUNET_TESTBED_RunHandle *h, 551 struct GNUNET_TESTBED_RunHandle *h,
553 unsigned int num_peers, 552 unsigned int num_peers,
554 struct GNUNET_TESTBED_Peer **p, 553 struct GNUNET_TESTBED_Peer **p,
555 unsigned int links_succeeded, 554 unsigned int links_succeeded,
556 unsigned int links_failed) 555 unsigned int links_failed)
557{ 556{
558 /* Testbed is ready with peers running and connected in a pre-defined overlay 557 /* Testbed is ready with peers running and connected in a pre-defined overlay
559 topology (FIXME) */ 558 topology (FIXME) */
560
561 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
562 "Connected to testbed_master()\n");
563
564 peers = p; 559 peers = p;
565 560 multicast_peers = GNUNET_new_array (PEERS_REQUESTED, struct MulticastPeerContext*);
566 mc_peers = GNUNET_new_array (PEERS_REQUESTED, struct multicast_peer*);
567 561
568 // Create test contexts for members 562 // Create test contexts for members
569 for (int i = 0; i<PEERS_REQUESTED; i++) 563 for (int i = 0; i<PEERS_REQUESTED; i++)
570 { 564 {
571 mc_peers[i] = GNUNET_new (struct multicast_peer); 565 multicast_peers[i] = GNUNET_new (struct MulticastPeerContext);
572 mc_peers[i]->peer = i; 566 multicast_peers[i]->peer = i;
573 mc_peers[i]->test_ok = GNUNET_NO; 567 multicast_peers[i]->test_ok = GNUNET_NO;
574 } 568 }
575
576 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 569 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
577 "Create origin peer\n"); 570 "Create origin peer\n");
578 571 op[0] =
579 op[0] = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */ 572 GNUNET_TESTBED_service_connect (/* Closure for operation */
580 peers[0], /* The peer whose service to connect to */ 573 NULL,
581 "multicast", /* The name of the service */ 574 /* The peer whose service to connect to */
582 service_connect, /* callback to call after a handle to service 575 peers[0],
583 is opened */ 576 /* The name of the service */
584 mc_peers[0], /* closure for the above callback */ 577 "multicast",
585 multicast_ca, /* callback to call with peer's configuration; 578 /* called after a handle to service is opened */
586 this should open the needed service connection */ 579 service_connect,
587 multicast_da, /* callback to be called when closing the 580 /* closure for the above callback */
588 opened service connection */ 581 multicast_peers[0],
589 mc_peers[0]); /* closure for the above two callbacks */ 582 /* called when opening the service connection */
590 583 multicast_connect,
591 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); /* Schedule a new task on shutdown */ 584 /* called when closing the service connection */
592 585 multicast_disconnect,
586 /* closure for the above two callbacks */
587 multicast_peers[0]);
588 /* Schedule a new task on shutdown */
589 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
593 /* Schedule the shutdown task with a delay of a few Seconds */ 590 /* Schedule the shutdown task with a delay of a few Seconds */
594 timeout_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 400), 591 timeout_tid =
595 &timeout_task, NULL); 592 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
593 (GNUNET_TIME_UNIT_SECONDS, 400),
594 &timeout_task,
595 NULL);
596} 596}
597 597
598 598
@@ -616,15 +616,21 @@ main (int argc, char *argv[])
616 } 616 }
617 617
618 result = GNUNET_SYSERR; 618 result = GNUNET_SYSERR;
619 ret = GNUNET_TESTBED_test_run 619 ret =
620 ("test-multicast-multipeer", /* test case name */ 620 GNUNET_TESTBED_test_run ("test-multicast-multipeer",
621 config_file, /* template configuration */ 621 config_file,
622 PEERS_REQUESTED, /* number of peers to start */ 622 /* number of peers to start */
623 0LL, /* Event mask - set to 0 for no event notifications */ 623 PEERS_REQUESTED,
624 NULL, /* Controller event callback */ 624 /* Event mask - set to 0 for no event notifications */
625 NULL, /* Closure for controller event callback */ 625 0LL,
626 testbed_master, /* continuation callback to be called when testbed setup is complete */ 626 /* Controller event callback */
627 NULL); /* Closure for the test_master callback */ 627 NULL,
628 /* Closure for controller event callback */
629 NULL,
630 /* called when testbed setup is complete */
631 testbed_master,
632 /* Closure for the test_master callback */
633 NULL);
628 if ( (GNUNET_OK != ret) || (GNUNET_OK != result) ) 634 if ( (GNUNET_OK != ret) || (GNUNET_OK != result) )
629 return 1; 635 return 1;
630 return 0; 636 return 0;
diff --git a/src/psyc/gnunet-service-psyc.c b/src/psyc/gnunet-service-psyc.c
index 73a3ae4ee..cf161435a 100644
--- a/src/psyc/gnunet-service-psyc.c
+++ b/src/psyc/gnunet-service-psyc.c
@@ -279,7 +279,7 @@ struct Channel
279 * Is the client disconnected? 279 * Is the client disconnected?
280 * #GNUNET_YES or #GNUNET_NO 280 * #GNUNET_YES or #GNUNET_NO
281 */ 281 */
282 uint8_t is_disconnected; 282 uint8_t is_disconnecting;
283 283
284 /** 284 /**
285 * Is this a channel master (#GNUNET_YES), or slave (#GNUNET_NO)? 285 * Is this a channel master (#GNUNET_YES), or slave (#GNUNET_NO)?
@@ -508,8 +508,6 @@ cleanup_master (struct Master *mst)
508{ 508{
509 struct Channel *chn = &mst->channel; 509 struct Channel *chn = &mst->channel;
510 510
511 if (NULL != mst->origin)
512 GNUNET_MULTICAST_origin_stop (mst->origin, NULL, NULL); // FIXME
513 GNUNET_CONTAINER_multihashmap_destroy (mst->join_reqs); 511 GNUNET_CONTAINER_multihashmap_destroy (mst->join_reqs);
514 GNUNET_CONTAINER_multihashmap_remove (masters, &chn->pub_key_hash, mst); 512 GNUNET_CONTAINER_multihashmap_remove (masters, &chn->pub_key_hash, mst);
515} 513}
@@ -546,11 +544,6 @@ cleanup_slave (struct Slave *slv)
546 GNUNET_free (slv->relays); 544 GNUNET_free (slv->relays);
547 slv->relays = NULL; 545 slv->relays = NULL;
548 } 546 }
549 if (NULL != slv->member)
550 {
551 GNUNET_MULTICAST_member_part (slv->member, NULL, NULL); // FIXME
552 slv->member = NULL;
553 }
554 GNUNET_CONTAINER_multihashmap_remove (slaves, &chn->pub_key_hash, slv); 547 GNUNET_CONTAINER_multihashmap_remove (slaves, &chn->pub_key_hash, slv);
555} 548}
556 549
@@ -603,15 +596,16 @@ client_notify_disconnect (void *cls,
603 if (NULL == chn) 596 if (NULL == chn)
604 { 597 {
605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 598 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
606 "%p User context is NULL in client_disconnect()\n", 599 "%p User context is NULL in client_notify_disconnect ()\n",
607 chn); 600 chn);
608 GNUNET_break (0); 601 GNUNET_break (0);
609 return; 602 return;
610 } 603 }
611 604
612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
613 "%p Client (%s) disconnected from channel %s\n", 606 "%p Client %p (%s) disconnected from channel %s\n",
614 chn, 607 chn,
608 client,
615 (GNUNET_YES == chn->is_master) ? "master" : "slave", 609 (GNUNET_YES == chn->is_master) ? "master" : "slave",
616 GNUNET_h2s (&chn->pub_key_hash)); 610 GNUNET_h2s (&chn->pub_key_hash));
617 611
@@ -645,15 +639,8 @@ client_notify_disconnect (void *cls,
645 chn, 639 chn,
646 (GNUNET_YES == chn->is_master) ? "master" : "slave", 640 (GNUNET_YES == chn->is_master) ? "master" : "slave",
647 GNUNET_h2s (&chn->pub_key_hash)); 641 GNUNET_h2s (&chn->pub_key_hash));
648 chn->is_disconnected = GNUNET_YES; 642 chn->is_disconnecting = GNUNET_YES;
649 if (NULL != chn->tmit_head) 643 cleanup_channel (chn);
650 { /* Send pending messages to multicast before cleanup. */
651 transmit_message (chn);
652 }
653 else
654 {
655 cleanup_channel (chn);
656 }
657 } 644 }
658} 645}
659 646
@@ -688,7 +675,7 @@ client_send_msg (const struct Channel *chn,
688 const struct GNUNET_MessageHeader *msg) 675 const struct GNUNET_MessageHeader *msg)
689{ 676{
690 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 677 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
691 "%p Sending message to clients.\n", 678 "Sending message to clients of channel %p.\n",
692 chn); 679 chn);
693 680
694 struct ClientList *cli = chn->clients_head; 681 struct ClientList *cli = chn->clients_head;
@@ -699,7 +686,6 @@ client_send_msg (const struct Channel *chn,
699 686
700 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cli->client), 687 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cli->client),
701 env); 688 env);
702
703 cli = cli->next; 689 cli = cli->next;
704 } 690 }
705} 691}
@@ -734,7 +720,7 @@ client_send_result (struct GNUNET_SERVICE_Client *client, uint64_t op_id,
734 GNUNET_memcpy (&res[1], data, data_size); 720 GNUNET_memcpy (&res[1], data, data_size);
735 721
736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
737 "%p Sending result to client for operation #%" PRIu64 ": %" PRId64 " (size: %u)\n", 723 "%p Sending result to client for OP ID %" PRIu64 ": %" PRId64 " (size: %u)\n",
738 client, 724 client,
739 GNUNET_ntohll (op_id), 725 GNUNET_ntohll (op_id),
740 result_code, 726 result_code,
@@ -1202,12 +1188,12 @@ fragment_queue_insert (struct Channel *chn,
1202 else if (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD == first_ptype 1188 else if (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD == first_ptype
1203 || frag_offset == fragq->header_size) 1189 || frag_offset == fragq->header_size)
1204 { /* header is now complete */ 1190 { /* header is now complete */
1205 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1206 "%p Header of message %" PRIu64 " is complete.\n", 1192 "%p Header of message %" PRIu64 " is complete.\n",
1207 chn, 1193 chn,
1208 GNUNET_ntohll (mmsg->message_id)); 1194 GNUNET_ntohll (mmsg->message_id));
1209 1195
1210 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1211 "%p Adding message %" PRIu64 " to queue.\n", 1197 "%p Adding message %" PRIu64 " to queue.\n",
1212 chn, 1198 chn,
1213 GNUNET_ntohll (mmsg->message_id)); 1199 GNUNET_ntohll (mmsg->message_id));
@@ -1215,7 +1201,7 @@ fragment_queue_insert (struct Channel *chn,
1215 } 1201 }
1216 else 1202 else
1217 { 1203 {
1218 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1219 "%p Header of message %" PRIu64 " is NOT complete yet: %" PRIu64 " != %" PRIu64 "\n", 1205 "%p Header of message %" PRIu64 " is NOT complete yet: %" PRIu64 " != %" PRIu64 "\n",
1220 chn, 1206 chn,
1221 GNUNET_ntohll (mmsg->message_id), 1207 GNUNET_ntohll (mmsg->message_id),
@@ -1230,7 +1216,7 @@ fragment_queue_insert (struct Channel *chn,
1230 if (frag_offset == fragq->size) 1216 if (frag_offset == fragq->size)
1231 fragq->state = MSG_FRAG_STATE_END; 1217 fragq->state = MSG_FRAG_STATE_END;
1232 else 1218 else
1233 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1234 "%p Message %" PRIu64 " is NOT complete yet: %" PRIu64 " != %" PRIu64 "\n", 1220 "%p Message %" PRIu64 " is NOT complete yet: %" PRIu64 " != %" PRIu64 "\n",
1235 chn, 1221 chn,
1236 GNUNET_ntohll (mmsg->message_id), 1222 GNUNET_ntohll (mmsg->message_id),
@@ -1285,7 +1271,7 @@ static void
1285fragment_queue_run (struct Channel *chn, uint64_t msg_id, 1271fragment_queue_run (struct Channel *chn, uint64_t msg_id,
1286 struct FragmentQueue *fragq, uint8_t drop) 1272 struct FragmentQueue *fragq, uint8_t drop)
1287{ 1273{
1288 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1289 "%p Running message fragment queue for message %" PRIu64 " (state: %u).\n", 1275 "%p Running message fragment queue for message %" PRIu64 " (state: %u).\n",
1290 chn, 1276 chn,
1291 msg_id, 1277 msg_id,
@@ -1413,7 +1399,7 @@ store_recv_state_modify_result (void *cls, int64_t result,
1413static uint64_t 1399static uint64_t
1414message_queue_run (struct Channel *chn) 1400message_queue_run (struct Channel *chn)
1415{ 1401{
1416 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1402 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1417 "%p Running message queue.\n", chn); 1403 "%p Running message queue.\n", chn);
1418 uint64_t n = 0; 1404 uint64_t n = 0;
1419 uint64_t msg_id; 1405 uint64_t msg_id;
@@ -1421,7 +1407,7 @@ message_queue_run (struct Channel *chn)
1421 while (GNUNET_YES == GNUNET_CONTAINER_heap_peek2 (chn->recv_msgs, NULL, 1407 while (GNUNET_YES == GNUNET_CONTAINER_heap_peek2 (chn->recv_msgs, NULL,
1422 &msg_id)) 1408 &msg_id))
1423 { 1409 {
1424 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1425 "%p Processing message %" PRIu64 " in queue.\n", chn, msg_id); 1411 "%p Processing message %" PRIu64 " in queue.\n", chn, msg_id);
1426 struct GNUNET_HashCode msg_id_hash; 1412 struct GNUNET_HashCode msg_id_hash;
1427 hash_key_from_hll (&msg_id_hash, msg_id); 1413 hash_key_from_hll (&msg_id_hash, msg_id);
@@ -1431,7 +1417,7 @@ message_queue_run (struct Channel *chn)
1431 1417
1432 if (NULL == fragq || fragq->state <= MSG_FRAG_STATE_HEADER) 1418 if (NULL == fragq || fragq->state <= MSG_FRAG_STATE_HEADER)
1433 { 1419 {
1434 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1435 "%p No fragq (%p) or header not complete.\n", 1421 "%p No fragq (%p) or header not complete.\n",
1436 chn, fragq); 1422 chn, fragq);
1437 break; 1423 break;
@@ -1453,7 +1439,7 @@ message_queue_run (struct Channel *chn)
1453 && (chn->max_message_id != msg_id - 1 1439 && (chn->max_message_id != msg_id - 1
1454 && chn->max_message_id != msg_id)) 1440 && chn->max_message_id != msg_id))
1455 { 1441 {
1456 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1442 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1457 "%p Out of order message. " 1443 "%p Out of order message. "
1458 "(%" PRIu64 " != %" PRIu64 " - 1)\n", 1444 "(%" PRIu64 " != %" PRIu64 " - 1)\n",
1459 chn, chn->max_message_id, msg_id); 1445 chn, chn->max_message_id, msg_id);
@@ -1469,7 +1455,7 @@ message_queue_run (struct Channel *chn)
1469 { 1455 {
1470 if (msg_id - fragq->state_delta != chn->max_state_message_id) 1456 if (msg_id - fragq->state_delta != chn->max_state_message_id)
1471 { 1457 {
1472 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1473 "%p Out of order stateful message. " 1459 "%p Out of order stateful message. "
1474 "(%" PRIu64 " - %" PRIu64 " != %" PRIu64 ")\n", 1460 "(%" PRIu64 " - %" PRIu64 " != %" PRIu64 ")\n",
1475 chn, msg_id, fragq->state_delta, chn->max_state_message_id); 1461 chn, msg_id, fragq->state_delta, chn->max_state_message_id);
@@ -1515,8 +1501,6 @@ message_queue_run (struct Channel *chn)
1515static uint64_t 1501static uint64_t
1516message_queue_drop (struct Channel *chn) 1502message_queue_drop (struct Channel *chn)
1517{ 1503{
1518 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1519 "%p Dropping message queue.\n", chn);
1520 uint64_t n = 0; 1504 uint64_t n = 0;
1521 uint64_t msg_id; 1505 uint64_t msg_id;
1522 while (GNUNET_YES == GNUNET_CONTAINER_heap_peek2 (chn->recv_msgs, NULL, 1506 while (GNUNET_YES == GNUNET_CONTAINER_heap_peek2 (chn->recv_msgs, NULL,
@@ -1703,7 +1687,7 @@ store_recv_slave_counters (void *cls, int result, uint64_t max_fragment_id,
1703 res.result_code = htonl (result); 1687 res.result_code = htonl (result);
1704 res.max_message_id = GNUNET_htonll (max_message_id); 1688 res.max_message_id = GNUNET_htonll (max_message_id);
1705 1689
1706 if (GNUNET_OK == result || GNUNET_NO == result) 1690 if (GNUNET_YES == result || GNUNET_NO == result)
1707 { 1691 {
1708 chn->max_message_id = max_message_id; 1692 chn->max_message_id = max_message_id;
1709 chn->max_state_message_id = max_state_message_id; 1693 chn->max_state_message_id = max_state_message_id;
@@ -1831,6 +1815,9 @@ handle_client_slave_join (void *cls,
1831 struct GNUNET_CRYPTO_EcdsaPublicKey slv_pub_key; 1815 struct GNUNET_CRYPTO_EcdsaPublicKey slv_pub_key;
1832 struct GNUNET_HashCode pub_key_hash, slv_pub_hash; 1816 struct GNUNET_HashCode pub_key_hash, slv_pub_hash;
1833 1817
1818 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1819 "got join request from client %p\n",
1820 client);
1834 GNUNET_CRYPTO_ecdsa_key_get_public (&req->slave_key, &slv_pub_key); 1821 GNUNET_CRYPTO_ecdsa_key_get_public (&req->slave_key, &slv_pub_key);
1835 GNUNET_CRYPTO_hash (&slv_pub_key, sizeof (slv_pub_key), &slv_pub_hash); 1822 GNUNET_CRYPTO_hash (&slv_pub_key, sizeof (slv_pub_key), &slv_pub_hash);
1836 GNUNET_CRYPTO_hash (&req->channel_pub_key, sizeof (req->channel_pub_key), &pub_key_hash); 1823 GNUNET_CRYPTO_hash (&req->channel_pub_key, sizeof (req->channel_pub_key), &pub_key_hash);
@@ -1905,7 +1892,7 @@ handle_client_slave_join (void *cls,
1905 GNUNET_CONTAINER_multihashmap_put (slaves, &chn->pub_key_hash, chn, 1892 GNUNET_CONTAINER_multihashmap_put (slaves, &chn->pub_key_hash, chn,
1906 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1893 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1907 chn->store_op = GNUNET_PSYCSTORE_counters_get (store, &chn->pub_key, 1894 chn->store_op = GNUNET_PSYCSTORE_counters_get (store, &chn->pub_key,
1908 &store_recv_slave_counters, slv); 1895 &store_recv_slave_counters, slv);
1909 } 1896 }
1910 else 1897 else
1911 { 1898 {
@@ -1952,8 +1939,9 @@ handle_client_slave_join (void *cls,
1952 } 1939 }
1953 1940
1954 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1941 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1955 "%p Client connected as slave to channel %s.\n", 1942 "Client %p connected as slave to channel %s.\n",
1956 slv, GNUNET_h2s (&chn->pub_key_hash)); 1943 client,
1944 GNUNET_h2s (&chn->pub_key_hash));
1957 1945
1958 struct ClientList *cli = GNUNET_malloc (sizeof (*cli)); 1946 struct ClientList *cli = GNUNET_malloc (sizeof (*cli));
1959 cli->client = client; 1947 cli->client = client;
@@ -2037,6 +2025,49 @@ handle_client_join_decision (void *cls,
2037} 2025}
2038 2026
2039 2027
2028static void
2029channel_part_cb (void *cls)
2030{
2031 struct GNUNET_SERVICE_Client *client = cls;
2032 struct GNUNET_MQ_Envelope *env;
2033
2034 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_PSYC_PART_ACK);
2035 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
2036 env);
2037}
2038
2039
2040static void
2041handle_client_part_request (void *cls,
2042 const struct GNUNET_MessageHeader *msg)
2043{
2044 struct Client *c = cls;
2045
2046 c->channel->is_disconnecting = GNUNET_YES;
2047 if (GNUNET_YES == c->channel->is_master)
2048 {
2049 struct Master *mst = (struct Master *) c->channel;
2050
2051 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2052 "Got part request from master %p\n",
2053 mst);
2054 GNUNET_assert (NULL != mst->origin);
2055 GNUNET_MULTICAST_origin_stop (mst->origin, channel_part_cb, c->client);
2056 }
2057 else
2058 {
2059 struct Slave *slv = (struct Slave *) c->channel;
2060
2061 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2062 "Got part request from slave %p\n",
2063 slv);
2064 GNUNET_assert (NULL != slv->member);
2065 GNUNET_MULTICAST_member_part (slv->member, channel_part_cb, c->client);
2066 }
2067 GNUNET_SERVICE_client_continue (c->client);
2068}
2069
2070
2040/** 2071/**
2041 * Send acknowledgement to a client. 2072 * Send acknowledgement to a client.
2042 * 2073 *
@@ -2096,7 +2127,7 @@ transmit_notify (void *cls, size_t *data_size, void *data)
2096 { 2127 {
2097 GNUNET_SCHEDULER_add_now (&schedule_transmit_message, chn); 2128 GNUNET_SCHEDULER_add_now (&schedule_transmit_message, chn);
2098 } 2129 }
2099 else if (GNUNET_YES == chn->is_disconnected 2130 else if (GNUNET_YES == chn->is_disconnecting
2100 && tmit_msg->last_ptype < GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END) 2131 && tmit_msg->last_ptype < GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END)
2101 { 2132 {
2102 /* FIXME: handle partial message (when still in_transmit) */ 2133 /* FIXME: handle partial message (when still in_transmit) */
@@ -2208,12 +2239,10 @@ transmit_message (struct Channel *chn)
2208static void 2239static void
2209master_queue_message (struct Master *mst, struct TransmitMessage *tmit_msg) 2240master_queue_message (struct Master *mst, struct TransmitMessage *tmit_msg)
2210{ 2241{
2211 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%p master_queue_message()\n", mst);
2212
2213 if (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD == tmit_msg->first_ptype) 2242 if (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD == tmit_msg->first_ptype)
2214 { 2243 {
2215 tmit_msg->id = ++mst->max_message_id; 2244 tmit_msg->id = ++mst->max_message_id;
2216 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2217 "%p master_queue_message: message_id=%" PRIu64 "\n", 2246 "%p master_queue_message: message_id=%" PRIu64 "\n",
2218 mst, tmit_msg->id); 2247 mst, tmit_msg->id);
2219 struct GNUNET_PSYC_MessageMethod *pmeth 2248 struct GNUNET_PSYC_MessageMethod *pmeth
@@ -2225,7 +2254,7 @@ master_queue_message (struct Master *mst, struct TransmitMessage *tmit_msg)
2225 } 2254 }
2226 else if (pmeth->flags & GNUNET_PSYC_MASTER_TRANSMIT_STATE_MODIFY) 2255 else if (pmeth->flags & GNUNET_PSYC_MASTER_TRANSMIT_STATE_MODIFY)
2227 { 2256 {
2228 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2229 "%p master_queue_message: state_delta=%" PRIu64 "\n", 2258 "%p master_queue_message: state_delta=%" PRIu64 "\n",
2230 mst, tmit_msg->id - mst->max_state_message_id); 2259 mst, tmit_msg->id - mst->max_state_message_id);
2231 pmeth->state_delta = GNUNET_htonll (tmit_msg->id 2260 pmeth->state_delta = GNUNET_htonll (tmit_msg->id
@@ -2234,7 +2263,7 @@ master_queue_message (struct Master *mst, struct TransmitMessage *tmit_msg)
2234 } 2263 }
2235 else 2264 else
2236 { 2265 {
2237 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2238 "%p master_queue_message: state not modified\n", mst); 2267 "%p master_queue_message: state not modified\n", mst);
2239 pmeth->state_delta = GNUNET_htonll (GNUNET_PSYC_STATE_NOT_MODIFIED); 2268 pmeth->state_delta = GNUNET_htonll (GNUNET_PSYC_STATE_NOT_MODIFIED);
2240 } 2269 }
@@ -2359,7 +2388,9 @@ handle_client_psyc_message (void *cls,
2359 if (GNUNET_YES != chn->is_ready) 2388 if (GNUNET_YES != chn->is_ready)
2360 { 2389 {
2361 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2390 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2362 "%p Channel is not ready yet, disconnecting client.\n", chn); 2391 "%p Channel is not ready yet, disconnecting client %p.\n",
2392 chn,
2393 client);
2363 GNUNET_break (0); 2394 GNUNET_break (0);
2364 GNUNET_SERVICE_client_drop (client); 2395 GNUNET_SERVICE_client_drop (client);
2365 return; 2396 return;
@@ -2789,9 +2820,9 @@ run (void *cls,
2789GNUNET_SERVICE_MAIN 2820GNUNET_SERVICE_MAIN
2790("psyc", 2821("psyc",
2791 GNUNET_SERVICE_OPTION_NONE, 2822 GNUNET_SERVICE_OPTION_NONE,
2792 run, 2823 &run,
2793 client_notify_connect, 2824 &client_notify_connect,
2794 client_notify_disconnect, 2825 &client_notify_disconnect,
2795 NULL, 2826 NULL,
2796 GNUNET_MQ_hd_fixed_size (client_master_start, 2827 GNUNET_MQ_hd_fixed_size (client_master_start,
2797 GNUNET_MESSAGE_TYPE_PSYC_MASTER_START, 2828 GNUNET_MESSAGE_TYPE_PSYC_MASTER_START,
@@ -2805,6 +2836,10 @@ GNUNET_SERVICE_MAIN
2805 GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION, 2836 GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION,
2806 struct GNUNET_PSYC_JoinDecisionMessage, 2837 struct GNUNET_PSYC_JoinDecisionMessage,
2807 NULL), 2838 NULL),
2839 GNUNET_MQ_hd_fixed_size (client_part_request,
2840 GNUNET_MESSAGE_TYPE_PSYC_PART_REQUEST,
2841 struct GNUNET_MessageHeader,
2842 NULL),
2808 GNUNET_MQ_hd_var_size (client_psyc_message, 2843 GNUNET_MQ_hd_var_size (client_psyc_message,
2809 GNUNET_MESSAGE_TYPE_PSYC_MESSAGE, 2844 GNUNET_MESSAGE_TYPE_PSYC_MESSAGE,
2810 struct GNUNET_MessageHeader, 2845 struct GNUNET_MessageHeader,
diff --git a/src/psyc/psyc_api.c b/src/psyc/psyc_api.c
index c93d8b383..d8f4c98bc 100644
--- a/src/psyc/psyc_api.c
+++ b/src/psyc/psyc_api.c
@@ -260,6 +260,10 @@ handle_channel_result (void *cls,
260 GNUNET_OP_result (chn->op, GNUNET_ntohll (res->op_id), 260 GNUNET_OP_result (chn->op, GNUNET_ntohll (res->op_id),
261 GNUNET_ntohll (res->result_code), 261 GNUNET_ntohll (res->result_code),
262 data, data_size, NULL); 262 data, data_size, NULL);
263
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
265 "handle_channel_result: Received result message with OP ID %" PRIu64 "\n",
266 GNUNET_ntohll (res->op_id));
263} 267}
264 268
265 269
@@ -555,6 +559,9 @@ handle_slave_join_decision (void *cls,
555static void 559static void
556channel_cleanup (struct GNUNET_PSYC_Channel *chn) 560channel_cleanup (struct GNUNET_PSYC_Channel *chn)
557{ 561{
562 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
563 "cleaning up channel %p\n",
564 chn);
558 if (NULL != chn->tmit) 565 if (NULL != chn->tmit)
559 { 566 {
560 GNUNET_PSYC_transmit_destroy (chn->tmit); 567 GNUNET_PSYC_transmit_destroy (chn->tmit);
@@ -562,6 +569,7 @@ channel_cleanup (struct GNUNET_PSYC_Channel *chn)
562 } 569 }
563 if (NULL != chn->recv) 570 if (NULL != chn->recv)
564 { 571 {
572
565 GNUNET_PSYC_receive_destroy (chn->recv); 573 GNUNET_PSYC_receive_destroy (chn->recv);
566 chn->recv = NULL; 574 chn->recv = NULL;
567 } 575 }
@@ -585,30 +593,12 @@ channel_cleanup (struct GNUNET_PSYC_Channel *chn)
585 593
586 594
587static void 595static void
588channel_disconnect (struct GNUNET_PSYC_Channel *chn, 596handle_channel_part_ack (void *cls,
589 GNUNET_ContinuationCallback cb, 597 const struct GNUNET_MessageHeader *msg)
590 void *cls)
591{ 598{
592 chn->is_disconnecting = GNUNET_YES; 599 struct GNUNET_PSYC_Channel *chn = cls;
593 chn->disconnect_cb = cb;
594 chn->disconnect_cls = cls;
595 600
596 if (NULL != chn->mq) 601 channel_cleanup (chn);
597 {
598 struct GNUNET_MQ_Envelope *env = GNUNET_MQ_get_last_envelope (chn->mq);
599 if (NULL != env)
600 {
601 GNUNET_MQ_notify_sent (env, (GNUNET_SCHEDULER_TaskCallback) channel_cleanup, chn);
602 }
603 else
604 {
605 channel_cleanup (chn);
606 }
607 }
608 else
609 {
610 channel_cleanup (chn);
611 }
612} 602}
613 603
614 604
@@ -671,6 +661,10 @@ master_connect (struct GNUNET_PSYC_Master *mst)
671 GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST, 661 GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST,
672 struct GNUNET_PSYC_JoinRequestMessage, 662 struct GNUNET_PSYC_JoinRequestMessage,
673 mst), 663 mst),
664 GNUNET_MQ_hd_fixed_size (channel_part_ack,
665 GNUNET_MESSAGE_TYPE_PSYC_PART_ACK,
666 struct GNUNET_MessageHeader,
667 chn),
674 GNUNET_MQ_hd_var_size (channel_message, 668 GNUNET_MQ_hd_var_size (channel_message,
675 GNUNET_MESSAGE_TYPE_PSYC_MESSAGE, 669 GNUNET_MESSAGE_TYPE_PSYC_MESSAGE,
676 struct GNUNET_PSYC_MessageHeader, 670 struct GNUNET_PSYC_MessageHeader,
@@ -694,8 +688,11 @@ master_connect (struct GNUNET_PSYC_Master *mst)
694 GNUNET_MQ_handler_end () 688 GNUNET_MQ_handler_end ()
695 }; 689 };
696 690
697 chn->mq = GNUNET_CLIENT_connect (chn->cfg, "psyc", 691 chn->mq = GNUNET_CLIENT_connect (chn->cfg,
698 handlers, master_disconnected, mst); 692 "psyc",
693 handlers,
694 &master_disconnected,
695 mst);
699 GNUNET_assert (NULL != chn->mq); 696 GNUNET_assert (NULL != chn->mq);
700 chn->tmit = GNUNET_PSYC_transmit_create (chn->mq); 697 chn->tmit = GNUNET_PSYC_transmit_create (chn->mq);
701 698
@@ -780,10 +777,13 @@ GNUNET_PSYC_master_stop (struct GNUNET_PSYC_Master *mst,
780 void *stop_cls) 777 void *stop_cls)
781{ 778{
782 struct GNUNET_PSYC_Channel *chn = &mst->chn; 779 struct GNUNET_PSYC_Channel *chn = &mst->chn;
780 struct GNUNET_MQ_Envelope *env;
783 781
784 /* FIXME: send msg to service */ 782 chn->is_disconnecting = GNUNET_YES;
785 783 chn->disconnect_cb = stop_cb;
786 channel_disconnect (chn, stop_cb, stop_cls); 784 chn->disconnect_cls = stop_cls;
785 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_PSYC_PART_REQUEST);
786 GNUNET_MQ_send (chn->mq, env);
787} 787}
788 788
789 789
@@ -931,7 +931,8 @@ slave_reconnect (void *cls)
931 * Reconnect after backoff period. 931 * Reconnect after backoff period.
932 */ 932 */
933static void 933static void
934slave_disconnected (void *cls, enum GNUNET_MQ_Error error) 934slave_disconnected (void *cls,
935 enum GNUNET_MQ_Error error)
935{ 936{
936 struct GNUNET_PSYC_Slave *slv = cls; 937 struct GNUNET_PSYC_Slave *slv = cls;
937 struct GNUNET_PSYC_Channel *chn = &slv->chn; 938 struct GNUNET_PSYC_Channel *chn = &slv->chn;
@@ -950,7 +951,7 @@ slave_disconnected (void *cls, enum GNUNET_MQ_Error error)
950 chn->mq = NULL; 951 chn->mq = NULL;
951 } 952 }
952 chn->reconnect_task = GNUNET_SCHEDULER_add_delayed (chn->reconnect_delay, 953 chn->reconnect_task = GNUNET_SCHEDULER_add_delayed (chn->reconnect_delay,
953 slave_reconnect, 954 &slave_reconnect,
954 slv); 955 slv);
955 chn->reconnect_delay = GNUNET_TIME_STD_BACKOFF (chn->reconnect_delay); 956 chn->reconnect_delay = GNUNET_TIME_STD_BACKOFF (chn->reconnect_delay);
956} 957}
@@ -970,6 +971,10 @@ slave_connect (struct GNUNET_PSYC_Slave *slv)
970 GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION, 971 GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION,
971 struct GNUNET_PSYC_JoinDecisionMessage, 972 struct GNUNET_PSYC_JoinDecisionMessage,
972 slv), 973 slv),
974 GNUNET_MQ_hd_fixed_size (channel_part_ack,
975 GNUNET_MESSAGE_TYPE_PSYC_PART_ACK,
976 struct GNUNET_MessageHeader,
977 chn),
973 GNUNET_MQ_hd_var_size (channel_message, 978 GNUNET_MQ_hd_var_size (channel_message,
974 GNUNET_MESSAGE_TYPE_PSYC_MESSAGE, 979 GNUNET_MESSAGE_TYPE_PSYC_MESSAGE,
975 struct GNUNET_PSYC_MessageHeader, 980 struct GNUNET_PSYC_MessageHeader,
@@ -993,9 +998,19 @@ slave_connect (struct GNUNET_PSYC_Slave *slv)
993 GNUNET_MQ_handler_end () 998 GNUNET_MQ_handler_end ()
994 }; 999 };
995 1000
996 chn->mq = GNUNET_CLIENT_connect (chn->cfg, "psyc", 1001 chn->mq = GNUNET_CLIENT_connect (chn->cfg,
997 handlers, slave_disconnected, slv); 1002 "psyc",
998 GNUNET_assert (NULL != chn->mq); 1003 handlers,
1004 &slave_disconnected,
1005 slv);
1006 if (NULL == chn->mq)
1007 {
1008 chn->reconnect_task = GNUNET_SCHEDULER_add_delayed (chn->reconnect_delay,
1009 &slave_reconnect,
1010 slv);
1011 chn->reconnect_delay = GNUNET_TIME_STD_BACKOFF (chn->reconnect_delay);
1012 return;
1013 }
999 chn->tmit = GNUNET_PSYC_transmit_create (chn->mq); 1014 chn->tmit = GNUNET_PSYC_transmit_create (chn->mq);
1000 1015
1001 GNUNET_MQ_send_copy (chn->mq, chn->connect_env); 1016 GNUNET_MQ_send_copy (chn->mq, chn->connect_env);
@@ -1107,10 +1122,13 @@ GNUNET_PSYC_slave_part (struct GNUNET_PSYC_Slave *slv,
1107 void *part_cls) 1122 void *part_cls)
1108{ 1123{
1109 struct GNUNET_PSYC_Channel *chn = &slv->chn; 1124 struct GNUNET_PSYC_Channel *chn = &slv->chn;
1125 struct GNUNET_MQ_Envelope *env;
1110 1126
1111 /* FIXME: send msg to service */ 1127 chn->is_disconnecting = GNUNET_YES;
1112 1128 chn->disconnect_cb = part_cb;
1113 channel_disconnect (chn, part_cb, part_cls); 1129 chn->disconnect_cls = part_cls;
1130 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_PSYC_PART_REQUEST);
1131 GNUNET_MQ_send (chn->mq, env);
1114} 1132}
1115 1133
1116 1134
@@ -1233,6 +1251,9 @@ GNUNET_PSYC_channel_slave_add (struct GNUNET_PSYC_Channel *chn,
1233 req->did_join = GNUNET_YES; 1251 req->did_join = GNUNET_YES;
1234 req->op_id = GNUNET_htonll (GNUNET_OP_add (chn->op, result_cb, cls, NULL)); 1252 req->op_id = GNUNET_htonll (GNUNET_OP_add (chn->op, result_cb, cls, NULL));
1235 1253
1254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1255 "GNUNET_PSYC_channel_slave_add, OP ID: %" PRIu64 "\n",
1256 GNUNET_ntohll (req->op_id));
1236 GNUNET_MQ_send (chn->mq, env); 1257 GNUNET_MQ_send (chn->mq, env);
1237} 1258}
1238 1259
@@ -1283,6 +1304,9 @@ GNUNET_PSYC_channel_slave_remove (struct GNUNET_PSYC_Channel *chn,
1283 req->did_join = GNUNET_NO; 1304 req->did_join = GNUNET_NO;
1284 req->op_id = GNUNET_htonll (GNUNET_OP_add (chn->op, result_cb, cls, NULL)); 1305 req->op_id = GNUNET_htonll (GNUNET_OP_add (chn->op, result_cb, cls, NULL));
1285 1306
1307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1308 "GNUNET_PSYC_channel_slave_remove, OP ID: %" PRIu64 "\n",
1309 GNUNET_ntohll (req->op_id));
1286 GNUNET_MQ_send (chn->mq, env); 1310 GNUNET_MQ_send (chn->mq, env);
1287} 1311}
1288 1312
@@ -1321,6 +1345,10 @@ channel_history_replay (struct GNUNET_PSYC_Channel *chn,
1321 req->message_limit = GNUNET_htonll (message_limit); 1345 req->message_limit = GNUNET_htonll (message_limit);
1322 req->flags = htonl (flags); 1346 req->flags = htonl (flags);
1323 req->op_id = GNUNET_htonll (hist->op_id); 1347 req->op_id = GNUNET_htonll (hist->op_id);
1348
1349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1350 "channel_history_replay, OP ID: %" PRIu64 "\n",
1351 GNUNET_ntohll (req->op_id));
1324 GNUNET_memcpy (&req[1], method_prefix, method_size); 1352 GNUNET_memcpy (&req[1], method_prefix, method_size);
1325 1353
1326 GNUNET_MQ_send (chn->mq, env); 1354 GNUNET_MQ_send (chn->mq, env);
@@ -1459,6 +1487,11 @@ channel_state_get (struct GNUNET_PSYC_Channel *chn,
1459 struct GNUNET_MQ_Envelope * 1487 struct GNUNET_MQ_Envelope *
1460 env = GNUNET_MQ_msg_extra (req, name_size, type); 1488 env = GNUNET_MQ_msg_extra (req, name_size, type);
1461 req->op_id = GNUNET_htonll (sr->op_id); 1489 req->op_id = GNUNET_htonll (sr->op_id);
1490
1491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1492 "channel_state_get, OP ID: %" PRIu64 "\n",
1493 GNUNET_ntohll (req->op_id));
1494
1462 GNUNET_memcpy (&req[1], name, name_size); 1495 GNUNET_memcpy (&req[1], name, name_size);
1463 1496
1464 GNUNET_MQ_send (chn->mq, env); 1497 GNUNET_MQ_send (chn->mq, env);
diff --git a/src/psyc/test_psyc.c b/src/psyc/test_psyc.c
index 03a1890b1..370befb9d 100644
--- a/src/psyc/test_psyc.c
+++ b/src/psyc/test_psyc.c
@@ -755,15 +755,22 @@ slave_add ()
755 755
756 756
757static void 757static void
758schedule_second_slave_join (void *cls)
759{
760 slave_join (TEST_SLAVE_JOIN_ACCEPT);
761}
762
763
764static void
758first_slave_parted (void *cls) 765first_slave_parted (void *cls)
759{ 766{
760 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "First slave parted.\n"); 767 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "First slave parted.\n");
761 slave_join (TEST_SLAVE_JOIN_ACCEPT); 768 GNUNET_SCHEDULER_add_now (&schedule_second_slave_join, NULL);
762} 769}
763 770
764 771
765static void 772static void
766schedule_slave_part (void *cls) 773schedule_first_slave_part (void *cls)
767{ 774{
768 GNUNET_PSYC_slave_part (slv, GNUNET_NO, &first_slave_parted, NULL); 775 GNUNET_PSYC_slave_part (slv, GNUNET_NO, &first_slave_parted, NULL);
769} 776}
@@ -783,7 +790,7 @@ join_decision_cb (void *cls,
783 case TEST_SLAVE_JOIN_REJECT: 790 case TEST_SLAVE_JOIN_REJECT:
784 GNUNET_assert (0 == is_admitted); 791 GNUNET_assert (0 == is_admitted);
785 GNUNET_assert (1 == join_req_count); 792 GNUNET_assert (1 == join_req_count);
786 GNUNET_SCHEDULER_add_now (&schedule_slave_part, NULL); 793 GNUNET_SCHEDULER_add_now (&schedule_first_slave_part, NULL);
787 break; 794 break;
788 795
789 case TEST_SLAVE_JOIN_ACCEPT: 796 case TEST_SLAVE_JOIN_ACCEPT:
@@ -844,11 +851,18 @@ slave_join (int t)
844 struct GNUNET_PSYC_Message * 851 struct GNUNET_PSYC_Message *
845 join_msg = GNUNET_PSYC_message_create ("_request_join", env, "some data", 9); 852 join_msg = GNUNET_PSYC_message_create ("_request_join", env, "some data", 9);
846 853
847 slv = GNUNET_PSYC_slave_join (cfg, &channel_pub_key, slave_key, 854 slv = GNUNET_PSYC_slave_join (cfg,
855 &channel_pub_key,
856 slave_key,
848 GNUNET_PSYC_SLAVE_JOIN_NONE, 857 GNUNET_PSYC_SLAVE_JOIN_NONE,
849 &origin, 0, NULL, 858 &origin,
850 &slave_message_cb, &slave_message_part_cb, 859 0,
851 &slave_connect_cb, &join_decision_cb, NULL, 860 NULL,
861 &slave_message_cb,
862 &slave_message_part_cb,
863 &slave_connect_cb,
864 &join_decision_cb,
865 NULL,
852 join_msg); 866 join_msg);
853 GNUNET_free (join_msg); 867 GNUNET_free (join_msg);
854 slv_chn = GNUNET_PSYC_slave_get_channel (slv); 868 slv_chn = GNUNET_PSYC_slave_get_channel (slv);
diff --git a/src/psyc/test_psyc.conf b/src/psyc/test_psyc.conf
index e69de29bb..e00a614d2 100644
--- a/src/psyc/test_psyc.conf
+++ b/src/psyc/test_psyc.conf
@@ -0,0 +1,16 @@
1@INLINE@ ../../contrib/no_forcestart.conf
2
3[PATHS]
4GNUNET_TEST_HOME = /tmp/gnunet-test-psyc/
5
6[transport]
7PLUGINS = tcp
8
9[nat]
10DISABLEV6 = YES
11ENABLE_UPNP = NO
12BEHIND_NAT = NO
13ALLOW_NAT = NO
14INTERNAL_ADDRESS = 127.0.0.1
15EXTERNAL_ADDRESS = 127.0.0.1
16
diff --git a/src/psycstore/psycstore_api.c b/src/psycstore/psycstore_api.c
index d79daa357..16f4a1ae9 100644
--- a/src/psycstore/psycstore_api.c
+++ b/src/psycstore/psycstore_api.c
@@ -148,14 +148,14 @@ handle_result_code (void *cls, const struct OperationResult *opres)
148 str, size - sizeof (*opres), (void **) &op)) 148 str, size - sizeof (*opres), (void **) &op))
149 { 149 {
150 LOG (GNUNET_ERROR_TYPE_DEBUG, 150 LOG (GNUNET_ERROR_TYPE_DEBUG,
151 "handle_result_code: Received result message with operation ID: %" PRIu64 "\n", 151 "handle_result_code: Received result message with OP ID: %" PRIu64 "\n",
152 GNUNET_ntohll (opres->op_id)); 152 GNUNET_ntohll (opres->op_id));
153 GNUNET_free (op); 153 GNUNET_free (op);
154 } 154 }
155 else 155 else
156 { 156 {
157 LOG (GNUNET_ERROR_TYPE_DEBUG, 157 LOG (GNUNET_ERROR_TYPE_DEBUG,
158 "handle_result_code: No callback registered for operation with ID %" PRIu64 ".\n", 158 "handle_result_code: No callback registered for OP ID %" PRIu64 ".\n",
159 GNUNET_ntohll (opres->op_id)); 159 GNUNET_ntohll (opres->op_id));
160 } 160 }
161 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS; 161 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
@@ -187,7 +187,7 @@ handle_result_counters (void *cls, const struct CountersResult *cres)
187 else 187 else
188 { 188 {
189 LOG (GNUNET_ERROR_TYPE_DEBUG, 189 LOG (GNUNET_ERROR_TYPE_DEBUG,
190 "handle_result_counters: No callback registered for operation with ID %" PRIu64 ".\n", 190 "handle_result_counters: No callback registered for OP ID %" PRIu64 ".\n",
191 GNUNET_ntohll (cres->op_id)); 191 GNUNET_ntohll (cres->op_id));
192 } 192 }
193 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS; 193 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
@@ -233,7 +233,7 @@ handle_result_fragment (void *cls, const struct FragmentResult *fres)
233 else 233 else
234 { 234 {
235 LOG (GNUNET_ERROR_TYPE_DEBUG, 235 LOG (GNUNET_ERROR_TYPE_DEBUG,
236 "handle_result_fragment: No callback registered for operation with ID %" PRIu64 ".\n", 236 "handle_result_fragment: No callback registered for OP ID %" PRIu64 ".\n",
237 GNUNET_ntohll (fres->op_id)); 237 GNUNET_ntohll (fres->op_id));
238 } 238 }
239 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS; 239 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
@@ -282,7 +282,7 @@ handle_result_state (void *cls, const struct StateResult *sres)
282 else 282 else
283 { 283 {
284 LOG (GNUNET_ERROR_TYPE_DEBUG, 284 LOG (GNUNET_ERROR_TYPE_DEBUG,
285 "handle_result_state: No callback registered for operation with ID %" PRIu64 ".\n", 285 "handle_result_state: No callback registered for OP ID %" PRIu64 ".\n",
286 GNUNET_ntohll (sres->op_id)); 286 GNUNET_ntohll (sres->op_id));
287 } 287 }
288 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS; 288 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
diff --git a/src/social/gnunet-service-social.c b/src/social/gnunet-service-social.c
index dee68fdb8..5b2a8ba9b 100644
--- a/src/social/gnunet-service-social.c
+++ b/src/social/gnunet-service-social.c
@@ -96,7 +96,7 @@ static struct GNUNET_CONTAINER_MultiHashMap *apps_places;
96 * Application subscriptions per place. 96 * Application subscriptions per place.
97 * H(place_pub_key) -> H(app_id) 97 * H(place_pub_key) -> H(app_id)
98 */ 98 */
99static struct GNUNET_CONTAINER_MultiHashMap *places_apps; 99//static struct GNUNET_CONTAINER_MultiHashMap *places_apps;
100 100
101/** 101/**
102 * Connected applications. 102 * Connected applications.
@@ -255,10 +255,10 @@ struct Place
255 uint8_t is_ready; 255 uint8_t is_ready;
256 256
257 /** 257 /**
258 * Is the client disconnected? 258 * Is the client disconnecting?
259 * #GNUNET_YES or #GNUNET_NO 259 * #GNUNET_YES or #GNUNET_NO
260 */ 260 */
261 uint8_t is_disconnected; 261 uint8_t is_disconnecting;
262 262
263 /** 263 /**
264 * Is this a host (#GNUNET_YES), or guest (#GNUNET_NO)? 264 * Is this a host (#GNUNET_YES), or guest (#GNUNET_NO)?
@@ -348,7 +348,7 @@ struct Guest
348 /** 348 /**
349 * Join request to be transmitted to the master on join. 349 * Join request to be transmitted to the master on join.
350 */ 350 */
351 struct GNUNET_MessageHeader *join_req; 351 struct GNUNET_MessageHeader *join_req; // FIXME: not used!
352 352
353 /** 353 /**
354 * Join decision received from PSYC. 354 * Join decision received from PSYC.
@@ -487,8 +487,6 @@ cleanup_host (struct Host *hst)
487{ 487{
488 struct Place *plc = &hst->place; 488 struct Place *plc = &hst->place;
489 489
490 if (NULL != hst->master)
491 GNUNET_PSYC_master_stop (hst->master, GNUNET_NO, NULL, NULL); // FIXME
492 GNUNET_CONTAINER_multihashmap_destroy (hst->join_reqs); 490 GNUNET_CONTAINER_multihashmap_destroy (hst->join_reqs);
493 GNUNET_CONTAINER_multihashmap_destroy (hst->relay_msgs); 491 GNUNET_CONTAINER_multihashmap_destroy (hst->relay_msgs);
494 GNUNET_CONTAINER_multihashmap_remove (hosts, &plc->pub_key_hash, plc); 492 GNUNET_CONTAINER_multihashmap_remove (hosts, &plc->pub_key_hash, plc);
@@ -505,7 +503,7 @@ cleanup_guest (struct Guest *gst)
505 struct GNUNET_CONTAINER_MultiHashMap * 503 struct GNUNET_CONTAINER_MultiHashMap *
506 plc_gst = GNUNET_CONTAINER_multihashmap_get (place_guests, 504 plc_gst = GNUNET_CONTAINER_multihashmap_get (place_guests,
507 &plc->pub_key_hash); 505 &plc->pub_key_hash);
508 GNUNET_assert (NULL != plc_gst); // FIXME 506 GNUNET_assert (NULL != plc_gst);
509 GNUNET_CONTAINER_multihashmap_remove (plc_gst, &plc->ego_pub_hash, gst); 507 GNUNET_CONTAINER_multihashmap_remove (plc_gst, &plc->ego_pub_hash, gst);
510 508
511 if (0 == GNUNET_CONTAINER_multihashmap_size (plc_gst)) 509 if (0 == GNUNET_CONTAINER_multihashmap_size (plc_gst))
@@ -520,8 +518,6 @@ cleanup_guest (struct Guest *gst)
520 GNUNET_free (gst->join_req); 518 GNUNET_free (gst->join_req);
521 if (NULL != gst->relays) 519 if (NULL != gst->relays)
522 GNUNET_free (gst->relays); 520 GNUNET_free (gst->relays);
523 if (NULL != gst->slave)
524 GNUNET_PSYC_slave_part (gst->slave, GNUNET_NO, NULL, NULL); // FIXME
525 GNUNET_CONTAINER_multihashmap_remove (guests, &plc->pub_key_hash, plc); 521 GNUNET_CONTAINER_multihashmap_remove (guests, &plc->pub_key_hash, plc);
526} 522}
527 523
@@ -537,8 +533,8 @@ cleanup_place (void *cls)
537 struct Place *plc = cls; 533 struct Place *plc = cls;
538 534
539 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 535 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
540 "%p Cleaning up place %s\n", 536 "cleaning up place %s\n",
541 plc, GNUNET_h2s (&plc->pub_key_hash)); 537 GNUNET_h2s (&plc->pub_key_hash));
542 538
543 (GNUNET_YES == plc->is_host) 539 (GNUNET_YES == plc->is_host)
544 ? cleanup_host ((struct Host *) plc) 540 ? cleanup_host ((struct Host *) plc)
@@ -583,12 +579,19 @@ client_notify_disconnect (void *cls,
583 { 579 {
584 if (cli->client == client) 580 if (cli->client == client)
585 { 581 {
586 GNUNET_CONTAINER_DLL_remove (plc->clients_head, plc->clients_tail, cli); 582 GNUNET_CONTAINER_DLL_remove (plc->clients_head,
583 plc->clients_tail,
584 cli);
587 GNUNET_free (cli); 585 GNUNET_free (cli);
588 break; 586 break;
589 } 587 }
590 cli = cli->next; 588 cli = cli->next;
591 } 589 }
590 if (GNUNET_YES == plc->is_disconnecting)
591 {
592 GNUNET_PSYC_slicer_destroy (plc->slicer);
593 GNUNET_free (plc);
594 }
592} 595}
593 596
594 597
@@ -605,46 +608,55 @@ client_notify_connect (void *cls,
605 struct GNUNET_SERVICE_Client *client, 608 struct GNUNET_SERVICE_Client *client,
606 struct GNUNET_MQ_Handle *mq) 609 struct GNUNET_MQ_Handle *mq)
607{ 610{
608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client connected: %p\n", client); 611 struct Client *c = GNUNET_new (struct Client);
609 612
610 struct Client *c = GNUNET_malloc (sizeof (*c)); 613 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
614 "Client %p connected with queue %p\n",
615 client,
616 mq);
611 c->client = client; 617 c->client = client;
612
613 return c; 618 return c;
614} 619}
615 620
616 621
617/** 622/**
618 * Send message to a client. 623 * Send message to all clients connected to a place and
619 */ 624 * takes care of freeing @env.
620static inline void
621client_send_msg (struct GNUNET_SERVICE_Client *client,
622 const struct GNUNET_MessageHeader *msg)
623{
624 struct GNUNET_MQ_Envelope *
625 env = GNUNET_MQ_msg_copy (msg);
626
627 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
628 env);
629}
630
631
632/**
633 * Send message to all clients connected to a place.
634 */ 625 */
635static void 626static void
636place_send_msg (const struct Place *plc, 627place_send_msg (const struct Place *plc,
637 const struct GNUNET_MessageHeader *msg) 628 struct GNUNET_MQ_Envelope *env)
638{ 629{
630 struct ClientListItem *cli = plc->clients_head;
631
639 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 632 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
640 "%p Sending message to clients of place.\n", plc); 633 "%p Sending message to clients of place.\n", plc);
641
642 struct ClientListItem *cli = plc->clients_head;
643 while (NULL != cli) 634 while (NULL != cli)
644 { 635 {
645 client_send_msg (cli->client, msg); 636 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
637 "Sending message to client %p\n",
638 cli);
639 GNUNET_MQ_send_copy (GNUNET_SERVICE_client_get_mq (cli->client),
640 env);
646 cli = cli->next; 641 cli = cli->next;
647 } 642 }
643 GNUNET_MQ_discard (env);
644}
645
646
647static void
648place_send_leave_ack (struct Place *plc)
649{
650 struct GNUNET_MQ_Envelope *env;
651
652 for (struct ClientListItem *cli = plc->clients_head;
653 NULL != cli;
654 cli = cli->next)
655 {
656 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE_ACK);
657 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cli->client),
658 env);
659 }
648} 660}
649 661
650 662
@@ -666,23 +678,21 @@ static void
666client_send_result (struct GNUNET_SERVICE_Client *client, uint64_t op_id, 678client_send_result (struct GNUNET_SERVICE_Client *client, uint64_t op_id,
667 int64_t result_code, const void *data, uint16_t data_size) 679 int64_t result_code, const void *data, uint16_t data_size)
668{ 680{
681 struct GNUNET_MQ_Envelope *env;
669 struct GNUNET_OperationResultMessage *res; 682 struct GNUNET_OperationResultMessage *res;
670 683
671 res = GNUNET_malloc (sizeof (*res) + data_size); 684 env = GNUNET_MQ_msg_extra (res,
672 res->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_RESULT_CODE); 685 data_size,
673 res->header.size = htons (sizeof (*res) + data_size); 686 GNUNET_MESSAGE_TYPE_PSYC_RESULT_CODE);
674 res->result_code = GNUNET_htonll (result_code); 687 res->result_code = GNUNET_htonll (result_code);
675 res->op_id = op_id; 688 res->op_id = op_id;
676 if (0 < data_size) 689 if (0 < data_size)
677 GNUNET_memcpy (&res[1], data, data_size); 690 GNUNET_memcpy (&res[1], data, data_size);
678
679 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 691 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
680 "%p Sending result to client for operation #%" PRIu64 ": " 692 "%p Sending result to client for operation #%" PRIu64 ": "
681 "%" PRId64 " (size: %u)\n", 693 "%" PRId64 " (size: %u)\n",
682 client, GNUNET_ntohll (op_id), result_code, data_size); 694 client, GNUNET_ntohll (op_id), result_code, data_size);
683 695 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
684 client_send_msg (client, &res->header);
685 GNUNET_free (res);
686} 696}
687 697
688 698
@@ -690,19 +700,21 @@ static void
690client_send_host_enter_ack (struct GNUNET_SERVICE_Client *client, 700client_send_host_enter_ack (struct GNUNET_SERVICE_Client *client,
691 struct Host *hst, uint32_t result) 701 struct Host *hst, uint32_t result)
692{ 702{
703 struct GNUNET_MQ_Envelope *env;
704 struct HostEnterAck *hack;
693 struct Place *plc = &hst->place; 705 struct Place *plc = &hst->place;
694 706
695 struct HostEnterAck hack; 707 env = GNUNET_MQ_msg (hack,
696 hack.header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER_ACK); 708 GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER_ACK);
697 hack.header.size = htons (sizeof (hack)); 709 hack->result_code = htonl (result);
698 hack.result_code = htonl (result); 710 hack->max_message_id = GNUNET_htonll (plc->max_message_id);
699 hack.max_message_id = GNUNET_htonll (plc->max_message_id); 711 hack->place_pub_key = plc->pub_key;
700 hack.place_pub_key = plc->pub_key;
701 712
702 if (NULL != client) 713 if (NULL != client)
703 client_send_msg (client, &hack.header); 714 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
715 env);
704 else 716 else
705 place_send_msg (plc, &hack.header); 717 place_send_msg (plc, env);
706} 718}
707 719
708 720
@@ -736,7 +748,8 @@ psyc_recv_join_request (void *cls,
736 GNUNET_CRYPTO_hash (slave_key, sizeof (*slave_key), &slave_key_hash); 748 GNUNET_CRYPTO_hash (slave_key, sizeof (*slave_key), &slave_key_hash);
737 GNUNET_CONTAINER_multihashmap_put (hst->join_reqs, &slave_key_hash, jh, 749 GNUNET_CONTAINER_multihashmap_put (hst->join_reqs, &slave_key_hash, jh,
738 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 750 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
739 place_send_msg (&hst->place, &req->header); 751 place_send_msg (&hst->place,
752 GNUNET_MQ_msg_copy (&req->header));
740} 753}
741 754
742 755
@@ -746,18 +759,29 @@ psyc_recv_join_request (void *cls,
746static void 759static void
747psyc_slave_connected (void *cls, int result, uint64_t max_message_id) 760psyc_slave_connected (void *cls, int result, uint64_t max_message_id)
748{ 761{
762 struct GNUNET_PSYC_CountersResultMessage *res;
763 struct GNUNET_MQ_Envelope *env;
749 struct Guest *gst = cls; 764 struct Guest *gst = cls;
750 struct Place *plc = &gst->place; 765 struct Place *plc = &gst->place;
766
751 plc->max_message_id = max_message_id; 767 plc->max_message_id = max_message_id;
752 plc->is_ready = GNUNET_YES; 768 plc->is_ready = GNUNET_YES;
769 env = GNUNET_MQ_msg (res,
770 GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER_ACK);
771 res->result_code =
772 (result != GNUNET_SYSERR) ? htonl (GNUNET_OK) : htonl (GNUNET_SYSERR);
773 res->max_message_id = GNUNET_htonll (plc->max_message_id);
774 place_send_msg (plc, env);
775}
753 776
754 struct GNUNET_PSYC_CountersResultMessage res;
755 res.header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER_ACK);
756 res.header.size = htons (sizeof (res));
757 res.result_code = htonl (result);
758 res.max_message_id = GNUNET_htonll (plc->max_message_id);
759 777
760 place_send_msg (plc, &res.header); 778static void
779slave_parted_after_join_decision (void *cls)
780{
781 struct Guest *gst = cls;
782
783 GNUNET_assert (NULL != gst->join_dcsn);
784 place_send_msg (&gst->place, GNUNET_MQ_msg_copy (&gst->join_dcsn->header));
761} 785}
762 786
763 787
@@ -771,7 +795,21 @@ psyc_recv_join_dcsn (void *cls,
771 const struct GNUNET_PSYC_Message *join_msg) 795 const struct GNUNET_PSYC_Message *join_msg)
772{ 796{
773 struct Guest *gst = cls; 797 struct Guest *gst = cls;
774 place_send_msg (&gst->place, &dcsn->header); 798
799 gst->join_dcsn = GNUNET_malloc (dcsn->header.size);
800 GNUNET_memcpy (gst->join_dcsn,
801 dcsn,
802 dcsn->header.size);
803 if (GNUNET_NO == is_admitted)
804 {
805 GNUNET_PSYC_slave_part (gst->slave,
806 GNUNET_NO,
807 &slave_parted_after_join_decision,
808 gst);
809 gst->slave = NULL;
810 return;
811 }
812 place_send_msg (&gst->place, GNUNET_MQ_msg_copy (&gst->join_dcsn->header));
775} 813}
776 814
777 815
@@ -792,7 +830,7 @@ psyc_recv_message (void *cls,
792 830
793 GNUNET_PSYC_slicer_message (plc->slicer, msg); 831 GNUNET_PSYC_slicer_message (plc->slicer, msg);
794 832
795 place_send_msg (plc, &msg->header); 833 place_send_msg (plc, GNUNET_MQ_msg_copy (&msg->header));
796} 834}
797 835
798 836
@@ -1096,9 +1134,6 @@ place_init (struct Place *plc)
1096static int 1134static int
1097place_add (const struct PlaceEnterRequest *ereq) 1135place_add (const struct PlaceEnterRequest *ereq)
1098{ 1136{
1099 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1100 "Adding place to hashmap:\n");
1101
1102 struct EgoPlacePublicKey ego_place_pub_key = { 1137 struct EgoPlacePublicKey ego_place_pub_key = {
1103 .ego_pub_key = ereq->ego_pub_key, 1138 .ego_pub_key = ereq->ego_pub_key,
1104 .place_pub_key = ereq->place_pub_key, 1139 .place_pub_key = ereq->place_pub_key,
@@ -1173,7 +1208,9 @@ app_place_add (const char *app_id,
1173 return GNUNET_NO; 1208 return GNUNET_NO;
1174 1209
1175 if (GNUNET_SYSERR == place_add (ereq)) 1210 if (GNUNET_SYSERR == place_add (ereq))
1211 {
1176 return GNUNET_SYSERR; 1212 return GNUNET_SYSERR;
1213 }
1177 1214
1178 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (app_places, &ego_place_pub_hash, NULL, 1215 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (app_places, &ego_place_pub_hash, NULL,
1179 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) 1216 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
@@ -1181,32 +1218,6 @@ app_place_add (const char *app_id,
1181 GNUNET_break (0); 1218 GNUNET_break (0);
1182 return GNUNET_SYSERR; 1219 return GNUNET_SYSERR;
1183 } 1220 }
1184
1185 struct GNUNET_HashCode place_pub_hash;
1186 GNUNET_CRYPTO_hash (&ereq->place_pub_key, sizeof (ereq->place_pub_key), &place_pub_hash);
1187
1188 struct GNUNET_CONTAINER_MultiHashMap *
1189 place_apps = GNUNET_CONTAINER_multihashmap_get (places_apps, &place_pub_hash);
1190 if (NULL == place_apps)
1191 {
1192 place_apps = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
1193 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (places_apps, &place_pub_hash, place_apps,
1194 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
1195 {
1196 GNUNET_break (0);
1197 }
1198 }
1199
1200 size_t app_id_size = strlen (app_id) + 1;
1201 void *app_id_value = GNUNET_malloc (app_id_size);
1202 GNUNET_memcpy (app_id_value, app_id, app_id_size);
1203
1204 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (place_apps, &app_id_hash, app_id_value,
1205 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1206 {
1207 GNUNET_break (0);
1208 }
1209
1210 return GNUNET_OK; 1221 return GNUNET_OK;
1211} 1222}
1212 1223
@@ -1223,7 +1234,10 @@ static int
1223app_place_save (const char *app_id, 1234app_place_save (const char *app_id,
1224 const struct PlaceEnterRequest *ereq) 1235 const struct PlaceEnterRequest *ereq)
1225{ 1236{
1226 app_place_add (app_id, ereq); 1237 if (GNUNET_SYSERR == app_place_add (app_id, ereq))
1238 {
1239 GNUNET_assert (0);
1240 }
1227 1241
1228 if (NULL == dir_places) 1242 if (NULL == dir_places)
1229 return GNUNET_SYSERR; 1243 return GNUNET_SYSERR;
@@ -1304,18 +1318,6 @@ app_place_remove (const char *app_id,
1304 if (NULL != app_places) 1318 if (NULL != app_places)
1305 GNUNET_CONTAINER_multihashmap_remove (app_places, &place_pub_hash, NULL); 1319 GNUNET_CONTAINER_multihashmap_remove (app_places, &place_pub_hash, NULL);
1306 1320
1307 struct GNUNET_CONTAINER_MultiHashMap *
1308 place_apps = GNUNET_CONTAINER_multihashmap_get (places_apps, &place_pub_hash);
1309 if (NULL != place_apps)
1310 {
1311 void *app_id_value = GNUNET_CONTAINER_multihashmap_get (place_apps, &app_id_hash);
1312 if (NULL != app_id_value)
1313 {
1314 GNUNET_CONTAINER_multihashmap_remove (place_apps, &app_id_hash, app_id_value);
1315 GNUNET_free (app_id_value);
1316 }
1317 }
1318
1319 int ret = GNUNET_OK; 1321 int ret = GNUNET_OK;
1320 1322
1321 if (0 != unlink (app_place_filename)) 1323 if (0 != unlink (app_place_filename))
@@ -1407,6 +1409,124 @@ msg_proc_parse (const struct MsgProcRequest *mpreq,
1407} 1409}
1408 1410
1409 1411
1412void
1413app_notify_place (const struct GNUNET_MessageHeader *msg,
1414 struct GNUNET_SERVICE_Client *client)
1415{
1416 struct AppPlaceMessage *amsg;
1417 struct GNUNET_MQ_Envelope *env;
1418 uint16_t msg_size = ntohs (msg->size);
1419
1420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1421 "%p Sending place notification of type %u to client.\n",
1422 client, ntohs (msg->type));
1423 switch (ntohs (msg->type))
1424 {
1425 case GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER:
1426 {
1427 struct HostEnterRequest *hreq = (struct HostEnterRequest *) msg;
1428 if (msg_size < sizeof (struct HostEnterRequest))
1429 return;
1430 env = GNUNET_MQ_msg (amsg,
1431 GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE);
1432 // FIXME: also notify about not entered places
1433 amsg->place_state = GNUNET_SOCIAL_PLACE_STATE_ENTERED;
1434 amsg->is_host = GNUNET_YES;
1435 amsg->ego_pub_key = hreq->ego_pub_key;
1436 amsg->place_pub_key = hreq->place_pub_key;
1437 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1438 env);
1439 break;
1440 }
1441 case GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER:
1442 {
1443 if (msg_size < sizeof (struct GuestEnterRequest))
1444 return;
1445 struct GuestEnterRequest *greq = (struct GuestEnterRequest *) msg;
1446 env = GNUNET_MQ_msg (amsg,
1447 GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE);
1448 // FIXME: also notify about not entered places
1449 amsg->place_state = GNUNET_SOCIAL_PLACE_STATE_ENTERED;
1450 amsg->is_host = GNUNET_NO;
1451 amsg->ego_pub_key = greq->ego_pub_key;
1452 amsg->place_pub_key = greq->place_pub_key;
1453 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1454 env);
1455 break;
1456 }
1457 default:
1458 return;
1459 }
1460}
1461
1462
1463void
1464app_notify_place_end (struct GNUNET_SERVICE_Client *client)
1465{
1466 struct GNUNET_MQ_Envelope *env;
1467
1468 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1469 "%p Sending end of place list notification to client\n",
1470 client);
1471 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE_END);
1472 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1473 env);
1474}
1475
1476
1477void
1478app_notify_ego (struct Ego *ego, struct GNUNET_SERVICE_Client *client)
1479{
1480 struct AppEgoMessage *emsg;
1481 struct GNUNET_MQ_Envelope *env;
1482 size_t name_size = strlen (ego->name) + 1;
1483
1484 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1485 "%p Sending ego notification to client: %s\n",
1486 client, ego->name);
1487 env = GNUNET_MQ_msg_extra (emsg,
1488 name_size,
1489 GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO);
1490 GNUNET_CRYPTO_ecdsa_key_get_public (&ego->key, &emsg->ego_pub_key);
1491 GNUNET_memcpy (&emsg[1], ego->name, name_size);
1492 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1493 env);
1494}
1495
1496
1497void
1498app_notify_ego_end (struct GNUNET_SERVICE_Client *client)
1499{
1500 struct GNUNET_MQ_Envelope *env;
1501
1502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1503 "%p Sending end of ego list notification to client\n",
1504 client);
1505 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO_END);
1506 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1507 env);
1508}
1509
1510
1511int
1512app_place_entry_notify (void *cls, const struct GNUNET_HashCode *key, void *value)
1513{
1514 struct GNUNET_MessageHeader *
1515 msg = GNUNET_CONTAINER_multihashmap_get (places, key);
1516 if (NULL != msg)
1517 app_notify_place (msg, cls);
1518 return GNUNET_YES;
1519}
1520
1521
1522int
1523ego_entry (void *cls, const struct GNUNET_HashCode *key, void *value)
1524{
1525 app_notify_ego (value, cls);
1526 return GNUNET_YES;
1527}
1528
1529
1410static int 1530static int
1411check_client_msg_proc_set (void *cls, 1531check_client_msg_proc_set (void *cls,
1412 const struct MsgProcRequest *mpreq) 1532 const struct MsgProcRequest *mpreq)
@@ -1518,9 +1638,8 @@ static void
1518handle_client_host_enter (void *cls, 1638handle_client_host_enter (void *cls,
1519 const struct HostEnterRequest *hr) 1639 const struct HostEnterRequest *hr)
1520{ 1640{
1521 struct Client *c = cls; 1641 struct Client *c = cls;
1522 struct GNUNET_SERVICE_Client *client = c->client; 1642 struct GNUNET_SERVICE_Client *client = c->client;
1523
1524 struct HostEnterRequest * 1643 struct HostEnterRequest *
1525 hreq = (struct HostEnterRequest *) GNUNET_copy_message (&hr->header); 1644 hreq = (struct HostEnterRequest *) GNUNET_copy_message (&hr->header);
1526 1645
@@ -1578,7 +1697,7 @@ handle_client_host_enter (void *cls,
1578 if (ret != GNUNET_SYSERR) 1697 if (ret != GNUNET_SYSERR)
1579 { 1698 {
1580 1699
1581 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1582 "%p Client connected as host to place %s.\n", 1701 "%p Client connected as host to place %s.\n",
1583 hst, GNUNET_h2s (&plc->pub_key_hash)); 1702 hst, GNUNET_h2s (&plc->pub_key_hash));
1584 1703
@@ -1586,6 +1705,7 @@ handle_client_host_enter (void *cls,
1586 cli->client = client; 1705 cli->client = client;
1587 GNUNET_CONTAINER_DLL_insert (plc->clients_head, plc->clients_tail, cli); 1706 GNUNET_CONTAINER_DLL_insert (plc->clients_head, plc->clients_tail, cli);
1588 c->place = plc; 1707 c->place = plc;
1708 app_notify_place (&hreq->header, client);
1589 } 1709 }
1590 1710
1591 GNUNET_CRYPTO_eddsa_key_clear (&hreq->place_key); 1711 GNUNET_CRYPTO_eddsa_key_clear (&hreq->place_key);
@@ -1622,8 +1742,12 @@ guest_enter (const struct GuestEnterRequest *greq, struct Guest **ret_gst)
1622 struct Ego *ego = GNUNET_CONTAINER_multihashmap_get (egos, &ego_pub_hash); 1742 struct Ego *ego = GNUNET_CONTAINER_multihashmap_get (egos, &ego_pub_hash);
1623 1743
1624 if (NULL == ego) 1744 if (NULL == ego)
1745 {
1625 return GNUNET_SYSERR; 1746 return GNUNET_SYSERR;
1747 }
1626 1748
1749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1750 "entering as guest\n");
1627 struct GNUNET_HashCode place_pub_hash; 1751 struct GNUNET_HashCode place_pub_hash;
1628 GNUNET_CRYPTO_hash (&greq->place_pub_key, sizeof (greq->place_pub_key), 1752 GNUNET_CRYPTO_hash (&greq->place_pub_key, sizeof (greq->place_pub_key),
1629 &place_pub_hash); 1753 &place_pub_hash);
@@ -1635,9 +1759,16 @@ guest_enter (const struct GuestEnterRequest *greq, struct Guest **ret_gst)
1635 if (NULL != plc_gst) 1759 if (NULL != plc_gst)
1636 gst = GNUNET_CONTAINER_multihashmap_get (plc_gst, &ego_pub_hash); 1760 gst = GNUNET_CONTAINER_multihashmap_get (plc_gst, &ego_pub_hash);
1637 1761
1638 if (NULL == gst || NULL == gst->slave) 1762 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1763 "plc_gst = %p, gst = %p\n",
1764 plc_gst,
1765 gst);
1766 if (NULL == gst)
1639 { 1767 {
1640 gst = GNUNET_new (struct Guest); 1768 gst = GNUNET_new (struct Guest);
1769 }
1770 if (NULL == gst->slave)
1771 {
1641 gst->origin = greq->origin; 1772 gst->origin = greq->origin;
1642 gst->relay_count = ntohl (greq->relay_count); 1773 gst->relay_count = ntohl (greq->relay_count);
1643 1774
@@ -1710,11 +1841,12 @@ guest_enter (const struct GuestEnterRequest *greq, struct Guest **ret_gst)
1710 plc_gst = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES); 1841 plc_gst = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES);
1711 (void) GNUNET_CONTAINER_multihashmap_put (place_guests, &plc->pub_key_hash, plc_gst, 1842 (void) GNUNET_CONTAINER_multihashmap_put (place_guests, &plc->pub_key_hash, plc_gst,
1712 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 1843 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1713 } 1844 (void) GNUNET_CONTAINER_multihashmap_put (plc_gst, &plc->ego_pub_hash, gst,
1714 (void) GNUNET_CONTAINER_multihashmap_put (plc_gst, &plc->ego_pub_hash, gst, 1845 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1715 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 1846 (void) GNUNET_CONTAINER_multihashmap_put (guests, &plc->pub_key_hash, gst,
1716 (void) GNUNET_CONTAINER_multihashmap_put (guests, &plc->pub_key_hash, gst,
1717 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1847 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1848
1849 }
1718 gst->slave 1850 gst->slave
1719 = GNUNET_PSYC_slave_join (cfg, &plc->pub_key, &plc->ego_key, 1851 = GNUNET_PSYC_slave_join (cfg, &plc->pub_key, &plc->ego_key,
1720 gst->join_flags, &gst->origin, 1852 gst->join_flags, &gst->origin,
@@ -1724,6 +1856,9 @@ guest_enter (const struct GuestEnterRequest *greq, struct Guest **ret_gst)
1724 &psyc_recv_join_dcsn, 1856 &psyc_recv_join_dcsn,
1725 gst, join_msg); 1857 gst, join_msg);
1726 plc->channel = GNUNET_PSYC_slave_get_channel (gst->slave); 1858 plc->channel = GNUNET_PSYC_slave_get_channel (gst->slave);
1859 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1860 "slave entered channel %p\n",
1861 plc->channel);
1727 ret = GNUNET_YES; 1862 ret = GNUNET_YES;
1728 } 1863 }
1729 1864
@@ -1734,78 +1869,96 @@ guest_enter (const struct GuestEnterRequest *greq, struct Guest **ret_gst)
1734 1869
1735 1870
1736static int 1871static int
1737check_client_guest_enter (void *cls, 1872client_guest_enter (struct Client *c,
1738 const struct GuestEnterRequest *greq) 1873 const struct GuestEnterRequest *greq)
1739{
1740 return GNUNET_OK;
1741}
1742
1743
1744/**
1745 * Handle a connecting client entering a place as guest.
1746 */
1747static void
1748handle_client_guest_enter (void *cls,
1749 const struct GuestEnterRequest *greq)
1750{ 1874{
1751 struct Client *c = cls; 1875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1876 "client_guest_enter\n");
1877 struct GNUNET_PSYC_CountersResultMessage *result_msg;
1878 struct GNUNET_MQ_Envelope *env;
1752 struct GNUNET_SERVICE_Client *client = c->client; 1879 struct GNUNET_SERVICE_Client *client = c->client;
1753
1754 uint16_t remaining = ntohs (greq->header.size) - sizeof (*greq); 1880 uint16_t remaining = ntohs (greq->header.size) - sizeof (*greq);
1755 const char *app_id = NULL; 1881 const char *app_id = NULL;
1756 uint16_t offset = GNUNET_STRINGS_buffer_tokenize ((const char *) &greq[1], 1882 uint16_t offset = GNUNET_STRINGS_buffer_tokenize ((const char *) &greq[1],
1757 remaining, 1, &app_id); 1883 remaining, 1, &app_id);
1758 if (0 == offset)
1759 {
1760 GNUNET_break (0);
1761 GNUNET_SERVICE_client_drop (client);
1762 return;
1763 }
1764
1765 struct Guest *gst = NULL; 1884 struct Guest *gst = NULL;
1766 struct Place *plc = NULL; 1885 struct Place *plc = NULL;
1767 1886
1887 if (0 == offset)
1888 {
1889 return GNUNET_SYSERR;
1890 }
1768 switch (guest_enter (greq, &gst)) 1891 switch (guest_enter (greq, &gst))
1769 { 1892 {
1770 case GNUNET_YES: 1893 case GNUNET_YES:
1894 {
1771 plc = c->place = &gst->place; 1895 plc = c->place = &gst->place;
1896 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1897 "guest entered successfully to local place %s\n",
1898 GNUNET_h2s (&plc->pub_key_hash));
1772 plc->guest = gst; 1899 plc->guest = gst;
1773 app_place_save (app_id, (const struct PlaceEnterRequest *) greq); 1900 app_place_save (app_id, (const struct PlaceEnterRequest *) greq);
1901 app_notify_place (&greq->header, client);
1774 break; 1902 break;
1775 1903 }
1776 case GNUNET_NO: 1904 case GNUNET_NO:
1777 { 1905 {
1778 plc = c->place = &gst->place; 1906 plc = c->place = &gst->place;
1907 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1908 "guest re-entered successfully to local place %s\n",
1909 GNUNET_h2s (&plc->pub_key_hash));
1779 plc->guest = gst; 1910 plc->guest = gst;
1780 1911 env = GNUNET_MQ_msg (result_msg,
1781 struct GNUNET_PSYC_CountersResultMessage res; 1912 GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER_ACK);
1782 res.header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER_ACK); 1913 result_msg->result_code = htonl (GNUNET_OK);
1783 res.header.size = htons (sizeof (res)); 1914 result_msg->max_message_id = GNUNET_htonll (plc->max_message_id);
1784 res.result_code = htonl (GNUNET_OK); 1915 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1785 res.max_message_id = GNUNET_htonll (plc->max_message_id); 1916 env);
1786
1787 client_send_msg (client, &res.header);
1788 if (NULL != gst->join_dcsn) 1917 if (NULL != gst->join_dcsn)
1789 client_send_msg (client, &gst->join_dcsn->header); 1918 {
1790 1919 env = GNUNET_MQ_msg_copy (&gst->join_dcsn->header);
1920 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1921 env);
1922 }
1791 break; 1923 break;
1792 } 1924 }
1793 case GNUNET_SYSERR: 1925 case GNUNET_SYSERR:
1794 GNUNET_break (0); 1926 {
1795 GNUNET_SERVICE_client_drop (client); 1927 return GNUNET_SYSERR;
1796 return; 1928 }
1797 } 1929 }
1798
1799 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1800 "%p Client connected as guest to place %s.\n",
1801 gst, GNUNET_h2s (&plc->pub_key_hash));
1802 1930
1803 struct ClientListItem *cli = GNUNET_new (struct ClientListItem); 1931 struct ClientListItem *cli = GNUNET_new (struct ClientListItem);
1804 cli->client = client; 1932 cli->client = client;
1805 GNUNET_CONTAINER_DLL_insert (plc->clients_head, plc->clients_tail, cli); 1933 GNUNET_CONTAINER_DLL_insert (plc->clients_head, plc->clients_tail, cli);
1934 return GNUNET_OK;
1935}
1806 1936
1807 c->place = plc; 1937
1808 GNUNET_SERVICE_client_continue (client); 1938static int
1939check_client_guest_enter (void *cls,
1940 const struct GuestEnterRequest *greq)
1941{
1942 return GNUNET_OK;
1943}
1944
1945
1946/**
1947 * Handle a connecting client entering a place as guest.
1948 */
1949static void
1950handle_client_guest_enter (void *cls,
1951 const struct GuestEnterRequest *greq)
1952{
1953 struct Client *c = cls;
1954
1955 if (GNUNET_SYSERR == client_guest_enter (c, greq))
1956 {
1957 GNUNET_break (0);
1958 GNUNET_SERVICE_client_drop (c->client);
1959 return;
1960 }
1961 GNUNET_SERVICE_client_continue (c->client);
1809} 1962}
1810 1963
1811 1964
@@ -1830,7 +1983,7 @@ gns_result_guest_enter (void *cls, uint32_t rd_count,
1830{ 1983{
1831 struct GuestEnterByNameClosure *gcls = cls; 1984 struct GuestEnterByNameClosure *gcls = cls;
1832 struct Client *c = gcls->client; 1985 struct Client *c = gcls->client;
1833 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1986 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1834 "%p GNS result: %u records.\n", 1987 "%p GNS result: %u records.\n",
1835 c, rd_count); 1988 c, rd_count);
1836 1989
@@ -1882,7 +2035,7 @@ gns_result_guest_enter (void *cls, uint32_t rd_count,
1882 p += relay_size; 2035 p += relay_size;
1883 GNUNET_memcpy (p, gcls->join_msg, join_msg_size); 2036 GNUNET_memcpy (p, gcls->join_msg, join_msg_size);
1884 2037
1885 handle_client_guest_enter (c, greq); 2038 client_guest_enter (c, greq);
1886 2039
1887 GNUNET_free (gcls->app_id); 2040 GNUNET_free (gcls->app_id);
1888 if (NULL != gcls->password) 2041 if (NULL != gcls->password)
@@ -1960,118 +2113,7 @@ handle_client_guest_enter_by_name (void *cls,
1960 GNUNET_GNSRECORD_TYPE_PLACE, 2113 GNUNET_GNSRECORD_TYPE_PLACE,
1961 GNUNET_GNS_LO_DEFAULT, 2114 GNUNET_GNS_LO_DEFAULT,
1962 &gns_result_guest_enter, gcls); 2115 &gns_result_guest_enter, gcls);
1963} 2116 GNUNET_SERVICE_client_continue (client);
1964
1965
1966void
1967app_notify_place (struct GNUNET_MessageHeader *msg,
1968 struct GNUNET_SERVICE_Client *client)
1969{
1970 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1971 "%p Sending place notification of type %u to client.\n",
1972 client, ntohs (msg->type));
1973
1974 uint16_t msg_size = ntohs (msg->size);
1975 struct AppPlaceMessage amsg;
1976 amsg.header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE);
1977 amsg.header.size = htons (sizeof (amsg));
1978 // FIXME: also notify about not entered places
1979 amsg.place_state = GNUNET_SOCIAL_PLACE_STATE_ENTERED;
1980
1981 switch (ntohs (msg->type))
1982 {
1983 case GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER:
1984 if (msg_size < sizeof (struct HostEnterRequest))
1985 return;
1986 struct HostEnterRequest *hreq = (struct HostEnterRequest *) msg;
1987 amsg.is_host = GNUNET_YES;
1988 amsg.ego_pub_key = hreq->ego_pub_key;
1989 amsg.place_pub_key = hreq->place_pub_key;
1990 break;
1991
1992 case GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER:
1993 if (msg_size < sizeof (struct GuestEnterRequest))
1994 return;
1995 struct GuestEnterRequest *greq = (struct GuestEnterRequest *) msg;
1996 amsg.is_host = GNUNET_NO;
1997 amsg.ego_pub_key = greq->ego_pub_key;
1998 amsg.place_pub_key = greq->place_pub_key;
1999 break;
2000
2001 default:
2002 return;
2003 }
2004
2005 client_send_msg (client, &amsg.header);
2006}
2007
2008
2009void
2010app_notify_place_end (struct GNUNET_SERVICE_Client *client)
2011{
2012 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2013 "%p Sending end of place list notification to client\n",
2014 client);
2015
2016 struct GNUNET_MessageHeader msg;
2017 msg.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE_END);
2018 msg.size = htons (sizeof (msg));
2019
2020 client_send_msg (client, &msg);
2021}
2022
2023
2024void
2025app_notify_ego (struct Ego *ego, struct GNUNET_SERVICE_Client *client)
2026{
2027 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2028 "%p Sending ego notification to client: %s\n",
2029 client, ego->name);
2030
2031 size_t name_size = strlen (ego->name) + 1;
2032 struct AppEgoMessage *emsg = GNUNET_malloc (sizeof (*emsg) + name_size);
2033 emsg->header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO);
2034 emsg->header.size = htons (sizeof (*emsg) + name_size);
2035
2036 GNUNET_CRYPTO_ecdsa_key_get_public (&ego->key, &emsg->ego_pub_key);
2037 GNUNET_memcpy (&emsg[1], ego->name, name_size);
2038
2039 client_send_msg (client, &emsg->header);
2040 GNUNET_free (emsg);
2041}
2042
2043
2044void
2045app_notify_ego_end (struct GNUNET_SERVICE_Client *client)
2046{
2047 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2048 "%p Sending end of ego list notification to client\n",
2049 client);
2050
2051 struct GNUNET_MessageHeader msg;
2052 msg.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO_END);
2053 msg.size = htons (sizeof (msg));
2054
2055 client_send_msg (client, &msg);
2056}
2057
2058
2059int
2060app_place_entry_notify (void *cls, const struct GNUNET_HashCode *key, void *value)
2061{
2062 struct GNUNET_MessageHeader *
2063 msg = GNUNET_CONTAINER_multihashmap_get (places, key);
2064 if (NULL != msg)
2065 app_notify_place (msg, cls);
2066 return GNUNET_YES;
2067}
2068
2069
2070int
2071ego_entry (void *cls, const struct GNUNET_HashCode *key, void *value)
2072{
2073 app_notify_ego (value, cls);
2074 return GNUNET_YES;
2075} 2117}
2076 2118
2077 2119
@@ -2154,13 +2196,15 @@ handle_client_app_detach (void *cls,
2154} 2196}
2155 2197
2156 2198
2157int 2199static void
2158app_places_entry_remove (void *cls, const struct GNUNET_HashCode *key, void *value) 2200place_leave_cb (void *cls)
2159{ 2201{
2160 struct Place *plc = cls; 2202 struct Place *plc = cls;
2161 const char *app_id = value; 2203
2162 app_place_remove (app_id, &plc->ego_pub_key, &plc->pub_key); 2204 place_send_leave_ack (plc);
2163 return GNUNET_YES; 2205 (GNUNET_YES == plc->is_host)
2206 ? cleanup_host ((struct Host *) plc)
2207 : cleanup_guest ((struct Guest *) plc);
2164} 2208}
2165 2209
2166 2210
@@ -2174,6 +2218,11 @@ handle_client_place_leave (void *cls,
2174 struct Client *c = cls; 2218 struct Client *c = cls;
2175 struct GNUNET_SERVICE_Client *client = c->client; 2219 struct GNUNET_SERVICE_Client *client = c->client;
2176 struct Place *plc = c->place; 2220 struct Place *plc = c->place;
2221
2222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2223 "got leave request from %s for place %s",
2224 plc->is_host? "host" : "slave",
2225 GNUNET_h2s (&plc->pub_key_hash));
2177 if (NULL == plc) 2226 if (NULL == plc)
2178 { 2227 {
2179 GNUNET_break (0); 2228 GNUNET_break (0);
@@ -2181,40 +2230,28 @@ handle_client_place_leave (void *cls,
2181 return; 2230 return;
2182 } 2231 }
2183 2232
2184 /* FIXME: remove all app subscriptions and leave this place */ 2233 if (GNUNET_YES != plc->is_disconnecting)
2185
2186 struct GNUNET_CONTAINER_MultiHashMap *
2187 place_apps = GNUNET_CONTAINER_multihashmap_get (places_apps, &plc->pub_key_hash);
2188 if (NULL != place_apps)
2189 { 2234 {
2190 GNUNET_CONTAINER_multihashmap_iterate (place_apps, app_places_entry_remove, plc); 2235 plc->is_disconnecting = GNUNET_YES;
2191 } 2236 if (plc->is_host)
2192 2237 {
2193 /* FIXME: disconnect from the network, but keep local connection for history access */ 2238 struct Host *host = plc->host;
2194 2239 GNUNET_assert (NULL != host);
2195 /* Disconnect all clients connected to the place */ 2240 GNUNET_PSYC_master_stop (host->master, GNUNET_NO, &place_leave_cb, plc);
2196 struct ClientListItem *cli = plc->clients_head, *next;
2197 while (NULL != cli)
2198 {
2199 GNUNET_CONTAINER_DLL_remove (plc->clients_head, plc->clients_tail, cli);
2200 GNUNET_SERVICE_client_drop (cli->client);
2201 next = cli->next;
2202 GNUNET_free (cli);
2203 cli = next;
2204 }
2205
2206 if (GNUNET_YES != plc->is_disconnected)
2207 {
2208 plc->is_disconnected = GNUNET_YES;
2209 if (NULL != plc->tmit_msgs_head)
2210 { /* Send pending messages to PSYC before cleanup. */
2211 psyc_transmit_message (plc);
2212 } 2241 }
2213 else 2242 else
2214 { 2243 {
2215 cleanup_place (plc); 2244 struct Guest *guest = plc->guest;
2245 GNUNET_assert (NULL != guest);
2246 GNUNET_PSYC_slave_part (guest->slave, GNUNET_NO, &place_leave_cb, plc);
2216 } 2247 }
2217 } 2248 }
2249 else
2250 {
2251 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2252 "got leave request but place is already leaving\n");
2253 }
2254 GNUNET_SERVICE_client_continue (client);
2218} 2255}
2219 2256
2220 2257
@@ -2273,6 +2310,9 @@ handle_client_join_decision (void *cls,
2273 ? (struct GNUNET_PSYC_Message *) &dcsn[1] 2310 ? (struct GNUNET_PSYC_Message *) &dcsn[1]
2274 : NULL; 2311 : NULL;
2275 2312
2313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2314 "jcls.msg = %p\n",
2315 jcls.msg);
2276 struct GNUNET_HashCode slave_pub_hash; 2316 struct GNUNET_HashCode slave_pub_hash;
2277 GNUNET_CRYPTO_hash (&dcsn->slave_pub_key, sizeof (dcsn->slave_pub_key), 2317 GNUNET_CRYPTO_hash (&dcsn->slave_pub_key, sizeof (dcsn->slave_pub_key),
2278 &slave_pub_hash); 2318 &slave_pub_hash);
@@ -2302,10 +2342,11 @@ handle_client_join_decision (void *cls,
2302static void 2342static void
2303send_message_ack (struct Place *plc, struct GNUNET_SERVICE_Client *client) 2343send_message_ack (struct Place *plc, struct GNUNET_SERVICE_Client *client)
2304{ 2344{
2305 struct GNUNET_MessageHeader res; 2345 struct GNUNET_MQ_Envelope *env;
2306 res.size = htons (sizeof (res)); 2346
2307 res.type = htons (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_ACK); 2347 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_ACK);
2308 client_send_msg (client, &res); 2348 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
2349 env);
2309} 2350}
2310 2351
2311 2352
@@ -2437,7 +2478,6 @@ psyc_transmit_notify_data (void *cls, uint16_t *data_size, void *data)
2437 { 2478 {
2438 *data_size = 0; 2479 *data_size = 0;
2439 tmit_msg = psyc_transmit_queue_next_msg (plc, tmit_msg); 2480 tmit_msg = psyc_transmit_queue_next_msg (plc, tmit_msg);
2440 plc->is_disconnected = GNUNET_YES;
2441 GNUNET_SERVICE_client_drop (tmit_frag->client); 2481 GNUNET_SERVICE_client_drop (tmit_frag->client);
2442 GNUNET_SCHEDULER_add_now (&cleanup_place, plc); 2482 GNUNET_SCHEDULER_add_now (&cleanup_place, plc);
2443 return ret; 2483 return ret;
@@ -2479,11 +2519,7 @@ psyc_transmit_notify_data (void *cls, uint16_t *data_size, void *data)
2479 { 2519 {
2480 psyc_transmit_message (plc); 2520 psyc_transmit_message (plc);
2481 } 2521 }
2482 else if (GNUNET_YES == plc->is_disconnected) 2522 /* FIXME: handle partial message (when still in_transmit) */
2483 {
2484 /* FIXME: handle partial message (when still in_transmit) */
2485 cleanup_place (plc);
2486 }
2487 } 2523 }
2488 return ret; 2524 return ret;
2489} 2525}
@@ -2597,7 +2633,6 @@ psyc_transmit_notify_mod (void *cls, uint16_t *data_size, void *data,
2597 *data_size = 0; 2633 *data_size = 0;
2598 ret = GNUNET_SYSERR; 2634 ret = GNUNET_SYSERR;
2599 tmit_msg = psyc_transmit_queue_next_msg (plc, tmit_msg); 2635 tmit_msg = psyc_transmit_queue_next_msg (plc, tmit_msg);
2600 plc->is_disconnected = GNUNET_YES;
2601 GNUNET_SERVICE_client_drop (tmit_frag->client); 2636 GNUNET_SERVICE_client_drop (tmit_frag->client);
2602 GNUNET_SCHEDULER_add_now (&cleanup_place, plc); 2637 GNUNET_SCHEDULER_add_now (&cleanup_place, plc);
2603 } 2638 }
@@ -2862,26 +2897,26 @@ psyc_transmit_queue_message (struct Place *plc,
2862} 2897}
2863 2898
2864 2899
2865/** 2900///**
2866 * Cancel transmission of current message to PSYC. 2901// * Cancel transmission of current message to PSYC.
2867 * 2902// *
2868 * @param plc Place to send to. 2903// * @param plc Place to send to.
2869 * @param client Client the message originates from. 2904// * @param client Client the message originates from.
2870 */ 2905// */
2871static void 2906//static void
2872psyc_transmit_cancel (struct Place *plc, struct GNUNET_SERVICE_Client *client) 2907//psyc_transmit_cancel (struct Place *plc, struct GNUNET_SERVICE_Client *client)
2873{ 2908//{
2874 uint16_t type = GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_CANCEL; 2909// uint16_t type = GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_CANCEL;
2875 2910//
2876 struct GNUNET_MessageHeader msg; 2911// struct GNUNET_MessageHeader msg;
2877 msg.size = htons (sizeof (msg)); 2912// msg.size = htons (sizeof (msg));
2878 msg.type = htons (type); 2913// msg.type = htons (type);
2879 2914//
2880 psyc_transmit_queue_message (plc, client, sizeof (msg), &msg, type, type, NULL); 2915// psyc_transmit_queue_message (plc, client, sizeof (msg), &msg, type, type, NULL);
2881 psyc_transmit_message (plc); 2916// psyc_transmit_message (plc);
2882 2917//
2883 /* FIXME: cleanup */ 2918// /* FIXME: cleanup */
2884} 2919//}
2885 2920
2886 2921
2887static int 2922static int
@@ -2902,17 +2937,19 @@ handle_client_psyc_message (void *cls,
2902 struct Client *c = cls; 2937 struct Client *c = cls;
2903 struct GNUNET_SERVICE_Client *client = c->client; 2938 struct GNUNET_SERVICE_Client *client = c->client;
2904 struct Place *plc = c->place; 2939 struct Place *plc = c->place;
2940 int ret;
2941
2905 if (NULL == plc) 2942 if (NULL == plc)
2906 { 2943 {
2944 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2945 "received PSYC message for non-existing client %p\n",
2946 client);
2907 GNUNET_break (0); 2947 GNUNET_break (0);
2908 GNUNET_SERVICE_client_drop (client); 2948 GNUNET_SERVICE_client_drop (client);
2909 return; 2949 return;
2910 } 2950 }
2911
2912 int ret = GNUNET_SYSERR;
2913
2914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2951 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2915 "%p Received message from client.\n", plc); 2952 "%p Received message of type %d from client.\n", plc, ntohs (msg->type));
2916 GNUNET_PSYC_log_message (GNUNET_ERROR_TYPE_DEBUG, msg); 2953 GNUNET_PSYC_log_message (GNUNET_ERROR_TYPE_DEBUG, msg);
2917 2954
2918 if (GNUNET_YES != plc->is_ready) 2955 if (GNUNET_YES != plc->is_ready)
@@ -2933,20 +2970,19 @@ handle_client_psyc_message (void *cls,
2933 "%p Received message with invalid payload size (%u) from client.\n", 2970 "%p Received message with invalid payload size (%u) from client.\n",
2934 plc, psize); 2971 plc, psize);
2935 GNUNET_break (0); 2972 GNUNET_break (0);
2936 psyc_transmit_cancel (plc, client);
2937 GNUNET_SERVICE_client_drop (client); 2973 GNUNET_SERVICE_client_drop (client);
2938 return; 2974 return;
2939 } 2975 }
2940 2976
2941 uint16_t first_ptype = 0, last_ptype = 0; 2977 uint16_t first_ptype = 0;
2942 if (GNUNET_SYSERR 2978 uint16_t last_ptype = 0;
2943 == GNUNET_PSYC_receive_check_parts (psize, (const char *) &msg[1], 2979 if (GNUNET_SYSERR ==
2944 &first_ptype, &last_ptype)) 2980 GNUNET_PSYC_receive_check_parts (psize, (const char *) &msg[1],
2981 &first_ptype, &last_ptype))
2945 { 2982 {
2946 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2983 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2947 "%p Received invalid message part from client.\n", plc); 2984 "%p Received invalid message part from client.\n", plc);
2948 GNUNET_break (0); 2985 GNUNET_break (0);
2949 psyc_transmit_cancel (plc, client);
2950 GNUNET_SERVICE_client_drop (client); 2986 GNUNET_SERVICE_client_drop (client);
2951 return; 2987 return;
2952 } 2988 }
@@ -2963,20 +2999,19 @@ handle_client_psyc_message (void *cls,
2963 c->tmit_msg = NULL; 2999 c->tmit_msg = NULL;
2964 ret = psyc_transmit_message (plc); 3000 ret = psyc_transmit_message (plc);
2965 } 3001 }
2966 3002 else
3003 {
3004 ret = GNUNET_SYSERR;
3005 }
2967 if (GNUNET_OK != ret) 3006 if (GNUNET_OK != ret)
2968 { 3007 {
2969 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3008 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2970 "%p Received invalid message part from client.\n", plc); 3009 "%p Received invalid message part from client.\n", plc);
2971 GNUNET_break (0); 3010 GNUNET_break (0);
2972 psyc_transmit_cancel (plc, client);
2973 ret = GNUNET_SYSERR;
2974 }
2975
2976 if (GNUNET_OK == ret)
2977 GNUNET_SERVICE_client_continue (client);
2978 else
2979 GNUNET_SERVICE_client_drop (client); 3011 GNUNET_SERVICE_client_drop (client);
3012 return;
3013 }
3014 GNUNET_SERVICE_client_continue (client);
2980} 3015}
2981 3016
2982 3017
@@ -3006,7 +3041,7 @@ psyc_recv_history_message (void *cls, const struct GNUNET_PSYC_MessageHeader *ms
3006 GNUNET_memcpy (&res[1], msg, size); 3041 GNUNET_memcpy (&res[1], msg, size);
3007 3042
3008 /** @todo FIXME: send only to requesting client */ 3043 /** @todo FIXME: send only to requesting client */
3009 place_send_msg (plc, &res->header); 3044 place_send_msg (plc, GNUNET_MQ_msg_copy (&res->header));
3010 3045
3011 GNUNET_free (res); 3046 GNUNET_free (res);
3012} 3047}
@@ -3108,29 +3143,24 @@ psyc_recv_state_var (void *cls,
3108 uint32_t value_size, 3143 uint32_t value_size,
3109 uint32_t full_value_size) 3144 uint32_t full_value_size)
3110{ 3145{
3146 struct GNUNET_OperationResultMessage *result_msg;
3147 struct GNUNET_MQ_Envelope *env;
3111 struct OperationClosure *opcls = cls; 3148 struct OperationClosure *opcls = cls;
3112 struct Client *c = opcls->client; 3149 struct Client *c = opcls->client;
3113 struct Place *plc = c->place; 3150 struct Place *plc = c->place;
3151 uint16_t size = ntohs (mod->size);
3114 3152
3115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3116 "%p Received state variable %s from PSYC\n", 3154 "%p Received state variable %s from PSYC\n",
3117 plc, name); 3155 plc, name);
3118 3156 env = GNUNET_MQ_msg_extra (result_msg,
3119 uint16_t size = ntohs (mod->size); 3157 size,
3120 3158 GNUNET_MESSAGE_TYPE_PSYC_STATE_RESULT);
3121 struct GNUNET_OperationResultMessage * 3159 result_msg->op_id = opcls->op_id;
3122 res = GNUNET_malloc (sizeof (*res) + size); 3160 result_msg->result_code = GNUNET_htonll (GNUNET_OK);
3123 res->header.size = htons (sizeof (*res) + size); 3161 GNUNET_memcpy (&result_msg[1], mod, size);
3124 res->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_STATE_RESULT);
3125 res->op_id = opcls->op_id;
3126 res->result_code = GNUNET_htonll (GNUNET_OK);
3127
3128 GNUNET_memcpy (&res[1], mod, size);
3129
3130 /** @todo FIXME: send only to requesting client */ 3162 /** @todo FIXME: send only to requesting client */
3131 place_send_msg (plc, &res->header); 3163 place_send_msg (plc, env);
3132
3133 GNUNET_free (res);
3134} 3164}
3135 3165
3136 3166
@@ -3184,7 +3214,7 @@ handle_client_state_get (void *cls,
3184 uint16_t size = ntohs (req->header.size); 3214 uint16_t size = ntohs (req->header.size);
3185 const char *name = (const char *) &req[1]; 3215 const char *name = (const char *) &req[1];
3186 3216
3187 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3188 "%p State get #%" PRIu64 ": %s\n", 3218 "%p State get #%" PRIu64 ": %s\n",
3189 plc, GNUNET_ntohll (req->op_id), name); 3219 plc, GNUNET_ntohll (req->op_id), name);
3190 3220
@@ -3382,7 +3412,7 @@ path_basename (const char *path)
3382 if (NULL != basename) 3412 if (NULL != basename)
3383 basename++; 3413 basename++;
3384 3414
3385 if (NULL == basename || '\0' == basename) 3415 if (NULL == basename || '\0' == *basename)
3386 return NULL; 3416 return NULL;
3387 3417
3388 return basename; 3418 return basename;
@@ -3468,7 +3498,10 @@ file_place_load (void *cls, const char *place_filename)
3468 return GNUNET_OK; 3498 return GNUNET_OK;
3469 } 3499 }
3470 3500
3471 app_place_add (plcls->app_id, ereq); 3501 if (GNUNET_SYSERR == app_place_add (plcls->app_id, ereq))
3502 {
3503 GNUNET_assert (0);
3504 }
3472 GNUNET_free (ereq); 3505 GNUNET_free (ereq);
3473 return GNUNET_OK; 3506 return GNUNET_OK;
3474} 3507}
@@ -3523,6 +3556,10 @@ identity_recv_ego (void *cls, struct GNUNET_IDENTITY_Ego *id_ego,
3523 if (NULL == id_ego) // end of initial list of egos 3556 if (NULL == id_ego) // end of initial list of egos
3524 return; 3557 return;
3525 3558
3559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3560 "social service received ego %s\n",
3561 name);
3562
3526 struct GNUNET_CRYPTO_EcdsaPublicKey ego_pub_key; 3563 struct GNUNET_CRYPTO_EcdsaPublicKey ego_pub_key;
3527 GNUNET_IDENTITY_ego_get_public_key (id_ego, &ego_pub_key); 3564 GNUNET_IDENTITY_ego_get_public_key (id_ego, &ego_pub_key);
3528 3565
@@ -3571,6 +3608,9 @@ run (void *cls,
3571 const struct GNUNET_CONFIGURATION_Handle *c, 3608 const struct GNUNET_CONFIGURATION_Handle *c,
3572 struct GNUNET_SERVICE_Handle *svc) 3609 struct GNUNET_SERVICE_Handle *svc)
3573{ 3610{
3611 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3612 "starting social service\n");
3613
3574 cfg = c; 3614 cfg = c;
3575 service = svc; 3615 service = svc;
3576 GNUNET_CRYPTO_get_peer_identity (cfg, &this_peer); 3616 GNUNET_CRYPTO_get_peer_identity (cfg, &this_peer);
@@ -3583,7 +3623,7 @@ run (void *cls,
3583 apps = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); 3623 apps = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
3584 places = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_NO); 3624 places = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_NO);
3585 apps_places = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_NO); 3625 apps_places = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_NO);
3586 places_apps = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_NO); 3626 //places_apps = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_NO);
3587 3627
3588 id = GNUNET_IDENTITY_connect (cfg, &identity_recv_ego, NULL); 3628 id = GNUNET_IDENTITY_connect (cfg, &identity_recv_ego, NULL);
3589 gns = GNUNET_GNS_connect (cfg); 3629 gns = GNUNET_GNS_connect (cfg);
diff --git a/src/social/gnunet-social.c b/src/social/gnunet-social.c
index de680b11c..12c5bf2e1 100644
--- a/src/social/gnunet-social.c
+++ b/src/social/gnunet-social.c
@@ -283,7 +283,7 @@ exit_fail ()
283static void 283static void
284host_left (void *cls) 284host_left (void *cls)
285{ 285{
286 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 286 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
287 "The host has left the place.\n"); 287 "The host has left the place.\n");
288 exit_success (); 288 exit_success ();
289} 289}
@@ -309,7 +309,7 @@ host_leave ()
309static void 309static void
310guest_left (void *cls) 310guest_left (void *cls)
311{ 311{
312 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 312 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
313 "Guest has left the place.\n"); 313 "Guest has left the place.\n");
314} 314}
315 315
@@ -518,7 +518,7 @@ look_var (void *cls,
518 uint32_t value_size, 518 uint32_t value_size,
519 uint32_t full_value_size) 519 uint32_t full_value_size)
520{ 520{
521 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 521 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
522 "Received var: %s\n%.*s\n", 522 "Received var: %s\n%.*s\n",
523 name, value_size, (const char *) value); 523 name, value_size, (const char *) value);
524} 524}
@@ -558,7 +558,7 @@ slicer_recv_method (void *cls,
558 const char *method_name) 558 const char *method_name)
559{ 559{
560 method_received = method_name; 560 method_received = method_name;
561 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 561 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
562 "Received method for message ID %" PRIu64 ":\n" 562 "Received method for message ID %" PRIu64 ":\n"
563 "%s (flags: %x)\n", 563 "%s (flags: %x)\n",
564 message_id, method_name, ntohl (meth->flags)); 564 message_id, method_name, ntohl (meth->flags));
@@ -584,7 +584,7 @@ slicer_recv_modifier (void *cls,
584 uint16_t full_value_size) 584 uint16_t full_value_size)
585{ 585{
586#if 0 586#if 0
587 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 587 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
588 "Received modifier for message ID %" PRIu64 ":\n" 588 "Received modifier for message ID %" PRIu64 ":\n"
589 "%c%s: %.*s (size: %u)\n", 589 "%c%s: %.*s (size: %u)\n",
590 message_id, oper, name, value_size, (const char *) value, value_size); 590 message_id, oper, name, value_size, (const char *) value, value_size);
@@ -608,7 +608,7 @@ slicer_recv_data (void *cls,
608 uint16_t data_size) 608 uint16_t data_size)
609{ 609{
610#if 0 610#if 0
611 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 611 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
612 "Received data for message ID %" PRIu64 ":\n" 612 "Received data for message ID %" PRIu64 ":\n"
613 "%.*s\n", 613 "%.*s\n",
614 message_id, data_size, (const char *) data); 614 message_id, data_size, (const char *) data);
@@ -631,7 +631,7 @@ slicer_recv_eom (void *cls,
631 uint8_t is_cancelled) 631 uint8_t is_cancelled)
632{ 632{
633 printf(".\n"); 633 printf(".\n");
634 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 634 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
635 "Received end of message ID %" PRIu64 635 "Received end of message ID %" PRIu64
636 ", cancelled: %u\n", 636 ", cancelled: %u\n",
637 message_id, is_cancelled); 637 message_id, is_cancelled);
@@ -668,7 +668,7 @@ guest_recv_entry_decision (void *cls,
668 int is_admitted, 668 int is_admitted,
669 const struct GNUNET_PSYC_Message *entry_msg) 669 const struct GNUNET_PSYC_Message *entry_msg)
670{ 670{
671 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 671 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
672 "Guest received entry decision %d\n", 672 "Guest received entry decision %d\n",
673 is_admitted); 673 is_admitted);
674 674
@@ -683,7 +683,7 @@ guest_recv_entry_decision (void *cls,
683 GNUNET_PSYC_message_parse (pmsg, &method_name, env, &data, &data_size); 683 GNUNET_PSYC_message_parse (pmsg, &method_name, env, &data, &data_size);
684 GNUNET_free (pmsg); 684 GNUNET_free (pmsg);
685 685
686 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 686 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
687 "%s\n%.*s\n", 687 "%s\n%.*s\n",
688 method_name, data_size, (const char *) data); 688 method_name, data_size, (const char *) data);
689 } 689 }
@@ -704,7 +704,7 @@ guest_recv_local_enter (void *cls, int result,
704 uint64_t max_message_id) 704 uint64_t max_message_id)
705{ 705{
706 char *pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key); 706 char *pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key);
707 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 707 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
708 "Guest entered local place: %s, max_message_id: %" PRIu64 "\n", 708 "Guest entered local place: %s, max_message_id: %" PRIu64 "\n",
709 pub_str, max_message_id); 709 pub_str, max_message_id);
710 GNUNET_free (pub_str); 710 GNUNET_free (pub_str);
@@ -802,7 +802,7 @@ host_answer_door (void *cls,
802 char * 802 char *
803 nym_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key); 803 nym_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key);
804 804
805 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 805 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
806 "Entry request: %s\n", nym_str); 806 "Entry request: %s\n", nym_str);
807 GNUNET_free (nym_str); 807 GNUNET_free (nym_str);
808 808
@@ -840,7 +840,7 @@ host_farewell (void *cls,
840 char * 840 char *
841 nym_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key); 841 nym_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key);
842 842
843 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 843 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
844 "Farewell: %s\n", nym_str); 844 "Farewell: %s\n", nym_str);
845 GNUNET_free (nym_str); 845 GNUNET_free (nym_str);
846} 846}
@@ -856,7 +856,7 @@ host_entered (void *cls, int result,
856{ 856{
857 place_pub_key = *pub_key; 857 place_pub_key = *pub_key;
858 char *pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key); 858 char *pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key);
859 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 859 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
860 "Host entered: %s, max_message_id: %" PRIu64 "\n", 860 "Host entered: %s, max_message_id: %" PRIu64 "\n",
861 pub_str, max_message_id); 861 pub_str, max_message_id);
862 GNUNET_free (pub_str); 862 GNUNET_free (pub_str);
diff --git a/src/social/social_api.c b/src/social/social_api.c
index d57d16cfb..89843831b 100644
--- a/src/social/social_api.c
+++ b/src/social/social_api.c
@@ -183,6 +183,7 @@ struct GNUNET_SOCIAL_Place
183 */ 183 */
184 struct GNUNET_PSYC_Slicer *slicer; 184 struct GNUNET_PSYC_Slicer *slicer;
185 185
186 // FIXME: do we need is_disconnecing like on the psyc and multicast APIs?
186 /** 187 /**
187 * Function called after disconnected from the service. 188 * Function called after disconnected from the service.
188 */ 189 */
@@ -371,6 +372,68 @@ struct ZoneAddNymHandle
371}; 372};
372 373
373 374
375/*** CLEANUP / DISCONNECT ***/
376
377
378static void
379host_cleanup (struct GNUNET_SOCIAL_Host *hst)
380{
381 if (NULL != hst->slicer)
382 {
383 GNUNET_PSYC_slicer_destroy (hst->slicer);
384 hst->slicer = NULL;
385 }
386 GNUNET_free (hst);
387}
388
389
390static void
391guest_cleanup (struct GNUNET_SOCIAL_Guest *gst)
392{
393 GNUNET_free (gst);
394}
395
396
397static void
398place_cleanup (struct GNUNET_SOCIAL_Place *plc)
399{
400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
401 "cleaning up place %p\n",
402 plc);
403 if (NULL != plc->tmit)
404 {
405 GNUNET_PSYC_transmit_destroy (plc->tmit);
406 plc->tmit = NULL;
407 }
408 if (NULL != plc->connect_env)
409 {
410 GNUNET_MQ_discard (plc->connect_env);
411 plc->connect_env = NULL;
412 }
413 if (NULL != plc->mq)
414 {
415 GNUNET_MQ_destroy (plc->mq);
416 plc->mq = NULL;
417 }
418 if (NULL != plc->disconnect_cb)
419 {
420 plc->disconnect_cb (plc->disconnect_cls);
421 plc->disconnect_cb = NULL;
422 }
423
424 (GNUNET_YES == plc->is_host)
425 ? host_cleanup ((struct GNUNET_SOCIAL_Host *) plc)
426 : guest_cleanup ((struct GNUNET_SOCIAL_Guest *) plc);
427}
428
429
430static void
431place_disconnect (struct GNUNET_SOCIAL_Place *plc)
432{
433 place_cleanup (plc);
434}
435
436
374/*** NYM ***/ 437/*** NYM ***/
375 438
376static struct GNUNET_SOCIAL_Nym * 439static struct GNUNET_SOCIAL_Nym *
@@ -428,7 +491,7 @@ host_recv_notice_place_leave_method (void *cls,
428 491
429 struct GNUNET_SOCIAL_Nym *nym = nym_get_or_create (&msg->slave_pub_key); 492 struct GNUNET_SOCIAL_Nym *nym = nym_get_or_create (&msg->slave_pub_key);
430 493
431 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
432 "Host received method for message ID %" PRIu64 " from nym %s: %s\n", 495 "Host received method for message ID %" PRIu64 " from nym %s: %s\n",
433 message_id, GNUNET_h2s (&nym->pub_key_hash), method_name); 496 message_id, GNUNET_h2s (&nym->pub_key_hash), method_name);
434 497
@@ -436,7 +499,7 @@ host_recv_notice_place_leave_method (void *cls,
436 hst->notice_place_leave_env = GNUNET_PSYC_env_create (); 499 hst->notice_place_leave_env = GNUNET_PSYC_env_create ();
437 500
438 char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&hst->notice_place_leave_nym->pub_key); 501 char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&hst->notice_place_leave_nym->pub_key);
439 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
440 "_notice_place_leave: got method from nym %s (%s).\n", 503 "_notice_place_leave: got method from nym %s (%s).\n",
441 GNUNET_h2s (&hst->notice_place_leave_nym->pub_key_hash), str); 504 GNUNET_h2s (&hst->notice_place_leave_nym->pub_key_hash), str);
442 GNUNET_free (str); 505 GNUNET_free (str);
@@ -458,7 +521,7 @@ host_recv_notice_place_leave_modifier (void *cls,
458 if (NULL == hst->notice_place_leave_env) 521 if (NULL == hst->notice_place_leave_env)
459 return; 522 return;
460 523
461 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 524 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
462 "Host received modifier for _notice_place_leave message with ID %" PRIu64 ":\n" 525 "Host received modifier for _notice_place_leave message with ID %" PRIu64 ":\n"
463 "%c%s: %.*s\n", 526 "%c%s: %.*s\n",
464 message_id, oper, name, value_size, (const char *) value); 527 message_id, oper, name, value_size, (const char *) value);
@@ -485,7 +548,7 @@ host_recv_notice_place_leave_eom (void *cls,
485 return; 548 return;
486 549
487 char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&hst->notice_place_leave_nym->pub_key); 550 char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&hst->notice_place_leave_nym->pub_key);
488 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 551 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
489 "_notice_place_leave: got EOM from nym %s (%s).\n", 552 "_notice_place_leave: got EOM from nym %s (%s).\n",
490 GNUNET_h2s (&hst->notice_place_leave_nym->pub_key_hash), str); 553 GNUNET_h2s (&hst->notice_place_leave_nym->pub_key_hash), str);
491 GNUNET_free (str); 554 GNUNET_free (str);
@@ -1015,100 +1078,24 @@ handle_app_place_end (void *cls,
1015} 1078}
1016 1079
1017 1080
1018/*** CLEANUP / DISCONNECT ***/ 1081/**
1019 1082 * Handler for a #GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE_ACK message received
1020 1083 * from the social service.
1021static void 1084 *
1022host_cleanup (struct GNUNET_SOCIAL_Host *hst) 1085 * @param cls the place of type `struct GNUNET_SOCIAL_Place`
1023{ 1086 * @param msg the message received from the service
1024 if (NULL != hst->slicer) 1087 */
1025 {
1026 GNUNET_PSYC_slicer_destroy (hst->slicer);
1027 hst->slicer = NULL;
1028 }
1029 GNUNET_free (hst);
1030}
1031
1032
1033static void 1088static void
1034guest_cleanup (struct GNUNET_SOCIAL_Guest *gst) 1089handle_place_leave_ack (void *cls,
1090 const struct GNUNET_MessageHeader *msg)
1035{ 1091{
1036 GNUNET_free (gst); 1092 struct GNUNET_SOCIAL_Place *plc = cls;
1037}
1038
1039 1093
1040static void
1041place_cleanup (struct GNUNET_SOCIAL_Place *plc)
1042{
1043 struct GNUNET_HashCode place_pub_hash;
1044 GNUNET_CRYPTO_hash (&plc->pub_key, sizeof (plc->pub_key), &place_pub_hash);
1045 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1094 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1046 "%s place cleanup: %s\n", 1095 "%s left place %p\n",
1047 GNUNET_YES == plc->is_host ? "host" : "guest", 1096 plc->is_host ? "host" : "guest",
1048 GNUNET_h2s (&place_pub_hash)); 1097 plc);
1049 1098 place_disconnect (plc);
1050 if (NULL != plc->tmit)
1051 {
1052 GNUNET_PSYC_transmit_destroy (plc->tmit);
1053 plc->tmit = NULL;
1054 }
1055 if (NULL != plc->connect_env)
1056 {
1057 GNUNET_MQ_discard (plc->connect_env);
1058 plc->connect_env = NULL;
1059 }
1060 if (NULL != plc->mq)
1061 {
1062 GNUNET_MQ_destroy (plc->mq);
1063 plc->mq = NULL;
1064 }
1065 if (NULL != plc->disconnect_cb)
1066 {
1067 plc->disconnect_cb (plc->disconnect_cls);
1068 plc->disconnect_cb = NULL;
1069 }
1070
1071 (GNUNET_YES == plc->is_host)
1072 ? host_cleanup ((struct GNUNET_SOCIAL_Host *) plc)
1073 : guest_cleanup ((struct GNUNET_SOCIAL_Guest *) plc);
1074}
1075
1076
1077void
1078place_disconnect (struct GNUNET_SOCIAL_Place *plc,
1079 GNUNET_ContinuationCallback cb,
1080 void *cls)
1081{
1082 plc->disconnect_cb = cb;
1083 plc->disconnect_cls = cls;
1084
1085 if (NULL != plc->mq)
1086 {
1087 struct GNUNET_MQ_Envelope *env = GNUNET_MQ_get_last_envelope (plc->mq);
1088 if (NULL != env)
1089 {
1090 GNUNET_MQ_notify_sent (env, (GNUNET_SCHEDULER_TaskCallback) place_cleanup, plc);
1091 }
1092 else
1093 {
1094 place_cleanup (plc);
1095 }
1096 }
1097 else
1098 {
1099 place_cleanup (plc);
1100 }
1101}
1102
1103
1104void
1105place_leave (struct GNUNET_SOCIAL_Place *plc)
1106{
1107 struct GNUNET_MessageHeader *msg;
1108 struct GNUNET_MQ_Envelope *
1109 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE);
1110
1111 GNUNET_MQ_send (plc->mq, env);
1112} 1099}
1113 1100
1114 1101
@@ -1168,6 +1155,10 @@ host_connect (struct GNUNET_SOCIAL_Host *hst)
1168 GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER_ACK, 1155 GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER_ACK,
1169 struct HostEnterAck, 1156 struct HostEnterAck,
1170 hst), 1157 hst),
1158 GNUNET_MQ_hd_fixed_size (place_leave_ack,
1159 GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE_ACK,
1160 struct GNUNET_MessageHeader,
1161 plc),
1171 GNUNET_MQ_hd_var_size (host_enter_request, 1162 GNUNET_MQ_hd_var_size (host_enter_request,
1172 GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST, 1163 GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST,
1173 struct GNUNET_PSYC_JoinRequestMessage, 1164 struct GNUNET_PSYC_JoinRequestMessage,
@@ -1516,6 +1507,9 @@ GNUNET_SOCIAL_host_announce (struct GNUNET_SOCIAL_Host *hst,
1516 void *notify_data_cls, 1507 void *notify_data_cls,
1517 enum GNUNET_SOCIAL_AnnounceFlags flags) 1508 enum GNUNET_SOCIAL_AnnounceFlags flags)
1518{ 1509{
1510 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1511 "PSYC_transmit_message for host, method: %s\n",
1512 method_name);
1519 if (GNUNET_OK == 1513 if (GNUNET_OK ==
1520 GNUNET_PSYC_transmit_message (hst->plc.tmit, method_name, env, 1514 GNUNET_PSYC_transmit_message (hst->plc.tmit, method_name, env,
1521 NULL, notify_data, notify_data_cls, flags)) 1515 NULL, notify_data, notify_data_cls, flags))
@@ -1580,7 +1574,11 @@ GNUNET_SOCIAL_host_disconnect (struct GNUNET_SOCIAL_Host *hst,
1580 GNUNET_ContinuationCallback disconnect_cb, 1574 GNUNET_ContinuationCallback disconnect_cb,
1581 void *cls) 1575 void *cls)
1582{ 1576{
1583 place_disconnect (&hst->plc, disconnect_cb, cls); 1577 struct GNUNET_SOCIAL_Place *plc = &hst->plc;
1578
1579 plc->disconnect_cb = disconnect_cb;
1580 plc->disconnect_cls = cls;
1581 place_disconnect (plc);
1584} 1582}
1585 1583
1586 1584
@@ -1607,10 +1605,15 @@ GNUNET_SOCIAL_host_leave (struct GNUNET_SOCIAL_Host *hst,
1607 GNUNET_ContinuationCallback disconnect_cb, 1605 GNUNET_ContinuationCallback disconnect_cb,
1608 void *cls) 1606 void *cls)
1609{ 1607{
1608 struct GNUNET_MQ_Envelope *envelope;
1609
1610 GNUNET_SOCIAL_host_announce (hst, "_notice_place_closing", env, NULL, NULL, 1610 GNUNET_SOCIAL_host_announce (hst, "_notice_place_closing", env, NULL, NULL,
1611 GNUNET_SOCIAL_ANNOUNCE_NONE); 1611 GNUNET_SOCIAL_ANNOUNCE_NONE);
1612 place_leave (&hst->plc); 1612 hst->plc.disconnect_cb = disconnect_cb;
1613 GNUNET_SOCIAL_host_disconnect (hst, disconnect_cb, cls); 1613 hst->plc.disconnect_cls = cls;
1614 envelope = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE);
1615 GNUNET_MQ_send (hst->plc.mq,
1616 envelope);
1614} 1617}
1615 1618
1616 1619
@@ -1670,6 +1673,10 @@ guest_connect (struct GNUNET_SOCIAL_Guest *gst)
1670 GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER_ACK, 1673 GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER_ACK,
1671 struct GNUNET_PSYC_CountersResultMessage, 1674 struct GNUNET_PSYC_CountersResultMessage,
1672 gst), 1675 gst),
1676 GNUNET_MQ_hd_fixed_size (place_leave_ack,
1677 GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE_ACK,
1678 struct GNUNET_MessageHeader,
1679 plc),
1673 GNUNET_MQ_hd_var_size (guest_enter_decision, 1680 GNUNET_MQ_hd_var_size (guest_enter_decision,
1674 GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION, 1681 GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION,
1675 struct GNUNET_PSYC_JoinDecisionMessage, 1682 struct GNUNET_PSYC_JoinDecisionMessage,
@@ -1896,6 +1903,64 @@ GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_SOCIAL_App *app,
1896} 1903}
1897 1904
1898 1905
1906struct ReconnectContext
1907{
1908 struct GNUNET_SOCIAL_Guest *guest;
1909 int *result;
1910 int64_t *max_message_id;
1911 GNUNET_SOCIAL_GuestEnterCallback enter_cb;
1912 void *enter_cls;
1913};
1914
1915
1916static void
1917guest_enter_reconnect_cb (void *cls,
1918 int result,
1919 const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
1920 uint64_t max_message_id)
1921{
1922 struct ReconnectContext *reconnect_ctx = cls;
1923
1924 GNUNET_assert (NULL != reconnect_ctx);
1925 reconnect_ctx->result = GNUNET_new (int);
1926 *(reconnect_ctx->result) = result;
1927 reconnect_ctx->max_message_id = GNUNET_new (int64_t);
1928 *(reconnect_ctx->max_message_id) = max_message_id;
1929}
1930
1931
1932static void
1933guest_entry_dcsn_reconnect_cb (void *cls,
1934 int is_admitted,
1935 const struct GNUNET_PSYC_Message *entry_resp)
1936{
1937 struct ReconnectContext *reconnect_ctx = cls;
1938 struct GNUNET_SOCIAL_Guest *gst = reconnect_ctx->guest;
1939
1940 GNUNET_assert (NULL != reconnect_ctx);
1941 GNUNET_assert (NULL != reconnect_ctx->result);
1942 GNUNET_assert (NULL != reconnect_ctx->max_message_id);
1943 if (GNUNET_YES != is_admitted)
1944 {
1945 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1946 "Guest was rejected after calling "
1947 "GNUNET_SOCIAL_guest_enter_reconnect ()\n");
1948 }
1949 else if (NULL != reconnect_ctx->enter_cb)
1950 {
1951 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1952 "guest reconnected!\n");
1953 reconnect_ctx->enter_cb (reconnect_ctx->enter_cls,
1954 *(reconnect_ctx->result),
1955 &gst->plc.pub_key,
1956 *(reconnect_ctx->max_message_id));
1957 }
1958 GNUNET_free (reconnect_ctx->result);
1959 GNUNET_free (reconnect_ctx->max_message_id);
1960 GNUNET_free (reconnect_ctx);
1961}
1962
1963
1899/** 1964/**
1900 * Reconnect to an already entered place as guest. 1965 * Reconnect to an already entered place as guest.
1901 * 1966 *
@@ -1906,8 +1971,8 @@ GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_SOCIAL_App *app,
1906 * Flags for the entry. 1971 * Flags for the entry.
1907 * @param slicer 1972 * @param slicer
1908 * Slicer to use for processing incoming requests from guests. 1973 * Slicer to use for processing incoming requests from guests.
1909 * @param local_enter_cb 1974 * @param enter_cb
1910 * Called upon connection established to the social service. 1975 * Called upon re-entering is complete.
1911 * @param entry_decision_cb 1976 * @param entry_decision_cb
1912 * Called upon receiving entry decision. 1977 * Called upon receiving entry decision.
1913 * 1978 *
@@ -1917,11 +1982,12 @@ struct GNUNET_SOCIAL_Guest *
1917GNUNET_SOCIAL_guest_enter_reconnect (struct GNUNET_SOCIAL_GuestConnection *gconn, 1982GNUNET_SOCIAL_guest_enter_reconnect (struct GNUNET_SOCIAL_GuestConnection *gconn,
1918 enum GNUNET_PSYC_SlaveJoinFlags flags, 1983 enum GNUNET_PSYC_SlaveJoinFlags flags,
1919 struct GNUNET_PSYC_Slicer *slicer, 1984 struct GNUNET_PSYC_Slicer *slicer,
1920 GNUNET_SOCIAL_GuestEnterCallback local_enter_cb, 1985 GNUNET_SOCIAL_GuestEnterCallback enter_cb,
1921 void *cls) 1986 void *cls)
1922{ 1987{
1923 struct GNUNET_SOCIAL_Guest *gst = GNUNET_malloc (sizeof (*gst)); 1988 struct GNUNET_SOCIAL_Guest *gst = GNUNET_malloc (sizeof (*gst));
1924 struct GNUNET_SOCIAL_Place *plc = &gst->plc; 1989 struct GNUNET_SOCIAL_Place *plc = &gst->plc;
1990 struct ReconnectContext *reconnect_ctx;
1925 1991
1926 uint16_t app_id_size = strlen (gconn->app->id) + 1; 1992 uint16_t app_id_size = strlen (gconn->app->id) + 1;
1927 struct GuestEnterRequest *greq; 1993 struct GuestEnterRequest *greq;
@@ -1940,10 +2006,15 @@ GNUNET_SOCIAL_guest_enter_reconnect (struct GNUNET_SOCIAL_GuestConnection *gconn
1940 plc->pub_key = gconn->plc_msg.place_pub_key; 2006 plc->pub_key = gconn->plc_msg.place_pub_key;
1941 plc->ego_pub_key = gconn->plc_msg.ego_pub_key; 2007 plc->ego_pub_key = gconn->plc_msg.ego_pub_key;
1942 2008
1943 plc->op = GNUNET_OP_create (); 2009 reconnect_ctx = GNUNET_new (struct ReconnectContext);
2010 reconnect_ctx->guest = gst;
2011 reconnect_ctx->enter_cb = enter_cb;
2012 reconnect_ctx->enter_cls = cls;
1944 2013
1945 gst->enter_cb = local_enter_cb; 2014 plc->op = GNUNET_OP_create ();
1946 gst->cb_cls = cls; 2015 gst->enter_cb = &guest_enter_reconnect_cb;
2016 gst->entry_dcsn_cb = &guest_entry_dcsn_reconnect_cb;
2017 gst->cb_cls = reconnect_ctx;
1947 2018
1948 guest_connect (gst); 2019 guest_connect (gst);
1949 return gst; 2020 return gst;
@@ -2028,7 +2099,11 @@ GNUNET_SOCIAL_guest_disconnect (struct GNUNET_SOCIAL_Guest *gst,
2028 GNUNET_ContinuationCallback disconnect_cb, 2099 GNUNET_ContinuationCallback disconnect_cb,
2029 void *cls) 2100 void *cls)
2030{ 2101{
2031 place_disconnect (&gst->plc, disconnect_cb, cls); 2102 struct GNUNET_SOCIAL_Place *plc = &gst->plc;
2103
2104 plc->disconnect_cb = disconnect_cb;
2105 plc->disconnect_cls = cls;
2106 place_disconnect (plc);
2032} 2107}
2033 2108
2034 2109
@@ -2054,10 +2129,15 @@ GNUNET_SOCIAL_guest_leave (struct GNUNET_SOCIAL_Guest *gst,
2054 GNUNET_ContinuationCallback disconnect_cb, 2129 GNUNET_ContinuationCallback disconnect_cb,
2055 void *cls) 2130 void *cls)
2056{ 2131{
2132 struct GNUNET_MQ_Envelope *envelope;
2133
2057 GNUNET_SOCIAL_guest_talk (gst, "_notice_place_leave", env, NULL, NULL, 2134 GNUNET_SOCIAL_guest_talk (gst, "_notice_place_leave", env, NULL, NULL,
2058 GNUNET_SOCIAL_TALK_NONE); 2135 GNUNET_SOCIAL_TALK_NONE);
2059 place_leave (&gst->plc); 2136 gst->plc.disconnect_cb = disconnect_cb;
2060 GNUNET_SOCIAL_guest_disconnect (gst, disconnect_cb, cls); 2137 gst->plc.disconnect_cls = cls;
2138 envelope = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE);
2139 GNUNET_MQ_send (gst->plc.mq,
2140 envelope);
2061} 2141}
2062 2142
2063 2143
diff --git a/src/social/test_social.c b/src/social/test_social.c
index 64ef10125..4d95cf005 100644
--- a/src/social/test_social.c
+++ b/src/social/test_social.c
@@ -129,22 +129,22 @@ enum
129 TEST_HOST_ANSWER_DOOR_REFUSE = 4, 129 TEST_HOST_ANSWER_DOOR_REFUSE = 4,
130 TEST_GUEST_RECV_ENTRY_DCSN_REFUSE = 5, 130 TEST_GUEST_RECV_ENTRY_DCSN_REFUSE = 5,
131 TEST_HOST_ANSWER_DOOR_ADMIT = 6, 131 TEST_HOST_ANSWER_DOOR_ADMIT = 6,
132 TEST_GUEST_RECV_ENTRY_DCSN_ADMIT = 9, 132 TEST_GUEST_RECV_ENTRY_DCSN_ADMIT = 7,
133 TEST_HOST_ANNOUNCE = 10, 133 TEST_HOST_ANNOUNCE = 8,
134 TEST_HOST_ANNOUNCE_END = 11, 134 TEST_HOST_ANNOUNCE_END = 9,
135 TEST_GUEST_TALK = 12, 135 TEST_GUEST_TALK = 10,
136 TEST_HOST_ANNOUNCE2 = 13, 136 TEST_HOST_ANNOUNCE2 = 11,
137 TEST_HOST_ANNOUNCE2_END = 14, 137 TEST_HOST_ANNOUNCE2_END = 12,
138 TEST_GUEST_HISTORY_REPLAY = 15, 138 TEST_GUEST_HISTORY_REPLAY = 13,
139 TEST_GUEST_HISTORY_REPLAY_LATEST = 16, 139 TEST_GUEST_HISTORY_REPLAY_LATEST = 14,
140 TEST_GUEST_LOOK_AT = 17, 140 TEST_GUEST_LOOK_AT = 15,
141 TEST_GUEST_LOOK_FOR = 18, 141 TEST_GUEST_LOOK_FOR = 16,
142 TEST_GUEST_LEAVE = 18, 142 TEST_GUEST_LEAVE = 17,
143 TEST_ZONE_ADD_PLACE = 20, 143 TEST_ZONE_ADD_PLACE = 18,
144 TEST_GUEST_ENTER_BY_NAME = 21, 144 TEST_GUEST_ENTER_BY_NAME = 19,
145 TEST_RECONNECT = 22, 145 TEST_RECONNECT = 20,
146 TEST_GUEST_LEAVE2 = 23, 146 TEST_GUEST_LEAVE2 = 21,
147 TEST_HOST_LEAVE = 24, 147 TEST_HOST_LEAVE = 22,
148} test; 148} test;
149 149
150 150
@@ -180,10 +180,28 @@ host_announce2 ();
180 180
181 181
182/** 182/**
183 * Clean up all resources used. 183 * Terminate the test case (failure).
184 *
185 * @param cls NULL
186 */
187static void
188end_badly (void *cls)
189{
190 end_badly_task = NULL;
191 GNUNET_SCHEDULER_shutdown ();
192 res = 2;
193 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
194 "Test FAILED.\n");
195}
196
197
198/**
199 * Terminate the test case (failure).
200 *
201 * @param cls NULL
184 */ 202 */
185static void 203static void
186cleanup () 204end_shutdown (void *cls)
187{ 205{
188 if (NULL != id) 206 if (NULL != id)
189 { 207 {
@@ -202,7 +220,11 @@ cleanup ()
202 GNUNET_PSYC_slicer_destroy (host_slicer); 220 GNUNET_PSYC_slicer_destroy (host_slicer);
203 host_slicer = NULL; 221 host_slicer = NULL;
204 } 222 }
205 223 if (NULL != end_badly_task)
224 {
225 GNUNET_SCHEDULER_cancel (end_badly_task);
226 end_badly_task = NULL;
227 }
206 if (NULL != gst) 228 if (NULL != gst)
207 { 229 {
208 GNUNET_SOCIAL_guest_leave (gst, NULL, NULL, NULL); 230 GNUNET_SOCIAL_guest_leave (gst, NULL, NULL, NULL);
@@ -216,21 +238,6 @@ cleanup ()
216 hst_plc = NULL; 238 hst_plc = NULL;
217 } 239 }
218 GNUNET_SOCIAL_app_disconnect (app, NULL, NULL); 240 GNUNET_SOCIAL_app_disconnect (app, NULL, NULL);
219 GNUNET_SCHEDULER_shutdown ();
220}
221
222
223/**
224 * Terminate the test case (failure).
225 *
226 * @param cls NULL
227 */
228static void
229end_badly (void *cls)
230{
231 res = 1;
232 cleanup ();
233 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test FAILED.\n");
234} 241}
235 242
236 243
@@ -242,9 +249,9 @@ end_badly (void *cls)
242static void 249static void
243end_normally (void *cls) 250end_normally (void *cls)
244{ 251{
252 GNUNET_SCHEDULER_shutdown ();
245 res = 0; 253 res = 0;
246 cleanup (); 254 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Test PASSED.\n");
247 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test PASSED.\n");
248} 255}
249 256
250 257
@@ -254,7 +261,7 @@ end_normally (void *cls)
254static void 261static void
255end () 262end ()
256{ 263{
257 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 264 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
258 "Test #%u: Ending tests.\n", test); 265 "Test #%u: Ending tests.\n", test);
259 266
260 if (end_badly_task != NULL) 267 if (end_badly_task != NULL)
@@ -271,7 +278,7 @@ transmit_resume (void *cls)
271{ 278{
272 struct TransmitClosure *tmit = cls; 279 struct TransmitClosure *tmit = cls;
273 280
274 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 281 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
275 "Test #%u: Transmission resumed.\n", test); 282 "Test #%u: Transmission resumed.\n", test);
276 if (NULL != tmit->host_ann) 283 if (NULL != tmit->host_ann)
277 GNUNET_SOCIAL_host_announce_resume (tmit->host_ann); 284 GNUNET_SOCIAL_host_announce_resume (tmit->host_ann);
@@ -296,7 +303,7 @@ notify_data (void *cls, uint16_t *data_size, void *data)
296 } 303 }
297 304
298 uint16_t size = strlen (tmit->data[tmit->n]); 305 uint16_t size = strlen (tmit->data[tmit->n]);
299 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 306 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
300 "Test #%u: Transmit notify data: %u bytes available, " 307 "Test #%u: Transmit notify data: %u bytes available, "
301 "processing fragment %u/%u (size %u).\n", 308 "processing fragment %u/%u (size %u).\n",
302 test, *data_size, tmit->n + 1, tmit->data_count, size); 309 test, *data_size, tmit->n + 1, tmit->data_count, size);
@@ -309,7 +316,7 @@ notify_data (void *cls, uint16_t *data_size, void *data)
309 316
310 if (GNUNET_YES != tmit->paused && 0 < tmit->data_delay[tmit->n]) 317 if (GNUNET_YES != tmit->paused && 0 < tmit->data_delay[tmit->n])
311 { 318 {
312 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 319 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
313 "Test #%u: Transmission paused.\n", test); 320 "Test #%u: Transmission paused.\n", test);
314 tmit->paused = GNUNET_YES; 321 tmit->paused = GNUNET_YES;
315 GNUNET_SCHEDULER_add_delayed ( 322 GNUNET_SCHEDULER_add_delayed (
@@ -331,7 +338,7 @@ notify_data (void *cls, uint16_t *data_size, void *data)
331static void 338static void
332host_left () 339host_left ()
333{ 340{
334 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 341 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
335 "Test #%u: The host has left the place.\n", test); 342 "Test #%u: The host has left the place.\n", test);
336 end (); 343 end ();
337} 344}
@@ -352,7 +359,7 @@ host_farewell2 (void *cls,
352 const struct GNUNET_SOCIAL_Nym *nym, 359 const struct GNUNET_SOCIAL_Nym *nym,
353 struct GNUNET_PSYC_Environment *env) 360 struct GNUNET_PSYC_Environment *env)
354{ 361{
355 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 362 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
356 "Nym left the place again.\n"); 363 "Nym left the place again.\n");
357 GNUNET_SCHEDULER_add_now (&schedule_host_leave, NULL); 364 GNUNET_SCHEDULER_add_now (&schedule_host_leave, NULL);
358} 365}
@@ -365,13 +372,14 @@ host_reconnected (void *cls, int result,
365{ 372{
366 place_pub_key = *home_pub_key; 373 place_pub_key = *home_pub_key;
367 GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash); 374 GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash);
368 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 375 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
369 "Test #%u: Host reconnected to place %s\n", 376 "Test #%u: Host reconnected to place %s\n",
370 test, GNUNET_h2s (&place_pub_hash)); 377 test, GNUNET_h2s (&place_pub_hash));
371 378
372 is_host_reconnected = GNUNET_YES; 379 is_host_reconnected = GNUNET_YES;
373 if (GNUNET_YES == is_guest_reconnected) 380 if (GNUNET_YES == is_guest_reconnected)
374 { 381 {
382 GNUNET_assert (NULL != gst);
375 GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL); 383 GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
376 } 384 }
377} 385}
@@ -382,7 +390,7 @@ guest_reconnected (void *cls, int result,
382 const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key, 390 const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
383 uint64_t max_message_id) 391 uint64_t max_message_id)
384{ 392{
385 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 393 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
386 "Test #%u: Guest reconnected to place: %d\n", 394 "Test #%u: Guest reconnected to place: %d\n",
387 test, result); 395 test, result);
388 GNUNET_assert (0 <= result); 396 GNUNET_assert (0 <= result);
@@ -390,6 +398,7 @@ guest_reconnected (void *cls, int result,
390 is_guest_reconnected = GNUNET_YES; 398 is_guest_reconnected = GNUNET_YES;
391 if (GNUNET_YES == is_host_reconnected) 399 if (GNUNET_YES == is_host_reconnected)
392 { 400 {
401 GNUNET_assert (NULL != gst);
393 GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL); 402 GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
394 } 403 }
395} 404}
@@ -398,7 +407,7 @@ guest_reconnected (void *cls, int result,
398static void 407static void
399app_connected (void *cls) 408app_connected (void *cls)
400{ 409{
401 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 410 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
402 "Test #%u: App connected: %p\n", test, cls); 411 "Test #%u: App connected: %p\n", test, cls);
403} 412}
404 413
@@ -411,21 +420,28 @@ app_recv_host (void *cls,
411 enum GNUNET_SOCIAL_AppPlaceState place_state) 420 enum GNUNET_SOCIAL_AppPlaceState place_state)
412{ 421{
413 struct GNUNET_HashCode host_pub_hash; 422 struct GNUNET_HashCode host_pub_hash;
414 GNUNET_CRYPTO_hash (host_pub_key, sizeof (*host_pub_key), &host_pub_hash);
415 423
416 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 424 GNUNET_CRYPTO_hash (host_pub_key,
425 sizeof (*host_pub_key),
426 &host_pub_hash);
427
428 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
417 "Test #%u: Got app host place notification: %s\n", 429 "Test #%u: Got app host place notification: %s\n",
418 test, GNUNET_h2s (&host_pub_hash)); 430 test,
431 GNUNET_h2s (&host_pub_hash));
419 432
420 if (test == TEST_RECONNECT) 433 if (test == TEST_RECONNECT)
421 { 434 {
422 if (0 == memcmp (&place_pub_key, host_pub_key, sizeof (*host_pub_key))) 435 if (0 == memcmp (&place_pub_key, host_pub_key, sizeof (*host_pub_key)))
423 { 436 {
424 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 437 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
425 "Test #%u: Reconnecting to host place: %s\n", 438 "Test #%u: Reconnecting to host place: %s\n",
426 test, GNUNET_h2s (&host_pub_hash)); 439 test, GNUNET_h2s (&host_pub_hash));
427 hst = GNUNET_SOCIAL_host_enter_reconnect (hconn, host_slicer, host_reconnected, 440 hst = GNUNET_SOCIAL_host_enter_reconnect (hconn, host_slicer,
428 host_answer_door, host_farewell2, NULL); 441 &host_reconnected,
442 &host_answer_door,
443 &host_farewell2,
444 NULL);
429 } 445 }
430 } 446 }
431} 447}
@@ -439,21 +455,30 @@ app_recv_guest (void *cls,
439 enum GNUNET_SOCIAL_AppPlaceState place_state) 455 enum GNUNET_SOCIAL_AppPlaceState place_state)
440{ 456{
441 struct GNUNET_HashCode guest_pub_hash; 457 struct GNUNET_HashCode guest_pub_hash;
442 GNUNET_CRYPTO_hash (guest_pub_key, sizeof (*guest_pub_key), &guest_pub_hash);
443 458
444 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 459 GNUNET_CRYPTO_hash (guest_pub_key,
460 sizeof (*guest_pub_key),
461 &guest_pub_hash);
462
463 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
445 "Test #%u: Got app guest place notification: %s\n", 464 "Test #%u: Got app guest place notification: %s\n",
446 test, GNUNET_h2s (&guest_pub_hash)); 465 test, GNUNET_h2s (&guest_pub_hash));
447 466
448 if (test == TEST_RECONNECT) 467 if (test == TEST_RECONNECT)
449 { 468 {
450 if (0 == memcmp (&place_pub_key, guest_pub_key, sizeof (*guest_pub_key))) 469 if (0 == memcmp (&place_pub_key,
470 guest_pub_key,
471 sizeof (*guest_pub_key)))
451 { 472 {
452 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 473 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
453 "Test #%u: Reconnecting to guest place: %s\n", 474 "Test #%u: Reconnecting to guest place: %s\n",
454 test, GNUNET_h2s (&guest_pub_hash)); 475 test, GNUNET_h2s (&guest_pub_hash));
455 gst = GNUNET_SOCIAL_guest_enter_reconnect (gconn, GNUNET_PSYC_SLAVE_JOIN_NONE, 476 gst = GNUNET_SOCIAL_guest_enter_reconnect (gconn,
456 guest_slicer, guest_reconnected, NULL); 477 GNUNET_PSYC_SLAVE_JOIN_NONE,
478 guest_slicer,
479 &guest_reconnected,
480 NULL);
481 GNUNET_assert (NULL != gst);
457 } 482 }
458 } 483 }
459} 484}
@@ -478,7 +503,7 @@ app_recv_ego (void *cls,
478 const char *name) 503 const char *name)
479{ 504{
480 char *ego_pub_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (ego_pub_key); 505 char *ego_pub_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (ego_pub_key);
481 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 506 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
482 "Test #%u: Got app ego notification: %p %s %s\n", 507 "Test #%u: Got app ego notification: %p %s %s\n",
483 test, ego, name, ego_pub_str); 508 test, ego, name, ego_pub_str);
484 GNUNET_free (ego_pub_str); 509 GNUNET_free (ego_pub_str);
@@ -487,15 +512,30 @@ app_recv_ego (void *cls,
487 { 512 {
488 host_ego = ego; 513 host_ego = ego;
489 host_pub_key = ego_pub_key; 514 host_pub_key = ego_pub_key;
490 GNUNET_assert (TEST_IDENTITIES_CREATE == test); 515 if (TEST_IDENTITIES_CREATE == test)
491 enter_if_ready (); 516 {
517 enter_if_ready ();
518 }
519 else
520 {
521 GNUNET_assert (TEST_RECONNECT == test);
522 }
492 } 523 }
493 else if (NULL != strstr (name, guest_name)) 524 else if (NULL != strstr (name, guest_name))
494 { 525 {
495 guest_ego = ego; 526 guest_ego = ego;
496 guest_pub_key = ego_pub_key; 527 guest_pub_key = ego_pub_key;
497 GNUNET_assert (TEST_IDENTITIES_CREATE == test); 528 if (TEST_IDENTITIES_CREATE == test)
498 enter_if_ready (); 529 {
530 enter_if_ready ();
531 }
532 else
533 {
534 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
535 "test = %d\n",
536 test);
537 GNUNET_assert (TEST_RECONNECT == test);
538 }
499 } 539 }
500} 540}
501 541
@@ -504,7 +544,6 @@ static void
504schedule_reconnect (void *cls) 544schedule_reconnect (void *cls)
505{ 545{
506 test = TEST_RECONNECT; 546 test = TEST_RECONNECT;
507
508 GNUNET_SOCIAL_host_disconnect (hst, NULL, NULL); 547 GNUNET_SOCIAL_host_disconnect (hst, NULL, NULL);
509 GNUNET_SOCIAL_guest_disconnect (gst, NULL, NULL); 548 GNUNET_SOCIAL_guest_disconnect (gst, NULL, NULL);
510 hst = NULL; 549 hst = NULL;
@@ -512,10 +551,10 @@ schedule_reconnect (void *cls)
512 551
513 GNUNET_SOCIAL_app_disconnect (app, NULL, NULL); 552 GNUNET_SOCIAL_app_disconnect (app, NULL, NULL);
514 app = GNUNET_SOCIAL_app_connect (cfg, app_id, 553 app = GNUNET_SOCIAL_app_connect (cfg, app_id,
515 app_recv_ego, 554 &app_recv_ego,
516 app_recv_host, 555 &app_recv_host,
517 app_recv_guest, 556 &app_recv_guest,
518 app_connected, 557 &app_connected,
519 NULL); 558 NULL);
520} 559}
521 560
@@ -524,7 +563,7 @@ static void
524host_recv_zone_add_place_result (void *cls, int64_t result, 563host_recv_zone_add_place_result (void *cls, int64_t result,
525 const void *data, uint16_t data_size) 564 const void *data, uint16_t data_size)
526{ 565{
527 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 566 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
528 "Test #%u: Zone add place result: %" PRId64 " (%.*s).\n", 567 "Test #%u: Zone add place result: %" PRId64 " (%.*s).\n",
529 test, result, data_size, (const char *) data); 568 test, result, data_size, (const char *) data);
530 GNUNET_assert (GNUNET_YES == result); 569 GNUNET_assert (GNUNET_YES == result);
@@ -538,7 +577,7 @@ static void
538zone_add_place () 577zone_add_place ()
539{ 578{
540 test = TEST_ZONE_ADD_PLACE; 579 test = TEST_ZONE_ADD_PLACE;
541 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 580 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
542 "Test #%u: Adding place to zone.\n", test); 581 "Test #%u: Adding place to zone.\n", test);
543 582
544 GNUNET_SOCIAL_zone_add_place (app, host_ego, "home", "let.me*in!", 583 GNUNET_SOCIAL_zone_add_place (app, host_ego, "home", "let.me*in!",
@@ -557,7 +596,7 @@ host_farewell (void *cls,
557 nym_key = GNUNET_SOCIAL_nym_get_pub_key (nym); 596 nym_key = GNUNET_SOCIAL_nym_get_pub_key (nym);
558 597
559 char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key); 598 char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key);
560 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 599 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
561 "Test #%u: Farewell: nym %s (%s) has left the place.\n", 600 "Test #%u: Farewell: nym %s (%s) has left the place.\n",
562 test, GNUNET_h2s (GNUNET_SOCIAL_nym_get_pub_key_hash (nym)), str); 601 test, GNUNET_h2s (GNUNET_SOCIAL_nym_get_pub_key_hash (nym)), str);
563 GNUNET_free (str); 602 GNUNET_free (str);
@@ -578,13 +617,13 @@ host_farewell (void *cls,
578static void 617static void
579guest_left (void *cls) 618guest_left (void *cls)
580{ 619{
581 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 620 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
582 "Test #%u: The guest has left the place.\n", test); 621 "Test #%u: The guest has left the place.\n", test);
583} 622}
584 623
585 624
586static void 625static void
587guest_leave() 626guest_leave ()
588{ 627{
589 if (test < TEST_RECONNECT) 628 if (test < TEST_RECONNECT)
590 test = TEST_GUEST_LEAVE; 629 test = TEST_GUEST_LEAVE;
@@ -615,11 +654,11 @@ guest_look_for_result (void *cls,
615 uint16_t data_size) 654 uint16_t data_size)
616{ 655{
617 struct ResultClosure *rcls = cls; 656 struct ResultClosure *rcls = cls;
618 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 657 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
619 "Test #%u: guest_look_for_result: %" PRId64 "\n", 658 "Test #%u: guest_look_for_result: %" PRId64 "\n",
620 test, result_code); 659 test, result_code);
621 GNUNET_assert (GNUNET_OK == result_code); 660 GNUNET_assert (GNUNET_OK == result_code);
622 GNUNET_assert (3 == rcls->n); 661 GNUNET_assert (6 == rcls->n);
623 GNUNET_free (rcls); 662 GNUNET_free (rcls);
624 GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL); 663 GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
625} 664}
@@ -635,7 +674,7 @@ guest_look_for_var (void *cls,
635{ 674{
636 struct ResultClosure *rcls = cls; 675 struct ResultClosure *rcls = cls;
637 rcls->n++; 676 rcls->n++;
638 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 677 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
639 "Test #%u: guest_look_for_var: %s\n%.*s\n", 678 "Test #%u: guest_look_for_var: %s\n%.*s\n",
640 test, name, value_size, (const char *) value); 679 test, name, value_size, (const char *) value);
641} 680}
@@ -656,7 +695,7 @@ guest_look_at_result (void *cls, int64_t result_code,
656{ 695{
657 struct ResultClosure *rcls = cls; 696 struct ResultClosure *rcls = cls;
658 697
659 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 698 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
660 "Test #%u: guest_look_at_result: %" PRId64 "\n", 699 "Test #%u: guest_look_at_result: %" PRId64 "\n",
661 test, result_code); 700 test, result_code);
662 GNUNET_assert (GNUNET_OK == result_code); 701 GNUNET_assert (GNUNET_OK == result_code);
@@ -677,7 +716,7 @@ guest_look_at_var (void *cls,
677 struct ResultClosure *rcls = cls; 716 struct ResultClosure *rcls = cls;
678 rcls->n++; 717 rcls->n++;
679 718
680 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 719 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
681 "Test #%u: guest_look_at_var: %s\n%.*s\n", 720 "Test #%u: guest_look_at_var: %s\n%.*s\n",
682 test ,name, value_size, (const char *) value); 721 test ,name, value_size, (const char *) value);
683} 722}
@@ -696,7 +735,7 @@ static void
696guest_recv_history_replay_latest_result (void *cls, int64_t result, 735guest_recv_history_replay_latest_result (void *cls, int64_t result,
697 const void *data, uint16_t data_size) 736 const void *data, uint16_t data_size)
698{ 737{
699 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 738 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
700 "Test #%u: Guest received latest history replay result " 739 "Test #%u: Guest received latest history replay result "
701 "(%" PRIu32 " messages, %" PRId64 " fragments):\n" 740 "(%" PRIu32 " messages, %" PRId64 " fragments):\n"
702 "%.*s\n", 741 "%.*s\n",
@@ -725,7 +764,7 @@ static void
725guest_recv_history_replay_result (void *cls, int64_t result, 764guest_recv_history_replay_result (void *cls, int64_t result,
726 const void *data, uint16_t data_size) 765 const void *data, uint16_t data_size)
727{ 766{
728 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 767 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
729 "Test #%u: Guest received history replay result: %" PRId64 "\n" 768 "Test #%u: Guest received history replay result: %" PRId64 "\n"
730 "%.*s\n", 769 "%.*s\n",
731 test, result, data_size, (const char *) data); 770 test, result, data_size, (const char *) data);
@@ -756,7 +795,7 @@ guest_recv_method (void *cls,
756 uint64_t message_id, 795 uint64_t message_id,
757 const char *method_name) 796 const char *method_name)
758{ 797{
759 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 798 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
760 "Test #%u: Guest received method for message ID %" PRIu64 ":\n" 799 "Test #%u: Guest received method for message ID %" PRIu64 ":\n"
761 "%s (flags: %x)\n", 800 "%s (flags: %x)\n",
762 test, message_id, method_name, ntohl (meth->flags)); 801 test, message_id, method_name, ntohl (meth->flags));
@@ -775,7 +814,7 @@ guest_recv_modifier (void *cls,
775 uint16_t value_size, 814 uint16_t value_size,
776 uint16_t full_value_size) 815 uint16_t full_value_size)
777{ 816{
778 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 817 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
779 "Test #%u: Guest received modifier for message ID %" PRIu64 ":\n" 818 "Test #%u: Guest received modifier for message ID %" PRIu64 ":\n"
780 "%c%s: %.*s (size: %u)\n", 819 "%c%s: %.*s (size: %u)\n",
781 test, message_id, oper, name, value_size, (const char *) value, value_size); 820 test, message_id, oper, name, value_size, (const char *) value, value_size);
@@ -793,7 +832,7 @@ guest_recv_mod_foo_bar (void *cls,
793 uint16_t value_size, 832 uint16_t value_size,
794 uint16_t full_value_size) 833 uint16_t full_value_size)
795{ 834{
796 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 835 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
797 "Test #%u: Guest received modifier matching _foo_bar for message ID %" PRIu64 ":\n" 836 "Test #%u: Guest received modifier matching _foo_bar for message ID %" PRIu64 ":\n"
798 "%c%s: %.*s (size: %u)\n", 837 "%c%s: %.*s (size: %u)\n",
799 test, message_id, oper, name, value_size, (const char *) value, value_size); 838 test, message_id, oper, name, value_size, (const char *) value, value_size);
@@ -811,7 +850,7 @@ guest_recv_data (void *cls,
811 const void *data, 850 const void *data,
812 uint16_t data_size) 851 uint16_t data_size)
813{ 852{
814 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 853 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
815 "Test #%u: Guest received data for message ID %" PRIu64 ":\n" 854 "Test #%u: Guest received data for message ID %" PRIu64 ":\n"
816 "%.*s\n", 855 "%.*s\n",
817 test, message_id, data_size, (const char *) data); 856 test, message_id, data_size, (const char *) data);
@@ -826,7 +865,7 @@ guest_recv_eom (void *cls,
826 uint64_t message_id, 865 uint64_t message_id,
827 uint8_t is_cancelled) 866 uint8_t is_cancelled)
828{ 867{
829 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 868 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
830 "Test #%u: Guest received end of message ID %" PRIu64 869 "Test #%u: Guest received end of message ID %" PRIu64
831 ", cancelled: %u\n", 870 ", cancelled: %u\n",
832 test, message_id, is_cancelled); 871 test, message_id, is_cancelled);
@@ -868,7 +907,7 @@ host_recv_method (void *cls,
868 uint64_t message_id, 907 uint64_t message_id,
869 const char *method_name) 908 const char *method_name)
870{ 909{
871 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 910 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
872 "Test #%u: Host received method for message ID %" PRIu64 ":\n" 911 "Test #%u: Host received method for message ID %" PRIu64 ":\n"
873 "%s\n", 912 "%s\n",
874 test, message_id, method_name); 913 test, message_id, method_name);
@@ -887,7 +926,7 @@ host_recv_modifier (void *cls,
887 uint16_t value_size, 926 uint16_t value_size,
888 uint16_t full_value_size) 927 uint16_t full_value_size)
889{ 928{
890 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 929 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
891 "Test #%u: Host received modifier for message ID %" PRIu64 ":\n" 930 "Test #%u: Host received modifier for message ID %" PRIu64 ":\n"
892 "%c%s: %.*s\n", 931 "%c%s: %.*s\n",
893 test, message_id, oper, name, value_size, (const char *) value); 932 test, message_id, oper, name, value_size, (const char *) value);
@@ -902,7 +941,7 @@ host_recv_data (void *cls,
902 const void *data, 941 const void *data,
903 uint16_t data_size) 942 uint16_t data_size)
904{ 943{
905 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 944 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
906 "Test #%u: Host received data for message ID %" PRIu64 ":\n" 945 "Test #%u: Host received data for message ID %" PRIu64 ":\n"
907 "%.*s\n", 946 "%.*s\n",
908 test, message_id, data_size, (const char *) data); 947 test, message_id, data_size, (const char *) data);
@@ -916,7 +955,7 @@ host_recv_eom (void *cls,
916 uint64_t message_id, 955 uint64_t message_id,
917 uint8_t is_cancelled) 956 uint8_t is_cancelled)
918{ 957{
919 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 958 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
920 "Test #%u: Host received end of message ID %" PRIu64 959 "Test #%u: Host received end of message ID %" PRIu64
921 ", cancelled: %u\n", 960 ", cancelled: %u\n",
922 test, message_id, is_cancelled); 961 test, message_id, is_cancelled);
@@ -981,7 +1020,7 @@ host_announce ()
981{ 1020{
982 test = TEST_HOST_ANNOUNCE; 1021 test = TEST_HOST_ANNOUNCE;
983 1022
984 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1023 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
985 "Test #%u: Host announcement.\n", test); 1024 "Test #%u: Host announcement.\n", test);
986 1025
987 tmit = (struct TransmitClosure) {}; 1026 tmit = (struct TransmitClosure) {};
@@ -1015,7 +1054,7 @@ host_announce2 ()
1015 1054
1016 test = TEST_HOST_ANNOUNCE2; 1055 test = TEST_HOST_ANNOUNCE2;
1017 1056
1018 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1057 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1019 "Test #%u: Host announcement 2.\n", test); 1058 "Test #%u: Host announcement 2.\n", test);
1020 1059
1021 tmit = (struct TransmitClosure) {}; 1060 tmit = (struct TransmitClosure) {};
@@ -1025,7 +1064,7 @@ host_announce2 ()
1025 GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN, 1064 GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
1026 "_foo2_bar", DATA2ARG ("FOO BAR")); 1065 "_foo2_bar", DATA2ARG ("FOO BAR"));
1027 GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN, 1066 GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
1028 "_foo2_bar", DATA2ARG ("FOO BAR BAZ")); 1067 "_foo2_bar_baz", DATA2ARG ("FOO BAR BAZ"));
1029 tmit.data[0] = "AAA BBB CCC "; 1068 tmit.data[0] = "AAA BBB CCC ";
1030 tmit.data[1] = "ABC DEF GHI JKL.\n"; 1069 tmit.data[1] = "ABC DEF GHI JKL.\n";
1031 tmit.data[2] = "TESTING ONE TWO THREE.\n"; 1070 tmit.data[2] = "TESTING ONE TWO THREE.\n";
@@ -1043,7 +1082,7 @@ guest_recv_entry_decision (void *cls,
1043 int is_admitted, 1082 int is_admitted,
1044 const struct GNUNET_PSYC_Message *entry_msg) 1083 const struct GNUNET_PSYC_Message *entry_msg)
1045{ 1084{
1046 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1085 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1047 "Test #%u: Guest received entry decision (try %u): %d.\n", 1086 "Test #%u: Guest received entry decision (try %u): %d.\n",
1048 test, join_req_count, is_admitted); 1087 test, join_req_count, is_admitted);
1049 1088
@@ -1068,7 +1107,8 @@ guest_recv_entry_decision (void *cls,
1068 { 1107 {
1069 case TEST_GUEST_RECV_ENTRY_DCSN_REFUSE: 1108 case TEST_GUEST_RECV_ENTRY_DCSN_REFUSE:
1070 GNUNET_assert (GNUNET_NO == is_admitted); 1109 GNUNET_assert (GNUNET_NO == is_admitted);
1071 guest_enter (); 1110 test = TEST_HOST_ANSWER_DOOR_ADMIT;
1111 GNUNET_SOCIAL_guest_disconnect (gst, &guest_enter, NULL);
1072 break; 1112 break;
1073 1113
1074 case TEST_GUEST_RECV_ENTRY_DCSN_ADMIT: 1114 case TEST_GUEST_RECV_ENTRY_DCSN_ADMIT:
@@ -1097,7 +1137,7 @@ host_answer_door (void *cls,
1097{ 1137{
1098 join_req_count++; 1138 join_req_count++;
1099 1139
1100 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1140 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1101 "Test #%u: Host received entry request from guest (try %u).\n", 1141 "Test #%u: Host received entry request from guest (try %u).\n",
1102 (uint8_t) test, join_req_count); 1142 (uint8_t) test, join_req_count);
1103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1118,7 +1158,7 @@ host_answer_door (void *cls,
1118 // fall through 1158 // fall through
1119 1159
1120 case TEST_GUEST_ENTER_BY_NAME: 1160 case TEST_GUEST_ENTER_BY_NAME:
1121 join_resp = GNUNET_PSYC_message_create ("_notice_place_admit", env, 1161 join_resp = GNUNET_PSYC_message_create ("_notice_place_admit", env,
1122 DATA2ARG ("Welcome, nym!")); 1162 DATA2ARG ("Welcome, nym!"));
1123 GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_YES, join_resp); 1163 GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_YES, join_resp);
1124 break; 1164 break;
@@ -1135,18 +1175,18 @@ guest_recv_local_enter (void *cls, int result,
1135 const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key, 1175 const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
1136 uint64_t max_message_id) 1176 uint64_t max_message_id)
1137{ 1177{
1138 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1178 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1139 "Test #%u: Guest entered to local place: %d\n", 1179 "Test #%u: Guest entered local place: %d\n",
1140 test, result); 1180 test, result);
1141 GNUNET_assert (0 <= result); 1181 GNUNET_assert (GNUNET_OK == result);
1142} 1182}
1143 1183
1144 1184
1145static void 1185static void
1146guest_enter () 1186guest_enter ()
1147{ 1187{
1148 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1188 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1149 "Test #%u: Entering to place as guest.\n", test); 1189 "Test #%u: Entering place as guest.\n", test);
1150 1190
1151 struct GuestEnterMessage *emsg = &guest_enter_msg; 1191 struct GuestEnterMessage *emsg = &guest_enter_msg;
1152 1192
@@ -1177,8 +1217,8 @@ static void
1177guest_enter_by_name () 1217guest_enter_by_name ()
1178{ 1218{
1179 test = TEST_GUEST_ENTER_BY_NAME; 1219 test = TEST_GUEST_ENTER_BY_NAME;
1180 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1220 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1181 "Test #%u: Entering to place by name as guest.\n", test); 1221 "Test #%u: Entering place by name as guest.\n", test);
1182 1222
1183 struct GuestEnterMessage *emsg = &guest_enter_msg; 1223 struct GuestEnterMessage *emsg = &guest_enter_msg;
1184 1224
@@ -1222,7 +1262,7 @@ guest_init ()
1222 guest_recv_data, guest_recv_eom, NULL); 1262 guest_recv_data, guest_recv_eom, NULL);
1223 GNUNET_PSYC_slicer_modifier_add (guest_slicer, "_foo_bar", 1263 GNUNET_PSYC_slicer_modifier_add (guest_slicer, "_foo_bar",
1224 guest_recv_mod_foo_bar, &mod_foo_bar_rcls); 1264 guest_recv_mod_foo_bar, &mod_foo_bar_rcls);
1225 test = TEST_HOST_ANSWER_DOOR_ADMIT; 1265 test = TEST_HOST_ANSWER_DOOR_REFUSE;
1226 1266
1227 GNUNET_SOCIAL_zone_add_nym (app, guest_ego, "host", host_pub_key, 1267 GNUNET_SOCIAL_zone_add_nym (app, guest_ego, "host", host_pub_key,
1228 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES), 1268 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES),
@@ -1270,8 +1310,8 @@ host_entered (void *cls, int result,
1270{ 1310{
1271 place_pub_key = *home_pub_key; 1311 place_pub_key = *home_pub_key;
1272 GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash); 1312 GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash);
1273 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1313 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1274 "Test #%u: Host entered to place %s\n", 1314 "Test #%u: Host entered place %s\n",
1275 test, GNUNET_h2s (&place_pub_hash)); 1315 test, GNUNET_h2s (&place_pub_hash));
1276 guest_enter (); 1316 guest_enter ();
1277} 1317}
@@ -1285,8 +1325,8 @@ host_enter ()
1285 host_recv_method, host_recv_modifier, 1325 host_recv_method, host_recv_modifier,
1286 host_recv_data, host_recv_eom, NULL); 1326 host_recv_data, host_recv_eom, NULL);
1287 1327
1288 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1328 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1289 "Test #%u: Entering to place as host.\n", test); 1329 "Test #%u: Entering place as host.\n", test);
1290 test = TEST_HOST_ENTER; 1330 test = TEST_HOST_ENTER;
1291 hst = GNUNET_SOCIAL_host_enter (app, host_ego, 1331 hst = GNUNET_SOCIAL_host_enter (app, host_ego,
1292 GNUNET_PSYC_CHANNEL_PRIVATE, 1332 GNUNET_PSYC_CHANNEL_PRIVATE,
@@ -1306,6 +1346,8 @@ start_app_if_ready ()
1306 { 1346 {
1307 return; 1347 return;
1308 } 1348 }
1349 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1350 "starting app...\n");
1309 app = GNUNET_SOCIAL_app_connect (cfg, 1351 app = GNUNET_SOCIAL_app_connect (cfg,
1310 app_id, 1352 app_id,
1311 app_recv_ego, 1353 app_recv_ego,
@@ -1324,17 +1366,17 @@ identity_ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego,
1324 { 1366 {
1325 if (ego == identity_host_ego) 1367 if (ego == identity_host_ego)
1326 { 1368 {
1327 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1369 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1328 "Host ego deleted\n"); 1370 "Host ego deleted\n");
1329 } 1371 }
1330 else if (ego == identity_guest_ego) 1372 else if (ego == identity_guest_ego)
1331 { 1373 {
1332 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1374 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1333 "Guest ego deleted\n"); 1375 "Guest ego deleted\n");
1334 } 1376 }
1335 else if (0 == strcmp (name, host_name)) 1377 else if (0 == strcmp (name, host_name))
1336 { 1378 {
1337 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1379 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1338 "Created ego %s\n", 1380 "Created ego %s\n",
1339 name); 1381 name);
1340 identity_host_ego = ego; 1382 identity_host_ego = ego;
@@ -1342,7 +1384,7 @@ identity_ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego,
1342 } 1384 }
1343 else if (0 == strcmp (name, guest_name)) 1385 else if (0 == strcmp (name, guest_name))
1344 { 1386 {
1345 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1387 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1346 "Created guest ego %s\n", 1388 "Created guest ego %s\n",
1347 name); 1389 name);
1348 identity_guest_ego = ego; 1390 identity_guest_ego = ego;
@@ -1370,9 +1412,11 @@ run (void *cls,
1370#endif 1412#endif
1371{ 1413{
1372 cfg = c; 1414 cfg = c;
1415 res = 1;
1373 end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 1416 end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
1374 &end_badly, NULL); 1417 &end_badly, NULL);
1375 1418 GNUNET_SCHEDULER_add_shutdown (&end_shutdown,
1419 NULL);
1376 GNUNET_CRYPTO_get_peer_identity (cfg, &this_peer); 1420 GNUNET_CRYPTO_get_peer_identity (cfg, &this_peer);
1377 1421
1378 id = GNUNET_IDENTITY_connect (cfg, &identity_ego_cb, NULL); 1422 id = GNUNET_IDENTITY_connect (cfg, &identity_ego_cb, NULL);
diff --git a/src/social/test_social.conf b/src/social/test_social.conf
index e69de29bb..7cf858b1c 100644
--- a/src/social/test_social.conf
+++ b/src/social/test_social.conf
@@ -0,0 +1,19 @@
1@INLINE@ ../../contrib/no_forcestart.conf
2
3[PATHS]
4GNUNET_TEST_HOME = /tmp/gnunet-test-social/
5
6[social]
7FORCESTART = YES
8
9[transport]
10PLUGINS = tcp
11
12[nat]
13DISABLEV6 = YES
14ENABLE_UPNP = NO
15BEHIND_NAT = NO
16ALLOW_NAT = NO
17INTERNAL_ADDRESS = 127.0.0.1
18EXTERNAL_ADDRESS = 127.0.0.1
19
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c
index 0cb136b99..87e966a01 100644
--- a/src/statistics/gnunet-service-statistics.c
+++ b/src/statistics/gnunet-service-statistics.c
@@ -998,7 +998,9 @@ client_disconnect_cb (void *cls,
998 * 998 *
999 * @param cls NULL 999 * @param cls NULL
1000 * @param message the message found on disk 1000 * @param message the message found on disk
1001 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing 1001 * @return #GNUNET_OK on success,
1002 * #GNUNET_NO to stop further processing (no error)
1003 * #GNUNET_SYSERR to stop further processing with error
1002 */ 1004 */
1003static int 1005static int
1004inject_message (void *cls, 1006inject_message (void *cls,
diff --git a/src/testbed/gnunet-helper-testbed.c b/src/testbed/gnunet-helper-testbed.c
index 392f257dd..9601e7567 100644
--- a/src/testbed/gnunet-helper-testbed.c
+++ b/src/testbed/gnunet-helper-testbed.c
@@ -292,8 +292,9 @@ child_death_task (void *cls)
292 * 292 *
293 * @param cls identification of the client 293 * @param cls identification of the client
294 * @param message the actual message 294 * @param message the actual message
295 * 295 * @return #GNUNET_OK on success,
296 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing 296 * #GNUNET_NO to stop further processing (no error)
297 * #GNUNET_SYSERR to stop further processing with error
297 */ 298 */
298static int 299static int
299tokenizer_cb (void *cls, 300tokenizer_cb (void *cls,
@@ -359,7 +360,7 @@ tokenizer_cb (void *cls,
359 cfg = GNUNET_CONFIGURATION_create (); 360 cfg = GNUNET_CONFIGURATION_create ();
360 if (GNUNET_OK != 361 if (GNUNET_OK !=
361 GNUNET_CONFIGURATION_deserialize (cfg, 362 GNUNET_CONFIGURATION_deserialize (cfg,
362 config, 363 config,
363 ul_config_size, 364 ul_config_size,
364 NULL)) 365 NULL))
365 { 366 {
diff --git a/src/transport/gnunet-helper-transport-wlan-dummy.c b/src/transport/gnunet-helper-transport-wlan-dummy.c
index 63ed9c4b7..f02d8bdd7 100644
--- a/src/transport/gnunet-helper-transport-wlan-dummy.c
+++ b/src/transport/gnunet-helper-transport-wlan-dummy.c
@@ -121,6 +121,9 @@ send_mac_to_plugin (char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac)
121 * 121 *
122 * @param cls the 'struct SendBuffer' to copy the converted message to 122 * @param cls the 'struct SendBuffer' to copy the converted message to
123 * @param hdr inbound message from the FIFO 123 * @param hdr inbound message from the FIFO
124 * @return #GNUNET_OK on success,
125 * #GNUNET_NO to stop further processing (no error)
126 * #GNUNET_SYSERR to stop further processing with error
124 */ 127 */
125static int 128static int
126stdin_send (void *cls, 129stdin_send (void *cls,
@@ -167,6 +170,9 @@ stdin_send (void *cls,
167 * 170 *
168 * @param cls the 'struct SendBuffer' to copy to 171 * @param cls the 'struct SendBuffer' to copy to
169 * @param hdr the message we received to copy to the buffer 172 * @param hdr the message we received to copy to the buffer
173 * @return #GNUNET_OK on success,
174 * #GNUNET_NO to stop further processing (no error)
175 * #GNUNET_SYSERR to stop further processing with error
170 */ 176 */
171static int 177static int
172file_in_send (void *cls, 178file_in_send (void *cls,
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c
index d9fade44f..6a9c1b0ba 100644
--- a/src/transport/plugin_transport_http_server.c
+++ b/src/transport/plugin_transport_http_server.c
@@ -1651,7 +1651,7 @@ server_send_callback (void *cls,
1651 * 1651 *
1652 * @param cls current session as closure 1652 * @param cls current session as closure
1653 * @param message the message to be forwarded to transport service 1653 * @param message the message to be forwarded to transport service
1654 * @return #GNUNET_OK 1654 * @return #GNUNET_OK (all OK)
1655 */ 1655 */
1656static int 1656static int
1657server_receive_mst_cb (void *cls, 1657server_receive_mst_cb (void *cls,
diff --git a/src/util/client.c b/src/util/client.c
index 3d74bff33..e5bf7e176 100644
--- a/src/util/client.c
+++ b/src/util/client.c
@@ -261,14 +261,27 @@ transmit_ready (void *cls)
261 pos = (const char *) cstate->msg; 261 pos = (const char *) cstate->msg;
262 len = ntohs (cstate->msg->size); 262 len = ntohs (cstate->msg->size);
263 GNUNET_assert (cstate->msg_off < len); 263 GNUNET_assert (cstate->msg_off < len);
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
265 "client: message of type %u trying to send with socket %p (MQ: %p\n",
266 ntohs(cstate->msg->type),
267 cstate->sock,
268 cstate->mq);
269
264 RETRY: 270 RETRY:
265 ret = GNUNET_NETWORK_socket_send (cstate->sock, 271 ret = GNUNET_NETWORK_socket_send (cstate->sock,
266 &pos[cstate->msg_off], 272 &pos[cstate->msg_off],
267 len - cstate->msg_off); 273 len - cstate->msg_off);
268 if (-1 == ret) 274 if (-1 == ret)
269 { 275 {
270 if (EINTR == errno) 276 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
277 "client: error during sending message of type %u\n",
278 ntohs(cstate->msg->type));
279 if (EINTR == errno){
280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
281 "client: retrying message of type %u\n",
282 ntohs(cstate->msg->type));
271 goto RETRY; 283 goto RETRY;
284 }
272 GNUNET_MQ_inject_error (cstate->mq, 285 GNUNET_MQ_inject_error (cstate->mq,
273 GNUNET_MQ_ERROR_WRITE); 286 GNUNET_MQ_ERROR_WRITE);
274 return; 287 return;
@@ -277,6 +290,9 @@ transmit_ready (void *cls)
277 cstate->msg_off += ret; 290 cstate->msg_off += ret;
278 if (cstate->msg_off < len) 291 if (cstate->msg_off < len)
279 { 292 {
293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
294 "client: rescheduling message of type %u\n",
295 ntohs(cstate->msg->type));
280 cstate->send_task 296 cstate->send_task
281 = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 297 = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
282 cstate->sock, 298 cstate->sock,
@@ -286,6 +302,9 @@ transmit_ready (void *cls)
286 GNUNET_MQ_impl_send_in_flight (cstate->mq); 302 GNUNET_MQ_impl_send_in_flight (cstate->mq);
287 return; 303 return;
288 } 304 }
305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
306 "client: sending message of type %u successful\n",
307 ntohs(cstate->msg->type));
289 cstate->msg = NULL; 308 cstate->msg = NULL;
290 GNUNET_MQ_impl_send_continue (cstate->mq); 309 GNUNET_MQ_impl_send_continue (cstate->mq);
291} 310}
@@ -297,7 +316,9 @@ transmit_ready (void *cls)
297 * 316 *
298 * @param cls the `struct ClientState` 317 * @param cls the `struct ClientState`
299 * @param msg message we received. 318 * @param msg message we received.
300 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing 319 * @return #GNUNET_OK on success,
320 * #GNUNET_NO to stop further processing due to disconnect (no error)
321 * #GNUNET_SYSERR to stop further processing due to error
301 */ 322 */
302static int 323static int
303recv_message (void *cls, 324recv_message (void *cls,
@@ -306,7 +327,7 @@ recv_message (void *cls,
306 struct ClientState *cstate = cls; 327 struct ClientState *cstate = cls;
307 328
308 if (GNUNET_YES == cstate->in_destroy) 329 if (GNUNET_YES == cstate->in_destroy)
309 return GNUNET_SYSERR; 330 return GNUNET_NO;
310 LOG (GNUNET_ERROR_TYPE_DEBUG, 331 LOG (GNUNET_ERROR_TYPE_DEBUG,
311 "Received message of type %u and size %u from %s\n", 332 "Received message of type %u and size %u from %s\n",
312 ntohs (msg->type), 333 ntohs (msg->type),
@@ -315,7 +336,7 @@ recv_message (void *cls,
315 GNUNET_MQ_inject_message (cstate->mq, 336 GNUNET_MQ_inject_message (cstate->mq,
316 msg); 337 msg);
317 if (GNUNET_YES == cstate->in_destroy) 338 if (GNUNET_YES == cstate->in_destroy)
318 return GNUNET_SYSERR; 339 return GNUNET_NO;
319 return GNUNET_OK; 340 return GNUNET_OK;
320} 341}
321 342
@@ -371,8 +392,12 @@ connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq,
371 GNUNET_SCHEDULER_cancel (cstate->recv_task); 392 GNUNET_SCHEDULER_cancel (cstate->recv_task);
372 if (NULL != cstate->retry_task) 393 if (NULL != cstate->retry_task)
373 GNUNET_SCHEDULER_cancel (cstate->retry_task); 394 GNUNET_SCHEDULER_cancel (cstate->retry_task);
374 if (NULL != cstate->sock) 395 if (NULL != cstate->sock){
396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
397 "client: destroying socket: %p\n",
398 cstate->sock);
375 GNUNET_NETWORK_socket_close (cstate->sock); 399 GNUNET_NETWORK_socket_close (cstate->sock);
400 }
376 cancel_aps (cstate); 401 cancel_aps (cstate);
377 GNUNET_free (cstate->service_name); 402 GNUNET_free (cstate->service_name);
378 GNUNET_free_non_null (cstate->hostname); 403 GNUNET_free_non_null (cstate->hostname);
@@ -794,8 +819,12 @@ connection_client_send_impl (struct GNUNET_MQ_Handle *mq,
794 GNUNET_assert (NULL == cstate->send_task); 819 GNUNET_assert (NULL == cstate->send_task);
795 cstate->msg = msg; 820 cstate->msg = msg;
796 cstate->msg_off = 0; 821 cstate->msg_off = 0;
797 if (NULL == cstate->sock) 822 if (NULL == cstate->sock){
823 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
824 "client: message of type %u waiting for socket\n",
825 ntohs(msg->type));
798 return; /* still waiting for connection */ 826 return; /* still waiting for connection */
827 }
799 cstate->send_task 828 cstate->send_task
800 = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 829 = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
801 cstate->sock, 830 cstate->sock,
diff --git a/src/util/mq.c b/src/util/mq.c
index 90b2aa968..8d71359ac 100644
--- a/src/util/mq.c
+++ b/src/util/mq.c
@@ -357,6 +357,12 @@ GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq,
357 } 357 }
358 GNUNET_assert (NULL == mq->envelope_head); 358 GNUNET_assert (NULL == mq->envelope_head);
359 mq->current_envelope = ev; 359 mq->current_envelope = ev;
360
361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
362 "mq: sending message of type %u, queue empty (MQ: %p)\n",
363 ntohs(ev->mh->type),
364 mq);
365
360 mq->send_impl (mq, 366 mq->send_impl (mq,
361 ev->mh, 367 ev->mh,
362 mq->impl_state); 368 mq->impl_state);
@@ -452,6 +458,11 @@ impl_send_continue (void *cls)
452 GNUNET_CONTAINER_DLL_remove (mq->envelope_head, 458 GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
453 mq->envelope_tail, 459 mq->envelope_tail,
454 mq->current_envelope); 460 mq->current_envelope);
461
462 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
463 "mq: sending message of type %u from queue\n",
464 ntohs(mq->current_envelope->mh->type));
465
455 mq->send_impl (mq, 466 mq->send_impl (mq,
456 mq->current_envelope->mh, 467 mq->current_envelope->mh,
457 mq->impl_state); 468 mq->impl_state);
@@ -840,6 +851,9 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq)
840 ev); 851 ev);
841 GNUNET_assert (0 < mq->queue_length); 852 GNUNET_assert (0 < mq->queue_length);
842 mq->queue_length--; 853 mq->queue_length--;
854 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
855 "MQ destroy drops message of type %u\n",
856 ntohs (ev->mh->type));
843 GNUNET_MQ_discard (ev); 857 GNUNET_MQ_discard (ev);
844 } 858 }
845 if (NULL != mq->current_envelope) 859 if (NULL != mq->current_envelope)
@@ -847,6 +861,9 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq)
847 /* we can only discard envelopes that 861 /* we can only discard envelopes that
848 * are not queued! */ 862 * are not queued! */
849 mq->current_envelope->parent_queue = NULL; 863 mq->current_envelope->parent_queue = NULL;
864 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
865 "MQ destroy drops current message of type %u\n",
866 ntohs (mq->current_envelope->mh->type));
850 GNUNET_MQ_discard (mq->current_envelope); 867 GNUNET_MQ_discard (mq->current_envelope);
851 mq->current_envelope = NULL; 868 mq->current_envelope = NULL;
852 GNUNET_assert (0 < mq->queue_length); 869 GNUNET_assert (0 < mq->queue_length);
@@ -928,6 +945,11 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev)
928 GNUNET_CONTAINER_DLL_remove (mq->envelope_head, 945 GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
929 mq->envelope_tail, 946 mq->envelope_tail,
930 mq->current_envelope); 947 mq->current_envelope);
948
949 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
950 "mq: sending canceled message of type %u queue\n",
951 ntohs(ev->mh->type));
952
931 mq->send_impl (mq, 953 mq->send_impl (mq,
932 mq->current_envelope->mh, 954 mq->current_envelope->mh,
933 mq->impl_state); 955 mq->impl_state);
diff --git a/src/util/mst.c b/src/util/mst.c
index 0d90c5d10..5e472965f 100644
--- a/src/util/mst.c
+++ b/src/util/mst.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2010, 2016 GNUnet e.V. 3 Copyright (C) 2010, 2016, 2017 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -126,6 +126,7 @@ GNUNET_MST_from_buffer (struct GNUNET_MessageStreamTokenizer *mst,
126 int need_align; 126 int need_align;
127 unsigned long offset; 127 unsigned long offset;
128 int ret; 128 int ret;
129 int cbret;
129 130
130 GNUNET_assert (mst->off <= mst->pos); 131 GNUNET_assert (mst->off <= mst->pos);
131 GNUNET_assert (mst->pos <= mst->curr_buf); 132 GNUNET_assert (mst->pos <= mst->curr_buf);
@@ -229,9 +230,17 @@ do_align:
229 if (one_shot == GNUNET_YES) 230 if (one_shot == GNUNET_YES)
230 one_shot = GNUNET_SYSERR; 231 one_shot = GNUNET_SYSERR;
231 mst->off += want; 232 mst->off += want;
232 if (GNUNET_SYSERR == mst->cb (mst->cb_cls, 233 if (GNUNET_OK !=
233 hdr)) 234 (cbret = mst->cb (mst->cb_cls,
235 hdr)))
236 {
237 if (GNUNET_SYSERR == cbret)
238 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
239 "Failure processing message of type %u and size %u\n",
240 ntohs (hdr->type),
241 ntohs (hdr->size));
234 return GNUNET_SYSERR; 242 return GNUNET_SYSERR;
243 }
235 if (mst->off == mst->pos) 244 if (mst->off == mst->pos)
236 { 245 {
237 /* reset to beginning of buffer, it's free right now! */ 246 /* reset to beginning of buffer, it's free right now! */
@@ -271,9 +280,17 @@ do_align:
271 } 280 }
272 if (one_shot == GNUNET_YES) 281 if (one_shot == GNUNET_YES)
273 one_shot = GNUNET_SYSERR; 282 one_shot = GNUNET_SYSERR;
274 if (GNUNET_SYSERR == mst->cb (mst->cb_cls, 283 if (GNUNET_OK !=
275 hdr)) 284 (cbret = mst->cb (mst->cb_cls,
285 hdr)))
286 {
287 if (GNUNET_SYSERR == cbret)
288 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
289 "Failure processing message of type %u and size %u\n",
290 ntohs (hdr->type),
291 ntohs (hdr->size));
276 return GNUNET_SYSERR; 292 return GNUNET_SYSERR;
293 }
277 buf += want; 294 buf += want;
278 size -= want; 295 size -= want;
279 } 296 }
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index 540a60557..4615ecee9 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -589,9 +589,7 @@ static void
589dump_backtrace (struct GNUNET_SCHEDULER_Task *t) 589dump_backtrace (struct GNUNET_SCHEDULER_Task *t)
590{ 590{
591#if EXECINFO 591#if EXECINFO
592 unsigned int i; 592 for (unsigned int i = 0; i < t->num_backtrace_strings; i++)
593
594 for (i = 0; i < t->num_backtrace_strings; i++)
595 LOG (GNUNET_ERROR_TYPE_DEBUG, 593 LOG (GNUNET_ERROR_TYPE_DEBUG,
596 "Task %p trace %u: %s\n", 594 "Task %p trace %u: %s\n",
597 t, 595 t,
diff --git a/src/util/service.c b/src/util/service.c
index fcdf45a51..b4eb33caa 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -1932,6 +1932,11 @@ do_send (void *cls)
1932 size_t left; 1932 size_t left;
1933 const char *buf; 1933 const char *buf;
1934 1934
1935 LOG (GNUNET_ERROR_TYPE_DEBUG,
1936 "service: sending message with type %u",
1937 ntohs(client->msg->type));
1938
1939
1935 client->send_task = NULL; 1940 client->send_task = NULL;
1936 buf = (const char *) client->msg; 1941 buf = (const char *) client->msg;
1937 left = ntohs (client->msg->size) - client->msg_pos; 1942 left = ntohs (client->msg->size) - client->msg_pos;
@@ -1941,6 +1946,8 @@ do_send (void *cls)
1941 GNUNET_assert (ret <= (ssize_t) left); 1946 GNUNET_assert (ret <= (ssize_t) left);
1942 if (0 == ret) 1947 if (0 == ret)
1943 { 1948 {
1949 LOG (GNUNET_ERROR_TYPE_DEBUG,
1950 "no data send");
1944 GNUNET_MQ_inject_error (client->mq, 1951 GNUNET_MQ_inject_error (client->mq,
1945 GNUNET_MQ_ERROR_WRITE); 1952 GNUNET_MQ_ERROR_WRITE);
1946 return; 1953 return;
@@ -1958,6 +1965,9 @@ do_send (void *cls)
1958 if (EPIPE != errno) 1965 if (EPIPE != errno)
1959 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 1966 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
1960 "send"); 1967 "send");
1968 LOG (GNUNET_ERROR_TYPE_DEBUG,
1969 "socket send returned with error code %i",
1970 errno);
1961 GNUNET_MQ_inject_error (client->mq, 1971 GNUNET_MQ_inject_error (client->mq,
1962 GNUNET_MQ_ERROR_WRITE); 1972 GNUNET_MQ_ERROR_WRITE);
1963 return; 1973 return;
@@ -2402,7 +2412,7 @@ resume_client_receive (void *cls)
2402 GNUNET_YES); 2412 GNUNET_YES);
2403 if (GNUNET_SYSERR == ret) 2413 if (GNUNET_SYSERR == ret)
2404 { 2414 {
2405 if (NULL != c->drop_task) 2415 if (NULL == c->drop_task)
2406 GNUNET_SERVICE_client_drop (c); 2416 GNUNET_SERVICE_client_drop (c);
2407 return; 2417 return;
2408 } 2418 }
@@ -2431,6 +2441,7 @@ resume_client_receive (void *cls)
2431void 2441void
2432GNUNET_SERVICE_client_continue (struct GNUNET_SERVICE_Client *c) 2442GNUNET_SERVICE_client_continue (struct GNUNET_SERVICE_Client *c)
2433{ 2443{
2444 GNUNET_assert (NULL == c->drop_task);
2434 GNUNET_assert (GNUNET_YES == c->needs_continue); 2445 GNUNET_assert (GNUNET_YES == c->needs_continue);
2435 GNUNET_assert (NULL == c->recv_task); 2446 GNUNET_assert (NULL == c->recv_task);
2436 c->needs_continue = GNUNET_NO; 2447 c->needs_continue = GNUNET_NO;
@@ -2513,6 +2524,24 @@ GNUNET_SERVICE_client_drop (struct GNUNET_SERVICE_Client *c)
2513{ 2524{
2514 struct GNUNET_SERVICE_Handle *sh = c->sh; 2525 struct GNUNET_SERVICE_Handle *sh = c->sh;
2515 2526
2527 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2528 "Client dropped: %p (MQ: %p)\n",
2529 c,
2530 c->mq);
2531
2532#if EXECINFO
2533 void *backtrace_array[MAX_TRACE_DEPTH];
2534 int num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
2535 char **backtrace_strings =
2536 backtrace_symbols (backtrace_array,
2537 t->num_backtrace_strings);
2538 for (unsigned int i = 0; i < num_backtrace_strings; i++)
2539 LOG (GNUNET_ERROR_TYPE_DEBUG,
2540 "client drop trace %u: %s\n",
2541 i,
2542 backtrace_strings[i]);
2543#endif
2544
2516 if (NULL != c->drop_task) 2545 if (NULL != c->drop_task)
2517 { 2546 {
2518 /* asked to drop twice! */ 2547 /* asked to drop twice! */
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c
index d9daaa7e2..bdc638176 100644
--- a/src/vpn/gnunet-service-vpn.c
+++ b/src/vpn/gnunet-service-vpn.c
@@ -2218,6 +2218,9 @@ route_packet (struct DestinationEntry *destination,
2218 * 2218 *
2219 * @param cls closure, NULL 2219 * @param cls closure, NULL
2220 * @param message message we got from the client (VPN channel interface) 2220 * @param message message we got from the client (VPN channel interface)
2221 * @return #GNUNET_OK on success,
2222 * #GNUNET_NO to stop further processing (no error)
2223 * #GNUNET_SYSERR to stop further processing with error
2221 */ 2224 */
2222static int 2225static int
2223message_token (void *cls, 2226message_token (void *cls,