- replace deprecated INCLUDES with AM_CPPFLAGS
[oweals/gnunet.git] / src / experimentation / gnunet-daemon-experimentation_nodes.c
index 8c3063ac93b62c6f7a3e52d981b6f2941f775999..a4da92d50e8d7449f4d8c8c477330b70fe26ab45 100644 (file)
@@ -148,7 +148,7 @@ cleanup_node (void *cls,
 
        GNUNET_free_non_null (n->issuer_id);
 
-       GNUNET_CONTAINER_multihashmap_remove (cur, key, value);
+       GNUNET_break (0 == GNUNET_CONTAINER_multihashmap_remove (cur, key, value));
        GNUNET_free (value);
        return GNUNET_OK;
 }
@@ -172,21 +172,21 @@ static int is_me (const struct GNUNET_PeerIdentity *id)
  * Core startup callback
  *
  * @param cls unused
- * @param server core service's server handle
  * @param my_identity my id
  */
 static void
 core_startup_handler (void *cls,
-                                                                                       struct GNUNET_CORE_Handle *server,
                       const struct GNUNET_PeerIdentity *my_identity)
 {
-       me = *my_identity;
+  me = *my_identity;
 }
 
-void
+
+static void
 schedule_transmisson (struct NodeComCtx *e_ctx);
 
-size_t
+
+static size_t
 transmit_read_wrapper (void *cls, size_t bufsize, void *buf)
 {
        struct NodeComCtx *e_ctx = cls;
@@ -207,7 +207,8 @@ transmit_read_wrapper (void *cls, size_t bufsize, void *buf)
        return res;
 }
 
-void
+
+static void
 schedule_transmisson (struct NodeComCtx *e_ctx)
 {
        if (NULL != e_ctx->n->cth)
@@ -217,7 +218,7 @@ schedule_transmisson (struct NodeComCtx *e_ctx)
                        &e_ctx->n->id, e_ctx->size, transmit_read_wrapper, e_ctx);
        if (NULL == e_ctx->n->cth)
        {
-               GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Cannot send message to peer `%s' for experiment `%s'\n"),
+               GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Cannot send message to peer `%s' for experiment `%s'\n"),
                                GNUNET_i2s(&e_ctx->n->id), e_ctx->e->name);
                GNUNET_free (e_ctx);
        }
@@ -236,24 +237,18 @@ remove_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
        struct Node *n = cls;
 
-       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Removing request for peer %s due to timeout\n"),
+       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing request for peer %s due to timeout\n",
                        GNUNET_i2s (&n->id));
 
        if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (nodes_requested, &n->id.hashPubKey))
        {
-                       GNUNET_CONTAINER_multihashmap_remove (nodes_requested, &n->id.hashPubKey, n);
+                       GNUNET_break (0 == GNUNET_CONTAINER_multihashmap_remove (nodes_requested, &n->id.hashPubKey, n));
                        update_stats (nodes_requested);
                        GNUNET_CONTAINER_multihashmap_put (nodes_inactive, &n->id.hashPubKey, n,
                                        GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
                        update_stats (nodes_inactive);
        }
-
        n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
-       if (NULL != n->cth)
-       {
-               GNUNET_CORE_notify_transmit_ready_cancel (n->cth);
-               n->cth = NULL;
-       }
 }
 
 
@@ -273,7 +268,7 @@ size_t send_experimentation_request_cb (void *cls, size_t bufsize, void *buf)
        size_t ri_size = sizeof (struct Experimentation_Issuer) * GSE_my_issuer_count;
        size_t total_size = msg_size + ri_size;
 
-       memset (buf, '0', bufsize);
+       memset (buf, '\0', bufsize);
        n->cth = NULL;
   if (buf == NULL)
   {
@@ -293,7 +288,7 @@ size_t send_experimentation_request_cb (void *cls, size_t bufsize, void *buf)
        memcpy (buf, &msg, msg_size);
        memcpy (&((char *) buf)[msg_size], GSE_my_issuer, ri_size);
 
-       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Sending request to peer %s\n"),
+       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Sending experimentation request to peer %s\n"),
                        GNUNET_i2s (&n->id));
        return total_size;
 }
@@ -367,7 +362,7 @@ size_t send_response_cb (void *cls, size_t bufsize, void *buf)
        memcpy (buf, &msg, msg_size);
        memcpy (&((char *) buf)[msg_size], GSE_my_issuer, ri_size);
 
-       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Sending response to peer %s\n"),
+       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending response to peer %s\n",
                        GNUNET_i2s (&n->id));
        return total_size;
 }
@@ -378,15 +373,7 @@ get_experiments_cb (struct Node *n, struct Experiment *e)
 {
        static int counter = 0;
        if (NULL == e)
-       {
-                       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Added %u experiments for peer %s\n"),
-                                       counter, GNUNET_i2s (&n->id));
-                       return;
-       }
-
-       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting experiment `%s' with peer %s\n"),
-                       e->name,
-                       GNUNET_i2s (&n->id));
+                       return; /* Done */
 
        /* Tell the scheduler to add a node with an experiment */
        GED_scheduler_add (n, e, GNUNET_YES);
@@ -434,7 +421,6 @@ static void node_make_active (struct Node *n)
        update_stats (nodes_active);
        GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Added peer `%s' as active node\n"),
                        GNUNET_i2s (&n->id));
