2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file experimentation/gnunet-daemon-experimentation_nodes.c
23 * @brief experimentation daemon: node management
24 * @author Christian Grothoff
25 * @author Matthias Wachs
28 #include "gnunet_getopt_lib.h"
29 #include "gnunet_util_lib.h"
30 #include "gnunet_core_service.h"
31 #include "gnunet_statistics_service.h"
32 #include "gnunet-daemon-experimentation.h"
35 #define FAST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
39 static struct GNUNET_CORE_Handle *ch;
45 static struct GNUNET_PeerIdentity me;
49 * Nodes with a pending request
51 struct GNUNET_CONTAINER_MultiHashMap *nodes_requested;
55 * Active experimentation nodes
57 struct GNUNET_CONTAINER_MultiHashMap *nodes_active;
61 * Inactive experimentation nodes
62 * To be excluded from future requests
64 struct GNUNET_CONTAINER_MultiHashMap *nodes_inactive;
68 struct NodeComCtx *prev;
69 struct NodeComCtx *next;
75 GNUNET_CONNECTION_TransmitReadyNotify notify;
83 * @param m hashmap to update values from
85 static void update_stats (struct GNUNET_CONTAINER_MultiHashMap *m)
87 GNUNET_assert (NULL != m);
88 GNUNET_assert (NULL != GED_stats);
90 if (m == nodes_active)
92 GNUNET_STATISTICS_set (GED_stats, "# nodes active",
93 GNUNET_CONTAINER_multihashmap_size(m), GNUNET_NO);
95 else if (m == nodes_inactive)
97 GNUNET_STATISTICS_set (GED_stats, "# nodes inactive",
98 GNUNET_CONTAINER_multihashmap_size(m), GNUNET_NO);
100 else if (m == nodes_requested)
102 GNUNET_STATISTICS_set (GED_stats, "# nodes requested",
103 GNUNET_CONTAINER_multihashmap_size(m), GNUNET_NO);
114 * @param cls the hashmap to clean up
115 * @param key key of the current node
116 * @param value related node object
117 * @return always GNUNET_OK
120 cleanup_node (void *cls,
121 const struct GNUNET_HashCode * key,
125 struct NodeComCtx *e_cur;
126 struct NodeComCtx *e_next;
127 struct GNUNET_CONTAINER_MultiHashMap *cur = cls;
130 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
132 GNUNET_SCHEDULER_cancel (n->timeout_task);
133 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
138 GNUNET_CORE_notify_transmit_ready_cancel (n->cth);
141 e_next = n->e_req_head;
142 while (NULL != (e_cur = e_next))
144 e_next = e_cur->next;
145 GNUNET_CONTAINER_DLL_remove (n->e_req_head, n->e_req_tail, e_cur);
149 GNUNET_free_non_null (n->issuer_id);
151 GNUNET_break (0 == GNUNET_CONTAINER_multihashmap_remove (cur, key, value));
158 * Check if id passed is my id
160 * @param id the id to check
161 * @return GNUNET_YES or GNUNET_NO
163 static int is_me (const struct GNUNET_PeerIdentity *id)
165 if (0 == memcmp (&me, id, sizeof (me)))
172 * Core startup callback
175 * @param my_identity my id
178 core_startup_handler (void *cls,
179 const struct GNUNET_PeerIdentity *my_identity)
186 schedule_transmisson (struct NodeComCtx *e_ctx);
190 transmit_read_wrapper (void *cls, size_t bufsize, void *buf)
192 struct NodeComCtx *e_ctx = cls;
193 struct NodeComCtx *next = NULL;
195 size_t res = e_ctx->notify (e_ctx->notify_cls, bufsize, buf);
196 e_ctx->n->cth = NULL;
198 GNUNET_CONTAINER_DLL_remove (e_ctx->n->e_req_head, e_ctx->n->e_req_tail, e_ctx);
199 next = e_ctx->n->e_req_head;
204 /* Schedule next message */
205 schedule_transmisson (next);
212 schedule_transmisson (struct NodeComCtx *e_ctx)
214 if (NULL != e_ctx->n->cth)
217 e_ctx->n->cth = GNUNET_CORE_notify_transmit_ready (ch, GNUNET_NO, 0, FAST_TIMEOUT,
218 &e_ctx->n->id, e_ctx->size, transmit_read_wrapper, e_ctx);
219 if (NULL == e_ctx->n->cth)
221 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Cannot send message to peer `%s' for experiment `%s'\n"),
222 GNUNET_i2s(&e_ctx->n->id), e_ctx->e->name);
230 * Remove experimentation request due to timeout
232 * @param cls the related node
233 * @param tc scheduler's task context
236 remove_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
238 struct Node *n = cls;
240 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing request for peer %s due to timeout\n",
241 GNUNET_i2s (&n->id));
243 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (nodes_requested, &n->id.hashPubKey))
245 GNUNET_break (0 == GNUNET_CONTAINER_multihashmap_remove (nodes_requested, &n->id.hashPubKey, n));
246 update_stats (nodes_requested);
247 GNUNET_CONTAINER_multihashmap_put (nodes_inactive, &n->id.hashPubKey, n,
248 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
249 update_stats (nodes_inactive);
251 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
256 * Core's transmit notify callback to send request
258 * @param cls the related node
259 * @param bufsize buffer size
260 * @param buf the buffer to copy to
261 * @return bytes passed
264 send_experimentation_request_cb (void *cls, size_t bufsize, void *buf)
266 struct Node *n = cls;
267 struct Experimentation_Request msg;
268 size_t msg_size = sizeof (msg);
269 size_t ri_size = sizeof (struct Experimentation_Issuer) * GSE_my_issuer_count;
270 size_t total_size = msg_size + ri_size;
275 /* client disconnected */
276 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected\n");
277 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
278 GNUNET_SCHEDULER_cancel (n->timeout_task);
279 GNUNET_SCHEDULER_add_now (&remove_request, n);
282 memset (buf, '\0', bufsize);
283 GNUNET_assert (bufsize >= total_size);
285 msg.msg.size = htons (total_size);
286 msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_REQUEST);
287 msg.capabilities = htonl (GSE_node_capabilities);
288 msg.issuer_count = htonl (GSE_my_issuer_count);
289 memcpy (buf, &msg, msg_size);
290 memcpy (&((char *) buf)[msg_size], GSE_my_issuer, ri_size);
292 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Sending experimentation request to peer %s\n"),
293 GNUNET_i2s (&n->id));
299 * Send request to peer to start add him to to the set of experimentation nodes
301 * @param peer the peer to send to
304 send_experimentation_request (const struct GNUNET_PeerIdentity *peer)
307 struct NodeComCtx *e_ctx;
311 c_issuers = GSE_my_issuer_count;
313 size = sizeof (struct Experimentation_Request) +
314 c_issuers * sizeof (struct Experimentation_Issuer);
315 n = GNUNET_malloc (sizeof (struct Node));
317 n->timeout_task = GNUNET_SCHEDULER_add_delayed (EXP_RESPONSE_TIMEOUT, &remove_request, n);
318 n->capabilities = NONE;
320 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
324 e_ctx->notify = &send_experimentation_request_cb;
325 e_ctx->notify_cls = n;
326 GNUNET_CONTAINER_DLL_insert_tail(n->e_req_head, n->e_req_tail, e_ctx);
327 schedule_transmisson (e_ctx);
329 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (nodes_requested,
330 &peer->hashPubKey, n, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
331 update_stats (nodes_requested);
336 * Core's transmit notify callback to send response
338 * @param cls the related node
339 * @param bufsize buffer size
340 * @param buf the buffer to copy to
341 * @return bytes passed
343 size_t send_response_cb (void *cls, size_t bufsize, void *buf)
345 struct Node *n = cls;
346 struct Experimentation_Response msg;
347 size_t ri_size = GSE_my_issuer_count * sizeof (struct Experimentation_Issuer);
348 size_t msg_size = sizeof (msg);
349 size_t total_size = msg_size + ri_size;
354 /* client disconnected */
355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected\n");
358 GNUNET_assert (bufsize >= total_size);
360 msg.msg.size = htons (total_size);
361 msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE);
362 msg.capabilities = htonl (GSE_node_capabilities);
363 msg.issuer_count = htonl (GSE_my_issuer_count);
364 memcpy (buf, &msg, msg_size);
365 memcpy (&((char *) buf)[msg_size], GSE_my_issuer, ri_size);
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending response to peer %s\n",
368 GNUNET_i2s (&n->id));
374 get_experiments_cb (struct Node *n, struct Experiment *e)
376 static int counter = 0;
380 /* Tell the scheduler to add a node with an experiment */
381 GED_scheduler_add (n, e, GNUNET_YES);
386 get_node (const struct GNUNET_PeerIdentity *id)
393 tmp = GNUNET_CONTAINER_multihashmap_get (nodes_active, &id->hashPubKey);
397 tmp = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &id->hashPubKey);
401 GNUNET_break (0); /* Multiple instances */
403 tmp = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &id->hashPubKey);
407 GNUNET_break (0); /* Multiple instances */
414 * Set a specific node as active
418 static void node_make_active (struct Node *n)
421 GNUNET_CONTAINER_multihashmap_put (nodes_active,
422 &n->id.hashPubKey, n, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
423 update_stats (nodes_active);
424 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Added peer `%s' as active node\n"),
425 GNUNET_i2s (&n->id));
426 /* Request experiments for this node to start them */
427 for (c1 = 0; c1 < n->issuer_count; c1++)
430 GED_experiments_get (n, &n->issuer_id[c1], &get_experiments_cb);
436 * Handle a request and send a response
438 * @param peer the source
439 * @param message the message
441 static void handle_request (const struct GNUNET_PeerIdentity *peer,
442 const struct GNUNET_MessageHeader *message)
445 struct NodeComCtx *e_ctx;
446 struct Experimentation_Request *rm = (struct Experimentation_Request *) message;
447 struct Experimentation_Issuer *rmi = (struct Experimentation_Issuer *) &rm[1];
451 uint32_t ic_accepted;
454 if (ntohs (message->size) < sizeof (struct Experimentation_Request))
459 ic = ntohl (rm->issuer_count);
460 if (ntohs (message->size) != sizeof (struct Experimentation_Request) + ic * sizeof (struct Experimentation_Issuer))
466 make_active = GNUNET_NO;
467 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_active, &peer->hashPubKey)))
471 else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &peer->hashPubKey)))
473 GNUNET_CONTAINER_multihashmap_remove (nodes_requested, &peer->hashPubKey, n);
474 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
476 GNUNET_SCHEDULER_cancel (n->timeout_task);
477 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
479 update_stats (nodes_requested);
480 make_active = GNUNET_YES;
482 else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &peer->hashPubKey)))
484 GNUNET_break (0 == GNUNET_CONTAINER_multihashmap_remove (nodes_inactive, &peer->hashPubKey, n));
485 update_stats (nodes_inactive);
486 make_active = GNUNET_YES;
490 /* Create new node */
491 n = GNUNET_malloc (sizeof (struct Node));
493 n->capabilities = NONE;
494 make_active = GNUNET_YES;
498 n->capabilities = ntohl (rm->capabilities);
500 /* Filter accepted issuer */
502 for (c1 = 0; c1 < ic; c1++)
504 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
507 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Request from peer `%s' with %u issuers, we accepted %u issuer \n",
508 GNUNET_i2s (peer), ic, ic_accepted);
509 GNUNET_free_non_null (n->issuer_id);
510 n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct GNUNET_PeerIdentity));
512 for (c1 = 0; c1 < ic; c1++)
514 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
516 n->issuer_id[c2] = rmi[c1].issuer_id;
520 n->issuer_count = ic_accepted;
522 if (GNUNET_YES == make_active)
523 node_make_active (n);
526 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
529 e_ctx->size = sizeof (struct Experimentation_Response) + GSE_my_issuer_count * sizeof (struct Experimentation_Issuer);
530 e_ctx->notify = &send_response_cb;
531 e_ctx->notify_cls = n;
533 GNUNET_CONTAINER_DLL_insert_tail(n->e_req_head, n->e_req_tail, e_ctx);
534 schedule_transmisson (e_ctx);
541 * @param peer the source
542 * @param message the message
544 static void handle_response (const struct GNUNET_PeerIdentity *peer,
545 const struct GNUNET_MessageHeader *message)
548 struct Experimentation_Response *rm = (struct Experimentation_Response *) message;
549 struct Experimentation_Issuer *rmi = (struct Experimentation_Issuer *) &rm[1];
551 uint32_t ic_accepted;
556 if (ntohs (message->size) < sizeof (struct Experimentation_Response))
561 ic = ntohl (rm->issuer_count);
562 if (ntohs (message->size) != sizeof (struct Experimentation_Response) + ic * sizeof (struct Experimentation_Issuer))
568 make_active = GNUNET_NO;
569 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_active, &peer->hashPubKey)))
571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from %s peer `%s'\n",
572 "RESPONSE", "active", GNUNET_i2s (peer));
574 else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &peer->hashPubKey)))
576 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from %s peer `%s'\n",
577 "RESPONSE", "requested", GNUNET_i2s (peer));
578 GNUNET_CONTAINER_multihashmap_remove (nodes_requested, &peer->hashPubKey, n);
579 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
581 GNUNET_SCHEDULER_cancel (n->timeout_task);
582 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
584 update_stats (nodes_requested);
585 make_active = GNUNET_YES;
587 else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &peer->hashPubKey)))
589 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from peer `%s'\n",
590 "RESPONSE", "inactive", GNUNET_i2s (peer));
591 GNUNET_break (0 == GNUNET_CONTAINER_multihashmap_remove (nodes_inactive, &peer->hashPubKey, n));
592 update_stats (nodes_inactive);
593 make_active = GNUNET_YES;
597 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from %s peer `%s'\n",
598 "RESPONSE", "unknown", GNUNET_i2s (peer));
603 n->capabilities = ntohl (rm->capabilities);
605 /* Filter accepted issuer */
607 for (c1 = 0; c1 < ic; c1++)
609 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Response from peer `%s' with %u issuers, we accepted %u issuer \n",
613 GNUNET_i2s (peer), ic, ic_accepted);
614 GNUNET_free_non_null (n->issuer_id);
615 n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct GNUNET_PeerIdentity));
617 for (c1 = 0; c1 < ic; c1++)
619 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
621 n->issuer_id[c2] = rmi[c1].issuer_id;
625 n->issuer_count = ic_accepted;
627 if (GNUNET_YES == make_active)
628 node_make_active (n);
634 * @param peer the source
635 * @param message the message
637 static void handle_start (const struct GNUNET_PeerIdentity *peer,
638 const struct GNUNET_MessageHeader *message)
642 const struct GED_start_message *msg;
645 struct Experiment *e;
658 size = ntohs (message->size);
659 if (size < sizeof (struct GED_start_message))
664 msg = (const struct GED_start_message *) message;
665 name_len = ntohl (msg->len_name);
666 if (size != sizeof (struct GED_start_message) + name_len)
678 name = (const char *) &msg[1];
679 if (name[name_len-1] != '\0')
685 if (name_len != strlen (name) + 1)
691 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
698 GED_scheduler_handle_start (n, e);
704 * @param peer the source
705 * @param message the message
707 static void handle_start_ack (const struct GNUNET_PeerIdentity *peer,
708 const struct GNUNET_MessageHeader *message)
712 const struct GED_start_ack_message *msg;
715 struct Experiment *e;
728 size = ntohs (message->size);
729 if (size < sizeof (struct GED_start_ack_message))
734 msg = (const struct GED_start_ack_message *) message;
735 name_len = ntohl (msg->len_name);
736 if (size != sizeof (struct GED_start_message) + name_len)
748 name = (const char *) &msg[1];
749 if (name[name_len-1] != '\0')
755 if (name_len != strlen (name) + 1)
761 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
767 GED_scheduler_handle_start_ack (n, e);
773 * @param peer the source
774 * @param message the message
776 static void handle_stop (const struct GNUNET_PeerIdentity *peer,
777 const struct GNUNET_MessageHeader *message)
781 const struct GED_stop_message *msg;
784 struct Experiment *e;
797 size = ntohs (message->size);
798 if (size < sizeof (struct GED_stop_message))
803 msg = (const struct GED_stop_message *) message;
804 name_len = ntohl (msg->len_name);
805 if (size != sizeof (struct GED_start_message) + name_len)
817 name = (const char *) &msg[1];
818 if (name[name_len-1] != '\0')
824 if (name_len != strlen (name) + 1)
830 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
836 GED_scheduler_handle_stop (n, e);
840 * Method called whenever a given peer connects.
843 * @param peer peer identity this notification is about
845 void core_connect_handler (void *cls,
846 const struct GNUNET_PeerIdentity *peer)
848 if (GNUNET_YES == is_me(peer))
851 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connected to peer %s\n"),
854 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (nodes_requested, &peer->hashPubKey))
855 return; /* We already sent a request */
857 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (nodes_active, &peer->hashPubKey))
858 return; /* This peer is known as active */
860 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (nodes_inactive, &peer->hashPubKey))
861 return; /* This peer is known as inactive */
863 send_experimentation_request (peer);
868 * Method called whenever a given peer disconnects.
871 * @param peer peer identity this notification is about
873 void core_disconnect_handler (void *cls,
874 const struct GNUNET_PeerIdentity * peer)
877 if (GNUNET_YES == is_me(peer))
880 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Disconnected from peer %s\n"),
883 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &peer->hashPubKey)))
884 cleanup_node (nodes_requested, &peer->hashPubKey, n);
886 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_active, &peer->hashPubKey)))
887 cleanup_node (nodes_active, &peer->hashPubKey, n);
889 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &peer->hashPubKey)))
890 cleanup_node (nodes_inactive, &peer->hashPubKey, n);
895 * Handle a request and send a response
898 * @param other the sender
899 * @param message the message
900 * @return GNUNET_OK to keep connection, GNUNET_SYSERR on error
903 core_receive_handler (void *cls,
904 const struct GNUNET_PeerIdentity *other,
905 const struct GNUNET_MessageHeader *message)
907 if (ntohs (message->size) < sizeof (struct GNUNET_MessageHeader))
910 return GNUNET_SYSERR;
913 switch (ntohs (message->type)) {
914 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_REQUEST:
915 handle_request (other, message);
917 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE:
918 handle_response (other, message);
920 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START:
921 handle_start (other, message);
923 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START_ACK:
924 handle_start_ack (other, message);
926 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_STOP:
927 handle_stop (other, message);
937 size_t node_experiment_start_cb (void *cls, size_t bufsize, void *buf)
939 struct NodeComCtx *e_ctx = cls;
940 struct GED_start_message *msg;
947 name_len = strlen(e_ctx->e->name) + 1;
948 size = sizeof (struct GED_start_message) + name_len;
950 msg = GNUNET_malloc (size);
951 msg->header.size = htons (size);
952 msg->header.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START);
953 msg->issuer = e_ctx->e->issuer;
954 msg->version_nbo = GNUNET_TIME_absolute_hton(e_ctx->e->version);
955 msg->len_name = htonl (name_len);
956 memcpy (&msg[1], e_ctx->e->name, name_len);
958 memcpy (buf, msg, size);
963 size_t node_experiment_start_ack_cb (void *cls, size_t bufsize, void *buf)
965 struct NodeComCtx *e_ctx = cls;
966 struct GED_start_ack_message *msg;
972 name_len = strlen(e_ctx->e->name) + 1;
973 size = sizeof (struct GED_start_ack_message) + name_len;
975 msg = GNUNET_malloc (size);
976 msg->header.size = htons (size);
977 msg->header.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START_ACK);
978 msg->issuer = e_ctx->e->issuer;
979 msg->version_nbo = GNUNET_TIME_absolute_hton(e_ctx->e->version);
980 msg->len_name = htonl (name_len);
981 memcpy (&msg[1], e_ctx->e->name, name_len);
983 memcpy (buf, msg, size);
992 * Confirm a experiment START with a node
994 * @return GNUNET_NO if core was busy with sending, GNUNET_OK otherwise
997 GED_nodes_send_start_ack (struct Node *n, struct Experiment *e)
999 struct NodeComCtx *e_ctx;
1001 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1002 "Sending %s for experiment request to peer `%s' for experiment `%s'\n",
1003 "START_ACK" ,GNUNET_i2s(&n->id), e->name);
1005 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
1008 e_ctx->size = sizeof (struct GED_start_ack_message) + strlen (e->name) + 1;
1009 e_ctx->notify = &node_experiment_start_ack_cb;
1010 e_ctx->notify_cls = e_ctx;
1012 GNUNET_CONTAINER_DLL_insert_tail (n->e_req_head, n->e_req_tail, e_ctx);
1013 schedule_transmisson (e_ctx);
1019 * Request a experiment to start with a node
1021 * @return GNUNET_NO if core was busy with sending, GNUNET_OK otherwise
1024 GED_nodes_send_start (struct Node *n, struct Experiment *e)
1026 struct NodeComCtx *e_ctx;
1028 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1029 "Sending %s for experiment request to peer `%s' for experiment `%s'\n",
1030 "START", GNUNET_i2s(&n->id), e->name);
1032 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
1035 e_ctx->size = sizeof (struct GED_start_message) + strlen (e->name) + 1;
1036 e_ctx->notify = &node_experiment_start_cb;
1037 e_ctx->notify_cls = e_ctx;
1039 GNUNET_CONTAINER_DLL_insert_tail (n->e_req_head, n->e_req_tail, e_ctx);
1040 schedule_transmisson (e_ctx);
1046 * Start the nodes management
1051 /* Connecting to core service to find partners */
1052 ch = GNUNET_CORE_connect (GED_cfg, NULL,
1053 &core_startup_handler,
1054 &core_connect_handler,
1055 &core_disconnect_handler,
1056 &core_receive_handler,
1057 GNUNET_NO, NULL, GNUNET_NO, NULL);
1060 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Failed to connect to CORE service!\n"));
1064 nodes_requested = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
1065 nodes_active = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
1066 nodes_inactive = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
1071 * Stop the nodes management
1078 GNUNET_CORE_disconnect (ch);
1082 if (NULL != nodes_requested)
1084 GNUNET_CONTAINER_multihashmap_iterate (nodes_requested,
1087 update_stats (nodes_requested);
1088 GNUNET_CONTAINER_multihashmap_destroy (nodes_requested);
1089 nodes_requested = NULL;
1092 if (NULL != nodes_active)
1094 GNUNET_CONTAINER_multihashmap_iterate (nodes_active,
1097 update_stats (nodes_active);
1098 GNUNET_CONTAINER_multihashmap_destroy (nodes_active);
1099 nodes_active = NULL;
1102 if (NULL != nodes_inactive)
1104 GNUNET_CONTAINER_multihashmap_iterate (nodes_inactive,
1107 update_stats (nodes_inactive);
1108 GNUNET_CONTAINER_multihashmap_destroy (nodes_inactive);
1109 nodes_inactive = NULL;
1113 /* end of gnunet-daemon-experimentation_nodes.c */