aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-07-03 17:04:57 +0000
committerBart Polot <bart@net.in.tum.de>2013-07-03 17:04:57 +0000
commitde8e1af3264a5c869bf85178efb58dd58a9b9be3 (patch)
tree1ac64b7db0577ae9d30089cff344f2852a546de7 /src
parent833e3b9e75e77374a9e85c765d356bfda8b248b8 (diff)
downloadgnunet-de8e1af3264a5c869bf85178efb58dd58a9b9be3.tar.gz
gnunet-de8e1af3264a5c869bf85178efb58dd58a9b9be3.zip
- prepare for relaible mesh
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_mesh_service.h14
-rw-r--r--src/mesh/gnunet-service-mesh.c68
-rw-r--r--src/mesh/mesh_api.c39
3 files changed, 120 insertions, 1 deletions
diff --git a/src/include/gnunet_mesh_service.h b/src/include/gnunet_mesh_service.h
index c64cfb64c..82fc3febd 100644
--- a/src/include/gnunet_mesh_service.h
+++ b/src/include/gnunet_mesh_service.h
@@ -229,6 +229,20 @@ GNUNET_MESH_tunnel_buffer (struct GNUNET_MESH_Tunnel *tunnel, int buffer);
229 229
230 230
231/** 231/**
232 * Turn on/off the reliability of the tunnel.
233 *
234 * If reliability is on, mesh will resend lost messages, similar to TCP.
235 * If reliability is off, mesh just do best effort, similar to UDP.
236 *
237 * @param tunnel Tunnel affected.
238 * @param reliable GNUNET_YES to turn reliability on,
239 * GNUNET_NO to have a best effort tunnel (default).
240 */
241void
242GNUNET_MESH_tunnel_reliable (struct GNUNET_MESH_Tunnel *tunnel, int reliable);
243
244
245/**
232 * Handle for a transmission request. 246 * Handle for a transmission request.
233 */ 247 */
234struct GNUNET_MESH_TransmitHandle; 248struct GNUNET_MESH_TransmitHandle;
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 7803bbf5a..d97ae74b1 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -321,6 +321,11 @@ struct MeshTunnel
321 int nobuffer; 321 int nobuffer;
322 322
323 /** 323 /**
324 * Is the tunnel reliable?
325 */
326 int reliable;
327
328 /**
324 * Force sending ACK? Flag to allow duplicate ACK on POLL. 329 * Force sending ACK? Flag to allow duplicate ACK on POLL.
325 */ 330 */
326 int force_ack; 331 int force_ack;
@@ -4322,6 +4327,63 @@ handle_local_tunnel_buffer (void *cls, struct GNUNET_SERVER_Client *client,
4322 4327
4323 4328
4324/** 4329/**
4330 * Handler for requests of seeting tunnel's reliability policy.
4331 *
4332 * @param cls Closure (unused).
4333 * @param client Identification of the client.
4334 * @param message The actual message.
4335 */
4336static void
4337handle_local_tunnel_reliability (void *cls, struct GNUNET_SERVER_Client *client,
4338 const struct GNUNET_MessageHeader *message)
4339{
4340 struct GNUNET_MESH_TunnelMessage *tunnel_msg;
4341 struct MeshClient *c;
4342 struct MeshTunnel *t;
4343 MESH_TunnelNumber tid;
4344
4345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4346 "Got a BUFFER request from client!\n");
4347
4348 /* Sanity check for client registration */
4349 if (NULL == (c = client_get (client)))
4350 {
4351 GNUNET_break (0);
4352 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
4353 return;
4354 }
4355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
4356
4357 tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message;
4358
4359 /* Retrieve tunnel */
4360 tid = ntohl (tunnel_msg->tunnel_id);
4361 t = tunnel_get_by_local_id(c, tid);
4362 if (NULL == t)
4363 {
4364 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " tunnel %X not found\n", tid);
4365 GNUNET_break (0);
4366 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
4367 return;
4368 }
4369
4370 switch (ntohs(message->type))
4371 {
4372 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_RELIABLE:
4373 t->reliable = GNUNET_YES;
4374 break;
4375 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_UNRELIABLE:
4376 t->reliable = GNUNET_NO;
4377 break;
4378 default:
4379 GNUNET_break (0);
4380 }
4381
4382 GNUNET_SERVER_receive_done (client, GNUNET_OK);
4383}
4384
4385
4386/**
4325 * Handler for client traffic directed to one peer 4387 * Handler for client traffic directed to one peer
4326 * 4388 *
4327 * @param cls closure 4389 * @param cls closure
@@ -4733,6 +4795,12 @@ static struct GNUNET_SERVER_MessageHandler client_handlers[] = {
4733 {&handle_local_tunnel_buffer, NULL, 4795 {&handle_local_tunnel_buffer, NULL,
4734 GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_NOBUFFER, 4796 GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_NOBUFFER,
4735 sizeof (struct GNUNET_MESH_TunnelMessage)}, 4797 sizeof (struct GNUNET_MESH_TunnelMessage)},
4798 {&handle_local_tunnel_reliability, NULL,
4799 GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_BUFFER,
4800 sizeof (struct GNUNET_MESH_TunnelMessage)},
4801 {&handle_local_tunnel_reliability, NULL,
4802 GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_NOBUFFER,
4803 sizeof (struct GNUNET_MESH_TunnelMessage)},
4736 {&handle_local_unicast, NULL, 4804 {&handle_local_unicast, NULL,
4737 GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0}, 4805 GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0},
4738 {&handle_local_to_origin, NULL, 4806 {&handle_local_to_origin, NULL,
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c
index 189580e50..87aa52b54 100644
--- a/src/mesh/mesh_api.c
+++ b/src/mesh/mesh_api.c
@@ -299,6 +299,11 @@ struct GNUNET_MESH_Tunnel
299 int buffering; 299 int buffering;
300 300
301 /** 301 /**
302 * Is the tunnel allowed to buffer?
303 */
304 int reliable;
305
306 /**
302 * Maximum allowed PID to send (last ACK recevied). 307 * Maximum allowed PID to send (last ACK recevied).
303 */ 308 */
304 uint32_t last_ack_recv; 309 uint32_t last_ack_recv;
@@ -751,6 +756,9 @@ do_reconnect (struct GNUNET_MESH_Handle *h)
751 756
752 if (GNUNET_NO == t->buffering) 757 if (GNUNET_NO == t->buffering)
753 GNUNET_MESH_tunnel_buffer (t, GNUNET_NO); 758 GNUNET_MESH_tunnel_buffer (t, GNUNET_NO);
759
760 if (GNUNET_YES == t->reliable)
761 GNUNET_MESH_tunnel_reliable (t, GNUNET_YES);
754 } 762 }
755 return GNUNET_YES; 763 return GNUNET_YES;
756} 764}
@@ -1120,7 +1128,6 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg)
1120 break; 1128 break;
1121 /* Notify of a new data packet in the tunnel */ 1129 /* Notify of a new data packet in the tunnel */
1122 case GNUNET_MESSAGE_TYPE_MESH_UNICAST: 1130 case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
1123 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
1124 case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: 1131 case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
1125 process_incoming_data (h, msg); 1132 process_incoming_data (h, msg);
1126 break; 1133 break;
@@ -1522,6 +1529,36 @@ GNUNET_MESH_tunnel_buffer (struct GNUNET_MESH_Tunnel *tunnel, int buffer)
1522} 1529}
1523 1530
1524 1531
1532/**
1533 * Turn on/off the reliability of the tunnel.
1534 *
1535 * If reliability is on, mesh will resend lost messages, similar to TCP.
1536 * If reliability is off, mesh just do best effort, similar to UDP.
1537 *
1538 * @param tunnel Tunnel affected.
1539 * @param reliable GNUNET_YES to turn reliability on,
1540 * GNUNET_NO to have a best effort tunnel (default).
1541 */
1542void
1543GNUNET_MESH_tunnel_reliable (struct GNUNET_MESH_Tunnel *tunnel, int reliable)
1544{
1545 struct GNUNET_MESH_TunnelMessage msg;
1546 struct GNUNET_MESH_Handle *h;
1547
1548 h = tunnel->mesh;
1549 tunnel->reliable = reliable;
1550
1551 if (GNUNET_YES == reliable)
1552 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_RELIABLE);
1553 else
1554 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_UNRELIABLE);
1555 msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
1556 msg.tunnel_id = htonl (tunnel->tid);
1557
1558 send_packet (h, &msg.header, NULL);
1559}
1560
1561
1525struct GNUNET_MESH_TransmitHandle * 1562struct GNUNET_MESH_TransmitHandle *
1526GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, 1563GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork,
1527 struct GNUNET_TIME_Relative maxdelay, 1564 struct GNUNET_TIME_Relative maxdelay,