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_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 server core service's server handle
176 * @param my_identity my id
179 core_startup_handler (void *cls,
180 struct GNUNET_CORE_Handle *server,
181 const struct GNUNET_PeerIdentity *my_identity)
187 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);
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_INFO, _("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_INFO, _("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_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
262 size_t send_experimentation_request_cb (void *cls, size_t bufsize, void *buf)
264 struct Node *n = cls;
265 struct Experimentation_Request msg;
266 size_t msg_size = sizeof (msg);
267 size_t ri_size = sizeof (struct Experimentation_Issuer) * GSE_my_issuer_count;
268 size_t total_size = msg_size + ri_size;
270 memset (buf, '0', bufsize);
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 GNUNET_assert (bufsize >= total_size);
283 msg.msg.size = htons (total_size);
284 msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_REQUEST);
285 msg.capabilities = htonl (GSE_node_capabilities);
286 msg.issuer_count = htonl (GSE_my_issuer_count);
287 memcpy (buf, &msg, msg_size);
288 memcpy (&((char *) buf)[msg_size], GSE_my_issuer, ri_size);
290 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Sending request to peer %s\n"),
291 GNUNET_i2s (&n->id));
297 * Send request to peer to start add him to to the set of experimentation nodes
299 * @param peer the peer to send to
301 static void send_experimentation_request (const struct GNUNET_PeerIdentity *peer)
304 struct NodeComCtx *e_ctx;
308 c_issuers = GSE_my_issuer_count;
310 size = sizeof (struct Experimentation_Request) +
311 c_issuers * sizeof (struct Experimentation_Issuer);
312 n = GNUNET_malloc (sizeof (struct Node));
314 n->timeout_task = GNUNET_SCHEDULER_add_delayed (EXP_RESPONSE_TIMEOUT, &remove_request, n);
315 n->capabilities = NONE;
317 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
321 e_ctx->notify = &send_experimentation_request_cb;
322 e_ctx->notify_cls = n;
323 GNUNET_CONTAINER_DLL_insert_tail(n->e_req_head, n->e_req_tail, e_ctx);
324 schedule_transmisson (e_ctx);
326 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (nodes_requested,
327 &peer->hashPubKey, n, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
328 update_stats (nodes_requested);
333 * Core's transmit notify callback to send response
335 * @param cls the related node
336 * @param bufsize buffer size
337 * @param buf the buffer to copy to
338 * @return bytes passed
340 size_t send_response_cb (void *cls, size_t bufsize, void *buf)
342 struct Node *n = cls;
343 struct Experimentation_Response msg;
344 size_t ri_size = GSE_my_issuer_count * sizeof (struct Experimentation_Issuer);
345 size_t msg_size = sizeof (msg);
346 size_t total_size = msg_size + ri_size;
351 /* client disconnected */
352 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected\n");
355 GNUNET_assert (bufsize >= total_size);
357 msg.msg.size = htons (total_size);
358 msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE);
359 msg.capabilities = htonl (GSE_node_capabilities);
360 msg.issuer_count = htonl (GSE_my_issuer_count);
361 memcpy (buf, &msg, msg_size);
362 memcpy (&((char *) buf)[msg_size], GSE_my_issuer, ri_size);
364 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Sending response to peer %s\n"),
365 GNUNET_i2s (&n->id));
371 get_experiments_cb (struct Node *n, struct Experiment *e)
373 static int counter = 0;
376 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Added %u experiments for peer %s\n"),
377 counter, GNUNET_i2s (&n->id));
381 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting experiment `%s' with peer %s\n"),
383 GNUNET_i2s (&n->id));
385 /* Tell the scheduler to add a node with an experiment */
386 GED_scheduler_add (n, e, GNUNET_YES);
391 get_node (const struct GNUNET_PeerIdentity *id)
398 tmp = GNUNET_CONTAINER_multihashmap_get (nodes_active, &id->hashPubKey);
402 tmp = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &id->hashPubKey);
406 GNUNET_break (0); /* Multiple instances */
408 tmp = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &id->hashPubKey);
412 GNUNET_break (0); /* Multiple instances */
419 * Set a specific node as active
423 static void node_make_active (struct Node *n)
426 GNUNET_CONTAINER_multihashmap_put (nodes_active,
427 &n->id.hashPubKey, n, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
428 update_stats (nodes_active);
429 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Added peer `%s' as active node\n"),
430 GNUNET_i2s (&n->id));
431 /* Request experiments for this node to start them */
432 for (c1 = 0; c1 < n->issuer_count; c1++)
435 GED_experiments_get (n, &n->issuer_id[c1], &get_experiments_cb);
441 * Handle a request and send a response
443 * @param peer the source
444 * @param message the message
446 static void handle_request (const struct GNUNET_PeerIdentity *peer,
447 const struct GNUNET_MessageHeader *message)
450 struct NodeComCtx *e_ctx;
451 struct Experimentation_Request *rm = (struct Experimentation_Request *) message;
452 struct Experimentation_Issuer *rmi = (struct Experimentation_Issuer *) &rm[1];
456 uint32_t ic_accepted;
459 if (ntohs (message->size) < sizeof (struct Experimentation_Request))
464 ic = ntohl (rm->issuer_count);
465 if (ntohs (message->size) != sizeof (struct Experimentation_Request) + ic * sizeof (struct Experimentation_Issuer))
471 make_active = GNUNET_NO;
472 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_active, &peer->hashPubKey)))
476 else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &peer->hashPubKey)))
478 GNUNET_CONTAINER_multihashmap_remove (nodes_requested, &peer->hashPubKey, n);
479 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
481 GNUNET_SCHEDULER_cancel (n->timeout_task);
482 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
484 update_stats (nodes_requested);
485 make_active = GNUNET_YES;
487 else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &peer->hashPubKey)))
489 GNUNET_CONTAINER_multihashmap_remove (nodes_inactive, &peer->hashPubKey, n);
490 update_stats (nodes_inactive);
491 make_active = GNUNET_YES;
495 /* Create new node */
496 n = GNUNET_malloc (sizeof (struct Node));
498 n->capabilities = NONE;
499 make_active = GNUNET_YES;
503 n->capabilities = ntohl (rm->capabilities);
505 /* Filter accepted issuer */
507 for (c1 = 0; c1 < ic; c1++)
509 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
512 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Request from peer `%s' with %u issuers, we accepted %u issuer \n"),
513 GNUNET_i2s (peer), ic, ic_accepted);
514 GNUNET_free_non_null (n->issuer_id);
515 n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct GNUNET_PeerIdentity));
517 for (c1 = 0; c1 < ic; c1++)
519 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
521 n->issuer_id[c2] = rmi[c1].issuer_id;
525 n->issuer_count = ic_accepted;
527 if (GNUNET_YES == make_active)
528 node_make_active (n);
531 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
534 e_ctx->size = sizeof (struct Experimentation_Response) + GSE_my_issuer_count * sizeof (struct Experimentation_Issuer);
535 e_ctx->notify = &send_response_cb;
536 e_ctx->notify_cls = n;
538 GNUNET_CONTAINER_DLL_insert_tail(n->e_req_head, n->e_req_tail, e_ctx);
539 schedule_transmisson (e_ctx);
546 * @param peer the source
547 * @param message the message
549 static void handle_response (const struct GNUNET_PeerIdentity *peer,
550 const struct GNUNET_MessageHeader *message)
553 struct Experimentation_Response *rm = (struct Experimentation_Response *) message;
554 struct Experimentation_Issuer *rmi = (struct Experimentation_Issuer *) &rm[1];
556 uint32_t ic_accepted;
561 if (ntohs (message->size) < sizeof (struct Experimentation_Response))
566 ic = ntohl (rm->issuer_count);
567 if (ntohs (message->size) != sizeof (struct Experimentation_Response) + ic * sizeof (struct Experimentation_Issuer))
573 make_active = GNUNET_NO;
574 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_active, &peer->hashPubKey)))
576 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received %s from %s peer `%s'\n"),
577 "RESPONSE", "active", GNUNET_i2s (peer));
579 else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &peer->hashPubKey)))
581 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received %s from %s peer `%s'\n"),
582 "RESPONSE", "requested", GNUNET_i2s (peer));
583 GNUNET_CONTAINER_multihashmap_remove (nodes_requested, &peer->hashPubKey, n);
584 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
586 GNUNET_SCHEDULER_cancel (n->timeout_task);
587 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
589 update_stats (nodes_requested);
590 make_active = GNUNET_YES;
592 else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &peer->hashPubKey)))
594 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received %s from peer `%s'\n"),
595 "RESPONSE", "inactive", GNUNET_i2s (peer));
596 GNUNET_CONTAINER_multihashmap_remove (nodes_inactive, &peer->hashPubKey, n);
597 update_stats (nodes_inactive);
598 make_active = GNUNET_YES;
602 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received %s from %s peer `%s'\n"),
603 "RESPONSE", "unknown", GNUNET_i2s (peer));
608 n->capabilities = ntohl (rm->capabilities);
610 /* Filter accepted issuer */
612 for (c1 = 0; c1 < ic; c1++)
614 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
617 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Response from peer `%s' with %u issuers, we accepted %u issuer \n"),
618 GNUNET_i2s (peer), ic, ic_accepted);
619 GNUNET_free_non_null (n->issuer_id);
620 n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct GNUNET_PeerIdentity));
622 for (c1 = 0; c1 < ic; c1++)
624 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
626 n->issuer_id[c2] = rmi[c1].issuer_id;
630 n->issuer_count = ic_accepted;
632 if (GNUNET_YES == make_active)
633 node_make_active (n);
639 * @param peer the source
640 * @param message the message
642 static void handle_start (const struct GNUNET_PeerIdentity *peer,
643 const struct GNUNET_MessageHeader *message)
647 const struct GED_start_message *msg;
650 struct Experiment *e;
663 size = ntohs (message->size);
664 if (size < sizeof (struct GED_start_message))
669 msg = (const struct GED_start_message *) message;
670 name_len = ntohl (msg->len_name);
671 if (size != sizeof (struct GED_start_message) + name_len)
683 name = (const char *) &msg[1];
684 if (name[name_len-1] != '\0')
690 if (name_len != strlen (name) + 1)
696 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
703 GED_scheduler_handle_start (n, e);
709 * @param peer the source
710 * @param message the message
712 static void handle_start_ack (const struct GNUNET_PeerIdentity *peer,
713 const struct GNUNET_MessageHeader *message)
717 const struct GED_start_ack_message *msg;
720 struct Experiment *e;
733 size = ntohs (message->size);
734 if (size < sizeof (struct GED_start_ack_message))
739 msg = (const struct GED_start_ack_message *) message;
740 name_len = ntohl (msg->len_name);
741 if (size != sizeof (struct GED_start_message) + name_len)
753 name = (const char *) &msg[1];
754 if (name[name_len-1] != '\0')
760 if (name_len != strlen (name) + 1)
766 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
772 GED_scheduler_handle_start_ack (n, e);
778 * @param peer the source
779 * @param message the message
781 static void handle_stop (const struct GNUNET_PeerIdentity *peer,
782 const struct GNUNET_MessageHeader *message)
786 const struct GED_stop_message *msg;
789 struct Experiment *e;
802 size = ntohs (message->size);
803 if (size < sizeof (struct GED_stop_message))
808 msg = (const struct GED_stop_message *) message;
809 name_len = ntohl (msg->len_name);
810 if (size != sizeof (struct GED_start_message) + name_len)
822 name = (const char *) &msg[1];
823 if (name[name_len-1] != '\0')
829 if (name_len != strlen (name) + 1)
835 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
841 GED_scheduler_handle_stop (n, e);
845 * Method called whenever a given peer connects.
848 * @param peer peer identity this notification is about
850 void core_connect_handler (void *cls,
851 const struct GNUNET_PeerIdentity *peer)
853 if (GNUNET_YES == is_me(peer))
856 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connected to peer %s\n"),
859 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (nodes_requested, &peer->hashPubKey))
860 return; /* We already sent a request */
862 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (nodes_active, &peer->hashPubKey))
863 return; /* This peer is known as active */
865 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (nodes_inactive, &peer->hashPubKey))
866 return; /* This peer is known as inactive */
868 send_experimentation_request (peer);
873 * Method called whenever a given peer disconnects.
876 * @param peer peer identity this notification is about
878 void core_disconnect_handler (void *cls,
879 const struct GNUNET_PeerIdentity * peer)
882 if (GNUNET_YES == is_me(peer))
885 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Disconnected from peer %s\n"),
888 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &peer->hashPubKey)))
889 cleanup_node (nodes_requested, &peer->hashPubKey, n);
891 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_active, &peer->hashPubKey)))
892 cleanup_node (nodes_active, &peer->hashPubKey, n);
894 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &peer->hashPubKey)))
895 cleanup_node (nodes_inactive, &peer->hashPubKey, n);
900 * Handle a request and send a response
903 * @param other the sender
904 * @param message the message
905 * @return GNUNET_OK to keep connection, GNUNET_SYSERR on error
908 core_receive_handler (void *cls,
909 const struct GNUNET_PeerIdentity *other,
910 const struct GNUNET_MessageHeader *message)
912 if (ntohs (message->size) < sizeof (struct GNUNET_MessageHeader))
915 return GNUNET_SYSERR;
918 switch (ntohs (message->type)) {
919 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_REQUEST:
920 handle_request (other, message);
922 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE:
923 handle_response (other, message);
925 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START:
926 handle_start (other, message);
928 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START_ACK:
929 handle_start_ack (other, message);
931 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_STOP:
932 handle_stop (other, message);
942 size_t node_experiment_start_cb (void *cls, size_t bufsize, void *buf)
944 struct NodeComCtx *e_ctx = cls;
945 struct GED_start_message *msg;
952 name_len = strlen(e_ctx->e->name) + 1;
953 size = sizeof (struct GED_start_message) + name_len;
955 msg = GNUNET_malloc (size);
956 msg->header.size = htons (size);
957 msg->header.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START);
958 msg->issuer = e_ctx->e->issuer;
959 msg->version_nbo = GNUNET_TIME_absolute_hton(e_ctx->e->version);
960 msg->len_name = htonl (name_len);
961 memcpy (&msg[1], e_ctx->e->name, name_len);
963 memcpy (buf, msg, size);
968 size_t node_experiment_start_ack_cb (void *cls, size_t bufsize, void *buf)
970 struct NodeComCtx *e_ctx = cls;
971 struct GED_start_ack_message *msg;
977 name_len = strlen(e_ctx->e->name) + 1;
978 size = sizeof (struct GED_start_ack_message) + name_len;
980 msg = GNUNET_malloc (size);
981 msg->header.size = htons (size);
982 msg->header.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START_ACK);
983 msg->issuer = e_ctx->e->issuer;
984 msg->version_nbo = GNUNET_TIME_absolute_hton(e_ctx->e->version);
985 msg->len_name = htonl (name_len);
986 memcpy (&msg[1], e_ctx->e->name, name_len);
988 memcpy (buf, msg, size);
997 * Confirm a experiment START with a node
999 * @return GNUNET_NO if core was busy with sending, GNUNET_OK otherwise
1002 GED_nodes_send_start_ack (struct Node *n, struct Experiment *e)
1004 struct NodeComCtx *e_ctx;
1006 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Sending %s for experiment request to peer `%s' for experiment `%s'\n"),
1007 "START_ACK" ,GNUNET_i2s(&n->id), e->name);
1009 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
1012 e_ctx->size = sizeof (struct GED_start_ack_message) + strlen (e->name) + 1;
1013 e_ctx->notify = &node_experiment_start_ack_cb;
1014 e_ctx->notify_cls = e_ctx;
1016 GNUNET_CONTAINER_DLL_insert_tail (n->e_req_head, n->e_req_tail, e_ctx);
1017 schedule_transmisson (e_ctx);
1023 * Request a experiment to start with a node
1025 * @return GNUNET_NO if core was busy with sending, GNUNET_OK otherwise
1028 GED_nodes_request_start (struct Node *n, struct Experiment *e)
1030 struct NodeComCtx *e_ctx;
1032 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Sending %s for experiment request to peer `%s' for experiment `%s'\n"),
1033 "START", GNUNET_i2s(&n->id), e->name);
1035 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
1038 e_ctx->size = sizeof (struct GED_start_message) + strlen (e->name) + 1;
1039 e_ctx->notify = &node_experiment_start_cb;
1040 e_ctx->notify_cls = e_ctx;
1042 GNUNET_CONTAINER_DLL_insert_tail (n->e_req_head, n->e_req_tail, e_ctx);
1043 schedule_transmisson (e_ctx);
1049 * Start the nodes management
1054 /* Connecting to core service to find partners */
1055 ch = GNUNET_CORE_connect (GED_cfg, NULL,
1056 &core_startup_handler,
1057 &core_connect_handler,
1058 &core_disconnect_handler,
1059 &core_receive_handler,
1060 GNUNET_NO, NULL, GNUNET_NO, NULL);
1063 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Failed to connect to CORE service!\n"));
1067 nodes_requested = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
1068 nodes_active = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
1069 nodes_inactive = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
1074 * Stop the nodes management
1081 GNUNET_CORE_disconnect (ch);
1085 if (NULL != nodes_requested)
1087 GNUNET_CONTAINER_multihashmap_iterate (nodes_requested,
1090 update_stats (nodes_requested);
1091 GNUNET_CONTAINER_multihashmap_destroy (nodes_requested);
1092 nodes_requested = NULL;
1095 if (NULL != nodes_active)
1097 GNUNET_CONTAINER_multihashmap_iterate (nodes_active,
1100 update_stats (nodes_active);
1101 GNUNET_CONTAINER_multihashmap_destroy (nodes_active);
1102 nodes_active = NULL;
1105 if (NULL != nodes_inactive)
1107 GNUNET_CONTAINER_multihashmap_iterate (nodes_inactive,
1110 update_stats (nodes_inactive);
1111 GNUNET_CONTAINER_multihashmap_destroy (nodes_inactive);
1112 nodes_inactive = NULL;
1116 /* end of gnunet-daemon-experimentation_nodes.c */