aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-11-27 16:38:11 +0000
committerBart Polot <bart@net.in.tum.de>2013-11-27 16:38:11 +0000
commit83b9ae7c4f2302350482a0763598906d219d6251 (patch)
treea3b8ad14b31cb66b1c1431df66c09cb74ebb7f1f /src
parent7b1f04400778be78d0494803e926474ffba25cc7 (diff)
downloadgnunet-83b9ae7c4f2302350482a0763598906d219d6251.tar.gz
gnunet-83b9ae7c4f2302350482a0763598906d219d6251.zip
- use only once KEEPALIVE message
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-service-mesh_connection.c35
-rw-r--r--src/mesh/gnunet-service-mesh_peer.c11
2 files changed, 25 insertions, 21 deletions
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,
749 * @param c Connection to keep alive.. 749 * @param c Connection to keep alive..
750 * @param fwd Is this a FWD keepalive? (owner -> dest). 750 * @param fwd Is this a FWD keepalive? (owner -> dest).
751 * 751 *
752 * FIXME use only one type, register in GMC_send_prebuilt_message() 752 * FIXME register in GMC_send_prebuilt_message()
753 */ 753 */
754static void 754static void
755connection_keepalive (struct MeshConnection *c, int fwd) 755connection_keepalive (struct MeshConnection *c, int fwd)
@@ -757,10 +757,6 @@ connection_keepalive (struct MeshConnection *c, int fwd)
757 struct GNUNET_MESH_ConnectionKeepAlive *msg; 757 struct GNUNET_MESH_ConnectionKeepAlive *msg;
758 size_t size = sizeof (struct GNUNET_MESH_ConnectionKeepAlive); 758 size_t size = sizeof (struct GNUNET_MESH_ConnectionKeepAlive);
759 char cbuf[size]; 759 char cbuf[size];
760 uint16_t type;
761
762 type = fwd ? GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE :
763 GNUNET_MESSAGE_TYPE_MESH_BCK_KEEPALIVE;
764 760
765 LOG (GNUNET_ERROR_TYPE_DEBUG, 761 LOG (GNUNET_ERROR_TYPE_DEBUG,
766 "sending %s keepalive for connection %s]\n", 762 "sending %s keepalive for connection %s]\n",
@@ -768,7 +764,7 @@ connection_keepalive (struct MeshConnection *c, int fwd)
768 764
769 msg = (struct GNUNET_MESH_ConnectionKeepAlive *) cbuf; 765 msg = (struct GNUNET_MESH_ConnectionKeepAlive *) cbuf;
770 msg->header.size = htons (size); 766 msg->header.size = htons (size);
771 msg->header.type = htons (type); 767 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_KEEPALIVE);
772 msg->cid = c->id; 768 msg->cid = c->id;
773 769
774 GMC_send_prebuilt_message (&msg->header, c, fwd, NULL, NULL); 770 GMC_send_prebuilt_message (&msg->header, c, fwd, NULL, NULL);
@@ -1964,6 +1960,7 @@ GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
1964 struct GNUNET_MESH_ConnectionKeepAlive *msg; 1960 struct GNUNET_MESH_ConnectionKeepAlive *msg;
1965 struct MeshConnection *c; 1961 struct MeshConnection *c;
1966 struct MeshPeer *neighbor; 1962 struct MeshPeer *neighbor;
1963 GNUNET_PEER_Id peer_id;
1967 int fwd; 1964 int fwd;
1968 1965
1969 msg = (struct GNUNET_MESH_ConnectionKeepAlive *) message; 1966 msg = (struct GNUNET_MESH_ConnectionKeepAlive *) message;
@@ -1978,15 +1975,25 @@ GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
1978 return GNUNET_OK; 1975 return GNUNET_OK;
1979 } 1976 }
1980 1977
1981 fwd = GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE == ntohs (message->type) ? 1978 /* Check if origin is as expected TODO refactor and reuse */
1982 GNUNET_YES : GNUNET_NO; 1979 peer_id = GNUNET_PEER_search (peer);
1983 1980 neighbor = get_prev_hop (c);
1984 /* Check if origin is as expected */ 1981 if (peer_id == GMP_get_short_id (neighbor))
1985 neighbor = get_hop (c, fwd);
1986 if (GNUNET_PEER_search (peer) != GMP_get_short_id (neighbor))
1987 { 1982 {
1988 GNUNET_break_op (0); 1983 fwd = GNUNET_YES;
1989 return GNUNET_OK; 1984 }
1985 else
1986 {
1987 neighbor = get_next_hop (c);
1988 if (peer_id == GMP_get_short_id (neighbor))
1989 {
1990 fwd = GNUNET_NO;
1991 }
1992 else
1993 {
1994 GNUNET_break_op (0);
1995 return GNUNET_OK;
1996 }
1990 } 1997 }
1991 1998
1992 connection_change_state (c, MESH_CONNECTION_READY); 1999 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[] = {
318 sizeof (struct GNUNET_MESH_ConnectionBroken)}, 318 sizeof (struct GNUNET_MESH_ConnectionBroken)},
319 {&GMC_handle_destroy, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY, 319 {&GMC_handle_destroy, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY,
320 sizeof (struct GNUNET_MESH_ConnectionDestroy)}, 320 sizeof (struct GNUNET_MESH_ConnectionDestroy)},
321 {&GMC_handle_keepalive, GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE, 321 {&GMC_handle_keepalive, GNUNET_MESSAGE_TYPE_MESH_KEEPALIVE,
322 sizeof (struct GNUNET_MESH_ConnectionKeepAlive)},
323 {&GMC_handle_keepalive, GNUNET_MESSAGE_TYPE_MESH_BCK_KEEPALIVE,
324 sizeof (struct GNUNET_MESH_ConnectionKeepAlive)}, 322 sizeof (struct GNUNET_MESH_ConnectionKeepAlive)},
325 {&GMC_handle_ack, GNUNET_MESSAGE_TYPE_MESH_ACK, 323 {&GMC_handle_ack, GNUNET_MESSAGE_TYPE_MESH_ACK,
326 sizeof (struct GNUNET_MESH_ACK)}, 324 sizeof (struct GNUNET_MESH_ACK)},
@@ -923,14 +921,13 @@ GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls)
923 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY: 921 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY:
924 LOG (GNUNET_ERROR_TYPE_INFO, "destroying a DESTROY message\n"); 922 LOG (GNUNET_ERROR_TYPE_INFO, "destroying a DESTROY message\n");
925 /* fall through */ 923 /* fall through */
926 case GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED:
927 case GNUNET_MESSAGE_TYPE_MESH_ACK:
928 case GNUNET_MESSAGE_TYPE_MESH_POLL:
929 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK: 924 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK:
930 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE: 925 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE:
931 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN: 926 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN:
932 case GNUNET_MESSAGE_TYPE_MESH_KX: 927 case GNUNET_MESSAGE_TYPE_MESH_KX:
933 LOG (GNUNET_ERROR_TYPE_DEBUG, "# prebuilt message\n");; 928 case GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED:
929 case GNUNET_MESSAGE_TYPE_MESH_ACK:
930 case GNUNET_MESSAGE_TYPE_MESH_POLL:
934 GNUNET_free_non_null (queue->cls); 931 GNUNET_free_non_null (queue->cls);
935 break; 932 break;
936 933