diff options
Diffstat (limited to 'src/psyc')
-rw-r--r-- | src/psyc/gnunet-service-psyc.c | 72 | ||||
-rw-r--r-- | src/psyc/psyc_api.c | 82 |
2 files changed, 111 insertions, 43 deletions
diff --git a/src/psyc/gnunet-service-psyc.c b/src/psyc/gnunet-service-psyc.c index 73a3ae4ee..8af3264fd 100644 --- a/src/psyc/gnunet-service-psyc.c +++ b/src/psyc/gnunet-service-psyc.c | |||
@@ -508,8 +508,8 @@ 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) | 511 | //if (NULL != mst->origin) |
512 | GNUNET_MULTICAST_origin_stop (mst->origin, NULL, NULL); // FIXME | 512 | // GNUNET_MULTICAST_origin_stop (mst->origin, cleanup_cb, cleanup_cls); |
513 | GNUNET_CONTAINER_multihashmap_destroy (mst->join_reqs); | 513 | GNUNET_CONTAINER_multihashmap_destroy (mst->join_reqs); |
514 | GNUNET_CONTAINER_multihashmap_remove (masters, &chn->pub_key_hash, mst); | 514 | GNUNET_CONTAINER_multihashmap_remove (masters, &chn->pub_key_hash, mst); |
515 | } | 515 | } |
@@ -546,11 +546,11 @@ cleanup_slave (struct Slave *slv) | |||
546 | GNUNET_free (slv->relays); | 546 | GNUNET_free (slv->relays); |
547 | slv->relays = NULL; | 547 | slv->relays = NULL; |
548 | } | 548 | } |
549 | if (NULL != slv->member) | 549 | //if (NULL != slv->member) |
550 | { | 550 | //{ |
551 | GNUNET_MULTICAST_member_part (slv->member, NULL, NULL); // FIXME | 551 | // GNUNET_MULTICAST_member_part (slv->member, cleanup_cb, cleanup_cls); |
552 | slv->member = NULL; | 552 | // slv->member = NULL; |
553 | } | 553 | //} |
554 | GNUNET_CONTAINER_multihashmap_remove (slaves, &chn->pub_key_hash, slv); | 554 | GNUNET_CONTAINER_multihashmap_remove (slaves, &chn->pub_key_hash, slv); |
555 | } | 555 | } |
556 | 556 | ||
@@ -646,14 +646,15 @@ client_notify_disconnect (void *cls, | |||
646 | (GNUNET_YES == chn->is_master) ? "master" : "slave", | 646 | (GNUNET_YES == chn->is_master) ? "master" : "slave", |
647 | GNUNET_h2s (&chn->pub_key_hash)); | 647 | GNUNET_h2s (&chn->pub_key_hash)); |
648 | chn->is_disconnected = GNUNET_YES; | 648 | chn->is_disconnected = GNUNET_YES; |
649 | if (NULL != chn->tmit_head) | 649 | cleanup_channel (chn); |
650 | { /* Send pending messages to multicast before cleanup. */ | 650 | //if (NULL != chn->tmit_head) |
651 | transmit_message (chn); | 651 | //{ /* Send pending messages to multicast before cleanup. */ |
652 | } | 652 | // transmit_message (chn); |
653 | else | 653 | //} |
654 | { | 654 | //else |
655 | cleanup_channel (chn); | 655 | //{ |
656 | } | 656 | // cleanup_channel (chn); |
657 | //} | ||
657 | } | 658 | } |
658 | } | 659 | } |
659 | 660 | ||
@@ -2037,6 +2038,43 @@ handle_client_join_decision (void *cls, | |||
2037 | } | 2038 | } |
2038 | 2039 | ||
2039 | 2040 | ||
2041 | static void | ||
2042 | channel_part_cb (void *cls) | ||
2043 | { | ||
2044 | struct GNUNET_SERVICE_Client *client = cls; | ||
2045 | struct GNUNET_MQ_Envelope *env; | ||
2046 | |||
2047 | env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_PSYC_PART_ACK); | ||
2048 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | ||
2049 | env); | ||
2050 | } | ||
2051 | |||
2052 | |||
2053 | static void | ||
2054 | handle_client_part_request (void *cls, | ||
2055 | const struct GNUNET_MessageHeader *msg) | ||
2056 | { | ||
2057 | struct Client *c = cls; | ||
2058 | |||
2059 | if (GNUNET_YES == c->channel->is_master) | ||
2060 | { | ||
2061 | struct Master *mst = (struct Master *) c->channel; | ||
2062 | |||
2063 | GNUNET_assert (NULL != mst->origin); | ||
2064 | GNUNET_MULTICAST_origin_stop (mst->origin, channel_part_cb, c->client); | ||
2065 | mst->origin = NULL; | ||
2066 | } | ||
2067 | else | ||
2068 | { | ||
2069 | struct Slave *slv = (struct Slave *) c->channel; | ||
2070 | |||
2071 | GNUNET_assert (NULL != slv->member); | ||
2072 | GNUNET_MULTICAST_member_part (slv->member, channel_part_cb, c->client); | ||
2073 | slv->member = NULL; | ||
2074 | } | ||
2075 | } | ||
2076 | |||
2077 | |||
2040 | /** | 2078 | /** |
2041 | * Send acknowledgement to a client. | 2079 | * Send acknowledgement to a client. |
2042 | * | 2080 | * |
@@ -2805,6 +2843,10 @@ GNUNET_SERVICE_MAIN | |||
2805 | GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION, | 2843 | GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION, |
2806 | struct GNUNET_PSYC_JoinDecisionMessage, | 2844 | struct GNUNET_PSYC_JoinDecisionMessage, |
2807 | NULL), | 2845 | NULL), |
2846 | GNUNET_MQ_hd_fixed_size (client_part_request, | ||
2847 | GNUNET_MESSAGE_TYPE_PSYC_PART_REQUEST, | ||
2848 | struct GNUNET_MessageHeader, | ||
2849 | NULL), | ||
2808 | GNUNET_MQ_hd_var_size (client_psyc_message, | 2850 | GNUNET_MQ_hd_var_size (client_psyc_message, |
2809 | GNUNET_MESSAGE_TYPE_PSYC_MESSAGE, | 2851 | GNUNET_MESSAGE_TYPE_PSYC_MESSAGE, |
2810 | struct GNUNET_MessageHeader, | 2852 | struct GNUNET_MessageHeader, |
diff --git a/src/psyc/psyc_api.c b/src/psyc/psyc_api.c index e7790d201..cdb9ce881 100644 --- a/src/psyc/psyc_api.c +++ b/src/psyc/psyc_api.c | |||
@@ -555,6 +555,10 @@ handle_slave_join_decision (void *cls, | |||
555 | static void | 555 | static void |
556 | channel_cleanup (struct GNUNET_PSYC_Channel *chn) | 556 | channel_cleanup (struct GNUNET_PSYC_Channel *chn) |
557 | { | 557 | { |
558 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
559 | "cleaning up channel %p\n", | ||
560 | chn); | ||
561 | GNUNET_assert (0); | ||
558 | if (NULL != chn->tmit) | 562 | if (NULL != chn->tmit) |
559 | { | 563 | { |
560 | GNUNET_PSYC_transmit_destroy (chn->tmit); | 564 | GNUNET_PSYC_transmit_destroy (chn->tmit); |
@@ -585,33 +589,43 @@ channel_cleanup (struct GNUNET_PSYC_Channel *chn) | |||
585 | 589 | ||
586 | 590 | ||
587 | static void | 591 | static void |
588 | channel_disconnect (struct GNUNET_PSYC_Channel *chn, | 592 | handle_channel_part_ack (void *cls, |
589 | GNUNET_ContinuationCallback cb, | 593 | const struct GNUNET_MessageHeader *msg) |
590 | void *cls) | ||
591 | { | 594 | { |
592 | chn->is_disconnecting = GNUNET_YES; | 595 | struct GNUNET_PSYC_Channel *chn = cls; |
593 | chn->disconnect_cb = cb; | ||
594 | chn->disconnect_cls = cls; | ||
595 | 596 | ||
596 | if (NULL != chn->mq) | 597 | 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 | } | 598 | } |
613 | 599 | ||
614 | 600 | ||
601 | //static void | ||
602 | //channel_disconnect (struct GNUNET_PSYC_Channel *chn, | ||
603 | // GNUNET_ContinuationCallback cb, | ||
604 | // void *cls) | ||
605 | //{ | ||
606 | // chn->is_disconnecting = GNUNET_YES; | ||
607 | // chn->disconnect_cb = cb; | ||
608 | // chn->disconnect_cls = cls; | ||
609 | // | ||
610 | // if (NULL != chn->mq) | ||
611 | // { | ||
612 | // struct GNUNET_MQ_Envelope *env = GNUNET_MQ_get_last_envelope (chn->mq); | ||
613 | // if (NULL != env) | ||
614 | // { | ||
615 | // GNUNET_MQ_notify_sent (env, (GNUNET_SCHEDULER_TaskCallback) channel_cleanup, chn); | ||
616 | // } | ||
617 | // else | ||
618 | // { | ||
619 | // channel_cleanup (chn); | ||
620 | // } | ||
621 | // } | ||
622 | // else | ||
623 | // { | ||
624 | // channel_cleanup (chn); | ||
625 | // } | ||
626 | //} | ||
627 | |||
628 | |||
615 | /*** MASTER ***/ | 629 | /*** MASTER ***/ |
616 | 630 | ||
617 | 631 | ||
@@ -671,6 +685,10 @@ master_connect (struct GNUNET_PSYC_Master *mst) | |||
671 | GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST, | 685 | GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST, |
672 | struct GNUNET_PSYC_JoinRequestMessage, | 686 | struct GNUNET_PSYC_JoinRequestMessage, |
673 | mst), | 687 | mst), |
688 | GNUNET_MQ_hd_fixed_size (channel_part_ack, | ||
689 | GNUNET_MESSAGE_TYPE_PSYC_PART_ACK, | ||
690 | struct GNUNET_MessageHeader, | ||
691 | chn), | ||
674 | GNUNET_MQ_hd_var_size (channel_message, | 692 | GNUNET_MQ_hd_var_size (channel_message, |
675 | GNUNET_MESSAGE_TYPE_PSYC_MESSAGE, | 693 | GNUNET_MESSAGE_TYPE_PSYC_MESSAGE, |
676 | struct GNUNET_PSYC_MessageHeader, | 694 | struct GNUNET_PSYC_MessageHeader, |
@@ -780,10 +798,12 @@ GNUNET_PSYC_master_stop (struct GNUNET_PSYC_Master *mst, | |||
780 | void *stop_cls) | 798 | void *stop_cls) |
781 | { | 799 | { |
782 | struct GNUNET_PSYC_Channel *chn = &mst->chn; | 800 | struct GNUNET_PSYC_Channel *chn = &mst->chn; |
801 | struct GNUNET_MQ_Envelope *env; | ||
783 | 802 | ||
784 | /* FIXME: send msg to service */ | 803 | chn->disconnect_cb = stop_cb; |
785 | 804 | chn->disconnect_cls = stop_cls; | |
786 | channel_disconnect (chn, stop_cb, stop_cls); | 805 | env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_PSYC_PART_REQUEST); |
806 | GNUNET_MQ_send (chn->mq, env); | ||
787 | } | 807 | } |
788 | 808 | ||
789 | 809 | ||
@@ -971,6 +991,10 @@ slave_connect (struct GNUNET_PSYC_Slave *slv) | |||
971 | GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION, | 991 | GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION, |
972 | struct GNUNET_PSYC_JoinDecisionMessage, | 992 | struct GNUNET_PSYC_JoinDecisionMessage, |
973 | slv), | 993 | slv), |
994 | GNUNET_MQ_hd_fixed_size (channel_part_ack, | ||
995 | GNUNET_MESSAGE_TYPE_PSYC_PART_ACK, | ||
996 | struct GNUNET_MessageHeader, | ||
997 | chn), | ||
974 | GNUNET_MQ_hd_var_size (channel_message, | 998 | GNUNET_MQ_hd_var_size (channel_message, |
975 | GNUNET_MESSAGE_TYPE_PSYC_MESSAGE, | 999 | GNUNET_MESSAGE_TYPE_PSYC_MESSAGE, |
976 | struct GNUNET_PSYC_MessageHeader, | 1000 | struct GNUNET_PSYC_MessageHeader, |
@@ -1118,10 +1142,12 @@ GNUNET_PSYC_slave_part (struct GNUNET_PSYC_Slave *slv, | |||
1118 | void *part_cls) | 1142 | void *part_cls) |
1119 | { | 1143 | { |
1120 | struct GNUNET_PSYC_Channel *chn = &slv->chn; | 1144 | struct GNUNET_PSYC_Channel *chn = &slv->chn; |
1145 | struct GNUNET_MQ_Envelope *env; | ||
1121 | 1146 | ||
1122 | /* FIXME: send msg to service */ | 1147 | chn->disconnect_cb = part_cb; |
1123 | 1148 | chn->disconnect_cls = part_cls; | |
1124 | channel_disconnect (chn, part_cb, part_cls); | 1149 | env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_PSYC_PART_REQUEST); |
1150 | GNUNET_MQ_send (chn->mq, env); | ||
1125 | } | 1151 | } |
1126 | 1152 | ||
1127 | 1153 | ||