aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-08-12 16:18:50 +0000
committerBart Polot <bart@net.in.tum.de>2013-08-12 16:18:50 +0000
commit99206c12844f13722688589530244ac7c56aab63 (patch)
treee9050d82d9f92f3ef72dccd46c2b52da3f21a09b
parenta345e89e5993856aa6780e24c0e580c10b50c4a1 (diff)
downloadgnunet-99206c12844f13722688589530244ac7c56aab63.tar.gz
gnunet-99206c12844f13722688589530244ac7c56aab63.zip
- tunnel queue
-rw-r--r--src/mesh/gnunet-service-mesh-enc.c113
1 files changed, 107 insertions, 6 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c
index f97d1750f..b7075aaae 100644
--- a/src/mesh/gnunet-service-mesh-enc.c
+++ b/src/mesh/gnunet-service-mesh-enc.c
@@ -523,6 +523,9 @@ struct MeshChannel
523}; 523};
524 524
525 525
526/**
527 * Struct containing all information regarding a connection to a peer.
528 */
526struct MeshConnection 529struct MeshConnection
527{ 530{
528 /** 531 /**
@@ -591,6 +594,29 @@ struct MeshConnection
591 594
592 595
593/** 596/**
597 * Struct used to queue messages in a tunnel.
598 */
599struct MeshTunnelQueue
600{
601 /**
602 * DLL
603 */
604 struct MeshTunnelQueue *next;
605 struct MeshTunnelQueue *prev;
606
607 /**
608 * Channel.
609 */
610 struct MeshChannel *ch;
611
612 /**
613 * Message to send.
614 */
615 /* struct GNUNET_MessageHeader *msg; */
616};
617
618
619/**
594 * Struct containing all information regarding a tunnel to a peer. 620 * Struct containing all information regarding a tunnel to a peer.
595 */ 621 */
596struct MeshTunnel2 622struct MeshTunnel2
@@ -671,6 +697,12 @@ struct MeshTunnel2
671 * Destroy flag: if true, destroy on last message. 697 * Destroy flag: if true, destroy on last message.
672 */ 698 */
673 int destroy; 699 int destroy;
700
701 /**
702 * Queued messages, to transmit once tunnel gets connected.
703 */
704 struct MeshTunnelQueue *tq_head;
705 struct MeshTunnelQueue *tq_tail;
674}; 706};
675 707
676 708
@@ -1495,7 +1527,7 @@ tunnel_get_connection (struct MeshTunnel2 *t, int fwd)
1495 1527
1496 1528
1497/** 1529/**
1498 * Get the total buffer space for a tunnel 1530 * Get the total buffer space for a tunnel.
1499 */ 1531 */
1500static unsigned int 1532static unsigned int
1501tunnel_get_buffer (struct MeshTunnel2 *t, int fwd) 1533tunnel_get_buffer (struct MeshTunnel2 *t, int fwd)
@@ -1648,6 +1680,8 @@ send_prebuilt_message_tunnel (struct GNUNET_MESH_Encrypted *msg,
1648 msg->ttl = default_ttl; 1680 msg->ttl = default_ttl;
1649 break; 1681 break;
1650 default: 1682 default:
1683 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "unkown type %s\n",
1684 GNUNET_MESH_DEBUG_M2S (type));
1651 GNUNET_break (0); 1685 GNUNET_break (0);
1652 } 1686 }
1653 1687
@@ -1670,7 +1704,7 @@ send_prebuilt_message_channel (const struct GNUNET_MessageHeader *message,
1670{ 1704{
1671 struct GNUNET_MESH_Encrypted *msg; 1705 struct GNUNET_MESH_Encrypted *msg;
1672 size_t size = ntohs (message->size); 1706 size_t size = ntohs (message->size);
1673 char *cbuf[size + sizeof (struct GNUNET_MESH_Encrypted)]; 1707 char *cbuf[sizeof (struct GNUNET_MESH_Encrypted) + size];
1674 uint16_t type; 1708 uint16_t type;
1675 uint64_t iv; 1709 uint64_t iv;
1676 1710
@@ -2747,6 +2781,58 @@ tunnel_change_state (struct MeshTunnel2* t, enum MeshTunnelState state)
2747} 2781}
2748 2782
2749 2783
2784/**
2785 * Cache a message to be sent once tunnel is online.
2786 *
2787 * @param t Tunnel to hold the message.
2788 * @param ch Channel the message is about.
2789 * @param msg Message itself (copy will be made).
2790 * @param fwd Is this fwd?
2791 */
2792static void
2793tunnel_queue_data (struct MeshTunnel2 *t,
2794 struct MeshChannel *ch,
2795 struct GNUNET_MessageHeader *msg,
2796 int fwd)
2797{
2798 struct MeshTunnelQueue *tq;
2799 uint16_t size = ntohs (msg->size);
2800
2801 tq = GNUNET_malloc (sizeof (struct MeshTunnelQueue) + size);
2802
2803 tq->ch = ch;
2804 memcpy (&tq[1], msg, size);
2805 GNUNET_CONTAINER_DLL_insert_tail (t->tq_head, t->tq_tail, tq);
2806}
2807
2808
2809/**
2810 * Send all cached messages that we can, tunnel is online.
2811 *
2812 * @param t Tunnel that holds the messages.
2813 * @param fwd Is this fwd?
2814 */
2815static void
2816tunnel_send_queued_data (struct MeshTunnel2 *t, int fwd)
2817{
2818 struct MeshTunnelQueue *tq;
2819 struct MeshTunnelQueue *next;
2820 unsigned int room;
2821
2822 room = tunnel_get_buffer (t, fwd);
2823 for (tq = t->tq_head; NULL != tq && room > 0; tq = next)
2824 {
2825 next = tq->next;
2826 room--;
2827 GNUNET_CONTAINER_DLL_remove (t->tq_head, t->tq_tail, tq);
2828 send_prebuilt_message_channel ((struct GNUNET_MessageHeader *) &tq[1],
2829 tq->ch, fwd);
2830
2831 GNUNET_free (tq);
2832 }
2833}
2834
2835
2750static void 2836static void
2751connection_change_state (struct MeshConnection* c, 2837connection_change_state (struct MeshConnection* c,
2752 enum MeshConnectionState state) 2838 enum MeshConnectionState state)
@@ -3631,7 +3717,7 @@ connection_send_destroy (struct MeshConnection *c)
3631 msg.cid = htonl (c->id); 3717 msg.cid = htonl (c->id);
3632 msg.tid = c->t->id; 3718 msg.tid = c->t->id;
3633 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3634 " sending tunnel destroy for connection %s[%X]\n", 3720 " sending connection destroy for connection %s[%X]\n",
3635 peer2s (c->t->peer), 3721 peer2s (c->t->peer),
3636 c->id); 3722 c->id);
3637 3723
@@ -3658,7 +3744,7 @@ channel_send_destroy (struct MeshChannel *ch)
3658 msg.header.size = htons (sizeof (msg)); 3744 msg.header.size = htons (sizeof (msg));
3659 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY); 3745 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY);
3660 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3746 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3661 " sending tunnel destroy for channel %s:%X\n", 3747 " sending channel destroy for channel %s:%X\n",
3662 peer2s (ch->t->peer), 3748 peer2s (ch->t->peer),
3663 ch->gid); 3749 ch->gid);
3664 3750
@@ -4920,12 +5006,15 @@ handle_mesh_connection_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
4920 } 5006 }
4921 connection_change_state (c, MESH_CONNECTION_READY); 5007 connection_change_state (c, MESH_CONNECTION_READY);
4922 connection_reset_timeout (c, GNUNET_NO); 5008 connection_reset_timeout (c, GNUNET_NO);
5009 if (MESH_TUNNEL_READY != c->t->state)
5010 tunnel_change_state (c->t, MESH_TUNNEL_READY);
5011 tunnel_send_queued_data (c->t, GNUNET_YES);
4923 5012
4924 /* Message for us? */ 5013 /* Message for us? */
4925 if (connection_is_terminal (c, GNUNET_NO)) 5014 if (connection_is_terminal (c, GNUNET_NO))
4926 { 5015 {
4927 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " It's for us!\n"); 5016 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " It's for us!\n");
4928 if (3 <= tunnel_count_connections(c->t) && NULL != c->t->peer->dhtget) 5017 if (3 <= tunnel_count_connections (c->t) && NULL != c->t->peer->dhtget)
4929 { 5018 {
4930 GNUNET_DHT_get_stop (c->t->peer->dhtget); 5019 GNUNET_DHT_get_stop (c->t->peer->dhtget);
4931 c->t->peer->dhtget = NULL; 5020 c->t->peer->dhtget = NULL;
@@ -5837,7 +5926,19 @@ handle_local_channel_create (void *cls, struct GNUNET_SERVER_Client *client,
5837 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATED CHANNEL %s[%x]:%u (%x)\n", 5926 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATED CHANNEL %s[%x]:%u (%x)\n",
5838 GNUNET_h2s (&t->id), ch->gid, ch->port, ch->lid_root); 5927 GNUNET_h2s (&t->id), ch->gid, ch->port, ch->lid_root);
5839 peer_connect (peer); 5928 peer_connect (peer);
5840 /* FIXME send create channel */ 5929
5930 /* Send create channel */
5931 {
5932 struct GNUNET_MESH_ChannelCreate msgcc;
5933
5934 msgcc.header.size = htons (sizeof (msgcc));
5935 msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE);
5936 msgcc.chid = htonl (ch->gid);
5937 msgcc.port = msg->port;
5938 msgcc.opt = msg->opt;
5939
5940 tunnel_queue_data (t, ch, &msgcc.header, GNUNET_YES);
5941 }
5841 5942
5842 GNUNET_SERVER_receive_done (client, GNUNET_OK); 5943 GNUNET_SERVER_receive_done (client, GNUNET_OK);
5843 return; 5944 return;