- stop using message types of payload on service side
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh.c
index 0d7f228d229f3494446a31adfc856ad49c07c89f..5b7e9991f957b468da48936bbfb8c820db6d7880 100644 (file)
@@ -440,10 +440,10 @@ struct MeshTunnel
      */
   uint32_t last_fwd_ack;
 
-  /**
-   * BCK ACK value received from the hop towards the owner of the tunnel,
-   * (previous node / owner): up to what message PID can we sent back to him.
-   */
+    /**
+     * BCK ACK value received from the hop towards the owner of the tunnel,
+     * (previous node / owner): up to what message PID can we sent back to him.
+     */
   uint32_t bck_ack;
 
     /**
@@ -487,11 +487,6 @@ struct MeshTunnel
      */
   unsigned int peers_ready;
 
-    /**
-     * Number of peers that have been added to the tunnel
-     */
-  unsigned int peers_total;
-
     /**
      * Client owner of the tunnel, if any
      */
@@ -771,7 +766,7 @@ struct MeshClient
   struct GNUNET_SERVER_Client *handle;
 
     /**
-     * Applications that this client has claimed to provide
+     * Applications that this client has claimed to provide: H(app) = app.
      */
   struct GNUNET_CONTAINER_MultiHashMap *apps;
 
@@ -997,7 +992,7 @@ static MESH_TunnelNumber next_tid;
 static MESH_TunnelNumber next_local_tid;
 
 /**
- * All application types provided by this peer.
+ * All application types provided by this peer: H(app) = *Client.
  */
 static struct GNUNET_CONTAINER_MultiHashMap *applications;
 
@@ -1464,7 +1459,7 @@ announce_application (void *cls, const struct GNUNET_HashCode * key, void *value
     return GNUNET_YES;
   }
   block.type = htonl (block.type);
-
+  DEBUG_DHT ("Putting APP key: %s\n", GNUNET_h2s (key));
   GNUNET_break (NULL != 
                 GNUNET_DHT_put (dht_handle, key,
                                dht_replication_level,
@@ -2031,7 +2026,9 @@ peer_info_delete_tunnel (void *cls, const struct GNUNET_HashCode * key, void *va
     {
       peer->ntunnels--;
       peer->tunnels[i] = peer->tunnels[peer->ntunnels];
-      peer->tunnels = GNUNET_realloc (peer->tunnels, peer->ntunnels);
+      peer->tunnels = 
+        GNUNET_realloc (peer->tunnels, 
+                        peer->ntunnels * sizeof(struct MeshTunnel *));
       return GNUNET_YES;
     }
   }
@@ -3035,7 +3032,6 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer)
   if (GNUNET_NO ==
       GNUNET_CONTAINER_multihashmap_contains (t->peers, &id.hashPubKey))
   {
-    t->peers_total++;
     GNUNET_array_append (peer->tunnels, peer->ntunnels, t);
     GNUNET_assert (GNUNET_OK ==
                    GNUNET_CONTAINER_multihashmap_put (t->peers, &id.hashPubKey,
@@ -5070,17 +5066,13 @@ queue_add (void *cls, uint16_t type, size_t size,
  * @param cls closure
  * @param message message
  * @param peer peer identity this notification is about
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
  *
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
 static int
 handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
-                         const struct GNUNET_MessageHeader *message,
-                         const struct GNUNET_ATS_Information *atsi,
-                         unsigned int atsi_count)
+                         const struct GNUNET_MessageHeader *message)
 {
   unsigned int own_pos;
   uint16_t size;
@@ -5256,17 +5248,13 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
  * @param cls closure
  * @param message message
  * @param peer peer identity this notification is about
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
  *
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
 static int
 handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
-                          const struct GNUNET_MessageHeader *message,
-                          const struct GNUNET_ATS_Information *atsi,
-                          unsigned int atsi_count)
+                          const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_MESH_ManipulatePath *msg;
   struct GNUNET_PeerIdentity *pi;
@@ -5340,17 +5328,13 @@ handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
  * @param cls closure
  * @param message message
  * @param peer peer identity this notification is about
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
  *
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
 static int
 handle_mesh_path_broken (void *cls, const struct GNUNET_PeerIdentity *peer,
-                         const struct GNUNET_MessageHeader *message,
-                         const struct GNUNET_ATS_Information *atsi,
-                         unsigned int atsi_count)
+                         const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_MESH_PathBroken *msg;
   struct MeshTunnel *t;
@@ -5381,17 +5365,13 @@ handle_mesh_path_broken (void *cls, const struct GNUNET_PeerIdentity *peer,
  * @param cls closure
  * @param message message
  * @param peer peer identity this notification is about
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
  *
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
 static int
 handle_mesh_tunnel_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
-                            const struct GNUNET_MessageHeader *message,
-                            const struct GNUNET_ATS_Information *atsi,
-                            unsigned int atsi_count)
+                            const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_MESH_TunnelDestroy *msg;
   struct MeshTunnel *t;
@@ -5453,16 +5433,12 @@ handle_mesh_tunnel_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
  * @param cls closure
  * @param peer peer identity this notification is about
  * @param message message
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
 static int
 handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
-                          const struct GNUNET_MessageHeader *message,
-                          const struct GNUNET_ATS_Information *atsi,
-                          unsigned int atsi_count)
+                          const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_MESH_Unicast *msg;
   struct GNUNET_PeerIdentity *neighbor;
@@ -5572,8 +5548,6 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
  * @param cls closure
  * @param message message
  * @param peer peer identity this notification is about
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  *
@@ -5581,9 +5555,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
  */
 static int
 handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer,
-                            const struct GNUNET_MessageHeader *message,
-                            const struct GNUNET_ATS_Information *atsi,
-                            unsigned int atsi_count)
+                            const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_MESH_Multicast *msg;
   struct MeshTunnel *t;
@@ -5656,17 +5628,13 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer,
  * @param cls closure
  * @param message message
  * @param peer peer identity this notification is about
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
  *
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
 static int
 handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
-                          const struct GNUNET_MessageHeader *message,
-                          const struct GNUNET_ATS_Information *atsi,
-                          unsigned int atsi_count)
+                          const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_MESH_ToOrigin *msg;
   struct GNUNET_PeerIdentity id;
