From 0f4a34c3c534fc01ded8ea3d94b990ca09d7ac0b Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Thu, 10 Oct 2013 12:46:15 +0000 Subject: [PATCH] - move queue canceling to peer.c --- src/mesh/gnunet-service-mesh_connection.c | 32 ++++-------------- src/mesh/gnunet-service-mesh_peer.c | 41 +++++++++++++++++++++++ src/mesh/gnunet-service-mesh_peer.h | 17 ++++++++++ 3 files changed, 65 insertions(+), 25 deletions(-) diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index e70211cb9..d7d6f89f7 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c @@ -723,8 +723,7 @@ connection_unlock_queue (struct MeshConnection *c, int fwd) static void connection_cancel_queues (struct MeshConnection *c, int fwd) { - struct MeshPeerQueue *q; - struct MeshPeerQueue *next; + struct MeshFlowControl *fc; struct MeshPeer *peer; @@ -733,32 +732,15 @@ connection_cancel_queues (struct MeshConnection *c, int fwd) GNUNET_break (0); return; } - fc = fwd ? &c->fwd_fc : &c->bck_fc; + peer = connection_get_hop (c, fwd); + GMP_queue_cancel (peer, c); - for (q = peer->queue_head; NULL != q; q = next) - { - next = q->next; - if (q->c == c) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "connection_cancel_queue %s\n", - GNUNET_MESH_DEBUG_M2S (q->type)); - queue_destroy (q, GNUNET_YES); - } - } - if (NULL == peer->queue_head) + fc = fwd ? &c->fwd_fc : &c->bck_fc; + if (GNUNET_SCHEDULER_NO_TASK != fc->poll_task) { - if (NULL != peer->core_transmit) - { - GNUNET_CORE_notify_transmit_ready_cancel (peer->core_transmit); - peer->core_transmit = NULL; - } - if (GNUNET_SCHEDULER_NO_TASK != fc->poll_task) - { - GNUNET_SCHEDULER_cancel (fc->poll_task); - fc->poll_task = GNUNET_SCHEDULER_NO_TASK; - } + GNUNET_SCHEDULER_cancel (fc->poll_task); + fc->poll_task = GNUNET_SCHEDULER_NO_TASK; } } diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c index d700f3aa2..5e44bbc86 100644 --- a/src/mesh/gnunet-service-mesh_peer.c +++ b/src/mesh/gnunet-service-mesh_peer.c @@ -1407,6 +1407,39 @@ GMP_queue_add (void *cls, uint16_t type, size_t size, } +/** + * Cancel all queued messages to a peer that belong to a certain connection. + * + * @param peer Peer towards whom to cancel. + * @param c Connection whose queued messages to cancel. + */ +void +GMP_queue_cancel (struct MeshPeer *peer, struct MeshConnection *c) +{ + struct MeshPeerQueue *q; + struct MeshPeerQueue *next; + + for (q = peer->queue_head; NULL != q; q = next) + { + next = q->next; + if (q->c == c) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "connection_cancel_queue %s\n", + GNUNET_MESH_DEBUG_M2S (q->type)); + GMP_queue_destroy (q, GNUNET_YES); + } + } + if (NULL == peer->queue_head) + { + if (NULL != peer->core_transmit) + { + GNUNET_CORE_notify_transmit_ready_cancel (peer->core_transmit); + peer->core_transmit = NULL; + } + } +} + /** * Initialize the peer subsystem. @@ -1624,6 +1657,14 @@ GMP_add_connection (struct MeshPeer *peer, } +/** + * Remove a connection from a neighboring peer. + * + * @param peer Peer to remove connection from. + * @param c Connection to remove. + * + * @return GNUNET_OK on success. + */ int GMP_remove_connection (struct MeshPeer *peer, const struct MeshConnection *c) diff --git a/src/mesh/gnunet-service-mesh_peer.h b/src/mesh/gnunet-service-mesh_peer.h index ad1955390..c898af351 100644 --- a/src/mesh/gnunet-service-mesh_peer.h +++ b/src/mesh/gnunet-service-mesh_peer.h @@ -97,6 +97,15 @@ GMP_queue_add (void *cls, uint16_t type, size_t size, int fwd, GMP_sent callback, void *callback_cls); +/** + * Cancel all queued messages to a peer that belong to a certain connection. + * + * @param peer Peer towards whom to cancel. + * @param c Connection whose queued messages to cancel. + */ +void +GMP_queue_cancel (struct MeshPeer *peer, struct MeshConnection *c); + /** * Set tunnel. * @@ -132,6 +141,14 @@ GMP_is_neighbor (const struct MeshPeer *peer); int GMP_add_connection (struct MeshPeer *peer, struct MeshConnection *c); +/** + * Remove a connection from a neighboring peer. + * + * @param peer Peer to remove connection from. + * @param c Connection to remove. + * + * @return GNUNET_OK on success. + */ int GMP_remove_connection (struct MeshPeer *peer, struct MeshConnection *c); -- 2.25.1