- debug
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_connection.c
index 5ca287cb157215b19863ee9333036807c9276e15..8a83adc51a44afed7a3eed60d4f7a43f75a739fe 100644 (file)
@@ -354,7 +354,7 @@ connection_change_state (struct MeshConnection* c,
 /**
  * Callback called when a queued message is sent.
  *
- * Calculates the average time 
+ * Calculates the average time and connection packet tracking.
  *
  * @param cls Closure.
  * @param c Connection this message was on.
@@ -373,8 +373,29 @@ message_sent (void *cls,
   struct MeshFlowControl *fc;
   double usecsperbyte;
 
+  fc = fwd ? &c->fwd_fc : &c->bck_fc;
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "!  Q_N- %p %u\n", fc, fc->queue_n);
+  fc->queue_n--;
+  c->pending_messages--;
+  if (GNUNET_YES == c->destroy && 0 == c->pending_messages)
+  {
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "!  destroying connection!\n");
+    GMC_destroy (c);
+  }
+  /* Send ACK if needed, after accounting for sent ID in fc->queue_n */
+  switch (type)
+  {
+    case GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED:
+      fc->last_pid_sent++;
+      LOG (GNUNET_ERROR_TYPE_DEBUG, "!   accounting pid %u\n", fc->last_pid_sent);
+//       send_ack (c, ch, fwd);
+      break;
+    default:
+      break;
+  }
+
   if (NULL == c->perf)
-    return; /* Only endpoints are interested in this. */
+    return; /* Only endpoints are interested in timing. */
 
   LOG (GNUNET_ERROR_TYPE_DEBUG, "!  message sent!\n");
   p = c->perf;
@@ -397,27 +418,6 @@ message_sent (void *cls,
   }
   p->idx = (p->idx + 1) % AVG_MSGS;
 
-  fc = fwd ? &c->fwd_fc : &c->bck_fc;
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "!  Q_N- %p %u\n", fc, fc->queue_n);
-  fc->queue_n--;
-  c->pending_messages--;
-  if (GNUNET_YES == c->destroy && 0 == c->pending_messages)
-  {
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "!  destroying connection!\n");
-    GMC_destroy (c);
-  }
-  /* Send ACK if needed, after accounting for sent ID in fc->queue_n */
-  switch (type)
-  {
-    case GNUNET_MESSAGE_TYPE_MESH_FWD:
-    case GNUNET_MESSAGE_TYPE_MESH_BCK:
-      fc->last_pid_sent++;
-      LOG (GNUNET_ERROR_TYPE_DEBUG, "!   accounting pid %u\n", fc->last_pid_sent);
-//       send_ack (c, ch, fwd);
-      break;
-    default:
-      break;
-  }
 //   if (NULL != c->t)
 //   {
 //     c->t->pending_messages--;
@@ -1309,23 +1309,23 @@ GMC_handle_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
  *
  * @param peer Peer identity this notification is about.
  * @param message Encrypted message.
- * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
  *
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
 static int
 handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer,
-                       const struct GNUNET_MESH_Encrypted *msg,
-                       int fwd)
+                       const struct GNUNET_MESH_Encrypted *msg)
 {
   struct MeshConnection *c;
   struct MeshPeer *neighbor;
   struct MeshFlowControl *fc;
+  GNUNET_PEER_Id peer_id;
   uint32_t pid;
   uint32_t ttl;
   uint16_t type;
   size_t size;
+  int fwd;
 
   /* Check size */
   size = ntohs (msg->header.size);
@@ -1350,15 +1350,27 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer,
     return GNUNET_OK;
   }
 
-  fc = fwd ? &c->bck_fc : &c->fwd_fc;
-
   /* Check if origin is as expected */
-  neighbor = get_hop (c, !fwd);
-  if (GNUNET_PEER_search (peer) != GMP_get_short_id (neighbor))
+  neighbor = get_prev_hop (c);
+  peer_id = GNUNET_PEER_search (peer);
+  if (peer_id == GMP_get_short_id (neighbor))
   {
-    GNUNET_break_op (0);
-    return GNUNET_OK;
+    fwd = GNUNET_YES;
+  }
+  else
+  {
+    neighbor = get_next_hop (c);
+    if (peer_id == GMP_get_short_id (neighbor))
+    {
+      fwd = GNUNET_NO;
+    }
+    else
+    {
+      GNUNET_break_op (0);
+      return GNUNET_OK;
+    }
   }
+  fc = fwd ? &c->bck_fc : &c->fwd_fc;
 
   /* Check PID */
   pid = ntohl (msg->pid);
@@ -1421,26 +1433,7 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer,
 
 
 /**
- * Core handler for mesh network traffic going orig->dest.
- *
- * @param cls Closure (unused).
- * @param message Message received.
- * @param peer Peer who sent the message.
- *
- * @return GNUNET_OK to keep the connection open,
- *         GNUNET_SYSERR to close it (signal serious error)
- */
-int
-GMC_handle_fwd (void *cls, const struct GNUNET_PeerIdentity *peer,
-                const struct GNUNET_MessageHeader *message)
-{
-  return handle_mesh_encrypted (peer,
-                                (struct GNUNET_MESH_Encrypted *)message,
-                                GNUNET_YES);
-}
-
-/**
- * Core handler for mesh network traffic going dest->orig.
+ * Core handler for encrypted mesh network traffic (channel mgmt, data).
  *
  * @param cls Closure (unused).
  * @param message Message received.
@@ -1450,12 +1443,11 @@ GMC_handle_fwd (void *cls, const struct GNUNET_PeerIdentity *peer,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
 int
-GMC_handle_bck (void *cls, const struct GNUNET_PeerIdentity *peer,
-                const struct GNUNET_MessageHeader *message)
+GMC_handle_encrypted (void *cls, const struct GNUNET_PeerIdentity *peer,
+                      const struct GNUNET_MessageHeader *message)
 {
   return handle_mesh_encrypted (peer,
-                                (struct GNUNET_MESH_Encrypted *)message,
-                                GNUNET_NO);
+                                (struct GNUNET_MESH_Encrypted *)message);
 }
 
 
@@ -2118,8 +2110,7 @@ GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
     struct GNUNET_MESH_ConnectionBroken  *bmsg;
     uint32_t ttl;
 
-    case GNUNET_MESSAGE_TYPE_MESH_FWD:
-    case GNUNET_MESSAGE_TYPE_MESH_BCK:
+    case GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED:
       emsg = (struct GNUNET_MESH_Encrypted *) data;
       ttl = ntohl (emsg->ttl);
       if (0 == ttl)