- undo mix of pid and mid
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh.c
index 7504fa223679d6c5a124a9bb405bc8f22ae9b878..c4f30c1ec91dbaa8c96aff757977b30bde17c5b3 100644 (file)
@@ -3750,26 +3750,25 @@ handle_mesh_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
     if (GMC_is_pid_bigger (pid, t->prev_fc.last_pid_recv)
         &&
           (GNUNET_NO == t->reliable ||
-           GNUNET_ntohll (msg->mid) == (t->bck_rel->mid_recv + 1)) )
+           GNUNET_ntohll (msg->mid) == t->bck_rel->mid_recv) )
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   " pid %u not seen yet, forwarding\n", pid);
       t->prev_fc.last_pid_recv = pid;
-      t->bck_rel->mid_recv++;
+      if (GNUNET_YES == t->reliable)
+        t->bck_rel->mid_recv++;
       tunnel_send_client_ucast (t, msg);
     }
     else
     {
 //       GNUNET_STATISTICS_update (stats, "# duplicate PID", 1, GNUNET_NO);
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  " Pid %u not expected (%u), sending FWD ACK!\n",
+                  " Pid %u not expected (%u), dropping!\n",
                   pid, t->prev_fc.last_pid_recv + 1);
     }
-    tunnel_send_fwd_ack (t, GNUNET_MESSAGE_TYPE_MESH_UNICAST);
     return GNUNET_OK;
   }
-  if (GMC_is_pid_bigger(pid, t->prev_fc.last_pid_recv))
-    t->prev_fc.last_pid_recv = pid;
+  t->prev_fc.last_pid_recv = pid;
   if (0 == t->next_hop)
   {
     GNUNET_break (0);
@@ -3874,8 +3873,7 @@ handle_mesh_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "  not for us, retransmitting...\n");
-  if (GMC_is_pid_bigger (pid, t->next_fc.last_pid_recv))
-    t->next_fc.last_pid_recv = pid;
+  t->next_fc.last_pid_recv = pid;
   if (0 == t->prev_hop) /* No owner AND no prev hop */
   {
     if (GNUNET_YES == t->destroy)
@@ -4394,6 +4392,27 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
 /******************************************************************************/
 
 
+/**
+ * Handler for client connection.
+ *
+ * @param cls Closure (unused).
+ * @param client Client handler.
+ */
+static void
+handle_local_client_connect (void *cls, struct GNUNET_SERVER_Client *client)
+{
+  struct MeshClient *c;
+
+  if (NULL == client)
+    return;
+  c = GNUNET_malloc (sizeof (struct MeshClient));
+  c->handle = client;
+  GNUNET_SERVER_client_keep (client);
+  GNUNET_SERVER_client_set_user_context (client, c);
+  GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c);
+}
+
+
 /**
  * Handler for client disconnection
  *
@@ -4421,12 +4440,19 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
                 c->id);
     GNUNET_SERVER_client_drop (c->handle);
     c->shutting_down = GNUNET_YES;
-    GNUNET_CONTAINER_multihashmap32_iterate (c->own_tunnels,
-                                             &tunnel_destroy_iterator, c);
-    GNUNET_CONTAINER_multihashmap32_iterate (c->incoming_tunnels,
+    if (NULL != c->own_tunnels)
+    {
+      GNUNET_CONTAINER_multihashmap32_iterate (c->own_tunnels,
+                                               &tunnel_destroy_iterator, c);
+      GNUNET_CONTAINER_multihashmap32_destroy (c->own_tunnels);
+    }
+
+    if (NULL != c->incoming_tunnels)
+    {
+      GNUNET_CONTAINER_multihashmap32_iterate (c->incoming_tunnels,
                                              &tunnel_destroy_iterator, c);
-    GNUNET_CONTAINER_multihashmap32_destroy (c->own_tunnels);
-    GNUNET_CONTAINER_multihashmap32_destroy (c->incoming_tunnels);
+      GNUNET_CONTAINER_multihashmap32_destroy (c->incoming_tunnels);
+    }
 
     if (NULL != c->ports)
       GNUNET_CONTAINER_multihashmap32_destroy (c->ports);
@@ -4476,14 +4502,11 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
   }
   size /= sizeof (uint32_t);
 
-  /* Create new client structure */
-  c = GNUNET_malloc (sizeof (struct MeshClient));
+  /* Initialize new client structure */
+  c = GNUNET_SERVER_client_get_user_context (client, struct MeshClient);
   c->id = next_client_id++; /* overflow not important: just for debug */
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  client id %u\n", c->id);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  client has %u ports\n", size);
-  c->handle = client;
-  GNUNET_SERVER_client_keep (client);
-  GNUNET_SERVER_client_set_user_context (client, c);
   if (size > 0)
   {
     uint32_t u32;
@@ -4506,7 +4529,6 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
     }
   }
 
-  GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c);
   c->own_tunnels = GNUNET_CONTAINER_multihashmap32_create (32);
   c->incoming_tunnels = GNUNET_CONTAINER_multihashmap32_create (32);
   GNUNET_SERVER_notification_context_add (nc, client);
@@ -5113,6 +5135,8 @@ static void
 server_init (void)
 {
   GNUNET_SERVER_add_handlers (server_handle, client_handlers);
+  GNUNET_SERVER_connect_notify (server_handle,
+                                &handle_local_client_connect, NULL);
   GNUNET_SERVER_disconnect_notify (server_handle,
                                    &handle_local_client_disconnect, NULL);
   nc = GNUNET_SERVER_notification_context_create (server_handle, 1);