From bc69fd462df9e2e2ad795586400cba74e8327dcd Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Thu, 10 Oct 2013 13:52:37 +0000 Subject: [PATCH] - fixes --- src/mesh/gnunet-service-mesh_channel.c | 24 ++-- src/mesh/gnunet-service-mesh_channel.h | 1 + src/mesh/gnunet-service-mesh_connection.c | 158 +++++++++++----------- src/mesh/gnunet-service-mesh_connection.h | 1 - src/mesh/gnunet-service-mesh_local.c | 2 +- src/mesh/gnunet-service-mesh_local.h | 2 +- src/mesh/gnunet-service-mesh_tunnel.c | 2 + 7 files changed, 91 insertions(+), 99 deletions(-) diff --git a/src/mesh/gnunet-service-mesh_channel.c b/src/mesh/gnunet-service-mesh_channel.c index 5f2ce2f8d..f59519311 100644 --- a/src/mesh/gnunet-service-mesh_channel.c +++ b/src/mesh/gnunet-service-mesh_channel.c @@ -526,8 +526,8 @@ channel_retransmit_message (void *cls, * is stalled. */ // FIXME access to queue elements is limited -// payload = (struct GNUNET_MESH_Data *) ©[1]; -// fwd = (rel == ch->root_rel); + payload = (struct GNUNET_MESH_Data *) ©[1]; + fwd = (rel == ch->root_rel); // c = GMT_get_connection (ch->t, fwd); // hop = connection_get_hop (c, fwd); // for (q = hop->queue_head; NULL != q; q = q->next) @@ -897,7 +897,7 @@ channel_destroy_iterator (void *cls, */ void handle_loopback (struct MeshChannel *ch, - struct GNUNET_MessageHeader *msgh, + const struct GNUNET_MessageHeader *msgh, int fwd) { uint16_t type; @@ -1200,8 +1200,6 @@ GMCH_handle_data (struct MeshChannel *ch, struct MeshChannelReliability *rel; struct MeshClient *c; uint32_t mid; - uint16_t type; - size_t size; /* Initialize FWD/BCK data */ c = fwd ? ch->dest : ch->root; @@ -1360,7 +1358,7 @@ GMCH_handle_create (const struct GNUNET_MESH_ChannelCreate *msg, chid = ntohl (msg->chid); /* Create channel */ - ch = channel_new (NULL, NULL, 0); /* FIXME t */ + ch = channel_new (NULL, NULL, 0); /* FIXME pass t */ ch->gid = chid; channel_set_options (ch, ntohl (msg->opt)); @@ -1372,11 +1370,11 @@ GMCH_handle_create (const struct GNUNET_MESH_ChannelCreate *msg, { /* TODO send reject */ LOG (GNUNET_ERROR_TYPE_DEBUG, " no client has port registered\n"); - /* TODO free ch */ - return; + channel_destroy (ch); + return NULL; } - channel_add_client (ch, c); + GMCH_add_client (ch, c); if (GNUNET_YES == ch->reliable) LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! Reliable\n"); @@ -1416,10 +1414,6 @@ GMCH_handle_destroy (struct MeshChannel *ch, const struct GNUNET_MESH_ChannelManage *msg, int fwd) { - MESH_ChannelNumber chid; - - /* Check if channel exists */ - chid = ntohl (msg->chid); if ( (fwd && NULL == ch->dest) || (!fwd && NULL == ch->root) ) { /* Not for us (don't destroy twice a half-open loopback channel) */ @@ -1442,8 +1436,6 @@ void GMCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message, struct MeshChannel *ch, int fwd) { - size_t size = ntohs (message->size); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Send on Channel %s:%X %s\n", GMT_2s (ch->t), ch->gid, fwd ? "FWD" : "BCK"); LOG (GNUNET_ERROR_TYPE_DEBUG, " %s\n", @@ -1451,7 +1443,7 @@ GMCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message, if (GMT_is_loopback (ch->t)) { - handle_loopback (ch->t, message, fwd); + handle_loopback (ch, message, fwd); return; } diff --git a/src/mesh/gnunet-service-mesh_channel.h b/src/mesh/gnunet-service-mesh_channel.h index a06319c34..1ea8c6d94 100644 --- a/src/mesh/gnunet-service-mesh_channel.h +++ b/src/mesh/gnunet-service-mesh_channel.h @@ -41,6 +41,7 @@ extern "C" #include "gnunet_util_lib.h" #include "mesh_protocol_enc.h" +#include "mesh_enc.h" /** * Struct containing all information regarding a channel to a remote client. diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index 86d241a82..7a27d3984 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c @@ -326,6 +326,64 @@ connection_get (const struct GNUNET_HashCode *cid) } +static void +connection_change_state (struct MeshConnection* c, + enum MeshConnectionState state) +{ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Connection %s state was %s\n", + GNUNET_h2s (&c->id), GMC_state2s (c->state)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Connection %s state is now %s\n", + GNUNET_h2s (&c->id), GMC_state2s (state)); + c->state = state; +} + + +/** + * Callback called when a queued message is sent. + * + * Calculates the average time + * + * @param cls Closure. + * @param c Connection this message was on. + * @param wait Time spent waiting for core (only the time for THIS message) + */ +static void +message_sent (void *cls, + struct MeshConnection *c, + struct GNUNET_TIME_Relative wait) +{ + struct MeshConnectionPerformance *p; + size_t size = (size_t) cls; + double usecsperbyte; + + if (NULL == c->perf) + return; /* Only endpoints are interested in this. */ + + p = c->perf; + usecsperbyte = ((double) wait.rel_value_us) / size; + if (p->size == AVG_MSGS) + { + /* Array is full. Substract oldest value, add new one and store. */ + p->avg -= (p->usecsperbyte[p->idx] / AVG_MSGS); + p->usecsperbyte[p->idx] = usecsperbyte; + p->avg += (p->usecsperbyte[p->idx] / AVG_MSGS); + } + else + { + /* Array not yet full. Add current value to avg and store. */ + p->usecsperbyte[p->idx] = usecsperbyte; + p->avg *= p->size; + p->avg += p->usecsperbyte[p->idx]; + p->size++; + p->avg /= p->size; + } + p->idx = (p->idx + 1) % AVG_MSGS; +} + + + /** * Send an ACK informing the predecessor about the available buffer space. * @@ -407,7 +465,7 @@ send_connection_ack (struct MeshConnection *connection, int fwd) sizeof (struct GNUNET_MESH_ConnectionACK), connection, NULL, fwd, &message_sent, sizeof (struct GNUNET_MESH_ConnectionACK)); - if (MESH_TUNNEL3_NEW == t->state) + if (MESH_TUNNEL3_NEW == GMT_get_state (t)) GMT_change_state (t, MESH_TUNNEL3_WAITING); if (MESH_CONNECTION_READY != connection->state) GMC_change_state (connection, MESH_CONNECTION_SENT); @@ -423,41 +481,26 @@ send_connection_ack (struct MeshConnection *connection, int fwd) static void send_connection_create (struct MeshConnection *connection) { - struct MeshTunnel3 *t; +enum MeshTunnel3State state; + size_t size; - t = connection->t; + size = sizeof (struct GNUNET_MESH_ConnectionCreate); + size += connection->path->length * sizeof (struct GNUNET_PeerIdentity); LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection create\n"); - queue_add (NULL, - GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE, - sizeof (struct GNUNET_MESH_ConnectionCreate) + - (connection->path->length * - sizeof (struct GNUNET_PeerIdentity)), - connection, - NULL, - GNUNET_YES); - if (NULL != t && - (MESH_TUNNEL3_SEARCHING == t->state || MESH_TUNNEL3_NEW == t->state)) - tunnel_change_state (t, MESH_TUNNEL3_WAITING); + GMP_queue_add (NULL, + GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE, + size, + connection, + NULL, + GNUNET_YES, &message_sent, size); + state = GMT_get_state (connection->t); + if (MESH_TUNNEL3_SEARCHING == state || MESH_TUNNEL3_NEW == state) + GMT_change_state (connection->t, MESH_TUNNEL3_WAITING); if (MESH_CONNECTION_NEW == connection->state) connection_change_state (connection, MESH_CONNECTION_SENT); } -static void -connection_change_state (struct MeshConnection* c, - enum MeshConnectionState state) -{ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Connection %s state was %s\n", - GNUNET_h2s (&c->id), GMC_state2s (c->state)); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Connection %s state is now %s\n", - GNUNET_h2s (&c->id), GMC_state2s (state)); - c->state = state; -} - - - /** * Send keepalive packets for a connection. * @@ -476,17 +519,15 @@ connection_keepalive (struct MeshConnection *c, int fwd) GNUNET_MESSAGE_TYPE_MESH_BCK_KEEPALIVE; LOG (GNUNET_ERROR_TYPE_DEBUG, - "sending %s keepalive for connection %s[%d]\n", - fwd ? "FWD" : "BCK", - peer2s (c->t->peer), - c->id); + "sending %s keepalive for connection %s[%d]\n", + fwd ? "FWD" : "BCK", GMT_2s (c->t), c->id); msg = (struct GNUNET_MESH_ConnectionKeepAlive *) cbuf; msg->header.size = htons (size); msg->header.type = htons (type); msg->cid = c->id; - send_prebuilt_message_connection (&msg->header, c, NULL, fwd); + GMC_send_prebuilt_message (&msg->header, c, NULL, fwd); } @@ -518,7 +559,7 @@ connection_recreate (struct MeshConnection *c, int fwd) static void connection_maintain (struct MeshConnection *c, int fwd) { - if (MESH_TUNNEL3_SEARCHING == c->t->state) + if (MESH_TUNNEL3_SEARCHING == GMT_get_state (c->t)) { /* TODO DHT GET with RO_BART */ return; @@ -925,49 +966,6 @@ unregister_neighbors (struct MeshConnection *c) } -/** - * Callback called when a queued message is sent. - * - * Calculates the average time - * - * @param cls Closure. - * @param c Connection this message was on. - * @param wait Time spent waiting for core (only the time for THIS message) - */ -static void -message_sent (void *cls, - struct MeshConnection *c, - struct GNUNET_TIME_Relative wait) -{ - struct MeshConnectionPerformance *p; - size_t size = (size_t) cls; - double usecsperbyte; - - if (NULL == c->perf) - return; /* Only endpoints are interested in this. */ - - p = c->perf; - usecsperbyte = ((double) wait.rel_value_us) / size; - if (p->size == AVG_MSGS) - { - /* Array is full. Substract oldest value, add new one and store. */ - p->avg -= (p->usecsperbyte[p->idx] / AVG_MSGS); - p->usecsperbyte[p->idx] = usecsperbyte; - p->avg += (p->usecsperbyte[p->idx] / AVG_MSGS); - } - else - { - /* Array not yet full. Add current value to avg and store. */ - p->usecsperbyte[p->idx] = usecsperbyte; - p->avg *= p->size; - p->avg += p->usecsperbyte[p->idx]; - p->size++; - p->avg /= p->size; - } - p->idx = (p->idx + 1) % AVG_MSGS; -} - - /******************************************************************************/ /******************************** API ***********************************/ /******************************************************************************/ @@ -2047,7 +2045,7 @@ GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, LOG (GNUNET_ERROR_TYPE_DEBUG, " poll %u\n", ntohl (pmsg->pid)); break; - case GNUNET_MESSAGE_TYPE_MESH_TUNNEL3_DESTROY: + case GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY: dmsg = (struct GNUNET_MESH_ConnectionDestroy *) data; dmsg->cid = c->id; dmsg->reserved = 0; @@ -2089,7 +2087,7 @@ GMC_send_destroy (struct MeshConnection *c) return; msg.header.size = htons (sizeof (msg)); - msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_TUNNEL3_DESTROY);; + msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY);; msg.cid = c->id; LOG (GNUNET_ERROR_TYPE_DEBUG, " sending connection destroy for connection %s\n", diff --git a/src/mesh/gnunet-service-mesh_connection.h b/src/mesh/gnunet-service-mesh_connection.h index 6b53b17cf..fafe0a59b 100644 --- a/src/mesh/gnunet-service-mesh_connection.h +++ b/src/mesh/gnunet-service-mesh_connection.h @@ -78,7 +78,6 @@ struct MeshConnection; - /** * Core handler for connection creation. * diff --git a/src/mesh/gnunet-service-mesh_local.c b/src/mesh/gnunet-service-mesh_local.c index 1e3bf1669..d4362d5e8 100644 --- a/src/mesh/gnunet-service-mesh_local.c +++ b/src/mesh/gnunet-service-mesh_local.c @@ -1054,7 +1054,7 @@ GML_send_ack (struct MeshChannel *ch, int fwd) void GML_send_channel_create (struct MeshClient *c, uint32_t id, uint32_t port, uint32_t opt, - struct GNUNET_PeerIdentity *peer) + const struct GNUNET_PeerIdentity *peer) { struct GNUNET_MESH_ChannelMessage msg; diff --git a/src/mesh/gnunet-service-mesh_local.h b/src/mesh/gnunet-service-mesh_local.h index 4befb24ac..6f4507770 100644 --- a/src/mesh/gnunet-service-mesh_local.h +++ b/src/mesh/gnunet-service-mesh_local.h @@ -165,7 +165,7 @@ GML_send_ack (struct MeshChannel *ch, int fwd); void GML_send_channel_create (struct MeshClient *c, uint32_t id, uint32_t port, uint32_t opt, - struct GNUNET_PeerIdentity *peer); + const struct GNUNET_PeerIdentity *peer); /** * Notify a client that a channel is no longer valid. diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c index 4e1373663..88a04eea6 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.c +++ b/src/mesh/gnunet-service-mesh_tunnel.c @@ -1003,6 +1003,8 @@ GMT_count_channels (struct MeshTunnel3 *t) enum MeshTunnel3State GMT_get_state (struct MeshTunnel3 *t) { + if (NULL == t) + return (enum MeshTunnel3State) -1; return t->state; } -- 2.25.1