gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r30092 - gnunet/src/mesh


From: gnunet
Subject: [GNUnet-SVN] r30092 - gnunet/src/mesh
Date: Thu, 10 Oct 2013 15:52:37 +0200

Author: bartpolot
Date: 2013-10-10 15:52:37 +0200 (Thu, 10 Oct 2013)
New Revision: 30092

Modified:
   gnunet/src/mesh/gnunet-service-mesh_channel.c
   gnunet/src/mesh/gnunet-service-mesh_channel.h
   gnunet/src/mesh/gnunet-service-mesh_connection.c
   gnunet/src/mesh/gnunet-service-mesh_connection.h
   gnunet/src/mesh/gnunet-service-mesh_local.c
   gnunet/src/mesh/gnunet-service-mesh_local.h
   gnunet/src/mesh/gnunet-service-mesh_tunnel.c
Log:
- fixes


Modified: gnunet/src/mesh/gnunet-service-mesh_channel.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_channel.c       2013-10-10 13:42:25 UTC 
(rev 30091)
+++ gnunet/src/mesh/gnunet-service-mesh_channel.c       2013-10-10 13:52:37 UTC 
(rev 30092)
@@ -526,8 +526,8 @@
    *   is stalled.
    */
 //   FIXME access to queue elements is limited
-//   payload = (struct GNUNET_MESH_Data *) &copy[1];
-//   fwd = (rel == ch->root_rel);
+  payload = (struct GNUNET_MESH_Data *) &copy[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 @@
  */
 void
 handle_loopback (struct MeshChannel *ch,
-                 struct GNUNET_MessageHeader *msgh,
+                 const struct GNUNET_MessageHeader *msgh,
                  int fwd)
 {
   uint16_t type;
@@ -1200,8 +1200,6 @@
   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 @@
   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 @@
   {
     /* 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 @@
                      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 @@
 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 @@
 
   if (GMT_is_loopback (ch->t))
   {
-    handle_loopback (ch->t, message, fwd);
+    handle_loopback (ch, message, fwd);
     return;
   }
 

Modified: gnunet/src/mesh/gnunet-service-mesh_channel.h
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_channel.h       2013-10-10 13:42:25 UTC 
(rev 30091)
+++ gnunet/src/mesh/gnunet-service-mesh_channel.h       2013-10-10 13:52:37 UTC 
(rev 30092)
@@ -41,6 +41,7 @@
 #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.

Modified: gnunet/src/mesh/gnunet-service-mesh_connection.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_connection.c    2013-10-10 13:42:25 UTC 
(rev 30091)
+++ gnunet/src/mesh/gnunet-service-mesh_connection.c    2013-10-10 13:52:37 UTC 
(rev 30092)
@@ -326,7 +326,65 @@
 }
 
 
+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.
  *
  * Note that for fwd ack, the FWD mean forward *traffic* (root->dest),
@@ -407,7 +465,7 @@
                  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 @@
 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 @@
                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 @@
 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 @@
 }
 
 
-/**
- * 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 @@
       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 @@
     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",

Modified: gnunet/src/mesh/gnunet-service-mesh_connection.h
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_connection.h    2013-10-10 13:42:25 UTC 
(rev 30091)
+++ gnunet/src/mesh/gnunet-service-mesh_connection.h    2013-10-10 13:52:37 UTC 
(rev 30092)
@@ -78,7 +78,6 @@
 
 
 
-
 /**
  * Core handler for connection creation.
  *

Modified: gnunet/src/mesh/gnunet-service-mesh_local.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_local.c 2013-10-10 13:42:25 UTC (rev 
30091)
+++ gnunet/src/mesh/gnunet-service-mesh_local.c 2013-10-10 13:52:37 UTC (rev 
30092)
@@ -1054,7 +1054,7 @@
 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;
 

Modified: gnunet/src/mesh/gnunet-service-mesh_local.h
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_local.h 2013-10-10 13:42:25 UTC (rev 
30091)
+++ gnunet/src/mesh/gnunet-service-mesh_local.h 2013-10-10 13:52:37 UTC (rev 
30092)
@@ -165,7 +165,7 @@
 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.

Modified: gnunet/src/mesh/gnunet-service-mesh_tunnel.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_tunnel.c        2013-10-10 13:42:25 UTC 
(rev 30091)
+++ gnunet/src/mesh/gnunet-service-mesh_tunnel.c        2013-10-10 13:52:37 UTC 
(rev 30092)
@@ -1003,6 +1003,8 @@
 enum MeshTunnel3State
 GMT_get_state (struct MeshTunnel3 *t)
 {
+  if (NULL == t)
+    return (enum MeshTunnel3State) -1;
   return t->state;
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]