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_util_lib.h"
29 #include "gnunet_core_service.h"
30 #include "gnunet_statistics_service.h"
31 #include "gnunet-daemon-experimentation.h"
34 #define FAST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
38 static struct GNUNET_CORE_Handle *ch;
44 static struct GNUNET_PeerIdentity me;
48 * Nodes with a pending request
50 struct GNUNET_CONTAINER_MultiHashMap *nodes_requested;
54 * Active experimentation nodes
56 struct GNUNET_CONTAINER_MultiHashMap *nodes_active;
60 * Inactive experimentation nodes
61 * To be excluded from future requests
63 struct GNUNET_CONTAINER_MultiHashMap *nodes_inactive;
67 struct NodeComCtx *prev;
68 struct NodeComCtx *next;
74 GNUNET_CONNECTION_TransmitReadyNotify notify;
82 * @param m hashmap to update values from
84 static void update_stats (struct GNUNET_CONTAINER_MultiHashMap *m)
86 GNUNET_assert (NULL != m);
87 GNUNET_assert (NULL != GED_stats);
89 if (m == nodes_active)
91 GNUNET_STATISTICS_set (GED_stats, "# nodes active",
92 GNUNET_CONTAINER_multihashmap_size(m), GNUNET_NO);
94 else if (m == nodes_inactive)
96 GNUNET_STATISTICS_set (GED_stats, "# nodes inactive",
97 GNUNET_CONTAINER_multihashmap_size(m), GNUNET_NO);
99 else if (m == nodes_requested)
101 GNUNET_STATISTICS_set (GED_stats, "# nodes requested",
102 GNUNET_CONTAINER_multihashmap_size(m), GNUNET_NO);
113 * @param cls the hashmap to clean up
114 * @param key key of the current node
115 * @param value related node object
116 * @return always GNUNET_OK
119 cleanup_node (void *cls,
120 const struct GNUNET_HashCode * key,
124 struct NodeComCtx *e_cur;
125 struct NodeComCtx *e_next;
126 struct GNUNET_CONTAINER_MultiHashMap *cur = cls;
129 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
131 GNUNET_SCHEDULER_cancel (n->timeout_task);
132 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
137 GNUNET_CORE_notify_transmit_ready_cancel (n->cth);
140 e_next = n->e_req_head;
141 while (NULL != (e_cur = e_next))
143 e_next = e_cur->next;
144 GNUNET_CONTAINER_DLL_remove (n->e_req_head, n->e_req_tail, e_cur);
148 GNUNET_free_non_null (n->issuer_id);
150 GNUNET_break (0 == GNUNET_CONTAINER_multihashmap_remove (cur, key, value));
157 * Check if id passed is my id
159 * @param id the id to check
160 * @return GNUNET_YES or GNUNET_NO
162 static int is_me (const struct GNUNET_PeerIdentity *id)
164 if (0 == memcmp (&me, id, sizeof (me)))
171 * Core startup callback
174 * @param my_identity my id
177 core_startup_handler (void *cls,
178 const struct GNUNET_PeerIdentity *my_identity)
185 schedule_transmisson (struct NodeComCtx *e_ctx);
189 transmit_read_wrapper (void *cls, size_t bufsize, void *buf)
191 struct NodeComCtx *e_ctx = cls;
192 struct NodeComCtx *next = NULL;
194 size_t res = e_ctx->notify (e_ctx->notify_cls, bufsize, buf);
195 e_ctx->n->cth = NULL;
197 GNUNET_CONTAINER_DLL_remove (e_ctx->n->e_req_head, e_ctx->n->e_req_tail, e_ctx);
198 next = e_ctx->n->e_req_head;
203 /* Schedule next message */
204 schedule_transmisson (next);
211 schedule_transmisson (struct NodeComCtx *e_ctx)
213 if (NULL != e_ctx->n->cth)
216 e_ctx->n->cth = GNUNET_CORE_notify_transmit_ready (ch, GNUNET_NO, 0, FAST_TIMEOUT,
217 &e_ctx->n->id, e_ctx->size, transmit_read_wrapper, e_ctx);
218 if (NULL == e_ctx->n->cth)
220 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Cannot send message to peer `%s' for experiment `%s'\n"),
221 GNUNET_i2s(&e_ctx->n->id), e_ctx->e->name);
229 * Remove experimentation request due to timeout
231 * @param cls the related node
232 * @param tc scheduler's task context
235 remove_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
237 struct Node *n = cls;
239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing request for peer %s due to timeout\n",
240 GNUNET_i2s (&n->id));
242 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (nodes_requested, &n->id.hashPubKey))
244 GNUNET_break (0 == GNUNET_CONTAINER_multihashmap_remove (nodes_requested, &n->id.hashPubKey, n));
245 update_stats (nodes_requested);
246 GNUNET_CONTAINER_multihashmap_put (nodes_inactive, &n->id.hashPubKey, n,
247 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
248 update_stats (nodes_inactive);
250 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
255 * Core's transmit notify callback to send request
257 * @param cls the related node
258 * @param bufsize buffer size
259 * @param buf the buffer to copy to
260 * @return bytes passed
263 send_experimentation_request_cb (void *cls, size_t bufsize, void *buf)
265 struct Node *n = cls;
266 struct Experimentation_Request msg;
267 size_t msg_size = sizeof (msg);
268 size_t ri_size = sizeof (struct Experimentation_Issuer) * GSE_my_issuer_count;
269 size_t total_size = msg_size + ri_size;
274 /* client disconnected */
275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected\n");
276 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
277 GNUNET_SCHEDULER_cancel (n->timeout_task);
278 GNUNET_SCHEDULER_add_now (&remove_request, n);
281 memset (buf, '\0', bufsize);
282 GNUNET_assert (bufsize >= total_size);
284 msg.msg.size = htons (total_size);
285 msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_REQUEST);
286 msg.capabilities = htonl (GSE_node_capabilities);
287 msg.issuer_count = htonl (GSE_my_issuer_count);
288 memcpy (buf, &msg, msg_size);
289 memcpy (&((char *) buf)[msg_size], GSE_my_issuer, ri_size);
291 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Sending experimentation request to peer %s\n"),
292 GNUNET_i2s (&n->id));
298 * Send request to peer to start add him to to the set of experimentation nodes
300 * @param peer the peer to send to
303 send_experimentation_request (const struct GNUNET_PeerIdentity *peer)
306 struct NodeComCtx *e_ctx;
310 c_issuers = GSE_my_issuer_count;
312 size = sizeof (struct Experimentation_Request) +
313 c_issuers * sizeof (struct Experimentation_Issuer);
314 n = GNUNET_malloc (sizeof (struct Node));
316 n->timeout_task = GNUNET_SCHEDULER_add_delayed (EXP_RESPONSE_TIMEOUT, &remove_request, n);
317 n->capabilities = NONE;
319 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
323 e_ctx->notify = &send_experimentation_request_cb;
324 e_ctx->notify_cls = n;
325 GNUNET_CONTAINER_DLL_insert_tail(n->e_req_head, n->e_req_tail, e_ctx);
326 schedule_transmisson (e_ctx);
328 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (nodes_requested,
329 &peer->hashPubKey, n, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
330 update_stats (nodes_requested);
335 * Core's transmit notify callback to send response
337 * @param cls the related node
338 * @param bufsize buffer size
339 * @param buf the buffer to copy to
340 * @return bytes passed
342 size_t send_response_cb (void *cls, size_t bufsize, void *buf)
344 struct Node *n = cls;
345 struct Experimentation_Response msg;
346 size_t ri_size = GSE_my_issuer_count * sizeof (struct Experimentation_Issuer);
347 size_t msg_size = sizeof (msg);
348 size_t total_size = msg_size + ri_size;
353 /* client disconnected */
354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected\n");
357 GNUNET_assert (bufsize >= total_size);
359 msg.msg.size = htons (total_size);
360 msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE);
361 msg.capabilities = htonl (GSE_node_capabilities);
362 msg.issuer_count = htonl (GSE_my_issuer_count);
363 memcpy (buf, &msg, msg_size);
364 memcpy (&((char *) buf)[msg_size], GSE_my_issuer, ri_size);
366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending response to peer %s\n",
367 GNUNET_i2s (&n->id));
373 get_experiments_cb (struct Node *n, struct Experiment *e)
375 static int counter = 0;
379 /* Tell the scheduler to add a node with an experiment */
380 GED_scheduler_add (n, e, GNUNET_YES);
385 get_node (const struct GNUNET_PeerIdentity *id)
392 tmp = GNUNET_CONTAINER_multihashmap_get (nodes_active, &id->hashPubKey);
396 tmp = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &id->hashPubKey);
400 GNUNET_break (0); /* Multiple instances */
402 tmp = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &id->hashPubKey);
406 GNUNET_break (0); /* Multiple instances */
413 * Set a specific node as active
417 static void node_make_active (struct Node *n)
420 GNUNET_CONTAINER_multihashmap_put (nodes_active,
421 &n->id.hashPubKey, n, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
422 update_stats (nodes_active);
423 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Added peer `%s' as active node\n"),
424 GNUNET_i2s (&n->id));
425 /* Request experiments for this node to start them */
426 for (c1 = 0; c1 < n->issuer_count; c1++)
429 GED_experiments_get (n, &n->issuer_id[c1], &get_experiments_cb);
435 * Handle a request and send a response
437 * @param peer the source
438 * @param message the message
440 static void handle_request (const struct GNUNET_PeerIdentity *peer,
441 const struct GNUNET_MessageHeader *message)
444 struct NodeComCtx *e_ctx;
445 struct Experimentation_Request *rm = (struct Experimentation_Request *) message;
446 struct Experimentation_Issuer *rmi = (struct Experimentation_Issuer *) &rm[1];
450 uint32_t ic_accepted;
453 if (ntohs (message->size) < sizeof (struct Experimentation_Request))
458 ic = ntohl (rm->issuer_count);
459 if (ntohs (message->size) != sizeof (struct Experimentation_Request) + ic * sizeof (struct Experimentation_Issuer))
465 make_active = GNUNET_NO;
466 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_active, &peer->hashPubKey)))
470 else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &peer->hashPubKey)))
472 GNUNET_CONTAINER_multihashmap_remove (nodes_requested, &peer->hashPubKey, n);
473 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
475 GNUNET_SCHEDULER_cancel (n->timeout_task);
476 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
478 update_stats (nodes_requested);
479 make_active = GNUNET_YES;
481 else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &peer->hashPubKey)))
483 GNUNET_break (0 == GNUNET_CONTAINER_multihashmap_remove (nodes_inactive, &peer->hashPubKey, n));
484 update_stats (nodes_inactive);
485 make_active = GNUNET_YES;
489 /* Create new node */
490 n = GNUNET_malloc (sizeof (struct Node));
492 n->capabilities = NONE;
493 make_active = GNUNET_YES;
497 n->capabilities = ntohl (rm->capabilities);
499 /* Filter accepted issuer */
501 for (c1 = 0; c1 < ic; c1++)
503 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Request from peer `%s' with %u issuers, we accepted %u issuer \n",
507 GNUNET_i2s (peer), ic, ic_accepted);
508 GNUNET_free_non_null (n->issuer_id);
509 n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct GNUNET_PeerIdentity));
511 for (c1 = 0; c1 < ic; c1++)
513 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
515 n->issuer_id[c2] = rmi[c1].issuer_id;
519 n->issuer_count = ic_accepted;
521 if (GNUNET_YES == make_active)
522 node_make_active (n);
525 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
528 e_ctx->size = sizeof (struct Experimentation_Response) + GSE_my_issuer_count * sizeof (struct Experimentation_Issuer);
529 e_ctx->notify = &send_response_cb;
530 e_ctx->notify_cls = n;
532 GNUNET_CONTAINER_DLL_insert_tail(n->e_req_head, n->e_req_tail, e_ctx);
533 schedule_transmisson (e_ctx);
540 * @param peer the source
541 * @param message the message
543 static void handle_response (const struct GNUNET_PeerIdentity *peer,
544 const struct GNUNET_MessageHeader *message)
547 struct Experimentation_Response *rm = (struct Experimentation_Response *) message;
548 struct Experimentation_Issuer *rmi = (struct Experimentation_Issuer *) &rm[1];
550 uint32_t ic_accepted;
555 if (ntohs (message->size) < sizeof (struct Experimentation_Response))
560 ic = ntohl (rm->issuer_count);
561 if (ntohs (message->size) != sizeof (struct Experimentation_Response) + ic * sizeof (struct Experimentation_Issuer))
567 make_active = GNUNET_NO;
568 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_active, &peer->hashPubKey)))
570 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from %s peer `%s'\n",
571 "RESPONSE", "active", GNUNET_i2s (peer));
573 else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &peer->hashPubKey)))
575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from %s peer `%s'\n",
576 "RESPONSE", "requested", GNUNET_i2s (peer));
577 GNUNET_CONTAINER_multihashmap_remove (nodes_requested, &peer->hashPubKey, n);
578 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
580 GNUNET_SCHEDULER_cancel (n->timeout_task);
581 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
583 update_stats (nodes_requested);
584 make_active = GNUNET_YES;
586 else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &peer->hashPubKey)))
588 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from peer `%s'\n",
589 "RESPONSE", "inactive", GNUNET_i2s (peer));
590 GNUNET_break (0 == GNUNET_CONTAINER_multihashmap_remove (nodes_inactive, &peer->hashPubKey, n));
591 update_stats (nodes_inactive);
592 make_active = GNUNET_YES;
596 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from %s peer `%s'\n",
597 "RESPONSE", "unknown", GNUNET_i2s (peer));
602 n->capabilities = ntohl (rm->capabilities);
604 /* Filter accepted issuer */
606 for (c1 = 0; c1 < ic; c1++)
608 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
611 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Response from peer `%s' with %u issuers, we accepted %u issuer \n",
612 GNUNET_i2s (peer), ic, ic_accepted);
613 GNUNET_free_non_null (n->issuer_id);
614 n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct GNUNET_PeerIdentity));
616 for (c1 = 0; c1 < ic; c1++)
618 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
620 n->issuer_id[c2] = rmi[c1].issuer_id;
624 n->issuer_count = ic_accepted;
626 if (GNUNET_YES == make_active)
627 node_make_active (n);
633 * @param peer the source
634 * @param message the message
636 static void handle_start (const struct GNUNET_PeerIdentity *peer,
637 const struct GNUNET_MessageHeader *message)
641 const struct GED_start_message *msg;
644 struct Experiment *e;
657 size = ntohs (message->size);
658 if (size < sizeof (struct GED_start_message))
663 msg = (const struct GED_start_message *) message;
664 name_len = ntohl (msg->len_name);
665 if (size != sizeof (struct GED_start_message) + name_len)
677 name = (const char *) &msg[1];
678 if (name[name_len-1] != '\0')
684 if (name_len != strlen (name) + 1)
690 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
697 GED_scheduler_handle_start (n, e);
703 * @param peer the source
704 * @param message the message
706 static void handle_start_ack (const struct GNUNET_PeerIdentity *peer,
707 const struct GNUNET_MessageHeader *message)
711 const struct GED_start_ack_message *msg;
714 struct Experiment *e;
727 size = ntohs (message->size);
728 if (size < sizeof (struct GED_start_ack_message))
733 msg = (const struct GED_start_ack_message *) message;
734 name_len = ntohl (msg->len_name);
735 if (size != sizeof (struct GED_start_message) + name_len)
747 name = (const char *) &msg[1];
748 if (name[name_len-1] != '\0')
754 if (name_len != strlen (name) + 1)
760 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
766 GED_scheduler_handle_start_ack (n, e);
772 * @param peer the source
773 * @param message the message
775 static void handle_stop (const struct GNUNET_PeerIdentity *peer,
776 const struct GNUNET_MessageHeader *message)
780 const struct GED_stop_message *msg;
783 struct Experiment *e;
796 size = ntohs (message->size);
797 if (size < sizeof (struct GED_stop_message))
802 msg = (const struct GED_stop_message *) message;
803 name_len = ntohl (msg->len_name);
804 if (size != sizeof (struct GED_start_message) + name_len)
816 name = (const char *) &msg[1];
817 if (name[name_len-1] != '\0')
823 if (name_len != strlen (name) + 1)
829 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
835 GED_scheduler_handle_stop (n, e);
839 * Method called whenever a given peer connects.
842 * @param peer peer identity this notification is about
844 void core_connect_handler (void *cls,
845 const struct GNUNET_PeerIdentity *peer)
847 if (GNUNET_YES == is_me(peer))
850 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connected to peer %s\n"),
853 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (nodes_requested, &peer->hashPubKey))
854 return; /* We already sent a request */
856 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (nodes_active, &peer->hashPubKey))
857 return; /* This peer is known as active */
859 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (nodes_inactive, &peer->hashPubKey))
860 return; /* This peer is known as inactive */
862 send_experimentation_request (peer);
867 * Method called whenever a given peer disconnects.
870 * @param peer peer identity this notification is about
872 void core_disconnect_handler (void *cls,
873 const struct GNUNET_PeerIdentity * peer)
876 if (GNUNET_YES == is_me(peer))
879 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Disconnected from peer %s\n"),
882 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &peer->hashPubKey)))
883 cleanup_node (nodes_requested, &peer->hashPubKey, n);
885 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_active, &peer->hashPubKey)))
886 cleanup_node (nodes_active, &peer->hashPubKey, n);
888 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &peer->hashPubKey)))
889 cleanup_node (nodes_inactive, &peer->hashPubKey, n);
894 * Handle a request and send a response
897 * @param other the sender
898 * @param message the message
899 * @return GNUNET_OK to keep connection, GNUNET_SYSERR on error
902 core_receive_handler (void *cls,
903 const struct GNUNET_PeerIdentity *other,
904 const struct GNUNET_MessageHeader *message)
906 if (ntohs (message->size) < sizeof (struct GNUNET_MessageHeader))
909 return GNUNET_SYSERR;
912 switch (ntohs (message->type)) {
913 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_REQUEST:
914 handle_request (other, message);
916 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE:
917 handle_response (other, message);
919 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START:
920 handle_start (other, message);
922 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START_ACK:
923 handle_start_ack (other, message);
925 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_STOP:
926 handle_stop (other, message);
936 size_t node_experiment_start_cb (void *cls, size_t bufsize, void *buf)
938 struct NodeComCtx *e_ctx = cls;
939 struct GED_start_message *msg;
946 name_len = strlen(e_ctx->e->name) + 1;
947 size = sizeof (struct GED_start_message) + name_len;
949 msg = GNUNET_malloc (size);
950 msg->header.size = htons (size);
951 msg->header.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START);
952 msg->issuer = e_ctx->e->issuer;
953 msg->version_nbo = GNUNET_TIME_absolute_hton(e_ctx->e->version);
954 msg->len_name = htonl (name_len);
955 memcpy (&msg[1], e_ctx->e->name, name_len);
957 memcpy (buf, msg, size);
962 size_t node_experiment_start_ack_cb (void *cls, size_t bufsize, void *buf)
964 struct NodeComCtx *e_ctx = cls;
965 struct GED_start_ack_message *msg;
971 name_len = strlen(e_ctx->e->name) + 1;
972 size = sizeof (struct GED_start_ack_message) + name_len;
974 msg = GNUNET_malloc (size);
975 msg->header.size = htons (size);
976 msg->header.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START_ACK);
977 msg->issuer = e_ctx->e->issuer;
978 msg->version_nbo = GNUNET_TIME_absolute_hton(e_ctx->e->version);
979 msg->len_name = htonl (name_len);
980 memcpy (&msg[1], e_ctx->e->name, name_len);
982 memcpy (buf, msg, size);
991 * Confirm a experiment START with a node
993 * @return GNUNET_NO if core was busy with sending, GNUNET_OK otherwise
996 GED_nodes_send_start_ack (struct Node *n, struct Experiment *e)
998 struct NodeComCtx *e_ctx;
1000 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1001 "Sending %s for experiment request to peer `%s' for experiment `%s'\n",
1002 "START_ACK" ,GNUNET_i2s(&n->id), e->name);
1004 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
1007 e_ctx->size = sizeof (struct GED_start_ack_message) + strlen (e->name) + 1;
1008 e_ctx->notify = &node_experiment_start_ack_cb;
1009 e_ctx->notify_cls = e_ctx;
1011 GNUNET_CONTAINER_DLL_insert_tail (n->e_req_head, n->e_req_tail, e_ctx);
1012 schedule_transmisson (e_ctx);
1018 * Request a experiment to start with a node
1020 * @return GNUNET_NO if core was busy with sending, GNUNET_OK otherwise
1023 GED_nodes_send_start (struct Node *n, struct Experiment *e)
1025 struct NodeComCtx *e_ctx;
1027 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1028 "Sending %s for experiment request to peer `%s' for experiment `%s'\n",
1029 "START", GNUNET_i2s(&n->id), e->name);
1031 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
1034 e_ctx->size = sizeof (struct GED_start_message) + strlen (e->name) + 1;
1035 e_ctx->notify = &node_experiment_start_cb;
1036 e_ctx->notify_cls = e_ctx;
1038 GNUNET_CONTAINER_DLL_insert_tail (n->e_req_head, n->e_req_tail, e_ctx);
1039 schedule_transmisson (e_ctx);
1045 * Start the nodes management
1050 /* Connecting to core service to find partners */
1051 ch = GNUNET_CORE_connect (GED_cfg, NULL,
1052 &core_startup_handler,
1053 &core_connect_handler,
1054 &core_disconnect_handler,
1055 &core_receive_handler,
1056 GNUNET_NO, NULL, GNUNET_NO, NULL);
1059 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Failed to connect to CORE service!\n"));
1063 nodes_requested = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
1064 nodes_active = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
1065 nodes_inactive = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
1070 * Stop the nodes management
1077 GNUNET_CORE_disconnect (ch);
1081 if (NULL != nodes_requested)
1083 GNUNET_CONTAINER_multihashmap_iterate (nodes_requested,
1086 update_stats (nodes_requested);
1087 GNUNET_CONTAINER_multihashmap_destroy (nodes_requested);
1088 nodes_requested = NULL;
1091 if (NULL != nodes_active)
1093 GNUNET_CONTAINER_multihashmap_iterate (nodes_active,
1096 update_stats (nodes_active);
1097 GNUNET_CONTAINER_multihashmap_destroy (nodes_active);
1098 nodes_active = NULL;
1101 if (NULL != nodes_inactive)
1103 GNUNET_CONTAINER_multihashmap_iterate (nodes_inactive,
1106 update_stats (nodes_inactive);
1107 GNUNET_CONTAINER_multihashmap_destroy (nodes_inactive);
1108 nodes_inactive = NULL;
1112 /* end of gnunet-daemon-experimentation_nodes.c */