diff options
author | Julius Bünger <buenger@mytum.de> | 2016-08-22 13:42:27 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2016-08-22 13:42:27 +0000 |
commit | fc3c65152a52aab6951b37e7d462aa9627a668a1 (patch) | |
tree | a8ed13a744fa21683cc16d602027bec14cc13cc8 /src/rps | |
parent | 43c73b22d65bb24511f7aa9c9168b4ff2e8d4d56 (diff) | |
download | gnunet-fc3c65152a52aab6951b37e7d462aa9627a668a1.tar.gz gnunet-fc3c65152a52aab6951b37e7d462aa9627a668a1.zip |
-rps fix: change way of online notification
Diffstat (limited to 'src/rps')
-rw-r--r-- | src/rps/gnunet-service-rps_peers.c | 128 |
1 files changed, 47 insertions, 81 deletions
diff --git a/src/rps/gnunet-service-rps_peers.c b/src/rps/gnunet-service-rps_peers.c index 665061dc0..0a8c48806 100644 --- a/src/rps/gnunet-service-rps_peers.c +++ b/src/rps/gnunet-service-rps_peers.c | |||
@@ -164,7 +164,7 @@ struct PeerContext | |||
164 | * | 164 | * |
165 | * To be canceled on shutdown. | 165 | * To be canceled on shutdown. |
166 | */ | 166 | */ |
167 | struct GNUNET_CADET_TransmitHandle *transmit_handle; | 167 | struct PendingMessage *liveliness_check_pending; |
168 | 168 | ||
169 | /** | 169 | /** |
170 | * Number of pending operations. | 170 | * Number of pending operations. |
@@ -471,21 +471,26 @@ set_peer_live (struct PeerContext *peer_ctx) | |||
471 | struct GNUNET_PeerIdentity *peer; | 471 | struct GNUNET_PeerIdentity *peer; |
472 | unsigned int i; | 472 | unsigned int i; |
473 | 473 | ||
474 | /* Cancle cadet transmit_handle if still scheduled */ | ||
475 | if (NULL != peer_ctx->transmit_handle) | ||
476 | { | ||
477 | GNUNET_CADET_notify_transmit_ready_cancel (peer_ctx->transmit_handle); | ||
478 | peer_ctx->transmit_handle = NULL; | ||
479 | } | ||
480 | |||
481 | peer = &peer_ctx->peer_id; | 474 | peer = &peer_ctx->peer_id; |
482 | (void) add_valid_peer (peer); | ||
483 | set_peer_flag (peer_ctx, Peers_ONLINE); | ||
484 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 475 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
485 | "Peer %s is live and valid, calling %i pending operations on it\n", | 476 | "Peer %s is live and valid, calling %i pending operations on it\n", |
486 | GNUNET_i2s (peer), | 477 | GNUNET_i2s (peer), |
487 | peer_ctx->num_pending_ops); | 478 | peer_ctx->num_pending_ops); |
488 | 479 | ||
480 | if (NULL != peer_ctx->liveliness_check_pending) | ||
481 | { | ||
482 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
483 | "Removing pending liveliness check for peer %s\n", | ||
484 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
485 | // TODO wait until cadet sets mq->cancel_impl | ||
486 | //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev); | ||
487 | GNUNET_free (peer_ctx->liveliness_check_pending); | ||
488 | peer_ctx->liveliness_check_pending = NULL; | ||
489 | } | ||
490 | |||
491 | (void) add_valid_peer (peer); | ||
492 | set_peer_flag (peer_ctx, Peers_ONLINE); | ||
493 | |||
489 | /* Call pending operations */ | 494 | /* Call pending operations */ |
490 | for (i = 0; i < peer_ctx->num_pending_ops; i++) | 495 | for (i = 0; i < peer_ctx->num_pending_ops; i++) |
491 | { | 496 | { |
@@ -543,7 +548,6 @@ get_mq (const struct GNUNET_PeerIdentity *peer) | |||
543 | struct PeerContext *peer_ctx; | 548 | struct PeerContext *peer_ctx; |
544 | 549 | ||
545 | peer_ctx = get_peer_ctx (peer); | 550 | peer_ctx = get_peer_ctx (peer); |
546 | GNUNET_assert (NULL == peer_ctx->transmit_handle); | ||
547 | 551 | ||
548 | if (NULL == peer_ctx->mq) | 552 | if (NULL == peer_ctx->mq) |
549 | { | 553 | { |
@@ -553,52 +557,27 @@ get_mq (const struct GNUNET_PeerIdentity *peer) | |||
553 | return peer_ctx->mq; | 557 | return peer_ctx->mq; |
554 | } | 558 | } |
555 | 559 | ||
560 | |||
556 | /** | 561 | /** |
557 | * @brief Callback that is called when a channel was effectively established. | 562 | * @brief This is called in response to the first message we sent as a |
558 | * | 563 | * liveliness check. |
559 | * This is an implementation of #GNUNET_CONNECTION_TransmitReadyNotify and | ||
560 | * given to #GNUNET_CADET_notify_transmit_ready_cancel and called when the | ||
561 | * channel was successfully established. | ||
562 | * | 564 | * |
563 | * This function type was originally ment to be called to provide the data to | 565 | * @param cls #PeerContext of peer with pending liveliness check |
564 | * be sent. This is called when the connection is ready to queue more data. | ||
565 | * However we use it to get notified about the successful establishement of a | ||
566 | * cadet channel. | ||
567 | * | ||
568 | * @a buf will be NULL and @a size zero if the | ||
569 | * connection was closed for writing in the meantime. | ||
570 | * | ||
571 | * @param cls closure | ||
572 | * @param size number of bytes available in @a buf | ||
573 | * @param buf where the callee should write the message | ||
574 | * @return number of bytes written to @a buf | ||
575 | */ | 566 | */ |
576 | //TODO | 567 | static void |
577 | static size_t | 568 | mq_liveliness_check_successful (void *cls) |
578 | cadet_notify_transmit_ready_cb (void *cls, size_t size, void *buf) | ||
579 | { | 569 | { |
580 | struct PeerContext *peer_ctx = (struct PeerContext *) cls; | 570 | struct PeerContext *peer_ctx = cls; |
581 | // TODO make sure the context is not deleted or the establishing of the | ||
582 | // channel is cancelled | ||
583 | 571 | ||
584 | peer_ctx->transmit_handle = NULL; | 572 | if (NULL != peer_ctx->liveliness_check_pending) |
585 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
586 | "Set ->transmit_handle = NULL for peer %s\n", | ||
587 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
588 | |||
589 | if ( (NULL != buf) && | ||
590 | (0 != size) ) | ||
591 | { | 573 | { |
574 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
575 | "Liveliness check for peer %s was successfull\n", | ||
576 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
577 | GNUNET_free (peer_ctx->liveliness_check_pending); | ||
578 | peer_ctx->liveliness_check_pending = NULL; | ||
592 | set_peer_live (peer_ctx); | 579 | set_peer_live (peer_ctx); |
593 | } | 580 | } |
594 | else | ||
595 | { | ||
596 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
597 | "Problems establishing a connection to peer %s in order to check liveliness\n", | ||
598 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
599 | // TODO reschedule? cleanup? | ||
600 | } | ||
601 | return 0; | ||
602 | } | 581 | } |
603 | 582 | ||
604 | /** | 583 | /** |
@@ -613,32 +592,19 @@ check_peer_live (struct PeerContext *peer_ctx) | |||
613 | "Get informed about peer %s getting live\n", | 592 | "Get informed about peer %s getting live\n", |
614 | GNUNET_i2s (&peer_ctx->peer_id)); | 593 | GNUNET_i2s (&peer_ctx->peer_id)); |
615 | 594 | ||
616 | if (NULL != peer_ctx->transmit_handle) | 595 | struct GNUNET_MQ_Handle *mq; |
617 | { | 596 | struct GNUNET_MQ_Envelope *ev; |
618 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 597 | |
619 | "Already waiting for notification\n"); | 598 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE); |
620 | return; | 599 | peer_ctx->liveliness_check_pending = GNUNET_new (struct PendingMessage); |
621 | } | 600 | peer_ctx->liveliness_check_pending->ev = ev; |
622 | if (NULL != peer_ctx->send_channel) | 601 | peer_ctx->liveliness_check_pending->peer_ctx = peer_ctx; |
623 | { | 602 | peer_ctx->liveliness_check_pending->type = "Check liveliness"; |
624 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 603 | mq = get_mq (&peer_ctx->peer_id); |
625 | "Already have established channel to peer\n"); | 604 | GNUNET_MQ_notify_sent (ev, |
626 | return; | 605 | mq_liveliness_check_successful, |
627 | } | 606 | peer_ctx); |
628 | (void) get_channel (&peer_ctx->peer_id); | 607 | GNUNET_MQ_send (mq, ev); |
629 | peer_ctx->transmit_handle = | ||
630 | GNUNET_CADET_notify_transmit_ready (peer_ctx->send_channel, | ||
631 | GNUNET_NO, | ||
632 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
633 | sizeof (struct GNUNET_MessageHeader), | ||
634 | cadet_notify_transmit_ready_cb, | ||
635 | peer_ctx); | ||
636 | if (NULL == peer_ctx->transmit_handle) | ||
637 | { | ||
638 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
639 | "Cadet was not able to queue the request (insufficient memory)\n"); | ||
640 | GNUNET_break (0); | ||
641 | } | ||
642 | } | 608 | } |
643 | 609 | ||
644 | /** | 610 | /** |
@@ -1155,8 +1121,6 @@ Peers_remove_peer (const struct GNUNET_PeerIdentity *peer) | |||
1155 | Peers_unset_peer_flag (peer, Peers_ONLINE); | 1121 | Peers_unset_peer_flag (peer, Peers_ONLINE); |
1156 | 1122 | ||
1157 | GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0); | 1123 | GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0); |
1158 | // TODO delete struct GNUNET_TRANSPORT_TransmitHandle *transmit_handle | ||
1159 | /* Cancle messages that have not been sent yet */ | ||
1160 | while (NULL != peer_ctx->pending_messages_head) | 1124 | while (NULL != peer_ctx->pending_messages_head) |
1161 | { | 1125 | { |
1162 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1126 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1166,13 +1130,15 @@ Peers_remove_peer (const struct GNUNET_PeerIdentity *peer) | |||
1166 | } | 1130 | } |
1167 | /* If we are still waiting for notification whether this peer is live | 1131 | /* If we are still waiting for notification whether this peer is live |
1168 | * cancel the according task */ | 1132 | * cancel the according task */ |
1169 | if (NULL != peer_ctx->transmit_handle) | 1133 | if (NULL != peer_ctx->liveliness_check_pending) |
1170 | { | 1134 | { |
1171 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1135 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1172 | "Trying to cancle transmit_handle for peer %s\n", | 1136 | "Removing pending liveliness check for peer %s\n", |
1173 | GNUNET_i2s (&peer_ctx->peer_id)); | 1137 | GNUNET_i2s (&peer_ctx->peer_id)); |
1174 | GNUNET_CADET_notify_transmit_ready_cancel (peer_ctx->transmit_handle); | 1138 | // TODO wait until cadet sets mq->cancel_impl |
1175 | peer_ctx->transmit_handle = NULL; | 1139 | //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev); |
1140 | GNUNET_free (peer_ctx->liveliness_check_pending); | ||
1141 | peer_ctx->liveliness_check_pending = NULL; | ||
1176 | } | 1142 | } |
1177 | if (NULL != peer_ctx->send_channel) | 1143 | if (NULL != peer_ctx->send_channel) |
1178 | { | 1144 | { |