From: Bart Polot Date: Thu, 4 Aug 2011 15:29:25 +0000 (+0000) Subject: Added handler for Path ACK messages X-Git-Tag: initial-import-from-subversion-38251~17469 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=a7463441f1251ec3480d60c7b7816f24104a9b75;p=oweals%2Fgnunet.git Added handler for Path ACK messages --- diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 02a78244f..f9961ffc0 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c @@ -1449,6 +1449,79 @@ handle_mesh_data_to_orig (void *cls, } +/** + * Core handler for path ACKs + * + * @param cls closure + * @param message message + * @param peer peer identity this notification is about + * @param atsi performance data + * @return GNUNET_OK to keep the connection open, + * GNUNET_SYSERR to close it (signal serious error) + */ +static int +handle_mesh_path_ack (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_MessageHeader *message, + const struct GNUNET_TRANSPORT_ATS_Information + *atsi) +{ + struct GNUNET_MESH_PathACK *msg; + struct GNUNET_PeerIdentity id; + struct MeshTunnel *t; + struct MeshPeerInfo *peer_info; + + msg = (struct GNUNET_MESH_PathACK *) message; + t = retrieve_tunnel(&msg->oid, msg->tid); + if (NULL == t) { + /* TODO notify that we don't know the tunnel */ + return GNUNET_OK; + } + + /* Message for us? */ + if (GNUNET_PEER_search(&msg->oid) == myid) { + struct GNUNET_MESH_PeerControl pc; + if (NULL == t->client) { + GNUNET_break(0); + return GNUNET_OK; + } + peer_info = get_peer_info(&msg->peer_id); + if (NULL == peer_info) { + GNUNET_break_op(0); + return GNUNET_OK; + } + peer_info->state = MESH_PEER_READY; + pc.header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED); + pc.header.size = htons(sizeof(struct GNUNET_MESH_PeerControl)); + pc.tunnel_id = htonl(t->local_tid); + GNUNET_PEER_resolve(peer_info->id, &pc.peer); + GNUNET_SERVER_notification_context_unicast(nc, + t->client->handle, + &pc.header, + GNUNET_NO); + return GNUNET_OK; + } + + peer_info = get_peer_info(&msg->oid); + if (NULL == peer_info) { + /* If we know the tunnel, we should DEFINITELY know the peer */ + GNUNET_break(0); + return GNUNET_OK; + } + GNUNET_PEER_resolve(get_first_hop(peer_info->path), &id); + msg = GNUNET_malloc(sizeof(struct GNUNET_MESH_PathACK)); + memcpy(msg, message, sizeof(struct GNUNET_MESH_PathACK)); + GNUNET_CORE_notify_transmit_ready(core_handle, + 0, + 0, + GNUNET_TIME_UNIT_FOREVER_REL, + &id, + sizeof(struct GNUNET_MESH_PathACK), + &send_core_data_raw, + msg); +} + + /** * Functions to handle messages from core */ @@ -1457,6 +1530,8 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = { {&handle_mesh_data_unicast, GNUNET_MESSAGE_TYPE_DATA_MESSAGE_FROM_ORIGIN, 0}, {&handle_mesh_data_multicast, GNUNET_MESSAGE_TYPE_DATA_MULTICAST, 0}, {&handle_mesh_data_to_orig, GNUNET_MESSAGE_TYPE_DATA_MESSAGE_TO_ORIGIN, 0}, + {&handle_mesh_path_ack, GNUNET_MESSAGE_TYPE_PATH_ACK, + sizeof(struct GNUNET_MESH_PathACK)}, {NULL, 0, 0} }; diff --git a/src/mesh/mesh_protocol.h b/src/mesh/mesh_protocol.h index 8868d0c66..c23e3a1a6 100644 --- a/src/mesh/mesh_protocol.h +++ b/src/mesh/mesh_protocol.h @@ -172,6 +172,11 @@ struct GNUNET_MESH_PathACK */ struct GNUNET_PeerIdentity oid; + /** + * ID of the endpoint + */ + struct GNUNET_PeerIdentity peer_id; + /* TODO: signature */ };