diff options
Diffstat (limited to 'src/mesh/gnunet-service-mesh_connection.c')
-rw-r--r-- | src/mesh/gnunet-service-mesh_connection.c | 35 |
1 files changed, 21 insertions, 14 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 | */ |
754 | static void | 754 | static void |
755 | connection_keepalive (struct MeshConnection *c, int fwd) | 755 | connection_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); |