@@ -5790,17 +5758,13 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
  * @param cls closure
  * @param message message
  * @param peer peer identity this notification is about
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
  *
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
 static int
 handle_mesh_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
-                 const struct GNUNET_MessageHeader *message,
-                 const struct GNUNET_ATS_Information *atsi,
-                 unsigned int atsi_count)
+                 const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_MESH_ACK *msg;
   struct MeshTunnel *t;
@@ -5856,17 +5820,13 @@ handle_mesh_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
  * @param cls closure
  * @param message message
  * @param peer peer identity this notification is about
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
  *
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
 static int
 handle_mesh_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
-                  const struct GNUNET_MessageHeader *message,
-                  const struct GNUNET_ATS_Information *atsi,
-                  unsigned int atsi_count)
+                  const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_MESH_Poll *msg;
   struct MeshTunnel *t;
@@ -5911,17 +5871,13 @@ handle_mesh_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
  * @param cls closure
  * @param message message
  * @param peer peer identity this notification is about
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
  *
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
 static int
 handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
-                      const struct GNUNET_MessageHeader *message,
-                      const struct GNUNET_ATS_Information *atsi,
-                      unsigned int atsi_count)
+                      const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_MESH_PathACK *msg;
   struct GNUNET_PeerIdentity id;
@@ -5989,6 +5945,11 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
       tree_set_status (t->tree, peer_info->id, MESH_PEER_READY);
       send_client_peer_connected (t, peer_info->id);
     }
+    if (NULL != peer_info->dhtget)
+    {
+      GNUNET_DHT_get_stop (peer_info->dhtget);
+      peer_info->dhtget = NULL;
+    }
     return GNUNET_OK;
   }
 
@@ -5996,12 +5957,6 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
               "  not for us, retransmitting...\n");
   GNUNET_PEER_resolve (tree_get_predecessor (t->tree), &id);
   peer_info = peer_info_get (&msg->oid);
-  if (NULL == peer_info)
-  {
-    /* If we know the tunnel, we should DEFINITELY know the peer */
-    GNUNET_break (0);
-    return GNUNET_OK;
-  }
   send_prebuilt_message (message, &id, t);
   return GNUNET_OK;
 }
@@ -6013,8 +5968,6 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
  * @param cls closure
  * @param message message
  * @param peer peer identity this notification is about
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  *
@@ -6022,9 +5975,7 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
  */
 static int
 handle_mesh_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
