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
263 size_t 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;
271 memset (buf, '\0', bufsize);
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 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
302 static void send_experimentation_request (const struct GNUNET_PeerIdentity *peer)
305 struct NodeComCtx *e_ctx;
309 c_issuers = GSE_my_issuer_count;
311 size = sizeof (struct Experimentation_Request) +
312 c_issuers * sizeof (struct Experimentation_Issuer);
313 n = GNUNET_malloc (sizeof (struct Node));
315 n->timeout_task = GNUNET_SCHEDULER_add_delayed (EXP_RESPONSE_TIMEOUT, &remove_request, n);
316 n->capabilities = NONE;
318 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
322 e_ctx->notify = &send_experimentation_request_cb;
323 e_ctx->notify_cls = n;
324 GNUNET_CONTAINER_DLL_insert_tail(n->e_req_head, n->e_req_tail, e_ctx);
325 schedule_transmisson (e_ctx);
327 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (nodes_requested,
328 &peer->hashPubKey, n, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
329 update_stats (nodes_requested);
334 * Core's transmit notify callback to send response
336 * @param cls the related node
337 * @param bufsize buffer size
338 * @param buf the buffer to copy to
339 * @return bytes passed
341 size_t send_response_cb (void *cls, size_t bufsize, void *buf)
343 struct Node *n = cls;
344 struct Experimentation_Response msg;
345 size_t ri_size = GSE_my_issuer_count * sizeof (struct Experimentation_Issuer);
346 size_t msg_size = sizeof (msg);
347 size_t total_size = msg_size + ri_size;
352 /* client disconnected */
353 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected\n");
356 GNUNET_assert (bufsize >= total_size);
358 msg.msg.size = htons (total_size);
359 msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE);
360 msg.capabilities = htonl (GSE_node_capabilities);
361 msg.issuer_count = htonl (GSE_my_issuer_count);
362 memcpy (buf, &msg, msg_size);
363 memcpy (&((char *) buf)[msg_size], GSE_my_issuer, ri_size);
365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending response to peer %s\n",
366 GNUNET_i2s (&n->id));
372 get_experiments_cb (struct Node *n, struct Experiment *e)
374 static int counter = 0;
378 /* Tell the scheduler to add a node with an experiment */
379 GED_scheduler_add (n, e, GNUNET_YES);
384 get_node (const struct GNUNET_PeerIdentity *id)
391 tmp = GNUNET_CONTAINER_multihashmap_get (nodes_active, &id->hashPubKey);
395 tmp = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &id->hashPubKey);
399 GNUNET_break (0); /* Multiple instances */
401 tmp = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &id->hashPubKey);
405 GNUNET_break (0); /* Multiple instances */
412 * Set a specific node as active
416 static void node_make_active (struct Node *n)
419 GNUNET_CONTAINER_multihashmap_put (nodes_active,
420 &n->id.hashPubKey, n, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
421 update_stats (nodes_active);
422 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Added peer `%s' as active node\n"),
423 GNUNET_i2s (&n->id));
424 /* Request experiments for this node to start them */
425 for (c1 = 0; c1 < n->issuer_count; c1++)
428 GED_experiments_get (n, &n->issuer_id[c1], &get_experiments_cb);
434 * Handle a request and send a response
436 * @param peer the source
437 * @param message the message
439 static void handle_request (const struct GNUNET_PeerIdentity *peer,
440 const struct GNUNET_MessageHeader *message)
443 struct NodeComCtx *e_ctx;
444 struct Experimentation_Request *rm = (struct Experimentation_Request *) message;
445 struct Experimentation_Issuer *rmi = (struct Experimentation_Issuer *) &rm[1];
449 uint32_t ic_accepted;
452 if (ntohs (message->size) < sizeof (struct Experimentation_Request))
457 ic = ntohl (rm->issuer_count);
458 if (ntohs (message->size) != sizeof (struct Experimentation_Request) + ic * sizeof (struct Experimentation_Issuer))
464 make_active = GNUNET_NO;
465 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_active, &peer->hashPubKey)))
469 else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &peer->hashPubKey)))
471 GNUNET_CONTAINER_multihashmap_remove (nodes_requested, &peer->hashPubKey, n);
472 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
474 GNUNET_SCHEDULER_cancel (n->timeout_task);
475 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
477 update_stats (nodes_requested);
478 make_active = GNUNET_YES;
480 else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &peer->hashPubKey)))
482 GNUNET_break (0 == GNUNET_CONTAINER_multihashmap_remove (nodes_inactive, &peer->hashPubKey, n));
483 update_stats (nodes_inactive);
484 make_active = GNUNET_YES;
488 /* Create new node */
489 n = GNUNET_malloc (sizeof (struct Node));
491 n->capabilities = NONE;
492 make_active = GNUNET_YES;
496 n->capabilities = ntohl (rm->capabilities);
498 /* Filter accepted issuer */
500 for (c1 = 0; c1 < ic; c1++)
502 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
505 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Request from peer `%s' with %u issuers, we accepted %u issuer \n",
506 GNUNET_i2s (peer), ic, ic_accepted);
507 GNUNET_free_non_null (n->issuer_id);
508 n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct GNUNET_PeerIdentity));
510 for (c1 = 0; c1 < ic; c1++)
512 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
514 n->issuer_id[c2] = rmi[c1].issuer_id;
518 n->issuer_count = ic_accepted;
520 if (GNUNET_YES == make_active)
521 node_make_active (n);
524 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
527 e_ctx->size = sizeof (struct Experimentation_Response) + GSE_my_issuer_count * sizeof (struct Experimentation_Issuer);
528 e_ctx->notify = &send_response_cb;
529 e_ctx->notify_cls = n;
531 GNUNET_CONTAINER_DLL_insert_tail(n->e_req_head, n->e_req_tail, e_ctx);
532 schedule_transmisson (e_ctx);
539 * @param peer the source
540 * @param message the message
542 static void handle_response (const struct GNUNET_PeerIdentity *peer,
543 const struct GNUNET_MessageHeader *message)
546 struct Experimentation_Response *rm = (struct Experimentation_Response *) message;
547 struct Experimentation_Issuer *rmi = (struct Experimentation_Issuer *) &rm[1];
549 uint32_t ic_accepted;
554 if (ntohs (message->size) < sizeof (struct Experimentation_Response))
559 ic = ntohl (rm->issuer_count);
560 if (ntohs (message->size) != sizeof (struct Experimentation_Response) + ic * sizeof (struct Experimentation_Issuer))
566 make_active = GNUNET_NO;
567 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_active, &peer->hashPubKey)))
569 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from %s peer `%s'\n",
570 "RESPONSE", "active", GNUNET_i2s (peer));
572 else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &peer->hashPubKey)))
574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from %s peer `%s'\n",
575 "RESPONSE", "requested", GNUNET_i2s (peer));
576 GNUNET_CONTAINER_multihashmap_remove (nodes_requested, &peer->hashPubKey, n);
577 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
579 GNUNET_SCHEDULER_cancel (n->timeout_task);
580 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
582 update_stats (nodes_requested);
583 make_active = GNUNET_YES;
585 else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &peer->hashPubKey)))
587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from peer `%s'\n",
588 "RESPONSE", "inactive", GNUNET_i2s (peer));
589 GNUNET_break (0 == GNUNET_CONTAINER_multihashmap_remove (nodes_inactive, &peer->hashPubKey, n));
590 update_stats (nodes_inactive);
591 make_active = GNUNET_YES;
595 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from %s peer `%s'\n",
596 "RESPONSE", "unknown", GNUNET_i2s (peer));
601 n->capabilities = ntohl (rm->capabilities);
603 /* Filter accepted issuer */
605 for (c1 = 0; c1 < ic; c1++)
607 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
610 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Response from peer `%s' with %u issuers, we accepted %u issuer \n",
611 GNUNET_i2s (peer), ic, ic_accepted);
612 GNUNET_free_non_null (n->issuer_id);
613 n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct GNUNET_PeerIdentity));
615 for (c1 = 0; c1 < ic; c1++)
617 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
619 n->issuer_id[c2] = rmi[c1].issuer_id;
623 n->issuer_count = ic_accepted;
625 if (GNUNET_YES == make_active)
626 node_make_active (n);
632 * @param peer the source
633 * @param message the message
635 static void handle_start (const struct GNUNET_PeerIdentity *peer,
636 const struct GNUNET_MessageHeader *message)
640 const struct GED_start_message *msg;
643 struct Experiment *e;
656 size = ntohs (message->size);
657 if (size < sizeof (struct GED_start_message))
662 msg = (const struct GED_start_message *) message;
663 name_len = ntohl (msg->len_name);
664 if (size != sizeof (struct GED_start_message) + name_len)
676 name = (const char *) &msg[1];
677 if (name[name_len-1] != '\0')
683 if (name_len != strlen (name) + 1)
689 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
696 GED_scheduler_handle_start (n, e);
702 * @param peer the source
703 * @param message the message
705 static void handle_start_ack (const struct GNUNET_PeerIdentity *peer,
706 const struct GNUNET_MessageHeader *message)
710 const struct GED_start_ack_message *msg;
713 struct Experiment *e;
726 size = ntohs (message->size);
727 if (size < sizeof (struct GED_start_ack_message))
732 msg = (const struct GED_start_ack_message *) message;
733 name_len = ntohl (msg->len_name);
734 if (size != sizeof (struct GED_start_message) + name_len)
746 name = (const char *) &msg[1];
747 if (name[name_len-1] != '\0')
753 if (name_len != strlen (name) + 1)
759 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
765 GED_scheduler_handle_start_ack (n, e);
771 * @param peer the source
772 * @param message the message
774 static void handle_stop (const struct GNUNET_PeerIdentity *peer,
775 const struct GNUNET_MessageHeader *message)
779 const struct GED_stop_message *msg;
782 struct Experiment *e;
795 size = ntohs (message->size);
796 if (size < sizeof (struct GED_stop_message))
801 msg = (const struct GED_stop_message *) message;
802 name_len = ntohl (msg->len_name);
803 if (size != sizeof (struct GED_start_message) + name_len)
815 name = (const char *) &msg[1];
816 if (name[name_len-1] != '\0')
822 if (name_len != strlen (name) + 1)
828 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
834 GED_scheduler_handle_stop (n, e);
838 * Method called whenever a given peer connects.
841 * @param peer peer identity this notification is about
843 void core_connect_handler (void *cls,
844 const struct GNUNET_PeerIdentity *peer)
846 if (GNUNET_YES == is_me(peer))
849 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connected to peer %s\n"),
852 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (nodes_requested, &peer->hashPubKey))
853 return; /* We already sent a request */
855 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (nodes_active, &peer->hashPubKey))
856 return; /* This peer is known as active */
858 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (nodes_inactive, &peer->hashPubKey))
859 return; /* This peer is known as inactive */
861 send_experimentation_request (peer);
866 * Method called whenever a given peer disconnects.
869 * @param peer peer identity this notification is about
871 void core_disconnect_handler (void *cls,
872 const struct GNUNET_PeerIdentity * peer)
875 if (GNUNET_YES == is_me(peer))
878 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Disconnected from peer %s\n"),
881 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &peer->hashPubKey)))
882 cleanup_node (nodes_requested, &peer->hashPubKey, n);
884 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_active, &peer->hashPubKey)))
885 cleanup_node (nodes_active, &peer->hashPubKey, n);
887 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &peer->hashPubKey)))
888 cleanup_node (nodes_inactive, &peer->hashPubKey, n);
893 * Handle a request and send a response
896 * @param other the sender
897 * @param message the message
898 * @return GNUNET_OK to keep connection, GNUNET_SYSERR on error
901 core_receive_handler (void *cls,
902 const struct GNUNET_PeerIdentity *other,
903 const struct GNUNET_MessageHeader *message)
905 if (ntohs (message->size) < sizeof (struct GNUNET_MessageHeader))
908 return GNUNET_SYSERR;
911 switch (ntohs (message->type)) {
912 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_REQUEST:
913 handle_request (other, message);
915 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE:
916 handle_response (other, message);
918 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START:
919 handle_start (other, message);
921 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START_ACK:
922 handle_start_ack (other, message);
924 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_STOP:
925 handle_stop (other, message);
935 size_t node_experiment_start_cb (void *cls, size_t bufsize, void *buf)
937 struct NodeComCtx *e_ctx = cls;
938 struct GED_start_message *msg;
945 name_len = strlen(e_ctx->e->name) + 1;
946 size = sizeof (struct GED_start_message) + name_len;
948 msg = GNUNET_malloc (size);
949 msg->header.size = htons (size);
950 msg->header.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START);
951 msg->issuer = e_ctx->e->issuer;
952 msg->version_nbo = GNUNET_TIME_absolute_hton(e_ctx->e->version);
953 msg->len_name = htonl (name_len);
954 memcpy (&msg[1], e_ctx->e->name, name_len);
956 memcpy (buf, msg, size);
961 size_t node_experiment_start_ack_cb (void *cls, size_t bufsize, void *buf)
963 struct NodeComCtx *e_ctx = cls;
964 struct GED_start_ack_message *msg;
970 name_len = strlen(e_ctx->e->name) + 1;
971 size = sizeof (struct GED_start_ack_message) + name_len;
973 msg = GNUNET_malloc (size);
974 msg->header.size = htons (size);
975 msg->header.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START_ACK);
976 msg->issuer = e_ctx->e->issuer;
977 msg->version_nbo = GNUNET_TIME_absolute_hton(e_ctx->e->version);
978 msg->len_name = htonl (name_len);
979 memcpy (&msg[1], e_ctx->e->name, name_len);
981 memcpy (buf, msg, size);
990 * Confirm a experiment START with a node
992 * @return GNUNET_NO if core was busy with sending, GNUNET_OK otherwise
995 GED_nodes_send_start_ack (struct Node *n, struct Experiment *e)
997 struct NodeComCtx *e_ctx;
999 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1000 "Sending %s for experiment request to peer `%s' for experiment `%s'\n",
1001 "START_ACK" ,GNUNET_i2s(&n->id), e->name);
1003 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
1006 e_ctx->size = sizeof (struct GED_start_ack_message) + strlen (e->name) + 1;
1007 e_ctx->notify = &node_experiment_start_ack_cb;
1008 e_ctx->notify_cls = e_ctx;
1010 GNUNET_CONTAINER_DLL_insert_tail (n->e_req_head, n->e_req_tail, e_ctx);
1011 schedule_transmisson (e_ctx);
1017 * Request a experiment to start with a node
1019 * @return GNUNET_NO if core was busy with sending, GNUNET_OK otherwise
1022 GED_nodes_send_start (struct Node *n, struct Experiment *e)
1024 struct NodeComCtx *e_ctx;
1026 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1027 "Sending %s for experiment request to peer `%s' for experiment `%s'\n",
1028 "START", GNUNET_i2s(&n->id), e->name);
1030 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
1033 e_ctx->size = sizeof (struct GED_start_message) + strlen (e->name) + 1;
1034 e_ctx->notify = &node_experiment_start_cb;
1035 e_ctx->notify_cls = e_ctx;
1037 GNUNET_CONTAINER_DLL_insert_tail (n->e_req_head, n->e_req_tail, e_ctx);
1038 schedule_transmisson (e_ctx);
1044 * Start the nodes management
1049 /* Connecting to core service to find partners */
1050 ch = GNUNET_CORE_connect (GED_cfg, NULL,
1051 &core_startup_handler,
1052 &core_connect_handler,
1053 &core_disconnect_handler,
1054 &core_receive_handler,
1055 GNUNET_NO, NULL, GNUNET_NO, NULL);
1058 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Failed to connect to CORE service!\n"));
1062 nodes_requested = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
1063 nodes_active = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
1064 nodes_inactive = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
1069 * Stop the nodes management
1076 GNUNET_CORE_disconnect (ch);
1080 if (NULL != nodes_requested)
1082 GNUNET_CONTAINER_multihashmap_iterate (nodes_requested,
1085 update_stats (nodes_requested);
1086 GNUNET_CONTAINER_multihashmap_destroy (nodes_requested);
1087 nodes_requested = NULL;
1090 if (NULL != nodes_active)
1092 GNUNET_CONTAINER_multihashmap_iterate (nodes_active,
1095 update_stats (nodes_active);
1096 GNUNET_CONTAINER_multihashmap_destroy (nodes_active);
1097 nodes_active = NULL;
1100 if (NULL != nodes_inactive)
1102 GNUNET_CONTAINER_multihashmap_iterate (nodes_inactive,
1105 update_stats (nodes_inactive);
1106 GNUNET_CONTAINER_multihashmap_destroy (nodes_inactive);
1107 nodes_inactive = NULL;
1111 /* end of gnunet-daemon-experimentation_nodes.c */