2 This file is part of GNUnet.
3 (C) 2012-2013 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)
39 static struct GNUNET_CORE_Handle *ch;
44 static struct GNUNET_PeerIdentity me;
47 * Nodes with a pending request
49 static struct GNUNET_CONTAINER_MultiPeerMap *nodes_requested;
52 * Active experimentation nodes
54 static struct GNUNET_CONTAINER_MultiPeerMap *nodes_active;
57 * Inactive experimentation nodes
58 * To be excluded from future requests
60 static struct GNUNET_CONTAINER_MultiPeerMap *nodes_inactive;
65 struct NodeComCtx *prev;
66 struct NodeComCtx *next;
72 GNUNET_CONNECTION_TransmitReadyNotify notify;
80 * @param m peermap to update values from
83 update_stats (struct GNUNET_CONTAINER_MultiPeerMap *m)
85 GNUNET_assert (NULL != m);
86 GNUNET_assert (NULL != GED_stats);
88 if (m == nodes_active)
90 GNUNET_STATISTICS_set (GED_stats, "# nodes active",
91 GNUNET_CONTAINER_multipeermap_size(m), GNUNET_NO);
93 else if (m == nodes_inactive)
95 GNUNET_STATISTICS_set (GED_stats, "# nodes inactive",
96 GNUNET_CONTAINER_multipeermap_size(m), GNUNET_NO);
98 else if (m == nodes_requested)
100 GNUNET_STATISTICS_set (GED_stats, "# nodes requested",
101 GNUNET_CONTAINER_multipeermap_size(m), GNUNET_NO);
111 * @param cls the peermap to clean up
112 * @param key key of the current node
113 * @param value related node object
114 * @return always #GNUNET_OK
117 cleanup_node (void *cls,
118 const struct GNUNET_PeerIdentity * key,
122 struct NodeComCtx *e_cur;
123 struct NodeComCtx *e_next;
124 struct GNUNET_CONTAINER_MultiPeerMap *cur = cls;
127 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
129 GNUNET_SCHEDULER_cancel (n->timeout_task);
130 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
135 GNUNET_CORE_notify_transmit_ready_cancel (n->cth);
138 e_next = n->e_req_head;
139 while (NULL != (e_cur = e_next))
141 e_next = e_cur->next;
142 GNUNET_CONTAINER_DLL_remove (n->e_req_head, n->e_req_tail, e_cur);
145 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_remove (cur, key, value));
152 * Check if id passed is my id
154 * @param id the id to check
155 * @return GNUNET_YES or GNUNET_NO
158 is_me (const struct GNUNET_PeerIdentity *id)
160 if (0 == memcmp (&me, id, sizeof (me)))
168 * Core startup callback
171 * @param my_identity my id
174 core_startup_handler (void *cls,
175 const struct GNUNET_PeerIdentity *my_identity)
182 schedule_transmisson (struct NodeComCtx *e_ctx);
186 transmit_read_wrapper (void *cls, size_t bufsize, void *buf)
188 struct NodeComCtx *e_ctx = cls;
189 struct NodeComCtx *next;
191 size_t res = e_ctx->notify (e_ctx->notify_cls, bufsize, buf);
192 e_ctx->n->cth = NULL;
194 GNUNET_CONTAINER_DLL_remove (e_ctx->n->e_req_head, e_ctx->n->e_req_tail, e_ctx);
195 next = e_ctx->n->e_req_head;
200 /* Schedule next message */
201 schedule_transmisson (next);
208 schedule_transmisson (struct NodeComCtx *e_ctx)
210 if (NULL != e_ctx->n->cth)
213 e_ctx->n->cth = GNUNET_CORE_notify_transmit_ready (ch, GNUNET_NO,
214 GNUNET_CORE_PRIO_BEST_EFFORT,
216 &e_ctx->n->id, e_ctx->size,
217 transmit_read_wrapper, e_ctx);
218 if (NULL == e_ctx->n->cth)
220 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
221 _("Cannot send message to peer `%s' for experiment `%s'\n"),
222 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,
240 "Removing request for peer %s due to timeout\n",
241 GNUNET_i2s (&n->id));
242 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (nodes_requested, &n->id))
244 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_remove (nodes_requested, &n->id, n));
245 update_stats (nodes_requested);
246 GNUNET_CONTAINER_multipeermap_put (nodes_inactive, &n->id, n,
247 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
248 update_stats (nodes_inactive);
250 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
255 append_public_key (void *cls,
256 const struct GNUNET_HashCode *key,
259 struct GNUNET_CRYPTO_EddsaPublicKey **issuers = cls;
260 struct Issuer *issuer = value;
262 *issuers[0] = issuer->pubkey;
263 *issuers = &((*issuers)[1]);
269 * Core's transmit notify callback to send request
271 * @param cls the related node
272 * @param bufsize buffer size
273 * @param buf the buffer to copy to
274 * @return bytes passed
277 send_experimentation_request_cb (void *cls, size_t bufsize, void *buf)
279 struct Node *n = cls;
280 struct Experimentation_Request msg;
281 unsigned int my_issuer_count = GNUNET_CONTAINER_multihashmap_size (valid_issuers);
282 size_t msg_size = sizeof (msg);
283 size_t ri_size = sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) * my_issuer_count;
284 size_t total_size = msg_size + ri_size;
285 struct GNUNET_CRYPTO_EddsaPublicKey *issuers;
290 /* client disconnected */
291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
292 "Client disconnected\n");
293 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
294 GNUNET_SCHEDULER_cancel (n->timeout_task);
295 GNUNET_SCHEDULER_add_now (&remove_request, n);
298 GNUNET_assert (bufsize >= total_size);
299 msg.msg.size = htons (total_size);
300 msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_REQUEST);
301 msg.capabilities = htonl (GSE_node_capabilities);
302 msg.issuer_count = htonl (my_issuer_count);
303 memcpy (buf, &msg, msg_size);
304 issuers = (struct GNUNET_CRYPTO_EddsaPublicKey *) buf + msg_size;
305 GNUNET_CONTAINER_multihashmap_iterate (valid_issuers,
308 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
309 _("Sending experimentation request to peer %s\n"),
310 GNUNET_i2s (&n->id));
316 * Send request to peer to start add him to to the set of experimentation nodes
318 * @param peer the peer to send to
321 send_experimentation_request (const struct GNUNET_PeerIdentity *peer)
324 struct NodeComCtx *e_ctx;
328 c_issuers = GNUNET_CONTAINER_multihashmap_size (valid_issuers);
329 size = sizeof (struct Experimentation_Request) +
330 c_issuers * sizeof (struct GNUNET_CRYPTO_EddsaPublicKey);
331 n = GNUNET_new (struct Node);
333 n->timeout_task = GNUNET_SCHEDULER_add_delayed (EXP_RESPONSE_TIMEOUT, &remove_request, n);
334 n->capabilities = NONE;
336 e_ctx = GNUNET_new (struct NodeComCtx);
340 e_ctx->notify = &send_experimentation_request_cb;
341 e_ctx->notify_cls = n;
342 GNUNET_CONTAINER_DLL_insert_tail(n->e_req_head, n->e_req_tail, e_ctx);
343 schedule_transmisson (e_ctx);
345 GNUNET_assert (GNUNET_OK ==
346 GNUNET_CONTAINER_multipeermap_put (nodes_requested,
348 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
349 update_stats (nodes_requested);
354 * Core's transmit notify callback to send response
356 * @param cls the related node
357 * @param bufsize buffer size
358 * @param buf the buffer to copy to
359 * @return bytes passed
362 send_response_cb (void *cls, size_t bufsize, void *buf)
364 struct Node *n = cls;
365 struct Experimentation_Response msg;
366 size_t c_issuers = GNUNET_CONTAINER_multihashmap_size (valid_issuers);
367 size_t ri_size = c_issuers * sizeof (struct GNUNET_CRYPTO_EddsaPublicKey);
368 size_t msg_size = sizeof (msg);
369 size_t total_size = msg_size + ri_size;
370 struct GNUNET_CRYPTO_EddsaPublicKey *issuers;
375 /* client disconnected */
376 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
377 "Client disconnected\n");
380 GNUNET_assert (bufsize >= total_size);
382 msg.msg.size = htons (total_size);
383 msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE);
384 msg.capabilities = htonl (GSE_node_capabilities);
385 msg.issuer_count = htonl (c_issuers);
386 memcpy (buf, &msg, msg_size);
387 issuers = (struct GNUNET_CRYPTO_EddsaPublicKey *) buf + msg_size;
388 GNUNET_CONTAINER_multihashmap_iterate (valid_issuers,
391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
392 "Sending response to peer %s\n",
393 GNUNET_i2s (&n->id));
399 get_experiments_cb (struct Node *n, struct Experiment *e)
401 static int counter = 0;
405 /* Tell the scheduler to add a node with an experiment */
406 GED_scheduler_add (n, e, GNUNET_YES);
412 get_node (const struct GNUNET_PeerIdentity *id)
419 tmp = GNUNET_CONTAINER_multipeermap_get (nodes_active, id);
423 tmp = GNUNET_CONTAINER_multipeermap_get (nodes_inactive, id);
427 GNUNET_break (0); /* Multiple instances */
429 tmp = GNUNET_CONTAINER_multipeermap_get (nodes_requested, id);
433 GNUNET_break (0); /* Multiple instances */
440 * Set a specific node as active
445 node_make_active (struct Node *n)
449 GNUNET_CONTAINER_multipeermap_put (nodes_active,
450 &n->id, n, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
451 update_stats (nodes_active);
452 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
453 _("Added peer `%s' as active node\n"),
454 GNUNET_i2s (&n->id));
455 /* Request experiments for this node to start them */
456 for (c1 = 0; c1 < n->issuer_count; c1++)
458 GED_experiments_get (n, &n->issuer_id[c1], &get_experiments_cb);
464 * Handle a request and send a response
466 * @param peer the source
467 * @param message the message
470 handle_request (const struct GNUNET_PeerIdentity *peer,
471 const struct GNUNET_MessageHeader *message)
474 struct NodeComCtx *e_ctx;
475 const struct Experimentation_Request *rm = (const struct Experimentation_Request *) message;
476 const struct GNUNET_CRYPTO_EddsaPublicKey *rmi = (const struct GNUNET_CRYPTO_EddsaPublicKey *) &rm[1];
477 unsigned int my_issuer_count = GNUNET_CONTAINER_multihashmap_size (valid_issuers);
481 uint32_t ic_accepted;
484 if (ntohs (message->size) < sizeof (struct Experimentation_Request))
489 ic = ntohl (rm->issuer_count);
490 if (ntohs (message->size) !=
491 sizeof (struct Experimentation_Request) + ic * sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))
497 make_active = GNUNET_NO;
498 if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_active, peer)))
502 else if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_requested, peer)))
504 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (nodes_requested, peer, n));
505 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
507 GNUNET_SCHEDULER_cancel (n->timeout_task);
508 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
510 update_stats (nodes_requested);
511 make_active = GNUNET_YES;
513 else if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_inactive, peer)))
515 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_remove (nodes_inactive, peer, n));
516 update_stats (nodes_inactive);
517 make_active = GNUNET_YES;
521 /* Create new node */
522 n = GNUNET_new (struct Node);
524 n->capabilities = NONE;
525 make_active = GNUNET_YES;
529 n->capabilities = ntohl (rm->capabilities);
531 /* Filter accepted issuer */
533 for (c1 = 0; c1 < ic; c1++)
535 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1]))
538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
539 "Request from peer `%s' with %u issuers, we accepted %u issuer \n",
540 GNUNET_i2s (peer), ic, ic_accepted);
541 GNUNET_free_non_null (n->issuer_id);
542 n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
544 for (c1 = 0; c1 < ic; c1++)
546 if (GNUNET_YES == GED_experiments_issuer_accepted (&rmi[c1]))
548 n->issuer_id[c2] = rmi[c1];
552 n->issuer_count = ic_accepted;
554 if (GNUNET_YES == make_active)
555 node_make_active (n);
558 e_ctx = GNUNET_new (struct NodeComCtx);
561 e_ctx->size = sizeof (struct Experimentation_Response) +
562 my_issuer_count * sizeof (struct GNUNET_CRYPTO_EddsaPublicKey);
563 e_ctx->notify = &send_response_cb;
564 e_ctx->notify_cls = n;
566 GNUNET_CONTAINER_DLL_insert_tail(n->e_req_head, n->e_req_tail, e_ctx);
567 schedule_transmisson (e_ctx);
574 * @param peer the source
575 * @param message the message
577 static void handle_response (const struct GNUNET_PeerIdentity *peer,
578 const struct GNUNET_MessageHeader *message)
581 const struct Experimentation_Response *rm = (const struct Experimentation_Response *) message;
582 const struct GNUNET_CRYPTO_EddsaPublicKey *rmi = (const struct GNUNET_CRYPTO_EddsaPublicKey *) &rm[1];
584 uint32_t ic_accepted;
589 if (ntohs (message->size) < sizeof (struct Experimentation_Response))
594 ic = ntohl (rm->issuer_count);
595 if (ntohs (message->size) != sizeof (struct Experimentation_Response) + ic * sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))
601 make_active = GNUNET_NO;
602 if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_active, peer)))
604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
605 "Received %s from %s peer `%s'\n",
606 "RESPONSE", "active", GNUNET_i2s (peer));
608 else if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_requested, peer)))
610 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from %s peer `%s'\n",
611 "RESPONSE", "requested", GNUNET_i2s (peer));
612 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (nodes_requested, peer, n));
613 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
615 GNUNET_SCHEDULER_cancel (n->timeout_task);
616 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
618 update_stats (nodes_requested);
619 make_active = GNUNET_YES;
621 else if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_inactive, peer)))
623 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
624 "Received %s from peer `%s'\n",
625 "RESPONSE", "inactive", GNUNET_i2s (peer));
626 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_remove (nodes_inactive, peer, n));
627 update_stats (nodes_inactive);
628 make_active = GNUNET_YES;
632 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from %s peer `%s'\n",
633 "RESPONSE", "unknown", GNUNET_i2s (peer));
638 n->capabilities = ntohl (rm->capabilities);
640 /* Filter accepted issuer */
642 for (c1 = 0; c1 < ic; c1++)
644 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1]))
647 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
648 "Response from peer `%s' with %u issuers, we accepted %u issuer \n",
649 GNUNET_i2s (peer), ic, ic_accepted);
650 GNUNET_free_non_null (n->issuer_id);
651 n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct GNUNET_PeerIdentity));
653 for (c1 = 0; c1 < ic; c1++)
655 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1]))
657 n->issuer_id[c2] = rmi[c1];
661 n->issuer_count = ic_accepted;
663 if (GNUNET_YES == make_active)
664 node_make_active (n);
671 * @param peer the source
672 * @param message the message
675 handle_start (const struct GNUNET_PeerIdentity *peer,
676 const struct GNUNET_MessageHeader *message)
680 const struct GED_start_message *msg;
683 struct Experiment *e;
696 size = ntohs (message->size);
697 if (size < sizeof (struct GED_start_message))
702 msg = (const struct GED_start_message *) message;
703 name_len = ntohl (msg->len_name);
704 if (size != sizeof (struct GED_start_message) + name_len)
716 name = (const char *) &msg[1];
717 if (name[name_len-1] != '\0')
722 if (name_len != strlen (name) + 1)
727 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
733 GED_scheduler_handle_start (n, e);
740 * @param peer the source
741 * @param message the message
744 handle_start_ack (const struct GNUNET_PeerIdentity *peer,
745 const struct GNUNET_MessageHeader *message)
749 const struct GED_start_ack_message *msg;
752 struct Experiment *e;
765 size = ntohs (message->size);
766 if (size < sizeof (struct GED_start_ack_message))
771 msg = (const struct GED_start_ack_message *) message;
772 name_len = ntohl (msg->len_name);
773 if (size != sizeof (struct GED_start_message) + name_len)
785 name = (const char *) &msg[1];
786 if (name[name_len-1] != '\0')
791 if (name_len != strlen (name) + 1)
797 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
803 GED_scheduler_handle_start_ack (n, e);
810 * @param peer the source
811 * @param message the message
814 handle_stop (const struct GNUNET_PeerIdentity *peer,
815 const struct GNUNET_MessageHeader *message)
819 const struct GED_stop_message *msg;
822 struct Experiment *e;
835 size = ntohs (message->size);
836 if (size < sizeof (struct GED_stop_message))
841 msg = (const struct GED_stop_message *) message;
842 name_len = ntohl (msg->len_name);
843 if (size != sizeof (struct GED_start_message) + name_len)
855 name = (const char *) &msg[1];
856 if (name[name_len-1] != '\0')
862 if (name_len != strlen (name) + 1)
868 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
874 GED_scheduler_handle_stop (n, e);
879 * Method called whenever a given peer connects.
882 * @param peer peer identity this notification is about
885 core_connect_handler (void *cls,
886 const struct GNUNET_PeerIdentity *peer)
888 if (GNUNET_YES == is_me(peer))
891 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connected to peer %s\n"),
894 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (nodes_requested, peer))
895 return; /* We already sent a request */
897 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (nodes_active, peer))
898 return; /* This peer is known as active */
900 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (nodes_inactive, peer))
901 return; /* This peer is known as inactive */
903 send_experimentation_request (peer);
908 * Method called whenever a given peer disconnects.
911 * @param peer peer identity this notification is about
914 core_disconnect_handler (void *cls,
915 const struct GNUNET_PeerIdentity * peer)
918 if (GNUNET_YES == is_me(peer))
921 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Disconnected from peer %s\n"),
924 if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_requested, peer)))
925 cleanup_node (nodes_requested, peer, n);
927 if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_active, peer)))
928 cleanup_node (nodes_active, peer, n);
930 if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_inactive, peer)))
931 cleanup_node (nodes_inactive, peer, n);
936 * Handle a request and send a response
939 * @param other the sender
940 * @param message the message
941 * @return GNUNET_OK to keep connection, GNUNET_SYSERR on error
944 core_receive_handler (void *cls,
945 const struct GNUNET_PeerIdentity *other,
946 const struct GNUNET_MessageHeader *message)
948 if (ntohs (message->size) < sizeof (struct GNUNET_MessageHeader))
951 return GNUNET_SYSERR;
954 switch (ntohs (message->type)) {
955 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_REQUEST:
956 handle_request (other, message);
958 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE:
959 handle_response (other, message);
961 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START:
962 handle_start (other, message);
964 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START_ACK:
965 handle_start_ack (other, message);
967 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_STOP:
968 handle_stop (other, message);
979 node_experiment_start_cb (void *cls, size_t bufsize, void *buf)
981 struct NodeComCtx *e_ctx = cls;
982 struct GED_start_message *msg;
989 name_len = strlen(e_ctx->e->name) + 1;
990 size = sizeof (struct GED_start_message) + name_len;
992 msg = GNUNET_malloc (size);
993 msg->header.size = htons (size);
994 msg->header.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START);
995 msg->issuer = e_ctx->e->issuer;
996 msg->version_nbo = GNUNET_TIME_absolute_hton(e_ctx->e->version);
997 msg->len_name = htonl (name_len);
998 memcpy (&msg[1], e_ctx->e->name, name_len);
1000 memcpy (buf, msg, size);
1007 node_experiment_start_ack_cb (void *cls, size_t bufsize, void *buf)
1009 struct NodeComCtx *e_ctx = cls;
1010 struct GED_start_ack_message *msg;
1016 name_len = strlen(e_ctx->e->name) + 1;
1017 size = sizeof (struct GED_start_ack_message) + name_len;
1019 msg = GNUNET_malloc (size);
1020 msg->header.size = htons (size);
1021 msg->header.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START_ACK);
1022 msg->issuer = e_ctx->e->issuer;
1023 msg->version_nbo = GNUNET_TIME_absolute_hton(e_ctx->e->version);
1024 msg->len_name = htonl (name_len);
1025 memcpy (&msg[1], e_ctx->e->name, name_len);
1027 memcpy (buf, msg, size);
1036 * Confirm a experiment START with a node
1038 * @return GNUNET_NO if core was busy with sending, GNUNET_OK otherwise
1041 GED_nodes_send_start_ack (struct Node *n, struct Experiment *e)
1043 struct NodeComCtx *e_ctx;
1045 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1046 "Sending %s for experiment request to peer `%s' for experiment `%s'\n",
1047 "START_ACK" ,GNUNET_i2s(&n->id), e->name);
1049 e_ctx = GNUNET_new (struct NodeComCtx);
1052 e_ctx->size = sizeof (struct GED_start_ack_message) + strlen (e->name) + 1;
1053 e_ctx->notify = &node_experiment_start_ack_cb;
1054 e_ctx->notify_cls = e_ctx;
1056 GNUNET_CONTAINER_DLL_insert_tail (n->e_req_head, n->e_req_tail, e_ctx);
1057 schedule_transmisson (e_ctx);
1063 * Request a experiment to start with a node
1065 * @return GNUNET_NO if core was busy with sending, GNUNET_OK otherwise
1068 GED_nodes_send_start (struct Node *n, struct Experiment *e)
1070 struct NodeComCtx *e_ctx;
1072 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1073 "Sending %s for experiment request to peer `%s' for experiment `%s'\n",
1074 "START", GNUNET_i2s(&n->id), e->name);
1076 e_ctx = GNUNET_new (struct NodeComCtx);
1079 e_ctx->size = sizeof (struct GED_start_message) + strlen (e->name) + 1;
1080 e_ctx->notify = &node_experiment_start_cb;
1081 e_ctx->notify_cls = e_ctx;
1083 GNUNET_CONTAINER_DLL_insert_tail (n->e_req_head, n->e_req_tail, e_ctx);
1084 schedule_transmisson (e_ctx);
1090 * Start the nodes management
1095 /* Connecting to core service to find partners */
1096 ch = GNUNET_CORE_connect (GED_cfg, NULL,
1097 &core_startup_handler,
1098 &core_connect_handler,
1099 &core_disconnect_handler,
1100 &core_receive_handler,
1101 GNUNET_NO, NULL, GNUNET_NO, NULL);
1104 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Failed to connect to CORE service!\n"));
1108 nodes_requested = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1109 nodes_active = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1110 nodes_inactive = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1115 * Stop the nodes management
1122 GNUNET_CORE_disconnect (ch);
1126 if (NULL != nodes_requested)
1128 GNUNET_CONTAINER_multipeermap_iterate (nodes_requested,
1131 update_stats (nodes_requested);
1132 GNUNET_CONTAINER_multipeermap_destroy (nodes_requested);
1133 nodes_requested = NULL;
1136 if (NULL != nodes_active)
1138 GNUNET_CONTAINER_multipeermap_iterate (nodes_active,
1141 update_stats (nodes_active);
1142 GNUNET_CONTAINER_multipeermap_destroy (nodes_active);
1143 nodes_active = NULL;
1146 if (NULL != nodes_inactive)
1148 GNUNET_CONTAINER_multipeermap_iterate (nodes_inactive,
1151 update_stats (nodes_inactive);
1152 GNUNET_CONTAINER_multipeermap_destroy (nodes_inactive);
1153 nodes_inactive = NULL;
1157 /* end of gnunet-daemon-experimentation_nodes.c */