aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-08-16 13:13:23 +0000
committerBart Polot <bart@net.in.tum.de>2013-08-16 13:13:23 +0000
commitf17d5295304a054d631ac9622cdb98f69b3ac6ad (patch)
tree66a6074eb424ed3af7181da9f7e0e9defbccf31c
parent53ec104a13f1dda8ecd0b28c3c5bf3f6e82e47e1 (diff)
downloadgnunet-f17d5295304a054d631ac9622cdb98f69b3ac6ad.tar.gz
gnunet-f17d5295304a054d631ac9622cdb98f69b3ac6ad.zip
- add channel_ack
-rw-r--r--src/mesh/gnunet-service-mesh-enc.c144
-rw-r--r--src/mesh/mesh_protocol_enc.h4
2 files changed, 141 insertions, 7 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c
index c67efdfea..ccb66f75f 100644
--- a/src/mesh/gnunet-service-mesh-enc.c
+++ b/src/mesh/gnunet-service-mesh-enc.c
@@ -147,12 +147,39 @@ enum MeshConnectionState
147 MESH_CONNECTION_SENT, 147 MESH_CONNECTION_SENT,
148 148
149 /** 149 /**
150 * Connection confirmed, ready to carry traffic.. 150 * Connection ACK sent, waiting for ACK.
151 */
152 MESH_CONNECTION_ACK,
153
154 /**
155 * Connection confirmed, ready to carry traffic.
151 */ 156 */
152 MESH_CONNECTION_READY, 157 MESH_CONNECTION_READY,
153}; 158};
154 159
155 160
161/**
162 * All the states a connection can be in.
163 */
164enum MeshChannelState
165{
166 /**
167 * Uninitialized status, should never appear in operation.
168 */
169 MESH_CHANNEL_NEW,
170
171 /**
172 * Connection create message sent, waiting for ACK.
173 */
174 MESH_CHANNEL_SENT,
175
176 /**
177 * Connection confirmed, ready to carry traffic..
178 */
179 MESH_CHANNEL_READY,
180};
181
182
156/******************************************************************************/ 183/******************************************************************************/
157/************************ DATA STRUCTURES ****************************/ 184/************************ DATA STRUCTURES ****************************/
158/******************************************************************************/ 185/******************************************************************************/
@@ -458,6 +485,11 @@ struct MeshChannel
458 MESH_ChannelNumber lid_dest; 485 MESH_ChannelNumber lid_dest;
459 486
460 /** 487 /**
488 * Channel state.
489 */
490 enum MeshChannelState state;
491
492 /**
461 * Next MID to use for fwd traffic. 493 * Next MID to use for fwd traffic.
462 */ 494 */
463 uint32_t mid_send_fwd; 495 uint32_t mid_send_fwd;
@@ -3611,6 +3643,37 @@ channel_send_connection_ack (struct MeshChannel *ch, uint32_t buffer, int fwd)
3611 3643
3612 3644
3613/** 3645/**
3646 * Channel was ACK'd by remote peer, mark as ready and cancel retransmission.
3647 *
3648 * @param ch Channel to mark as ready.
3649 * @param fwd Was the CREATE message sent fwd?
3650 */
3651static void
3652channel_confirm (struct MeshChannel *ch, int fwd)
3653{
3654 struct MeshChannelReliability *rel;
3655 struct MeshReliableMessage *copy;
3656 struct MeshReliableMessage *next;
3657
3658 ch->state = MESH_CHANNEL_READY;
3659
3660 rel = fwd ? ch->fwd_rel : ch->bck_rel;
3661 for (copy = rel->head_sent; NULL != copy; copy = next)
3662 {
3663 struct GNUNET_MessageHeader *msg;
3664
3665 next = copy->next;
3666 msg = (struct GNUNET_MessageHeader *) &copy[1];
3667 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE)
3668 {
3669 rel_message_free (copy);
3670 /* TODO return? */
3671 }
3672 }
3673}
3674
3675
3676/**
3614 * Send keepalive packets for a connection. 3677 * Send keepalive packets for a connection.
3615 * 3678 *
3616 * @param c Connection to keep alive.. 3679 * @param c Connection to keep alive..
@@ -3754,6 +3817,29 @@ connection_send_destroy (struct MeshConnection *c)
3754 3817
3755 3818
3756/** 3819/**
3820 * Confirm we got a channel create.
3821 *
3822 * @param ch The channel to confirm.
3823 * @param fwd Should we send the ACK fwd?
3824 */
3825static void
3826channel_send_ack (struct MeshChannel *ch, int fwd)
3827{
3828 struct GNUNET_MESH_ChannelManage msg;
3829
3830 msg.header.size = htons (sizeof (msg));
3831 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_ACK);
3832 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3833 " sending channel destroy for channel %s:%X\n",
3834 peer2s (ch->t->peer),
3835 ch->gid);
3836
3837 msg.chid = htonl (ch->gid);
3838 send_prebuilt_message_channel (&msg.header, ch, fwd);
3839}
3840
3841
3842/**
3757 * Send a message to all clients (local and remote) of this channel 3843 * Send a message to all clients (local and remote) of this channel
3758 * notifying that the channel is no longer valid. 3844 * notifying that the channel is no longer valid.
3759 * 3845 *
@@ -3765,7 +3851,7 @@ connection_send_destroy (struct MeshConnection *c)
3765static void 3851static void
3766channel_send_destroy (struct MeshChannel *ch) 3852channel_send_destroy (struct MeshChannel *ch)
3767{ 3853{
3768 struct GNUNET_MESH_ChannelDestroy msg; 3854 struct GNUNET_MESH_ChannelManage msg;
3769 3855
3770 msg.header.size = htons (sizeof (msg)); 3856 msg.header.size = htons (sizeof (msg));
3771 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY); 3857 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY);
@@ -5203,6 +5289,7 @@ handle_mesh_connection_destroy (void *cls,
5203 return GNUNET_OK; 5289 return GNUNET_OK;
5204} 5290}
5205 5291
5292
5206/** 5293/**
5207 * Handler for channel create messages. 5294 * Handler for channel create messages.
5208 * 5295 *
@@ -5267,12 +5354,54 @@ handle_channel_create (struct MeshTunnel2 *t,
5267 } 5354 }
5268 5355
5269 send_local_channel_create (ch); 5356 send_local_channel_create (ch);
5357 channel_send_ack (ch, !fwd);
5270 5358
5271 return GNUNET_OK; 5359 return GNUNET_OK;
5272} 5360}
5273 5361
5274 5362
5275/** 5363/**
5364 * Handler for channel ack messages.
5365 *
5366 * @param t Tunnel this channel is to be created in.
5367 * @param msg Message.
5368 * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
5369 *
5370 * @return GNUNET_OK to keep the connection open,
5371 * GNUNET_SYSERR to close it (signal serious error)
5372 */
5373static int
5374handle_channel_ack (struct MeshTunnel2 *t,
5375 struct GNUNET_MESH_ChannelManage *msg,
5376 int fwd)
5377{
5378 MESH_ChannelNumber chid;
5379 struct MeshChannel *ch;
5380
5381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received Channel ACK\n");
5382 /* Check message size */
5383 if (ntohs (msg->header.size) != sizeof (struct GNUNET_MESH_ChannelManage))
5384 {
5385 GNUNET_break_op (0);
5386 return GNUNET_OK;
5387 }
5388
5389 /* Check if channel exists */
5390 chid = ntohl (msg->chid);
5391 ch = channel_get (t, chid);
5392 if (NULL == ch)
5393 {
5394 GNUNET_break_op (0);
5395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " channel %u unknown!!\n", chid);
5396 return GNUNET_OK;
5397 }
5398
5399 channel_confirm (ch, !fwd);
5400 return GNUNET_OK;
5401}
5402
5403
5404/**
5276 * Handler for channel destroy messages. 5405 * Handler for channel destroy messages.
5277 * 5406 *
5278 * @param t Tunnel this channel is to be destroyed of. 5407 * @param t Tunnel this channel is to be destroyed of.
@@ -5284,14 +5413,14 @@ handle_channel_create (struct MeshTunnel2 *t,
5284 */ 5413 */
5285static int 5414static int
5286handle_channel_destroy (struct MeshTunnel2 *t, 5415handle_channel_destroy (struct MeshTunnel2 *t,
5287 struct GNUNET_MESH_ChannelDestroy *msg, 5416 struct GNUNET_MESH_ChannelManage *msg,
5288 int fwd) 5417 int fwd)
5289{ 5418{
5290 MESH_ChannelNumber chid; 5419 MESH_ChannelNumber chid;
5291 struct MeshChannel *ch; 5420 struct MeshChannel *ch;
5292 5421
5293 /* Check message size */ 5422 /* Check message size */
5294 if (ntohs (msg->header.size) != sizeof (struct GNUNET_MESH_ChannelDestroy)) 5423 if (ntohs (msg->header.size) != sizeof (struct GNUNET_MESH_ChannelManage))
5295 { 5424 {
5296 GNUNET_break_op (0); 5425 GNUNET_break_op (0);
5297 return GNUNET_OK; 5426 return GNUNET_OK;
@@ -5435,9 +5564,14 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer,
5435 (struct GNUNET_MESH_ChannelCreate *) msgh, 5564 (struct GNUNET_MESH_ChannelCreate *) msgh,
5436 fwd); 5565 fwd);
5437 break; 5566 break;
5567 case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_ACK:
5568 return handle_channel_ack (t,
5569 (struct GNUNET_MESH_ChannelManage *) msgh,
5570 fwd);
5571 break;
5438 case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY: 5572 case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY:
5439 return handle_channel_destroy (t, 5573 return handle_channel_destroy (t,
5440 (struct GNUNET_MESH_ChannelDestroy *) 5574 (struct GNUNET_MESH_ChannelManage *)
5441 msgh, 5575 msgh,
5442 fwd); 5576 fwd);
5443 break; 5577 break;
diff --git a/src/mesh/mesh_protocol_enc.h b/src/mesh/mesh_protocol_enc.h
index 350d015b9..3ed81005e 100644
--- a/src/mesh/mesh_protocol_enc.h
+++ b/src/mesh/mesh_protocol_enc.h
@@ -164,10 +164,10 @@ struct GNUNET_MESH_ChannelCreate
164 uint32_t opt GNUNET_PACKED; 164 uint32_t opt GNUNET_PACKED;
165}; 165};
166 166
167struct GNUNET_MESH_ChannelDestroy 167struct GNUNET_MESH_ChannelManage
168{ 168{
169 /** 169 /**
170 * Type: GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY 170 * Type: GNUNET_MESSAGE_TYPE_MESH_CHANNEL_{ACK|DESTROY}
171 */ 171 */
172 struct GNUNET_MessageHeader header; 172 struct GNUNET_MessageHeader header;
173 173