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);
251 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
254 GNUNET_CORE_notify_transmit_ready_cancel (n->cth);
261 * Core's transmit notify callback to send request
263 * @param cls the related node
264 * @param bufsize buffer size
265 * @param buf the buffer to copy to
266 * @return bytes passed
268 size_t send_experimentation_request_cb (void *cls, size_t bufsize, void *buf)
270 struct Node *n = cls;
271 struct Experimentation_Request msg;
272 size_t msg_size = sizeof (msg);
273 size_t ri_size = sizeof (struct Experimentation_Issuer) * GSE_my_issuer_count;
274 size_t total_size = msg_size + ri_size;
276 memset (buf, '0', bufsize);
280 /* client disconnected */
281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected\n");
282 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
283 GNUNET_SCHEDULER_cancel (n->timeout_task);
284 GNUNET_SCHEDULER_add_now (&remove_request, n);
287 GNUNET_assert (bufsize >= total_size);
289 msg.msg.size = htons (total_size);
290 msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_REQUEST);
291 msg.capabilities = htonl (GSE_node_capabilities);
292 msg.issuer_count = htonl (GSE_my_issuer_count);
293 memcpy (buf, &msg, msg_size);
294 memcpy (&((char *) buf)[msg_size], GSE_my_issuer, ri_size);
296 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Sending request to peer %s\n"),
297 GNUNET_i2s (&n->id));
303 * Send request to peer to start add him to to the set of experimentation nodes
305 * @param peer the peer to send to
307 static void send_experimentation_request (const struct GNUNET_PeerIdentity *peer)
310 struct NodeComCtx *e_ctx;
314 c_issuers = GSE_my_issuer_count;
316 size = sizeof (struct Experimentation_Request) +
317 c_issuers * sizeof (struct Experimentation_Issuer);
318 n = GNUNET_malloc (sizeof (struct Node));
320 n->timeout_task = GNUNET_SCHEDULER_add_delayed (EXP_RESPONSE_TIMEOUT, &remove_request, n);
321 n->capabilities = NONE;
323 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
327 e_ctx->notify = &send_experimentation_request_cb;
328 e_ctx->notify_cls = n;
329 GNUNET_CONTAINER_DLL_insert_tail(n->e_req_head, n->e_req_tail, e_ctx);
330 schedule_transmisson (e_ctx);
332 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (nodes_requested,
333 &peer->hashPubKey, n, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
334 update_stats (nodes_requested);
339 * Core's transmit notify callback to send response
341 * @param cls the related node
342 * @param bufsize buffer size
343 * @param buf the buffer to copy to
344 * @return bytes passed
346 size_t send_response_cb (void *cls, size_t bufsize, void *buf)
348 struct Node *n = cls;
349 struct Experimentation_Response msg;
350 size_t ri_size = GSE_my_issuer_count * sizeof (struct Experimentation_Issuer);
351 size_t msg_size = sizeof (msg);
352 size_t total_size = msg_size + ri_size;
357 /* client disconnected */
358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected\n");
361 GNUNET_assert (bufsize >= total_size);
363 msg.msg.size = htons (total_size);
364 msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE);
365 msg.capabilities = htonl (GSE_node_capabilities);
366 msg.issuer_count = htonl (GSE_my_issuer_count);
367 memcpy (buf, &msg, msg_size);
368 memcpy (&((char *) buf)[msg_size], GSE_my_issuer, ri_size);
370 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Sending response to peer %s\n"),
371 GNUNET_i2s (&n->id));
377 get_experiments_cb (struct Node *n, struct Experiment *e)
379 static int counter = 0;
382 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Added %u experiments for peer %s\n"),
383 counter, GNUNET_i2s (&n->id));
387 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting experiment `%s' with peer %s\n"),
389 GNUNET_i2s (&n->id));
391 /* Tell the scheduler to add a node with an experiment */
392 GED_scheduler_add (n, e, GNUNET_YES);
397 get_node (const struct GNUNET_PeerIdentity *id)
404 tmp = GNUNET_CONTAINER_multihashmap_get (nodes_active, &id->hashPubKey);
408 tmp = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &id->hashPubKey);
412 GNUNET_break (0); /* Multiple instances */
414 tmp = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &id->hashPubKey);
418 GNUNET_break (0); /* Multiple instances */
425 * Set a specific node as active
429 static void node_make_active (struct Node *n)
432 GNUNET_CONTAINER_multihashmap_put (nodes_active,
433 &n->id.hashPubKey, n, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
434 update_stats (nodes_active);
435 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Added peer `%s' as active node\n"),
436 GNUNET_i2s (&n->id));
438 /* Request experiments for this node to start them */
439 for (c1 = 0; c1 < n->issuer_count; c1++)
442 GED_experiments_get (n, &n->issuer_id[c1], &get_experiments_cb);
448 * Handle a request and send a response
450 * @param peer the source
451 * @param message the message
453 static void handle_request (const struct GNUNET_PeerIdentity *peer,
454 const struct GNUNET_MessageHeader *message)
457 struct NodeComCtx *e_ctx;
458 struct Experimentation_Request *rm = (struct Experimentation_Request *) message;
459 struct Experimentation_Issuer *rmi = (struct Experimentation_Issuer *) &rm[1];
463 uint32_t ic_accepted;
466 if (ntohs (message->size) < sizeof (struct Experimentation_Request))
471 ic = ntohl (rm->issuer_count);
472 if (ntohs (message->size) != sizeof (struct Experimentation_Request) + ic * sizeof (struct Experimentation_Issuer))
478 make_active = GNUNET_NO;
479 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_active, &peer->hashPubKey)))
483 else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &peer->hashPubKey)))
485 GNUNET_CONTAINER_multihashmap_remove (nodes_requested, &peer->hashPubKey, n);
486 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
488 GNUNET_SCHEDULER_cancel (n->timeout_task);
489 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
493 GNUNET_CORE_notify_transmit_ready_cancel (n->cth);
496 update_stats (nodes_requested);
497 make_active = GNUNET_YES;
499 else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &peer->hashPubKey)))
501 GNUNET_CONTAINER_multihashmap_remove (nodes_inactive, &peer->hashPubKey, n);
502 update_stats (nodes_inactive);
503 make_active = GNUNET_YES;
507 /* Create new node */
508 n = GNUNET_malloc (sizeof (struct Node));
510 n->capabilities = NONE;
511 make_active = GNUNET_YES;
515 n->capabilities = ntohl (rm->capabilities);
517 /* Filter accepted issuer */
519 for (c1 = 0; c1 < ic; c1++)
521 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
524 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Request from peer `%s' with %u issuers, we accepted %u issuer \n"),
525 GNUNET_i2s (peer), ic, ic_accepted);
526 GNUNET_free_non_null (n->issuer_id);
527 n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct GNUNET_PeerIdentity));
529 for (c1 = 0; c1 < ic; c1++)
531 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
533 n->issuer_id[c2] = rmi[c1].issuer_id;
537 n->issuer_count = ic_accepted;
539 if (GNUNET_YES == make_active)
540 node_make_active (n);
543 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
546 e_ctx->size = sizeof (struct Experimentation_Response) + GSE_my_issuer_count * sizeof (struct Experimentation_Issuer);
547 e_ctx->notify = &send_response_cb;
548 e_ctx->notify_cls = n;
550 GNUNET_CONTAINER_DLL_insert_tail(n->e_req_head, n->e_req_tail, e_ctx);
551 schedule_transmisson (e_ctx);
558 * @param peer the source
559 * @param message the message
561 static void handle_response (const struct GNUNET_PeerIdentity *peer,
562 const struct GNUNET_MessageHeader *message)
565 struct Experimentation_Response *rm = (struct Experimentation_Response *) message;
566 struct Experimentation_Issuer *rmi = (struct Experimentation_Issuer *) &rm[1];
568 uint32_t ic_accepted;
573 if (ntohs (message->size) < sizeof (struct Experimentation_Response))
578 ic = ntohl (rm->issuer_count);
579 if (ntohs (message->size) != sizeof (struct Experimentation_Response) + ic * sizeof (struct Experimentation_Issuer))
585 make_active = GNUNET_NO;
586 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_active, &peer->hashPubKey)))
588 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received %s from %s peer `%s'\n"),
589 "RESPONSE", "active", GNUNET_i2s (peer));
591 else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &peer->hashPubKey)))
593 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received %s from %s peer `%s'\n"),
594 "RESPONSE", "requested", GNUNET_i2s (peer));
595 GNUNET_CONTAINER_multihashmap_remove (nodes_requested, &peer->hashPubKey, n);
596 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
598 GNUNET_SCHEDULER_cancel (n->timeout_task);
599 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
603 GNUNET_CORE_notify_transmit_ready_cancel (n->cth);
606 update_stats (nodes_requested);
607 make_active = GNUNET_YES;
609 else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &peer->hashPubKey)))
611 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received %s from peer `%s'\n"),
612 "RESPONSE", "inactive", GNUNET_i2s (peer));
613 GNUNET_CONTAINER_multihashmap_remove (nodes_inactive, &peer->hashPubKey, n);
614 update_stats (nodes_inactive);
615 make_active = GNUNET_YES;
619 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received %s from %s peer `%s'\n"),
620 "RESPONSE", "unknown", GNUNET_i2s (peer));
625 n->capabilities = ntohl (rm->capabilities);
627 /* Filter accepted issuer */
629 for (c1 = 0; c1 < ic; c1++)
631 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
634 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Response from peer `%s' with %u issuers, we accepted %u issuer \n"),
635 GNUNET_i2s (peer), ic, ic_accepted);
636 GNUNET_free_non_null (n->issuer_id);
637 n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct GNUNET_PeerIdentity));
639 for (c1 = 0; c1 < ic; c1++)
641 if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
643 n->issuer_id[c2] = rmi[c1].issuer_id;
647 n->issuer_count = ic_accepted;
649 if (GNUNET_YES == make_active)
650 node_make_active (n);
656 * @param peer the source
657 * @param message the message
659 static void handle_start (const struct GNUNET_PeerIdentity *peer,
660 const struct GNUNET_MessageHeader *message)
664 const struct GED_start_message *msg;
667 struct Experiment *e;
680 size = ntohs (message->size);
681 if (size < sizeof (struct GED_start_message))
686 msg = (const struct GED_start_message *) message;
687 name_len = ntohl (msg->len_name);
688 if (size != sizeof (struct GED_start_message) + name_len)
700 name = (const char *) &msg[1];
701 if (name[name_len-1] != '\0')
707 if (name_len != strlen (name) + 1)
713 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
720 GED_scheduler_handle_start (n, e);
726 * @param peer the source
727 * @param message the message
729 static void handle_start_ack (const struct GNUNET_PeerIdentity *peer,
730 const struct GNUNET_MessageHeader *message)
734 const struct GED_start_ack_message *msg;
737 struct Experiment *e;
750 size = ntohs (message->size);
751 if (size < sizeof (struct GED_start_ack_message))
756 msg = (const struct GED_start_ack_message *) message;
757 name_len = ntohl (msg->len_name);
758 if (size != sizeof (struct GED_start_message) + name_len)
770 name = (const char *) &msg[1];
771 if (name[name_len-1] != '\0')
777 if (name_len != strlen (name) + 1)
783 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
789 GED_scheduler_handle_start_ack (n, e);
795 * @param peer the source
796 * @param message the message
798 static void handle_stop (const struct GNUNET_PeerIdentity *peer,
799 const struct GNUNET_MessageHeader *message)
803 const struct GED_stop_message *msg;
806 struct Experiment *e;
819 size = ntohs (message->size);
820 if (size < sizeof (struct GED_stop_message))
825 msg = (const struct GED_stop_message *) message;
826 name_len = ntohl (msg->len_name);
827 if (size != sizeof (struct GED_start_message) + name_len)
839 name = (const char *) &msg[1];
840 if (name[name_len-1] != '\0')
846 if (name_len != strlen (name) + 1)
852 e = GED_experiments_find (&msg->issuer, name, GNUNET_TIME_absolute_ntoh(msg->version_nbo));
858 GED_scheduler_handle_stop (n, e);
862 * Method called whenever a given peer connects.
865 * @param peer peer identity this notification is about
867 void core_connect_handler (void *cls,
868 const struct GNUNET_PeerIdentity *peer)
870 if (GNUNET_YES == is_me(peer))
873 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connected to peer %s\n"),
876 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (nodes_requested, &peer->hashPubKey))
877 return; /* We already sent a request */
879 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (nodes_active, &peer->hashPubKey))
880 return; /* This peer is known as active */
882 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (nodes_inactive, &peer->hashPubKey))
883 return; /* This peer is known as inactive */
885 send_experimentation_request (peer);
890 * Method called whenever a given peer disconnects.
893 * @param peer peer identity this notification is about
895 void core_disconnect_handler (void *cls,
896 const struct GNUNET_PeerIdentity * peer)
899 if (GNUNET_YES == is_me(peer))
902 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Disconnected from peer %s\n"),
905 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_requested, &peer->hashPubKey)))
906 cleanup_node (nodes_requested, &peer->hashPubKey, n);
908 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_active, &peer->hashPubKey)))
909 cleanup_node (nodes_active, &peer->hashPubKey, n);
911 if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_inactive, &peer->hashPubKey)))
912 cleanup_node (nodes_inactive, &peer->hashPubKey, n);
917 * Handle a request and send a response
920 * @param other the sender
921 * @param message the message
922 * @return GNUNET_OK to keep connection, GNUNET_SYSERR on error
925 core_receive_handler (void *cls,
926 const struct GNUNET_PeerIdentity *other,
927 const struct GNUNET_MessageHeader *message)
929 if (ntohs (message->size) < sizeof (struct GNUNET_MessageHeader))
932 return GNUNET_SYSERR;
935 switch (ntohs (message->type)) {
936 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_REQUEST:
937 handle_request (other, message);
939 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE:
940 handle_response (other, message);
942 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START:
943 handle_start (other, message);
945 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START_ACK:
946 handle_start_ack (other, message);
948 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_STOP:
949 handle_stop (other, message);
959 size_t node_experiment_start_cb (void *cls, size_t bufsize, void *buf)
961 struct NodeComCtx *e_ctx = cls;
962 struct GED_start_message *msg;
969 name_len = strlen(e_ctx->e->name) + 1;
970 size = sizeof (struct GED_start_message) + name_len;
972 msg = GNUNET_malloc (size);
973 msg->header.size = htons (size);
974 msg->header.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START);
975 msg->issuer = e_ctx->e->issuer;
976 msg->version_nbo = GNUNET_TIME_absolute_hton(e_ctx->e->version);
977 msg->len_name = htonl (name_len);
978 memcpy (&msg[1], e_ctx->e->name, name_len);
980 memcpy (buf, msg, size);
985 size_t node_experiment_start_ack_cb (void *cls, size_t bufsize, void *buf)
987 struct NodeComCtx *e_ctx = cls;
988 struct GED_start_ack_message *msg;
994 name_len = strlen(e_ctx->e->name) + 1;
995 size = sizeof (struct GED_start_ack_message) + name_len;
997 msg = GNUNET_malloc (size);
998 msg->header.size = htons (size);
999 msg->header.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START_ACK);
1000 msg->issuer = e_ctx->e->issuer;
1001 msg->version_nbo = GNUNET_TIME_absolute_hton(e_ctx->e->version);
1002 msg->len_name = htonl (name_len);
1003 memcpy (&msg[1], e_ctx->e->name, name_len);
1005 memcpy (buf, msg, size);
1014 * Confirm a experiment START with a node
1016 * @return GNUNET_NO if core was busy with sending, GNUNET_OK otherwise
1019 GED_nodes_send_start_ack (struct Node *n, struct Experiment *e)
1021 struct NodeComCtx *e_ctx;
1023 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Sending %s for experiment request to peer `%s' for experiment `%s'\n"),
1024 "START_ACK" ,GNUNET_i2s(&n->id), e->name);
1026 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
1029 e_ctx->size = sizeof (struct GED_start_ack_message) + strlen (e->name) + 1;
1030 e_ctx->notify = &node_experiment_start_ack_cb;
1031 e_ctx->notify_cls = e_ctx;
1033 GNUNET_CONTAINER_DLL_insert_tail (n->e_req_head, n->e_req_tail, e_ctx);
1034 schedule_transmisson (e_ctx);
1040 * Request a experiment to start with a node
1042 * @return GNUNET_NO if core was busy with sending, GNUNET_OK otherwise
1045 GED_nodes_request_start (struct Node *n, struct Experiment *e)
1047 struct NodeComCtx *e_ctx;
1049 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Sending %s for experiment request to peer `%s' for experiment `%s'\n"),
1050 "START", GNUNET_i2s(&n->id), e->name);
1052 e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
1055 e_ctx->size = sizeof (struct GED_start_message) + strlen (e->name) + 1;
1056 e_ctx->notify = &node_experiment_start_cb;
1057 e_ctx->notify_cls = e_ctx;
1059 GNUNET_CONTAINER_DLL_insert_tail (n->e_req_head, n->e_req_tail, e_ctx);
1060 schedule_transmisson (e_ctx);
1066 * Start the nodes management
1071 /* Connecting to core service to find partners */
1072 ch = GNUNET_CORE_connect (GED_cfg, NULL,
1073 &core_startup_handler,
1074 &core_connect_handler,
1075 &core_disconnect_handler,
1076 &core_receive_handler,
1077 GNUNET_NO, NULL, GNUNET_NO, NULL);
1080 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Failed to connect to CORE service!\n"));
1084 nodes_requested = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
1085 nodes_active = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
1086 nodes_inactive = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
1091 * Stop the nodes management
1096 if (NULL != nodes_requested)
1098 GNUNET_CONTAINER_multihashmap_iterate (nodes_requested,
1101 update_stats (nodes_requested);
1102 GNUNET_CONTAINER_multihashmap_destroy (nodes_requested);
1103 nodes_requested = NULL;
1106 if (NULL != nodes_active)
1108 GNUNET_CONTAINER_multihashmap_iterate (nodes_active,
1111 update_stats (nodes_active);
1112 GNUNET_CONTAINER_multihashmap_destroy (nodes_active);
1113 nodes_active = NULL;
1116 if (NULL != nodes_inactive)
1118 GNUNET_CONTAINER_multihashmap_iterate (nodes_inactive,
1121 update_stats (nodes_inactive);
1122 GNUNET_CONTAINER_multihashmap_destroy (nodes_inactive);
1123 nodes_inactive = NULL;
1127 GNUNET_CORE_disconnect (ch);
1132 /* end of gnunet-daemon-experimentation_nodes.c */