aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh-enc.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-08-05 13:57:57 +0000
committerBart Polot <bart@net.in.tum.de>2013-08-05 13:57:57 +0000
commiteb9bed96fdffc5b38e3e8972d91066279efee8f5 (patch)
treee260d5e8382a3275fe03773c4dec8345a257988b /src/mesh/gnunet-service-mesh-enc.c
parentcb3cd715c8498b3c2b0e37cdb0ce784622ea876d (diff)
downloadgnunet-eb9bed96fdffc5b38e3e8972d91066279efee8f5.tar.gz
gnunet-eb9bed96fdffc5b38e3e8972d91066279efee8f5.zip
- handle connection keep-alives
Diffstat (limited to 'src/mesh/gnunet-service-mesh-enc.c')
-rw-r--r--src/mesh/gnunet-service-mesh-enc.c48
1 files changed, 27 insertions, 21 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c
index 4c9a24edd..d27cdca76 100644
--- a/src/mesh/gnunet-service-mesh-enc.c
+++ b/src/mesh/gnunet-service-mesh-enc.c
@@ -4849,6 +4849,7 @@ handle_mesh_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
4849 GNUNET_NO); 4849 GNUNET_NO);
4850 return GNUNET_OK; 4850 return GNUNET_OK;
4851 } 4851 }
4852
4852 ack = ntohl (msg->ack); 4853 ack = ntohl (msg->ack);
4853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ACK %u\n", ack); 4854 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ACK %u\n", ack);
4854 4855
@@ -4964,40 +4965,45 @@ static int
4964handle_mesh_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer, 4965handle_mesh_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
4965 const struct GNUNET_MessageHeader *message) 4966 const struct GNUNET_MessageHeader *message)
4966{ 4967{
4967 struct GNUNET_MESH_TunnelKeepAlive *msg; 4968 struct GNUNET_MESH_ConnectionKeepAlive *msg;
4968 struct MeshTunnel *t; 4969 struct MeshConnection *c;
4969 struct MeshClient *c; 4970 struct MeshPeer *neighbor;
4970 GNUNET_PEER_Id hop;
4971 int fwd; 4971 int fwd;
4972 4972
4973 msg = (struct GNUNET_MESH_TunnelKeepAlive *) message; 4973 msg = (struct GNUNET_MESH_ConnectionKeepAlive *) message;
4974 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got a keepalive packet from %s\n", 4974 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got a keepalive packet from %s\n",
4975 GNUNET_i2s (peer)); 4975 GNUNET_i2s (peer));
4976 4976
4977 t = channel_get (&msg->oid, ntohl (msg->tid)); 4977 c = connection_get (&msg->tid, ntohl (msg->cid));
4978 if (NULL == t) 4978 if (NULL == c)
4979 { 4979 {
4980 /* TODO notify that we dont know that tunnel */ 4980 GNUNET_STATISTICS_update (stats, "# keepalive on unknown connection", 1,
4981 GNUNET_STATISTICS_update (stats, "# keepalive on unknown tunnel", 1,
4982 GNUNET_NO); 4981 GNUNET_NO);
4983 return GNUNET_OK; 4982 return GNUNET_OK;
4984 } 4983 }
4985 4984
4986 fwd = GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE == ntohs (message->type) ? 4985 fwd = GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE == ntohs (message->type) ?
4987 GNUNET_YES : GNUNET_NO; 4986 GNUNET_YES : GNUNET_NO;
4988 c = fwd ? t->client : t->owner;
4989 hop = fwd ? t->next_hop : t->prev_hop;
4990 4987
4991 if (NULL != c) 4988 /* Check if origin is as expected */
4992 tunnel_change_state (t, MESH_TUNNEL_READY); 4989 neighbor = fwd ? connection_get_prev_hop (c) : connection_get_next_hop (c);
4993 tunnel_reset_timeout (t, fwd); 4990 if (peer_get (peer)->id != neighbor->id)
4994 if (NULL != c || 0 == hop || myid == hop) 4991 {
4992 GNUNET_break_op (0);
4993 return GNUNET_OK;
4994 }
4995
4996 connection_change_state (c, MESH_CONNECTION_READY);
4997 connection_reset_timeout (c, fwd);
4998
4999 if (NULL != c->t->channel_head)
4995 return GNUNET_OK; 5000 return GNUNET_OK;
4996 5001
4997 GNUNET_STATISTICS_update (stats, "# keepalives forwarded", 1, GNUNET_NO); 5002 GNUNET_STATISTICS_update (stats, "# keepalives forwarded", 1, GNUNET_NO);
4998 send_prebuilt_message (message, hop, t); 5003 send_prebuilt_message_connection (message, c, NULL, fwd);
5004
4999 return GNUNET_OK; 5005 return GNUNET_OK;
5000 } 5006}
5001 5007
5002 5008
5003 5009
@@ -5013,16 +5019,16 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
5013 sizeof (struct GNUNET_MESH_ConnectionBroken)}, 5019 sizeof (struct GNUNET_MESH_ConnectionBroken)},
5014 {&handle_mesh_connection_destroy, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY, 5020 {&handle_mesh_connection_destroy, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY,
5015 sizeof (struct GNUNET_MESH_ConnectionDestroy)}, 5021 sizeof (struct GNUNET_MESH_ConnectionDestroy)},
5016 {&handle_mesh_fwd, GNUNET_MESSAGE_TYPE_MESH_FWD, 0},
5017 {&handle_mesh_bck, GNUNET_MESSAGE_TYPE_MESH_BCK, 0},
5018 {&handle_mesh_keepalive, GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE, 5022 {&handle_mesh_keepalive, GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE,
5019 sizeof (struct GNUNET_MESH_TunnelKeepAlive)}, 5023 sizeof (struct GNUNET_MESH_ConnectionKeepAlive)},
5020 {&handle_mesh_keepalive, GNUNET_MESSAGE_TYPE_MESH_BCK_KEEPALIVE, 5024 {&handle_mesh_keepalive, GNUNET_MESSAGE_TYPE_MESH_BCK_KEEPALIVE,
5021 sizeof (struct GNUNET_MESH_TunnelKeepAlive)}, 5025 sizeof (struct GNUNET_MESH_ConnectionKeepAlive)},
5022 {&handle_mesh_ack, GNUNET_MESSAGE_TYPE_MESH_ACK, 5026 {&handle_mesh_ack, GNUNET_MESSAGE_TYPE_MESH_ACK,
5023 sizeof (struct GNUNET_MESH_ACK)}, 5027 sizeof (struct GNUNET_MESH_ACK)},
5024 {&handle_mesh_poll, GNUNET_MESSAGE_TYPE_MESH_POLL, 5028 {&handle_mesh_poll, GNUNET_MESSAGE_TYPE_MESH_POLL,
5025 sizeof (struct GNUNET_MESH_Poll)}, 5029 sizeof (struct GNUNET_MESH_Poll)},
5030 {&handle_mesh_fwd, GNUNET_MESSAGE_TYPE_MESH_FWD, 0},
5031 {&handle_mesh_bck, GNUNET_MESSAGE_TYPE_MESH_BCK, 0},
5026 {NULL, 0, 0} 5032 {NULL, 0, 0}
5027}; 5033};
5028 5034