aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rps/gnunet-service-rps.c97
1 files changed, 65 insertions, 32 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 14f8e26bf..591b39756 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -574,25 +574,15 @@ hist_update (void *cls, struct GNUNET_PeerIdentity *ids, uint32_t num_peers)
574 574
575 575
576/** 576/**
577 * Callback that is called when a channel was effectively established. 577 * Set the peer flag to living and call the outstanding operations on this peer.
578 * This is given to ntfy_tmt_rdy and called when the channel was
579 * successfully established.
580 */ 578 */
581static size_t 579static size_t
582peer_is_live (void *cls, size_t size, void *buf) 580peer_is_live (struct PeerContext *peer_ctx)
583{ 581{
584 struct PeerContext *ctx = cls;
585 struct GNUNET_PeerIdentity *peer; 582 struct GNUNET_PeerIdentity *peer;
586 struct PeerContext *peer_ctx;
587 583
588 //if (NULL == buf || 584 peer = &peer_ctx->peer_id;
589 // 0 == size) 585 set_peer_flag (peer_ctx, LIVING);
590 // TODO check
591
592 ctx->is_live_task = NULL;
593 peer = &ctx->peer_id;
594 peer_ctx = get_peer_ctx (peer_map, peer);
595 peer_ctx->peer_flags |= LIVING;
596 586
597 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer %s is live\n", GNUNET_i2s (peer)); 587 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer %s is live\n", GNUNET_i2s (peer));
598 588
@@ -605,11 +595,34 @@ peer_is_live (void *cls, size_t size, void *buf)
605 GNUNET_array_grow (peer_ctx->outstanding_ops, peer_ctx->num_outstanding_ops, 0); 595 GNUNET_array_grow (peer_ctx->outstanding_ops, peer_ctx->num_outstanding_ops, 0);
606 } 596 }
607 597
598 return 0;
599}
600
601
602/**
603 * Callback that is called when a channel was effectively established.
604 * This is given to ntfy_tmt_rdy and called when the channel was
605 * successfully established.
606 */
607static size_t
608cadet_ntfy_tmt_rdy_cb (void *cls, size_t size, void *buf)
609{
610 struct PeerContext *peer_ctx = (struct PeerContext *) cls;
611
612 if (NULL != buf ||
613 0 != size)
614 peer_is_live (peer_ctx);
615
608 //if (NULL != peer_ctx->is_live_task) 616 //if (NULL != peer_ctx->is_live_task)
609 //{ 617 //{
618 // LOG (GNUNET_ERROR_TYPE_DEBUG,
619 // "Trying to cancle is_live_task for peer %s\n",
620 // GNUNET_i2s (&peer_ctx->peer_id));
610 // GNUNET_CADET_notify_transmit_ready_cancel (peer_ctx->is_live_task); 621 // GNUNET_CADET_notify_transmit_ready_cancel (peer_ctx->is_live_task);
611 // peer_ctx->is_live_task = NULL; // needed? 622 // peer_ctx->is_live_task = NULL;
612 //} 623 //}
624 peer_ctx->is_live_task = NULL;
625
613 return 0; 626 return 0;
614} 627}
615 628
@@ -623,26 +636,44 @@ get_channel (struct GNUNET_CONTAINER_MultiPeerMap *peer_map,
623{ 636{
624 struct PeerContext *ctx; 637 struct PeerContext *ctx;
625 638
639 LOG (GNUNET_ERROR_TYPE_DEBUG,
640 "Trying to establish channel to peer %s\n",
641 GNUNET_i2s (peer));
642
626 ctx = get_peer_ctx (peer_map, peer); 643 ctx = get_peer_ctx (peer_map, peer);
627 if (NULL == ctx->send_channel) 644 if (NULL == ctx->send_channel)
628 { 645 {
629 ctx->send_channel = GNUNET_CADET_channel_create (cadet_handle, NULL, peer, 646 ctx->send_channel = GNUNET_CADET_channel_create (cadet_handle,
647 NULL,
648 peer,
630 GNUNET_RPS_CADET_PORT, 649 GNUNET_RPS_CADET_PORT,
631 GNUNET_CADET_OPTION_RELIABLE); 650 GNUNET_CADET_OPTION_RELIABLE);
632 651
633 if (NULL == ctx->recv_channel) 652 /* If we don't know whether peer is live,
653 * get notified when we know it is live. */
654 if (NULL == ctx->recv_channel
655 && NULL == ctx->is_live_task)
634 { 656 {
635 ctx->peer_id = *peer; 657 ctx->peer_id = *peer;
658 LOG (GNUNET_ERROR_TYPE_DEBUG,
659 "Get informed about peer %s getting live\n",
660 GNUNET_i2s (peer));
636 ctx->is_live_task = 661 ctx->is_live_task =
637 GNUNET_CADET_notify_transmit_ready (ctx->send_channel, GNUNET_NO, 662 GNUNET_CADET_notify_transmit_ready (ctx->send_channel,
663 GNUNET_NO,
638 GNUNET_TIME_UNIT_FOREVER_REL, 664 GNUNET_TIME_UNIT_FOREVER_REL,
639 sizeof (struct GNUNET_MessageHeader), 665 sizeof (struct GNUNET_MessageHeader),
640 peer_is_live, ctx); 666 cadet_ntfy_tmt_rdy_cb,
667 ctx);
641 } 668 }
669 // FIXME check whether this is NULL
642 670
643 // do I have to explicitly put it in the peer_map? 671 // do I have to explicitly put it in the peer_map?
644 (void) GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, 672 (void) GNUNET_CONTAINER_multipeermap_put
645 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); 673 (peer_map,
674 peer,
675 ctx,
676 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
646 } 677 }
647 return ctx->send_channel; 678 return ctx->send_channel;
648} 679}
@@ -1621,7 +1652,7 @@ handle_inbound_channel (void *cls,
1621 uint32_t port, 1652 uint32_t port,
1622 enum GNUNET_CADET_ChannelOption options) 1653 enum GNUNET_CADET_ChannelOption options)
1623{ 1654{
1624 struct PeerContext *ctx; 1655 struct PeerContext *peer_ctx;
1625 1656
1626 LOG (GNUNET_ERROR_TYPE_DEBUG, 1657 LOG (GNUNET_ERROR_TYPE_DEBUG,
1627 "New channel was established to us (Peer %s).\n", 1658 "New channel was established to us (Peer %s).\n",
@@ -1631,20 +1662,22 @@ handle_inbound_channel (void *cls,
1631 1662
1632 // we might not even store the recv_channel 1663 // we might not even store the recv_channel
1633 1664
1634 ctx = get_peer_ctx (peer_map, initiator); 1665 peer_ctx = get_peer_ctx (peer_map, initiator);
1635 if (NULL != ctx->recv_channel) 1666 // FIXME what do we do if a channel is established twice?
1636 { 1667 // overwrite? Clean old channel? ...?
1637 ctx->recv_channel = channel; 1668 //if (NULL != peer_ctx->recv_channel)
1638 } 1669 //{
1639 1670 // peer_ctx->recv_channel = channel;
1640 ctx->peer_flags |= LIVING; 1671 //}
1672 peer_ctx->recv_channel = channel;
1641 1673
1642 //ctx->peer_flags = IN_OTHER_GOSSIP_LIST; 1674 peer_ctx->mq = NULL;
1643 ctx->mq = NULL;
1644 1675
1645 (void) GNUNET_CONTAINER_multipeermap_put (peer_map, initiator, ctx, 1676 (void) GNUNET_CONTAINER_multipeermap_put (peer_map, initiator, peer_ctx,
1646 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); 1677 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
1647 1678
1679 peer_is_live (peer_ctx);
1680
1648 return NULL; // TODO 1681 return NULL; // TODO
1649} 1682}
1650 1683