aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2012-09-07 11:17:19 +0000
committerBart Polot <bart@net.in.tum.de>2012-09-07 11:17:19 +0000
commitea0f8a1c0590aaefa01babd703369fe05d65a6a3 (patch)
tree884dd9ac50657706c3e9ea697549f68dc5e1b453 /src
parent7db25207f58fba64bbf4648255d5b796318b3c8e (diff)
downloadgnunet-ea0f8a1c0590aaefa01babd703369fe05d65a6a3.tar.gz
gnunet-ea0f8a1c0590aaefa01babd703369fe05d65a6a3.zip
Added explicit keepalive to mesh
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-service-mesh.c70
-rw-r--r--src/mesh/mesh_protocol.h23
2 files changed, 75 insertions, 18 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index f48568590..96df854e4 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -37,7 +37,6 @@
37 * TODO: 37 * TODO:
38 * - error reporting (CREATE/CHANGE/ADD/DEL?) -- new message! 38 * - error reporting (CREATE/CHANGE/ADD/DEL?) -- new message!
39 * - partial disconnect reporting -- same as error reporting? 39 * - partial disconnect reporting -- same as error reporting?
40 * - add vs create? change vs. keep-alive? same msg or different ones? -- thinking...
41 * - add ping message 40 * - add ping message
42 * - relay corking down to core 41 * - relay corking down to core
43 * - set ttl relative to tree depth 42 * - set ttl relative to tree depth
@@ -5688,6 +5687,51 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
5688 5687
5689 5688
5690/** 5689/**
5690 * Core handler for mesh keepalives.
5691 *
5692 * @param cls closure
5693 * @param message message
5694 * @param peer peer identity this notification is about
5695 * @param atsi performance data
5696 * @param atsi_count number of records in 'atsi'
5697 * @return GNUNET_OK to keep the connection open,
5698 * GNUNET_SYSERR to close it (signal serious error)
5699 *
5700 * TODO: Check who we got this from, to validate route.
5701 */
5702static int
5703handle_mesh_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
5704 const struct GNUNET_MessageHeader *message,
5705 const struct GNUNET_ATS_Information *atsi,
5706 unsigned int atsi_count)
5707{
5708 struct GNUNET_MESH_TunnelKeepAlive *msg;
5709 struct MeshTunnel *t;
5710
5711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got a keepalive packet from %s\n",
5712 GNUNET_i2s (peer));
5713
5714 msg = (struct GNUNET_MESH_TunnelKeepAlive *) message;
5715 t = tunnel_get (&msg->oid, ntohl (msg->tid));
5716
5717 if (NULL == t)
5718 {
5719 /* TODO notify that we dont know that tunnel */
5720 GNUNET_STATISTICS_update (stats, "# keepalive on unknown tunnel", 1, GNUNET_NO);
5721 GNUNET_break_op (0);
5722 return GNUNET_OK;
5723 }
5724
5725 tunnel_reset_timeout (t);
5726
5727 GNUNET_STATISTICS_update (stats, "# keepalives forwarded", 1, GNUNET_NO);
5728 tunnel_send_multicast (t, message, GNUNET_NO);
5729 return GNUNET_OK;
5730 }
5731
5732
5733
5734/**
5691 * Functions to handle messages from core 5735 * Functions to handle messages from core
5692 */ 5736 */
5693static struct GNUNET_CORE_MessageHandler core_handlers[] = { 5737static struct GNUNET_CORE_MessageHandler core_handlers[] = {
@@ -5699,6 +5743,8 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
5699 sizeof (struct GNUNET_MESH_TunnelDestroy)}, 5743 sizeof (struct GNUNET_MESH_TunnelDestroy)},
5700 {&handle_mesh_data_unicast, GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0}, 5744 {&handle_mesh_data_unicast, GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0},
5701 {&handle_mesh_data_multicast, GNUNET_MESSAGE_TYPE_MESH_MULTICAST, 0}, 5745 {&handle_mesh_data_multicast, GNUNET_MESSAGE_TYPE_MESH_MULTICAST, 0},
5746 {&handle_mesh_keepalive, GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE,
5747 sizeof (struct GNUNET_MESH_TunnelKeepAlive)},
5702 {&handle_mesh_data_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0}, 5748 {&handle_mesh_data_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0},
5703 {&handle_mesh_ack, GNUNET_MESSAGE_TYPE_MESH_ACK, 5749 {&handle_mesh_ack, GNUNET_MESSAGE_TYPE_MESH_ACK,
5704 sizeof (struct GNUNET_MESH_ACK)}, 5750 sizeof (struct GNUNET_MESH_ACK)},
@@ -5776,41 +5822,29 @@ notify_client_connection_failure (void *cls, size_t size, void *buf)
5776 * 5822 *
5777 * @param cls Closure (tunnel for which to send the keepalive). 5823 * @param cls Closure (tunnel for which to send the keepalive).
5778 * @param tc Notification context. 5824 * @param tc Notification context.
5779 *
5780 * TODO: implement explicit multicast keepalive?
5781 */ 5825 */
5782static void 5826static void
5783path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 5827path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5784{ 5828{
5785 struct MeshTunnel *t = cls; 5829 struct MeshTunnel *t = cls;
5786 struct GNUNET_MessageHeader *payload; 5830 struct GNUNET_MESH_TunnelKeepAlive *msg;
5787 struct GNUNET_MESH_Multicast *msg; 5831 size_t size = sizeof (struct GNUNET_MESH_TunnelKeepAlive);
5788 size_t size =
5789 sizeof (struct GNUNET_MESH_Multicast) +
5790 sizeof (struct GNUNET_MessageHeader);
5791 char cbuf[size]; 5832 char cbuf[size];
5792 5833
5834 t->path_refresh_task = GNUNET_SCHEDULER_NO_TASK;
5793 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 5835 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
5794 { 5836 {
5795 return; 5837 return;
5796 } 5838 }
5797 t->path_refresh_task = GNUNET_SCHEDULER_NO_TASK;
5798 5839
5799 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5840 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5800 "sending keepalive for tunnel %d\n", t->id.tid); 5841 "sending keepalive for tunnel %d\n", t->id.tid);
5801 5842
5802 msg = (struct GNUNET_MESH_Multicast *) cbuf; 5843 msg = (struct GNUNET_MESH_TunnelKeepAlive *) cbuf;
5803 msg->header.size = htons (size); 5844 msg->header.size = htons (size);
5804 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST); 5845 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE);
5805 // FIXME: change type to != MULTICAST
5806 msg->oid = my_full_id; 5846 msg->oid = my_full_id;
5807 msg->tid = htonl (t->id.tid); 5847 msg->tid = htonl (t->id.tid);
5808 msg->ttl = htonl (default_ttl);
5809 msg->pid = htonl (t->fwd_pid + 1);
5810 t->fwd_pid++;
5811 payload = (struct GNUNET_MessageHeader *) &msg[1];
5812 payload->size = htons (sizeof (struct GNUNET_MessageHeader));
5813 payload->type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE);
5814 tunnel_send_multicast (t, &msg->header, GNUNET_YES); 5848 tunnel_send_multicast (t, &msg->header, GNUNET_YES);
5815 5849
5816 t->path_refresh_task = 5850 t->path_refresh_task =
diff --git a/src/mesh/mesh_protocol.h b/src/mesh/mesh_protocol.h
index e2a18b1d8..38c57607b 100644
--- a/src/mesh/mesh_protocol.h
+++ b/src/mesh/mesh_protocol.h
@@ -313,6 +313,29 @@ struct GNUNET_MESH_TunnelDestroy
313}; 313};
314 314
315 315
316/**
317 * Message to destroy a tunnel
318 */
319struct GNUNET_MESH_TunnelKeepAlive
320{
321 /**
322 * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE
323 */
324 struct GNUNET_MessageHeader header;
325
326 /**
327 * TID of the tunnel
328 */
329 uint32_t tid GNUNET_PACKED;
330
331 /**
332 * OID of the tunnel
333 */
334 struct GNUNET_PeerIdentity oid;
335};
336
337
338
316GNUNET_NETWORK_STRUCT_END 339GNUNET_NETWORK_STRUCT_END
317 340
318#if 0 /* keep Emacsens' auto-indent happy */ 341#if 0 /* keep Emacsens' auto-indent happy */