aboutsummaryrefslogtreecommitdiff
path: root/src/experimentation/gnunet-daemon-experimentation_nodes.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/experimentation/gnunet-daemon-experimentation_nodes.c')
-rw-r--r--src/experimentation/gnunet-daemon-experimentation_nodes.c129
1 files changed, 126 insertions, 3 deletions
diff --git a/src/experimentation/gnunet-daemon-experimentation_nodes.c b/src/experimentation/gnunet-daemon-experimentation_nodes.c
index a77e841b8..0782e7ff1 100644
--- a/src/experimentation/gnunet-daemon-experimentation_nodes.c
+++ b/src/experimentation/gnunet-daemon-experimentation_nodes.c
@@ -547,6 +547,44 @@ static void handle_response (const struct GNUNET_PeerIdentity *peer,
547} 547}
548 548
549/** 549/**
550 * Handle a response
551 *
552 * @param peer the source
553 * @param message the message
554 */
555static void handle_start (const struct GNUNET_PeerIdentity *peer,
556 const struct GNUNET_MessageHeader *message)
557{
558fprintf (stderr, "FIXME\n");
559 GNUNET_STATISTICS_update (GSE_stats, "# experiments running",
560 1, GNUNET_NO);
561}
562
563/**
564 * Handle a response
565 *
566 * @param peer the source
567 * @param message the message
568 */
569static void handle_start_ack (const struct GNUNET_PeerIdentity *peer,
570 const struct GNUNET_MessageHeader *message)
571{
572
573}
574
575/**
576 * Handle a response
577 *
578 * @param peer the source
579 * @param message the message
580 */
581static void handle_stop (const struct GNUNET_PeerIdentity *peer,
582 const struct GNUNET_MessageHeader *message)
583{
584
585}
586
587/**
550 * Method called whenever a given peer connects. 588 * Method called whenever a given peer connects.
551 * 589 *
552 * @param cls closure 590 * @param cls closure
@@ -619,6 +657,15 @@ core_receive_handler (void *cls,
619 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE: 657 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE:
620 handle_response (other, message); 658 handle_response (other, message);
621 break; 659 break;
660 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START:
661 handle_start (other, message);
662 break;
663 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START_ACK:
664 handle_start_ack (other, message);
665 break;
666 case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_STOP:
667 handle_stop (other, message);
668 break;
622 default: 669 default:
623 break; 670 break;
624 } 671 }
@@ -626,12 +673,88 @@ core_receive_handler (void *cls,
626 return GNUNET_OK; 673 return GNUNET_OK;
627} 674}
628 675
676#define FAST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
629 677
630void 678struct GNUNET_EXPERIMENTATION_start_message
631GNUNET_EXPERIMENT_nodes_request_start (struct Node *n, struct Experiment *e)
632{ 679{
633 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Sending start request to peer `%s' for experiment `%s'\n"), 680 struct GNUNET_MessageHeader header;
681};
682
683struct ExperimentStartCtx
684{
685 struct ExperimentStartCtx *prev;
686 struct ExperimentStartCtx *next;
687
688 struct Node *n;
689 struct Experiment *e;
690};
691
692size_t node_experiment_start_cb (void *cls, size_t bufsize, void *buf)
693{
694 struct ExperimentStartCtx *e_ctx = cls;
695 struct GNUNET_EXPERIMENTATION_start_message msg;
696
697 GNUNET_CONTAINER_DLL_remove (e_ctx->n->e_req_head, e_ctx->n->e_req_tail, e_ctx);
698 e_ctx->n->cth = NULL;
699 if (NULL == buf)
700 {
701 GNUNET_free (e_ctx);
702 return 0;
703 }
704
705 size_t size = sizeof (struct GNUNET_EXPERIMENTATION_start_message);
706 msg.header.size = htons (size);
707 msg.header.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START);
708
709 memcpy (buf, &msg, size);
710 GNUNET_free (e_ctx);
711 return size;
712}
713
714int
715GNUNET_EXPERIMENTATION_nodes_rts (struct Node *n)
716{
717 if (NULL == n->cth)
718 return GNUNET_YES;
719 else
720 return GNUNET_NO;
721
722}
723
724/**
725 * Request a experiment to start with a node
726 *
727 * @return GNUNET_NO if core was busy with sending, GNUNET_OK otherwise
728 */
729int
730GNUNET_EXPERIMENTATION_nodes_request_start (struct Node *n, struct Experiment *e)
731{
732 struct ExperimentStartCtx *e_ctx;
733
734 if (NULL != n->cth)
735 {
736 GNUNET_break (0); /* should call rts before */
737 return GNUNET_NO;
738 }
739
740 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Sending experiment start request to peer `%s' for experiment `%s'\n"),
634 GNUNET_i2s(&n->id), e->name); 741 GNUNET_i2s(&n->id), e->name);
742
743 e_ctx = GNUNET_malloc (sizeof (struct ExperimentStartCtx));
744 e_ctx->n = n;
745 e_ctx->e = e;
746 n->cth = GNUNET_CORE_notify_transmit_ready (ch, GNUNET_NO, 0, FAST_TIMEOUT, &n->id,
747 sizeof (struct GNUNET_EXPERIMENTATION_start_message),
748 &node_experiment_start_cb, e_ctx);
749 if (NULL == n->cth)
750 {
751 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Cannot send experiment start request to peer `%s' for experiment `%s'\n"),
752 GNUNET_i2s(&n->id), e->name);
753 GNUNET_free (e_ctx);
754 }
755 GNUNET_CONTAINER_DLL_insert (n->e_req_head, n->e_req_tail, e_ctx);
756
757 return GNUNET_OK;
635} 758}
636 759
637 760