From 83b9ae7c4f2302350482a0763598906d219d6251 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Wed, 27 Nov 2013 16:38:11 +0000 Subject: - use only once KEEPALIVE message --- src/mesh/gnunet-service-mesh_connection.c | 35 ++++++++++++++++++------------- src/mesh/gnunet-service-mesh_peer.c | 11 ++++------ 2 files changed, 25 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index 545b7b3f1..73e947753 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c @@ -749,7 +749,7 @@ send_broken (struct MeshConnection *c, * @param c Connection to keep alive.. * @param fwd Is this a FWD keepalive? (owner -> dest). * - * FIXME use only one type, register in GMC_send_prebuilt_message() + * FIXME register in GMC_send_prebuilt_message() */ static void connection_keepalive (struct MeshConnection *c, int fwd) @@ -757,10 +757,6 @@ connection_keepalive (struct MeshConnection *c, int fwd) struct GNUNET_MESH_ConnectionKeepAlive *msg; size_t size = sizeof (struct GNUNET_MESH_ConnectionKeepAlive); char cbuf[size]; - uint16_t type; - - type = fwd ? GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE : - GNUNET_MESSAGE_TYPE_MESH_BCK_KEEPALIVE; LOG (GNUNET_ERROR_TYPE_DEBUG, "sending %s keepalive for connection %s]\n", @@ -768,7 +764,7 @@ connection_keepalive (struct MeshConnection *c, int fwd) msg = (struct GNUNET_MESH_ConnectionKeepAlive *) cbuf; msg->header.size = htons (size); - msg->header.type = htons (type); + msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_KEEPALIVE); msg->cid = c->id; GMC_send_prebuilt_message (&msg->header, c, fwd, NULL, NULL); @@ -1964,6 +1960,7 @@ GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MESH_ConnectionKeepAlive *msg; struct MeshConnection *c; struct MeshPeer *neighbor; + GNUNET_PEER_Id peer_id; int fwd; msg = (struct GNUNET_MESH_ConnectionKeepAlive *) message; @@ -1978,15 +1975,25 @@ GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer, return GNUNET_OK; } - fwd = GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE == ntohs (message->type) ? - GNUNET_YES : GNUNET_NO; - - /* Check if origin is as expected */ - neighbor = get_hop (c, fwd); - if (GNUNET_PEER_search (peer) != GMP_get_short_id (neighbor)) + /* Check if origin is as expected TODO refactor and reuse */ + peer_id = GNUNET_PEER_search (peer); + neighbor = get_prev_hop (c); + if (peer_id == GMP_get_short_id (neighbor)) { - GNUNET_break_op (0); - return GNUNET_OK; + fwd = GNUNET_YES; + } + else + { + neighbor = get_next_hop (c); + if (peer_id == GMP_get_short_id (neighbor)) + { + fwd = GNUNET_NO; + } + else + { + GNUNET_break_op (0); + return GNUNET_OK; + } } connection_change_state (c, MESH_CONNECTION_READY); diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c index f18dcbb76..dfc673321 100644 --- a/src/mesh/gnunet-service-mesh_peer.c +++ b/src/mesh/gnunet-service-mesh_peer.c @@ -318,9 +318,7 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = { sizeof (struct GNUNET_MESH_ConnectionBroken)}, {&GMC_handle_destroy, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY, sizeof (struct GNUNET_MESH_ConnectionDestroy)}, - {&GMC_handle_keepalive, GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE, - sizeof (struct GNUNET_MESH_ConnectionKeepAlive)}, - {&GMC_handle_keepalive, GNUNET_MESSAGE_TYPE_MESH_BCK_KEEPALIVE, + {&GMC_handle_keepalive, GNUNET_MESSAGE_TYPE_MESH_KEEPALIVE, sizeof (struct GNUNET_MESH_ConnectionKeepAlive)}, {&GMC_handle_ack, GNUNET_MESSAGE_TYPE_MESH_ACK, sizeof (struct GNUNET_MESH_ACK)}, @@ -923,14 +921,13 @@ GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls) case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY: LOG (GNUNET_ERROR_TYPE_INFO, "destroying a DESTROY message\n"); /* fall through */ - case GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED: - case GNUNET_MESSAGE_TYPE_MESH_ACK: - case GNUNET_MESSAGE_TYPE_MESH_POLL: case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK: case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE: case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN: case GNUNET_MESSAGE_TYPE_MESH_KX: - LOG (GNUNET_ERROR_TYPE_DEBUG, "# prebuilt message\n");; + case GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED: + case GNUNET_MESSAGE_TYPE_MESH_ACK: + case GNUNET_MESSAGE_TYPE_MESH_POLL: GNUNET_free_non_null (queue->cls); break; -- cgit v1.2.3