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, 0, FAST_TIMEOUT,
214 &e_ctx->n->id, e_ctx->size,
215 transmit_read_wrapper, e_ctx);
216 if (NULL == e_ctx->n->cth)
218 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
219 _("Cannot send message to peer `%s' for experiment `%s'\n"),
220 GNUNET_i2s(&e_ctx->n->id), e_ctx->e->name);
227 * Remove experimentation request due to timeout
229 * @param cls the related node
230 * @param tc scheduler's task context
233 remove_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
235 struct Node *n = cls;
237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
238 "Removing request for peer %s due to timeout\n",
239 GNUNET_i2s (&n->id));
240 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (nodes_requested, &n->id))
242 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_remove (nodes_requested, &n->id, n));
243 update_stats (nodes_requested);
244 GNUNET_CONTAINER_multipeermap_put (nodes_inactive, &n->id, n,
245 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
246 update_stats (nodes_inactive);
248 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
253 append_public_key (void *cls,
254 const struct GNUNET_HashCode *key,
257 struct GNUNET_CRYPTO_EddsaPublicKey **issuers = cls;
258 struct Issuer *issuer = value;
260 *issuers[0] = issuer->pubkey;
261 *issuers = &((*issuers)[1]);
267 * Core's transmit notify callback to send request
269 * @param cls the related node
270 * @param bufsize buffer size
271 * @param buf the buffer to copy to
272 * @return bytes passed
275 send_experimentation_request_cb (void *cls, size_t bufsize, void *buf)
277 struct Node *n = cls;
278 struct Experimentation_Request msg;
279 unsigned int my_issuer_count = GNUNET_CONTAINER_multihashmap_size (valid_issuers);
280 size_t msg_size = sizeof (msg);
281 size_t ri_size = sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) * my_issuer_count;
282 size_t total_size = msg_size + ri_size;
283 struct GNUNET_CRYPTO_EddsaPublicKey *issuers;
288 /* client disconnected */
289 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
290 "Client disconnected\n");
291 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
292 GNUNET_SCHEDULER_cancel (n->timeout_task);
293 GNUNET_SCHEDULER_add_now (&remove_request, n);
296 GNUNET_assert (bufsize >= total_size);
297 msg.msg.size = htons (total_size);
298 msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_REQUEST);
299 msg.capabilities = htonl (GSE_node_capabilities);
300 msg.issuer_count = htonl (my_issuer_count);
301 memcpy (buf, &msg, msg_size);
302 issuers = (struct GNUNET_CRYPTO_EddsaPublicKey *) buf + msg_size;
303 GNUNET_CONTAINER_multihashmap_iterate (valid_issuers,
306 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
307 _("Sending experimentation request to peer %s\n"),
308 GNUNET_i2s (&n->id));
314 * Send request to peer to start add him to to the set of experimentation nodes
316 * @param peer the peer to send to
319 send_experimentation_request (const struct GNUNET_PeerIdentity *peer)
322 struct NodeComCtx *e_ctx;
326 c_issuers = GNUNET_CONTAINER_multihashmap_size (valid_issuers);
327 size = sizeof (struct Experimentation_Request) +
328 c_issuers * sizeof (struct GNUNET_CRYPTO_EddsaPublicKey);
329 n = GNUNET_new (struct Node);
331 n->timeout_task = GNUNET_SCHEDULER_add_delayed (EXP_RESPONSE_TIMEOUT, &remove_request, n);
332 n->capabilities = NONE;
334 e_ctx = GNUNET_new (struct NodeComCtx);
338 e_ctx->notify = &send_experimentation_request_cb;
339 e_ctx->notify_cls = n;
340 GNUNET_CONTAINER_DLL_insert_tail(n->e_req_head, n->e_req_tail, e_ctx);
341 schedule_transmisson (e_ctx);
343 GNUNET_assert (GNUNET_OK ==
344 GNUNET_CONTAINER_multipeermap_put (nodes_requested,
346 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
347 update_stats (nodes_requested);
352 * Core's transmit notify callback to send response
354 * @param cls the related node
355 * @param bufsize buffer size
356 * @param buf the buffer to copy to
357 * @return bytes passed
360 send_response_cb (void *cls, size_t bufsize, void *buf)
362 struct Node *n = cls;
363 struct Experimentation_Response msg;
364 size_t c_issuers = GNUNET_CONTAINER_multihashmap_size (valid_issuers);
365 size_t ri_size = c_issuers * sizeof (struct GNUNET_CRYPTO_EddsaPublicKey);
366 size_t msg_size = sizeof (msg);
367 size_t total_size = msg_size + ri_size;
368 struct GNUNET_CRYPTO_EddsaPublicKey *issuers;
373 /* client disconnected */
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
375 "Client disconnected\n");
378 GNUNET_assert (bufsize >= total_size);
380 msg.msg.size = htons (total_size);
381 msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE);
382 msg.capabilities = htonl (GSE_node_capabilities);
383 msg.issuer_count = htonl (c_issuers);
384 memcpy (buf, &msg, msg_size);
385 issuers = (struct GNUNET_CRYPTO_EddsaPublicKey *) buf + msg_size;
386 GNUNET_CONTAINER_multihashmap_iterate (valid_issuers,
389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
390 "Sending response to peer %s\n",
391 GNUNET_i2s (&n->id));
397 get_experiments_cb (struct Node *n, struct Experiment *e)
399 static int counter = 0;
403 /* Tell the scheduler to add a node with an experiment */
404 GED_scheduler_add (n, e, GNUNET_YES);
410 get_node (const struct GNUNET_PeerIdentity *id)
417 tmp = GNUNET_CONTAINER_multipeermap_get (nodes_active, id);
421 tmp = GNUNET_CONTAINER_multipeermap_get (nodes_inactive, id);
425 GNUNET_break (0); /* Multiple instances */
427 tmp = GNUNET_CONTAINER_multipeermap_get (nodes_requested, id);
431 GNUNET_break (0); /* Multiple instances */
438 * Set a specific node as active
443 node_make_active (struct Node *n)
447 GNUNET_CONTAINER_multipeermap_put (nodes_active,
448 &n->id, n, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
449 update_stats (nodes_active);
450 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
451 _("Added peer `%s' as active node\n"),
452 GNUNET_i2s (&n->id));
453 /* Request experiments for this node to start them */
454 for (c1 = 0; c1 < n->issuer_count; c1++)
456 GED_experiments_get (n, &n->issuer_id[c1], &get_experiments_cb);
462 * Handle a request and send a response
464 * @param peer the source
465 * @param message the message
468 handle_request (const struct GNUNET_PeerIdentity *peer,
469 const struct GNUNET_MessageHeader *message)
472 struct NodeComCtx *e_ctx;
473 const struct Experimentation_Request *rm = (const struct Experimentation_Request *) message;
474 const struct GNUNET_CRYPTO_EddsaPublicKey *rmi = (const struct GNUNET_CRYPTO_EddsaPublicKey *) &rm[1];
475 unsigned int my_issuer_count = GNUNET_CONTAINER_multihashmap_size (valid_issuers);
479 uint32_t ic_accepted;
482 if (ntohs (message->size) < sizeof (struct Experimentation_Request))
487 ic = ntohl (rm->issuer_count);
488 if (ntohs (message->size) !=
489 sizeof (struct Experimentation_Request) + ic * sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))
495 make_active = GNUNET_NO;
496 if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_active, peer)))
500 else if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_requested, peer)))
502 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (nodes_requested, peer, n));
503 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
505 GNUNET_SCHEDULER_cancel (n->timeout_task);
506 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
508 update_stats (nodes_requested);
509 make_active = GNUNET_YES;
511 else if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_inactive, peer)))
513 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_remove (nodes_inactive, peer, n));
514 update_stats (nodes_inactive);
515 make_active = GNUNET_YES;
519 /* Create new node */
520 n = GNUNET_new (struct Node);
522 n->capabilities = NONE;
523 make_active = GNUNET_YES;
527 n->capabilities = ntohl (rm->capabilities);
529 /* Filter accepted issuer */
531 for (c1 = 0; c1 < ic; c1++)
533 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1]))
536 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
537 "Request from peer `%s' with %u issuers, we accepted %u issuer \n",
538 GNUNET_i2s (peer), ic, ic_accepted);
539 GNUNET_free_non_null (n->issuer_id);
540 n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
542 for (c1 = 0; c1 < ic; c1++)
544 if (GNUNET_YES == GED_experiments_issuer_accepted (&rmi[c1]))
546 n->issuer_id[c2] = rmi[c1];
550 n->issuer_count = ic_accepted;
552 if (GNUNET_YES == make_active)
553 node_make_active (n);
556 e_ctx = GNUNET_new (struct NodeComCtx);
559 e_ctx->size = sizeof (struct Experimentation_Response) +
560 my_issuer_count * sizeof (struct GNUNET_CRYPTO_EddsaPublicKey);
561 e_ctx->notify = &send_response_cb;
562 e_ctx->notify_cls = n;
564 GNUNET_CONTAINER_DLL_insert_tail(n->e_req_head, n->e_req_tail, e_ctx);
565 schedule_transmisson (e_ctx);
572 * @param peer the source
573 * @param message the message
575 static void handle_response (const struct GNUNET_PeerIdentity *peer,
576 const struct GNUNET_MessageHeader *message)
579 const struct Experimentation_Response *rm = (const struct Experimentation_Response *) message;
580 const struct GNUNET_CRYPTO_EddsaPublicKey *rmi = (const struct GNUNET_CRYPTO_EddsaPublicKey *) &rm[1];
582 uint32_t ic_accepted;
587 if (ntohs (message->size) < sizeof (struct Experimentation_Response))
592 ic = ntohl (rm->issuer_count);
593 if (ntohs (message->size) != sizeof (struct Experimentation_Response) + ic * sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))
599 make_active = GNUNET_NO;
600 if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_active, peer)))
602 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
603 "Received %s from %s peer `%s'\n",
604 "RESPONSE", "active", GNUNET_i2s (peer));
606 else if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_requested, peer)))
608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from %s peer `%s'\n",
609 "RESPONSE", "requested", GNUNET_i2s (peer));
610 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (nodes_requested, peer, n));
611 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
613 GNUNET_SCHEDULER_cancel (n->timeout_task);
614 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
616 update_stats (nodes_requested);
617 make_active = GNUNET_YES;
619 else if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_inactive, peer)))
621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
622 "Received %s from peer `%s'\n",
623 "RESPONSE", "inactive", GNUNET_i2s (peer));
624 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_remove (nodes_inactive, peer, n));
625 update_stats (nodes_inactive);
626 make_active = GNUNET_YES;
630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from %s peer `%s'\n",
631 "RESPONSE", "unknown", GNUNET_i2s (peer));
636 n->capabilities = ntohl (rm->capabilities);
638 /* Filter accepted issuer */
640 for (c1 = 0; c1 < ic; c1++)
642 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1]))
645 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
646 "Response from peer `%s' with %u issuers, we accepted %u issuer \n",
647 GNUNET_i2s (peer), ic, ic_accepted);
648 GNUNET_free_non_null (n->issuer_id);
649 n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct GNUNET_PeerIdentity));
651 for (c1 = 0; c1 < ic; c1++)
653 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1]))
655 n->issuer_id[c2] = rmi[c1];
659 n->issuer_count = ic_accepted;
661 if (GNUNET_YES == make_active)
662 node_make_active (n);
669 * @param peer the source
670 * @param message the message
673 handle_start (const struct GNUNET_PeerIdentity *peer,
674 const struct GNUNET_MessageHeader *message)
678 const struct GED_start_message *msg;
681 struct Experiment *e;
694 size = ntohs (message->size);
695 if (size < sizeof (struct GED_start_message))
700 msg = (const struct GED_start_message *) message;
701 name_len = ntohl (msg->len_name);
702 if (size != sizeof (struct GED_start_message) + name_len)
714 name = (const char *) &msg[1];
715 if (name[name_len-1] != '\0')
720 if (name_len != strlen (name) + 1)
725 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
731 GED_scheduler_handle_start (n, e);
738 * @param peer the source
739 * @param message the message
742 handle_start_ack (const struct GNUNET_PeerIdentity *peer,
743 const struct GNUNET_MessageHeader *message)
747 const struct GED_start_ack_message *msg;
750 struct Experiment *e;
763 size = ntohs (message->size);
764 if (size < sizeof (struct GED_start_ack_message))
769 msg = (const struct GED_start_ack_message *) message;
770 name_len = ntohl (msg->len_name);
771 if (size != sizeof (struct GED_start_message) + name_len)
783 name = (const char *) &msg[1];
784 if (name[name_len-1] != '\0')
789 if (name_len != strlen (name) + 1)
795 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
801 GED_scheduler_handle_start_ack (n, e);
808 * @param peer the source
809 * @param message the message
812 handle_stop (const struct GNUNET_PeerIdentity *peer,
813 const struct GNUNET_MessageHeader *message)
817 const struct GED_stop_message *msg;
820 struct Experiment *e;
833 size = ntohs (message->size);
834 if (size < sizeof (struct GED_stop_message))
839 msg = (const struct GED_stop_message *) message;
840 name_len = ntohl (msg->len_name);
841 if (size != sizeof (struct GED_start_message) + name_len)
853 name = (const char *) &msg[1];
854 if (name[name_len-1] != '\0')
860 if (name_len != strlen (name) + 1)
866 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
872 GED_scheduler_handle_stop (n, e);
877 * Method called whenever a given peer connects.
880 * @param peer peer identity this notification is about
883 core_connect_handler (void *cls,
884 const struct GNUNET_PeerIdentity *peer)
886 if (GNUNET_YES == is_me(peer))
889 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connected to peer %s\n"),
892 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (nodes_requested, peer))
893 return; /* We already sent a request */
895 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (nodes_active, peer))
896 return; /* This peer is known as active */
898 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (nodes_inactive, peer))
899 return; /* This peer is known as inactive */
901 send_experimentation_request (peer);
906 * Method called whenever a given peer disconnects.
909 * @param peer peer identity this notification is about
912 core_disconnect_handler (void *cls,
913 const struct GNUNET_PeerIdentity * peer)
916 if (GNUNET_YES == is_me(peer))
919 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Disconnected from peer %s\n"),
922 if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_requested, peer)))
923 cleanup_node (nodes_requested, peer, n);
925 if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_active, peer)))
926 cleanup_node (nodes_active, peer, n);
928 if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_inactive, peer)))
929 cleanup_node (nodes_inactive, peer, n);
934 * Handle a request and send a response
937 * @param other the sender
938 * @param message the message
939 * @return GNUNET_OK to keep connection, GNUNET_SYSERR on error
942 core_receive_handler (void *cls,
943 const struct GNUNET_PeerIdentity *other,
944 const struct GNUNET_MessageHeader *message)
946 if (ntohs (message->size) < sizeof (struct GNUNET_MessageHeader))
949 return GNUNET_SYSERR;
952 switch (ntohs (message->type)) {
953 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_REQUEST:
954 handle_request (other, message);
956 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE:
957 handle_response (other, message);
959 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START:
960 handle_start (other, message);
962 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START_ACK:
963 handle_start_ack (other, message);
965 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_STOP:
966 handle_stop (other, message);
977 node_experiment_start_cb (void *cls, size_t bufsize, void *buf)
979 struct NodeComCtx *e_ctx = cls;
980 struct GED_start_message *msg;
987 name_len = strlen(e_ctx->e->name) + 1;
988 size = sizeof (struct GED_start_message) + name_len;
990 msg = GNUNET_malloc (size);
991 msg->header.size = htons (size);
992 msg->header.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START);
993 msg->issuer = e_ctx->e->issuer;
994 msg->version_nbo = GNUNET_TIME_absolute_hton(e_ctx->e->version);
995 msg->len_name = htonl (name_len);
996 memcpy (&msg[1], e_ctx->e->name, name_len);
998 memcpy (buf, msg, size);
1005 node_experiment_start_ack_cb (void *cls, size_t bufsize, void *buf)
1007 struct NodeComCtx *e_ctx = cls;
1008 struct GED_start_ack_message *msg;
1014 name_len = strlen(e_ctx->e->name) + 1;
1015 size = sizeof (struct GED_start_ack_message) + name_len;
1017 msg = GNUNET_malloc (size);
1018 msg->header.size = htons (size);
1019 msg->header.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START_ACK);
1020 msg->issuer = e_ctx->e->issuer;
1021 msg->version_nbo = GNUNET_TIME_absolute_hton(e_ctx->e->version);
1022 msg->len_name = htonl (name_len);
1023 memcpy (&msg[1], e_ctx->e->name, name_len);
1025 memcpy (buf, msg, size);
1034 * Confirm a experiment START with a node
1036 * @return GNUNET_NO if core was busy with sending, GNUNET_OK otherwise
1039 GED_nodes_send_start_ack (struct Node *n, struct Experiment *e)
1041 struct NodeComCtx *e_ctx;
1043 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1044 "Sending %s for experiment request to peer `%s' for experiment `%s'\n",
1045 "START_ACK" ,GNUNET_i2s(&n->id), e->name);
1047 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
1050 e_ctx->size = sizeof (struct GED_start_ack_message) + strlen (e->name) + 1;
1051 e_ctx->notify = &node_experiment_start_ack_cb;
1052 e_ctx->notify_cls = e_ctx;
1054 GNUNET_CONTAINER_DLL_insert_tail (n->e_req_head, n->e_req_tail, e_ctx);
1055 schedule_transmisson (e_ctx);
1061 * Request a experiment to start with a node
1063 * @return GNUNET_NO if core was busy with sending, GNUNET_OK otherwise
1066 GED_nodes_send_start (struct Node *n, struct Experiment *e)
1068 struct NodeComCtx *e_ctx;
1070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1071 "Sending %s for experiment request to peer `%s' for experiment `%s'\n",
1072 "START", GNUNET_i2s(&n->id), e->name);
1074 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
1077 e_ctx->size = sizeof (struct GED_start_message) + strlen (e->name) + 1;
1078 e_ctx->notify = &node_experiment_start_cb;
1079 e_ctx->notify_cls = e_ctx;
1081 GNUNET_CONTAINER_DLL_insert_tail (n->e_req_head, n->e_req_tail, e_ctx);
1082 schedule_transmisson (e_ctx);
1088 * Start the nodes management
1093 /* Connecting to core service to find partners */
1094 ch = GNUNET_CORE_connect (GED_cfg, NULL,
1095 &core_startup_handler,
1096 &core_connect_handler,
1097 &core_disconnect_handler,
1098 &core_receive_handler,
1099 GNUNET_NO, NULL, GNUNET_NO, NULL);
1102 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Failed to connect to CORE service!\n"));
1106 nodes_requested = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1107 nodes_active = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1108 nodes_inactive = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1113 * Stop the nodes management
1120 GNUNET_CORE_disconnect (ch);
1124 if (NULL != nodes_requested)
1126 GNUNET_CONTAINER_multipeermap_iterate (nodes_requested,
1129 update_stats (nodes_requested);
1130 GNUNET_CONTAINER_multipeermap_destroy (nodes_requested);
1131 nodes_requested = NULL;
1134 if (NULL != nodes_active)
1136 GNUNET_CONTAINER_multipeermap_iterate (nodes_active,
1139 update_stats (nodes_active);
1140 GNUNET_CONTAINER_multipeermap_destroy (nodes_active);
1141 nodes_active = NULL;
1144 if (NULL != nodes_inactive)
1146 GNUNET_CONTAINER_multipeermap_iterate (nodes_inactive,
1149 update_stats (nodes_inactive);
1150 GNUNET_CONTAINER_multipeermap_destroy (nodes_inactive);
1151 nodes_inactive = NULL;
1155 /* end of gnunet-daemon-experimentation_nodes.c */