-                       const struct GNUNET_MessageHeader *message,
-                       const struct GNUNET_ATS_Information *atsi,
-                       unsigned int atsi_count)
+                       const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_MESH_TunnelKeepAlive *msg;
   struct MeshTunnel *t;
@@ -6094,9 +6045,10 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
 static int
 deregister_app (void *cls, const struct GNUNET_HashCode * key, void *value)
 {
-  struct GNUNET_CONTAINER_MultiHashMap *h = cls;
+  struct MeshClient *c = cls;
+
   GNUNET_break (GNUNET_YES ==
-                GNUNET_CONTAINER_multihashmap_remove (h, key, value));
+                GNUNET_CONTAINER_multihashmap_remove (applications, key, c));
   return GNUNET_OK;
 }
 
@@ -6212,10 +6164,10 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
   GNUNET_PEER_resolve (path_info->peer->id, &pi);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  for %s\n", GNUNET_i2s (&pi));
 
-  p = path_build_from_dht (get_path, get_path_length, put_path,
-                           put_path_length);
+  p = path_build_from_dht (get_path, get_path_length,
+                           put_path, put_path_length);
   path_add_to_peers (p, GNUNET_NO);
-  path_destroy(p);
+  path_destroy (p);
   for (i = 0; i < path_info->peer->ntunnels; i++)
   {
     tunnel_add_peer (path_info->peer->tunnels[i], path_info->peer);
@@ -6337,7 +6289,7 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
     /* deregister clients applications */
     if (NULL != c->apps)
     {
-      GNUNET_CONTAINER_multihashmap_iterate (c->apps, &deregister_app, c->apps);
+      GNUNET_CONTAINER_multihashmap_iterate (c->apps, &deregister_app, c);
       GNUNET_CONTAINER_multihashmap_destroy (c->apps);
     }
     if (0 == GNUNET_CONTAINER_multihashmap_size (applications) &&
@@ -7373,7 +7325,7 @@ handle_local_unicast (void *cls, struct GNUNET_SERVER_Client *client,
     copy->ttl = htonl (default_ttl);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "  calling generic handler...\n");
-    handle_mesh_data_unicast (NULL, &my_full_id, &copy->header, NULL, 0);
+    handle_mesh_data_unicast (NULL, &my_full_id, &copy->header);
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "receive done OK\n");
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -7482,7 +7434,7 @@ handle_local_to_origin (void *cls, struct GNUNET_SERVER_Client *client,
     copy->sender = my_full_id;
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "  calling generic handler...\n");
-    handle_mesh_data_to_orig (NULL, &my_full_id, &copy->header, NULL, 0);
+    handle_mesh_data_to_orig (NULL, &my_full_id, &copy->header);
   }
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 
@@ -7573,7 +7525,7 @@ handle_local_multicast (void *cls, struct GNUNET_SERVER_Client *client,
     GNUNET_assert (ntohl (copy->pid) == (t->fwd_pid + 1));
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "  calling generic handler...\n");
-    handle_mesh_data_multicast (client, &my_full_id, &copy->header, NULL, 0);
+    handle_mesh_data_multicast (client, &my_full_id, &copy->header);
   }
 
   GNUNET_SERVER_receive_done (t->owner->handle, GNUNET_OK);
@@ -7914,8 +7866,7 @@ handle_local_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client,
   *resp = *msg;
   resp->npeers = 0;
   ctx.msg = resp;
-  ctx.lookup = GNUNET_CONTAINER_multihashmap_create (4 * t->peers_total,
-                                                     GNUNET_YES);
+  ctx.lookup = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES);
   ctx.c = c;
 
   /* Collect and send information */
@@ -8032,13 +7983,9 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server,
  *
  * @param cls closure
  * @param peer peer identity this notification is about
- * @param atsi performance data for the connection
- * @param atsi_count number of records in 'atsi'
  */
 static void
-core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
-              const struct GNUNET_ATS_Information *atsi,
-              unsigned int atsi_count)
+core_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
 {
   struct MeshPeerInfo *peer_info;
   struct MeshPeerPath *path;
@@ -8306,13 +8253,13 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
   server_handle = server;
 
   if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY",
+      GNUNET_CONFIGURATION_get_value_filename (c, "PEER", "PRIVATE_KEY",
                                                &keyfile))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 _
                 ("%s service is lacking key configuration settings (%s).  Exiting.\n"),
-                "mesh", "hostkey");
+                "mesh", "peer/privatekey");
     GNUNET_SCHEDULER_shutdown ();
     return;
   }