From 46244f4cb8abfb65de29fb8de8aad2209d449ecb Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Wed, 18 Dec 2013 20:33:26 +0000 Subject: [PATCH] - send notification immediately if a connection fails to be created - allow to queue messages with no connection --- src/mesh/gnunet-service-mesh_connection.c | 49 ++++++++++++++++++++++- src/mesh/gnunet-service-mesh_peer.c | 25 +++++------- 2 files changed, 58 insertions(+), 16 deletions(-) diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index ef2df2ce3..c31ee2aab 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c @@ -790,6 +790,39 @@ send_broken (struct MeshConnection *c, } +/** + * Send a notification that a connection is broken, when a connection + * isn't even created. + * + * @param connection_id Connection ID. + * @param id1 Peer that has disconnected. + * @param id2 Peer that has disconnected. + * @param peer Peer to notify (neighbor who sent the connection). + */ +static void +send_broken2 (struct GNUNET_HashCode *connection_id, + const struct GNUNET_PeerIdentity *id1, + const struct GNUNET_PeerIdentity *id2, + GNUNET_PEER_Id peer_id) +{ + struct GNUNET_MESH_ConnectionBroken *msg; + struct MeshPeer *neighbor; + + msg = GNUNET_new (struct GNUNET_MESH_ConnectionBroken); + msg->header.size = htons (sizeof (struct GNUNET_MESH_ConnectionBroken)); + msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN); + msg->cid = *connection_id; + msg->peer1 = *id1; + msg->peer2 = *id2; + neighbor = GMP_get_short (peer_id); + GMP_queue_add (neighbor, msg, + GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED, + sizeof (struct GNUNET_MESH_ConnectionBroken), + NULL, GNUNET_SYSERR, /* connection, fwd */ + NULL, NULL); /* continuation */ +} + + /** * Send keepalive packets for a connection. * @@ -1383,15 +1416,29 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer, size, &own_pos); if (NULL == path) return GNUNET_OK; + if (0 == own_pos) + { + GNUNET_break_op (0); + return GNUNET_OK; + } LOG (GNUNET_ERROR_TYPE_DEBUG, " Own position: %u\n", own_pos); - GMP_add_path_to_all (path, GNUNET_NO); LOG (GNUNET_ERROR_TYPE_DEBUG, " Creating connection\n"); c = GMC_new (cid, NULL, path_duplicate (path), own_pos); if (NULL == c) { + if (path->length - 1 == own_pos) + { + /* If we are destination, why did the creation fail? */ + GNUNET_break (0); + return GNUNET_OK; + } + send_broken2 (cid, &my_full_id, + GNUNET_PEER_resolve2 (path->peers[own_pos + 1]), + path->peers[own_pos - 1]); path_destroy (path); return GNUNET_OK; } + GMP_add_path_to_all (path, GNUNET_NO); connection_reset_timeout (c, GNUNET_YES); } else diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c index 4d183bbd6..8f13d0bb1 100644 --- a/src/mesh/gnunet-service-mesh_peer.c +++ b/src/mesh/gnunet-service-mesh_peer.c @@ -858,9 +858,7 @@ queue_send (void *cls, size_t size, void *buf) case GNUNET_MESSAGE_TYPE_MESH_KX: case GNUNET_MESSAGE_TYPE_MESH_ACK: case GNUNET_MESSAGE_TYPE_MESH_POLL: - LOG (GNUNET_ERROR_TYPE_DEBUG, - "* raw: %s\n", - GM_m2s (queue->type)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "* raw: %s\n", GM_m2s (queue->type)); data_size = send_core_data_raw (queue->cls, size, buf); break; case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE: @@ -911,14 +909,13 @@ queue_send (void *cls, size_t size, void *buf) if (NULL == peer->core_transmit) { peer->core_transmit = - GNUNET_CORE_notify_transmit_ready(core_handle, - 0, - 0, - GNUNET_TIME_UNIT_FOREVER_REL, - dst_id, - queue->size, - &queue_send, - peer); + GNUNET_CORE_notify_transmit_ready (core_handle, + 0, 0, + GNUNET_TIME_UNIT_FOREVER_REL, + dst_id, + queue->size, + &queue_send, + peer); queue->start_waiting = GNUNET_TIME_absolute_get (); } else @@ -956,7 +953,6 @@ GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls) struct MeshPeer *peer; peer = queue->peer; - GNUNET_assert (NULL != queue->c); if (GNUNET_YES == clear_cls) { @@ -1013,7 +1009,7 @@ GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls) * build the message to be sent if not already prebuilt. * @param type Type of the message, 0 for a raw message. * @param size Size of the message. - * @param c Connection this message belongs to (cannot be NULL). + * @param c Connection this message belongs to (can be NULL). * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!) * @param cont Continuation to be called once CORE has taken the message. * @param cont_cls Closure for @c cont. @@ -1034,7 +1030,6 @@ GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size, "queue add %s %s towards %s (size %u) on c %p (%s)\n", GM_f2s (fwd), GM_m2s (type), GMP_2s(peer), size, c, GMC_2s (c)); - GNUNET_assert (NULL != c); if (NULL == peer->connections) { @@ -1055,7 +1050,7 @@ GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size, LOG (GNUNET_ERROR_TYPE_DEBUG, "priority %d\n", priority); - call_core = GMC_is_sendable (c, fwd); + call_core = NULL == c ? GNUNET_YES : GMC_is_sendable (c, fwd); queue = GNUNET_malloc (sizeof (struct MeshPeerQueue)); queue->cls = cls; queue->type = type; -- 2.25.1