diff options
Diffstat (limited to 'src/rps/gnunet-service-rps.c')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 122 |
1 files changed, 67 insertions, 55 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 1b9681663..84fb33be2 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -243,7 +243,7 @@ struct PeerContext | |||
243 | 243 | ||
244 | /** | 244 | /** |
245 | * This is pobably followed by 'statistical' data (when we first saw | 245 | * This is pobably followed by 'statistical' data (when we first saw |
246 | * him, how did we get his ID, how many pushes (in a timeinterval), | 246 | * it, how did we get its ID, how many pushes (in a timeinterval), |
247 | * ...) | 247 | * ...) |
248 | */ | 248 | */ |
249 | }; | 249 | }; |
@@ -503,6 +503,8 @@ add_valid_peer (const struct GNUNET_PeerIdentity *peer) | |||
503 | return ret; | 503 | return ret; |
504 | } | 504 | } |
505 | 505 | ||
506 | static void | ||
507 | remove_pending_message (struct PendingMessage *pending_msg, int cancel); | ||
506 | 508 | ||
507 | /** | 509 | /** |
508 | * @brief Set the peer flag to living and | 510 | * @brief Set the peer flag to living and |
@@ -531,7 +533,7 @@ set_peer_live (struct PeerContext *peer_ctx) | |||
531 | GNUNET_i2s (&peer_ctx->peer_id)); | 533 | GNUNET_i2s (&peer_ctx->peer_id)); |
532 | // TODO wait until cadet sets mq->cancel_impl | 534 | // TODO wait until cadet sets mq->cancel_impl |
533 | //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev); | 535 | //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev); |
534 | GNUNET_free (peer_ctx->liveliness_check_pending); | 536 | remove_pending_message (peer_ctx->liveliness_check_pending, GNUNET_YES); |
535 | peer_ctx->liveliness_check_pending = NULL; | 537 | peer_ctx->liveliness_check_pending = NULL; |
536 | } | 538 | } |
537 | 539 | ||
@@ -653,56 +655,6 @@ get_mq (const struct GNUNET_PeerIdentity *peer) | |||
653 | return peer_ctx->mq; | 655 | return peer_ctx->mq; |
654 | } | 656 | } |
655 | 657 | ||
656 | |||
657 | /** | ||
658 | * @brief This is called in response to the first message we sent as a | ||
659 | * liveliness check. | ||
660 | * | ||
661 | * @param cls #PeerContext of peer with pending liveliness check | ||
662 | */ | ||
663 | static void | ||
664 | mq_liveliness_check_successful (void *cls) | ||
665 | { | ||
666 | struct PeerContext *peer_ctx = cls; | ||
667 | |||
668 | if (NULL != peer_ctx->liveliness_check_pending) | ||
669 | { | ||
670 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
671 | "Liveliness check for peer %s was successfull\n", | ||
672 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
673 | GNUNET_free (peer_ctx->liveliness_check_pending); | ||
674 | peer_ctx->liveliness_check_pending = NULL; | ||
675 | set_peer_live (peer_ctx); | ||
676 | } | ||
677 | } | ||
678 | |||
679 | /** | ||
680 | * Issue a check whether peer is live | ||
681 | * | ||
682 | * @param peer_ctx the context of the peer | ||
683 | */ | ||
684 | static void | ||
685 | check_peer_live (struct PeerContext *peer_ctx) | ||
686 | { | ||
687 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
688 | "Get informed about peer %s getting live\n", | ||
689 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
690 | |||
691 | struct GNUNET_MQ_Handle *mq; | ||
692 | struct GNUNET_MQ_Envelope *ev; | ||
693 | |||
694 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE); | ||
695 | peer_ctx->liveliness_check_pending = GNUNET_new (struct PendingMessage); | ||
696 | peer_ctx->liveliness_check_pending->ev = ev; | ||
697 | peer_ctx->liveliness_check_pending->peer_ctx = peer_ctx; | ||
698 | peer_ctx->liveliness_check_pending->type = "Check liveliness"; | ||
699 | mq = get_mq (&peer_ctx->peer_id); | ||
700 | GNUNET_MQ_notify_sent (ev, | ||
701 | mq_liveliness_check_successful, | ||
702 | peer_ctx); | ||
703 | GNUNET_MQ_send (mq, ev); | ||
704 | } | ||
705 | |||
706 | /** | 658 | /** |
707 | * @brief Add an envelope to a message passed to mq to list of pending messages | 659 | * @brief Add an envelope to a message passed to mq to list of pending messages |
708 | * | 660 | * |
@@ -757,6 +709,54 @@ remove_pending_message (struct PendingMessage *pending_msg, int cancel) | |||
757 | 709 | ||
758 | 710 | ||
759 | /** | 711 | /** |
712 | * @brief This is called in response to the first message we sent as a | ||
713 | * liveliness check. | ||
714 | * | ||
715 | * @param cls #PeerContext of peer with pending liveliness check | ||
716 | */ | ||
717 | static void | ||
718 | mq_liveliness_check_successful (void *cls) | ||
719 | { | ||
720 | struct PeerContext *peer_ctx = cls; | ||
721 | |||
722 | if (NULL != peer_ctx->liveliness_check_pending) | ||
723 | { | ||
724 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
725 | "Liveliness check for peer %s was successfull\n", | ||
726 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
727 | remove_pending_message (peer_ctx->liveliness_check_pending, GNUNET_YES); | ||
728 | peer_ctx->liveliness_check_pending = NULL; | ||
729 | set_peer_live (peer_ctx); | ||
730 | } | ||
731 | } | ||
732 | |||
733 | /** | ||
734 | * Issue a check whether peer is live | ||
735 | * | ||
736 | * @param peer_ctx the context of the peer | ||
737 | */ | ||
738 | static void | ||
739 | check_peer_live (struct PeerContext *peer_ctx) | ||
740 | { | ||
741 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
742 | "Get informed about peer %s getting live\n", | ||
743 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
744 | |||
745 | struct GNUNET_MQ_Handle *mq; | ||
746 | struct GNUNET_MQ_Envelope *ev; | ||
747 | |||
748 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE); | ||
749 | peer_ctx->liveliness_check_pending = | ||
750 | insert_pending_message (&peer_ctx->peer_id, ev, "Check liveliness"); | ||
751 | mq = get_mq (&peer_ctx->peer_id); | ||
752 | GNUNET_MQ_notify_sent (ev, | ||
753 | mq_liveliness_check_successful, | ||
754 | peer_ctx); | ||
755 | GNUNET_MQ_send (mq, ev); | ||
756 | } | ||
757 | |||
758 | |||
759 | /** | ||
760 | * @brief Check whether function of type #PeerOp was already scheduled | 760 | * @brief Check whether function of type #PeerOp was already scheduled |
761 | * | 761 | * |
762 | * The array with pending operations will probably never grow really big, so | 762 | * The array with pending operations will probably never grow really big, so |
@@ -1256,6 +1256,13 @@ Peers_remove_peer (const struct GNUNET_PeerIdentity *peer) | |||
1256 | "Removing unsent %s\n", | 1256 | "Removing unsent %s\n", |
1257 | peer_ctx->pending_messages_head->type); | 1257 | peer_ctx->pending_messages_head->type); |
1258 | /* Cancle pending message, too */ | 1258 | /* Cancle pending message, too */ |
1259 | if ( (NULL != peer_ctx->liveliness_check_pending) && | ||
1260 | (0 == memcmp (peer_ctx->pending_messages_head, | ||
1261 | peer_ctx->liveliness_check_pending, | ||
1262 | sizeof (struct PendingMessage))) ) | ||
1263 | { | ||
1264 | peer_ctx->liveliness_check_pending = NULL; | ||
1265 | } | ||
1259 | remove_pending_message (peer_ctx->pending_messages_head, GNUNET_YES); | 1266 | remove_pending_message (peer_ctx->pending_messages_head, GNUNET_YES); |
1260 | } | 1267 | } |
1261 | /* If we are still waiting for notification whether this peer is live | 1268 | /* If we are still waiting for notification whether this peer is live |
@@ -1267,7 +1274,7 @@ Peers_remove_peer (const struct GNUNET_PeerIdentity *peer) | |||
1267 | GNUNET_i2s (&peer_ctx->peer_id)); | 1274 | GNUNET_i2s (&peer_ctx->peer_id)); |
1268 | // TODO wait until cadet sets mq->cancel_impl | 1275 | // TODO wait until cadet sets mq->cancel_impl |
1269 | //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev); | 1276 | //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev); |
1270 | GNUNET_free (peer_ctx->liveliness_check_pending); | 1277 | remove_pending_message (peer_ctx->liveliness_check_pending, GNUNET_YES); |
1271 | peer_ctx->liveliness_check_pending = NULL; | 1278 | peer_ctx->liveliness_check_pending = NULL; |
1272 | } | 1279 | } |
1273 | channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_SENDING); | 1280 | channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_SENDING); |
@@ -2728,7 +2735,7 @@ cleanup_destroyed_channel (void *cls, | |||
2728 | return; | 2735 | return; |
2729 | } | 2736 | } |
2730 | else | 2737 | else |
2731 | { /* Other peer destroyed our sending channel that he is supposed to keep | 2738 | { /* Other peer destroyed our sending channel that it is supposed to keep |
2732 | * open. It probably went down. Remove it from our knowledge. */ | 2739 | * open. It probably went down. Remove it from our knowledge. */ |
2733 | Peers_cleanup_destroyed_channel (cls, channel); | 2740 | Peers_cleanup_destroyed_channel (cls, channel); |
2734 | remove_peer (peer); | 2741 | remove_peer (peer); |
@@ -2893,7 +2900,6 @@ client_respond (void *cls, | |||
2893 | GNUNET_memcpy (&out_msg[1], | 2900 | GNUNET_memcpy (&out_msg[1], |
2894 | peer_ids, | 2901 | peer_ids, |
2895 | num_peers * sizeof (struct GNUNET_PeerIdentity)); | 2902 | num_peers * sizeof (struct GNUNET_PeerIdentity)); |
2896 | GNUNET_free (peer_ids); | ||
2897 | 2903 | ||
2898 | cli_ctx = reply_cls->cli_ctx; | 2904 | cli_ctx = reply_cls->cli_ctx; |
2899 | GNUNET_assert (NULL != cli_ctx); | 2905 | GNUNET_assert (NULL != cli_ctx); |
@@ -3210,6 +3216,10 @@ handle_peer_push (void *cls, | |||
3210 | tmp_att_peer); | 3216 | tmp_att_peer); |
3211 | add_peer_array_to_set (peer, 1, att_peer_set); | 3217 | add_peer_array_to_set (peer, 1, att_peer_set); |
3212 | } | 3218 | } |
3219 | else | ||
3220 | { | ||
3221 | GNUNET_free (tmp_att_peer); | ||
3222 | } | ||
3213 | } | 3223 | } |
3214 | 3224 | ||
3215 | 3225 | ||
@@ -3588,6 +3598,7 @@ handle_client_act_malicious (void *cls, | |||
3588 | 3598 | ||
3589 | num_mal_peers_sent = ntohl (msg->num_peers) - 1; | 3599 | num_mal_peers_sent = ntohl (msg->num_peers) - 1; |
3590 | num_mal_peers_old = num_mal_peers; | 3600 | num_mal_peers_old = num_mal_peers; |
3601 | GNUNET_assert (GNUNET_MAX_MALLOC_CHECKED > num_mal_peers_sent); | ||
3591 | GNUNET_array_grow (mal_peers, | 3602 | GNUNET_array_grow (mal_peers, |
3592 | num_mal_peers, | 3603 | num_mal_peers, |
3593 | num_mal_peers + num_mal_peers_sent); | 3604 | num_mal_peers + num_mal_peers_sent); |
@@ -4172,6 +4183,7 @@ shutdown_task (void *cls) | |||
4172 | { | 4183 | { |
4173 | tmp_att_peer = att_peers_head; | 4184 | tmp_att_peer = att_peers_head; |
4174 | GNUNET_CONTAINER_DLL_remove (att_peers_head, att_peers_tail, tmp_att_peer); | 4185 | GNUNET_CONTAINER_DLL_remove (att_peers_head, att_peers_tail, tmp_att_peer); |
4186 | GNUNET_free (tmp_att_peer); | ||
4175 | } | 4187 | } |
4176 | #endif /* ENABLE_MALICIOUS */ | 4188 | #endif /* ENABLE_MALICIOUS */ |
4177 | } | 4189 | } |