-return;
        /* Request experiments for this node to start them */
        for (c1 = 0; c1 < n->issuer_count; c1++)
        {
@@ -488,17 +474,12 @@ static void handle_request (const struct GNUNET_PeerIdentity *peer,
                                GNUNET_SCHEDULER_cancel (n->timeout_task);
                                n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
                        }
-                       if (NULL != n->cth)
-                       {
-                               GNUNET_CORE_notify_transmit_ready_cancel (n->cth);
-                               n->cth = NULL;
-                       }
                        update_stats (nodes_requested);
                        make_active = GNUNET_YES;
        }
        else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &peer->hashPubKey)))
        {
-                       GNUNET_CONTAINER_multihashmap_remove (nodes_inactive, &peer->hashPubKey, n);
+                 GNUNET_break (0 == GNUNET_CONTAINER_multihashmap_remove (nodes_inactive, &peer->hashPubKey, n));
                        update_stats (nodes_inactive);
                        make_active = GNUNET_YES;
        }
@@ -521,7 +502,7 @@ static void handle_request (const struct GNUNET_PeerIdentity *peer,
                if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
                        ic_accepted ++;
        }
-       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Request from peer `%s' with %u issuers, we accepted %u issuer \n"),
+       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Request from peer `%s' with %u issuers, we accepted %u issuer \n",
                        GNUNET_i2s (peer), ic, ic_accepted);
        GNUNET_free_non_null (n->issuer_id);
        n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct GNUNET_PeerIdentity));
@@ -585,12 +566,12 @@ static void handle_response (const struct GNUNET_PeerIdentity *peer,
        make_active = GNUNET_NO;
        if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_active, &peer->hashPubKey)))
        {
-                       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received %s from %s peer `%s'\n"),
+                       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from %s peer `%s'\n",
                                        "RESPONSE", "active", GNUNET_i2s (peer));
        }
        else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &peer->hashPubKey)))
        {
-                       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received %s from %s peer `%s'\n"),
+                       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from %s peer `%s'\n",
                                        "RESPONSE", "requested", GNUNET_i2s (peer));
                        GNUNET_CONTAINER_multihashmap_remove (nodes_requested, &peer->hashPubKey, n);
                        if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
@@ -598,25 +579,20 @@ static void handle_response (const struct GNUNET_PeerIdentity *peer,
                                GNUNET_SCHEDULER_cancel (n->timeout_task);
                                n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
                        }
-                       if (NULL != n->cth)
-                       {
-                               GNUNET_CORE_notify_transmit_ready_cancel (n->cth);
-                               n->cth = NULL;
-                       }
                        update_stats (nodes_requested);
                        make_active = GNUNET_YES;
        }
        else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &peer->hashPubKey)))
        {
-                       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received %s from peer `%s'\n"),
+                       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from peer `%s'\n",
                                        "RESPONSE", "inactive", GNUNET_i2s (peer));
-                       GNUNET_CONTAINER_multihashmap_remove (nodes_inactive, &peer->hashPubKey, n);
+                       GNUNET_break (0 == GNUNET_CONTAINER_multihashmap_remove (nodes_inactive, &peer->hashPubKey, n));
                        update_stats (nodes_inactive);
                        make_active = GNUNET_YES;
        }
        else
        {
-                       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received %s from %s peer `%s'\n"),
+                       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from %s peer `%s'\n",
                                        "RESPONSE", "unknown", GNUNET_i2s (peer));
                        return;
        }
@@ -631,7 +607,7 @@ static void handle_response (const struct GNUNET_PeerIdentity *peer,
                if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
                        ic_accepted ++;
        }
-       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Response from peer `%s' with %u issuers, we accepted %u issuer \n"),
+       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Response from peer `%s' with %u issuers, we accepted %u issuer \n",
                        GNUNET_i2s (peer), ic, ic_accepted);
        GNUNET_free_non_null (n->issuer_id);
        n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct GNUNET_PeerIdentity));
@@ -1020,7 +996,8 @@ GED_nodes_send_start_ack (struct Node *n, struct Experiment *e)
 {
        struct NodeComCtx *e_ctx;
 
-       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Sending %s for experiment request to peer `%s' for experiment `%s'\n"),
+       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                       "Sending %s for experiment request to peer `%s' for experiment `%s'\n",
                        "START_ACK" ,GNUNET_i2s(&n->id), e->name);
 
        e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
@@ -1042,11 +1019,12 @@ GED_nodes_send_start_ack (struct Node *n, struct Experiment *e)
  * @return GNUNET_NO if core was busy with sending, GNUNET_OK otherwise
  */
 int
-GED_nodes_request_start (struct Node *n, struct Experiment *e)
+GED_nodes_send_start (struct Node *n, struct Experiment *e)
 {
        struct NodeComCtx *e_ctx;
 
-       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Sending %s for experiment request to peer `%s' for experiment `%s'\n"),
+       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                       "Sending %s for experiment request to peer `%s' for experiment `%s'\n",
                        "START", GNUNET_i2s(&n->id), e->name);
 
        e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
@@ -1093,6 +1071,12 @@ GED_nodes_start ()
 void
 GED_nodes_stop ()
 {
+  if (NULL != ch)
+  {
+               GNUNET_CORE_disconnect (ch);
+               ch = NULL;
+  }
+
   if (NULL != nodes_requested)
   {
                GNUNET_CONTAINER_multihashmap_iterate (nodes_requested,
@@ -1122,11 +1106,6 @@ GED_nodes_stop ()
                GNUNET_CONTAINER_multihashmap_destroy (nodes_inactive);
                nodes_inactive = NULL;
   }
-  if (NULL != ch)
-  {
-               GNUNET_CORE_disconnect (ch);
-               ch = NULL;
-  }
 }
 
 /* end of gnunet-daemon-experimentation_nodes.c */