From f02bdf449974e76388e1fd5dff03f6c4e6bc39fd Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Thu, 10 Oct 2013 15:15:25 +0000 Subject: [PATCH] - fixes --- src/mesh/gnunet-service-mesh_connection.c | 91 +++++++--------------- src/mesh/gnunet-service-mesh_connection.h | 11 +++ src/mesh/gnunet-service-mesh_peer.c | 94 ++++++++++++++++++----- src/mesh/gnunet-service-mesh_peer.h | 3 + 4 files changed, 116 insertions(+), 83 deletions(-) diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index 69115b835..06ca072e9 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c @@ -470,7 +470,8 @@ send_connection_ack (struct MeshConnection *connection, int fwd) GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK, sizeof (struct GNUNET_MESH_ConnectionACK), connection, NULL, fwd, - &message_sent, sizeof (struct GNUNET_MESH_ConnectionACK)); + &message_sent, + (void *) sizeof (struct GNUNET_MESH_ConnectionACK)); if (MESH_TUNNEL3_NEW == GMT_get_state (t)) GMT_change_state (t, MESH_TUNNEL3_WAITING); if (MESH_CONNECTION_READY != connection->state) @@ -498,7 +499,7 @@ enum MeshTunnel3State state; size, connection, NULL, - GNUNET_YES, &message_sent, size); + GNUNET_YES, &message_sent, (void *) size); state = GMT_get_state (connection->t); if (MESH_TUNNEL3_SEARCHING == state || MESH_TUNNEL3_NEW == state) GMT_change_state (connection->t, MESH_TUNNEL3_WAITING); @@ -678,34 +679,6 @@ connection_get_hop (struct MeshConnection *c, int fwd) } -/** - * Get the first transmittable message for a connection. - * - * @param c Connection. - * @param fwd Is this FWD? - * - * @return First transmittable message. - */ -static struct MeshPeerQueue * -connection_get_first_message (struct MeshConnection *c, int fwd) -{ - struct MeshPeerQueue *q; - struct MeshPeer *p; - - p = connection_get_hop (c, fwd); - - for (q = p->queue_head; NULL != q; q = q->next) - { - if (q->c != c) - continue; - if (queue_is_sendable (q)) - return q; - } - - return NULL; -} - - /** * @brief Re-initiate traffic on this connection if necessary. * @@ -720,8 +693,6 @@ static void connection_unlock_queue (struct MeshConnection *c, int fwd) { struct MeshPeer *peer; - struct MeshPeerQueue *q; - size_t size; LOG (GNUNET_ERROR_TYPE_DEBUG, "connection_unlock_queue %s on %s\n", @@ -734,30 +705,7 @@ connection_unlock_queue (struct MeshConnection *c, int fwd) } peer = connection_get_hop (c, fwd); - - if (NULL != peer->core_transmit) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, " already unlocked!\n"); - return; /* Already unlocked */ - } - - q = connection_get_first_message (c, fwd); - if (NULL == q) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, " queue empty!\n"); - return; /* Nothing to transmit */ - } - - size = q->size; - peer->core_transmit = - GNUNET_CORE_notify_transmit_ready (core_handle, - GNUNET_NO, - 0, - GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_PEER_resolve2 (peer->id), - size, - &queue_send, - peer); + GMP_queue_unlock (peer, c); } @@ -822,7 +770,7 @@ connection_poll (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_POLL); msg.header.size = htons (sizeof (msg)); LOG (GNUNET_ERROR_TYPE_DEBUG, " *** pid (%u)!\n", fc->last_pid_sent); - send_prebuilt_message_connection (&msg.header, c, NULL, fc == &c->fwd_fc); + GMC_send_prebuilt_message (&msg.header, c, NULL, fc == &c->fwd_fc); fc->poll_time = GNUNET_TIME_STD_BACKOFF (fc->poll_time); fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time, &connection_poll, fc); @@ -940,14 +888,14 @@ register_neighbors (struct MeshConnection *c) if (GNUNET_NO == GMP_is_neighbor (peer)) { GMC_destroy (c); - return NULL; + return; } GMP_add_connection (peer, c); peer = connection_get_prev_hop (c); if (GNUNET_NO == GMP_is_neighbor (peer)) { GMC_destroy (c); - return NULL; + return; } GMP_add_connection (peer, c); } @@ -1048,10 +996,10 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer, LOG (GNUNET_ERROR_TYPE_DEBUG, " ... adding %s\n", GNUNET_i2s (&id[i])); path->peers[i] = GNUNET_PEER_intern (&id[i]); - if (path->peers[i] == my_short_id) + if (path->peers[i] == myid) own_pos = i; } - if (own_pos == 0 && path->peers[own_pos] != my_short_id) + if (own_pos == 0 && path->peers[own_pos] != myid) { /* create path: self not found in path through self */ GNUNET_break_op (0); @@ -1086,7 +1034,7 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer, if (NULL == orig_peer->tunnel) { - orig_peer->tunnel = tunnel_new (); + orig_peer->tunnel = GMT_new (); orig_peer->tunnel->peer = orig_peer; } GMT_add_connection (orig_peer->tunnel, c); @@ -1985,6 +1933,25 @@ GMC_is_terminal (struct MeshConnection *c, int fwd) } +/** + * See if we are allowed to send by the next hop in the given direction. + * + * @param c Connection. + * @param fwd Is this about fwd traffic? + * + * @return GNUNET_YES in case it's OK. + */ +int +GMC_is_sendable (struct MeshConnection *c, int fwd) +{ + struct MeshFlowControl *fc; + + fc = fwd ? &c->fwd_fc : &c->bck_fc; + if (GMC_is_pid_bigger (fc->last_ack_recv, fc->last_pid_sent)) + return GNUNET_YES; + return GNUNET_NO; +} + /** * Sends an already built message on a connection, properly registering * all used resources. diff --git a/src/mesh/gnunet-service-mesh_connection.h b/src/mesh/gnunet-service-mesh_connection.h index fafe0a59b..0d70764c2 100644 --- a/src/mesh/gnunet-service-mesh_connection.h +++ b/src/mesh/gnunet-service-mesh_connection.h @@ -369,6 +369,17 @@ GMC_is_origin (struct MeshConnection *c, int fwd); int GMC_is_terminal (struct MeshConnection *c, int fwd); +/** + * See if we are allowed to send by the next hop in the given direction. + * + * @param c Connection. + * @param fwd Is this about fwd traffic? + * + * @return GNUNET_YES in case it's OK. + */ +int +GMC_is_sendable (struct MeshConnection *c, int fwd); + /** * Sends an already built message on a connection, properly registering * all used resources. diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c index 48d5eda7c..42717b8eb 100644 --- a/src/mesh/gnunet-service-mesh_peer.c +++ b/src/mesh/gnunet-service-mesh_peer.c @@ -1002,7 +1002,7 @@ queue_send (void *cls, size_t size, void *buf) if (GNUNET_YES == t->destroy && 0 == t->pending_messages) { // LOG (GNUNET_ERROR_TYPE_DEBUG, "* destroying tunnel!\n"); - tunnel_destroy (t); + GMT_destroy (t); } } LOG (GNUNET_ERROR_TYPE_DEBUG, "* Return %d\n", data_size); @@ -1010,6 +1010,22 @@ queue_send (void *cls, size_t size, void *buf) } +static int +queue_is_sendable (struct MeshPeerQueue *q) +{ + /* Is PID-independent? */ + switch (q->type) + { + case GNUNET_MESSAGE_TYPE_MESH_ACK: + case GNUNET_MESSAGE_TYPE_MESH_POLL: + return GNUNET_YES; + } + + if (GMC_is_sendable (q->c, q->fwd)) + return GNUNET_YES; + + return GNUNET_NO; +} /** * Get first sendable message. @@ -1033,26 +1049,6 @@ peer_get_first_message (const struct MeshPeer *peer) } -static int -queue_is_sendable (struct MeshPeerQueue *q) -{ - struct MeshFlowControl *fc; - - /* Is PID-independent? */ - switch (q->type) - { - case GNUNET_MESSAGE_TYPE_MESH_ACK: - case GNUNET_MESSAGE_TYPE_MESH_POLL: - return GNUNET_YES; - } - - /* Is PID allowed? */ - fc = q->fwd ? &q->c->fwd_fc : &q->c->bck_fc; - if (GMC_is_pid_bigger (fc->last_ack_recv, fc->last_pid_sent)) - return GNUNET_YES; - - return GNUNET_NO; -} /******************************************************************************/ @@ -1313,6 +1309,62 @@ GMP_queue_cancel (struct MeshPeer *peer, struct MeshConnection *c) } +/** + * Get the first transmittable message for a connection. + * + * @param peer Neighboring peer. + * @param c Connection. + * + * @return First transmittable message. + */ +static struct MeshPeerQueue * +connection_get_first_message (struct MeshPeer *peer, struct MeshConnection *c) +{ + struct MeshPeerQueue *q; + + for (q = peer->queue_head; NULL != q; q = q->next) + { + if (q->c != c) + continue; + if (queue_is_sendable (q)) + return q; + } + + return NULL; +} + +void +GMP_queue_unlock (struct MeshPeer *peer, struct MeshConnection *c) +{ + struct MeshPeerQueue *q; + size_t size; + + if (NULL != peer->core_transmit) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, " already unlocked!\n"); + return; /* Already unlocked */ + } + + q = connection_get_first_message (c); + if (NULL == q) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, " queue empty!\n"); + return; /* Nothing to transmit */ + } + + size = q->size; + peer->core_transmit = + GNUNET_CORE_notify_transmit_ready (core_handle, + GNUNET_NO, + 0, + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_PEER_resolve2 (peer->id), + size, + &queue_send, + peer); +} + + /** * Initialize the peer subsystem. * diff --git a/src/mesh/gnunet-service-mesh_peer.h b/src/mesh/gnunet-service-mesh_peer.h index 3f31069dc..1918a7842 100644 --- a/src/mesh/gnunet-service-mesh_peer.h +++ b/src/mesh/gnunet-service-mesh_peer.h @@ -106,6 +106,9 @@ GMP_queue_add (void *cls, uint16_t type, size_t size, void GMP_queue_cancel (struct MeshPeer *peer, struct MeshConnection *c); +void +GMP_queue_unlock (struct MeshPeer *peer, struct MeshConnection *c); + /** * Set tunnel. * -- 2.25.1