aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_group.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2011-03-14 18:30:08 +0000
committerNathan S. Evans <evans@in.tum.de>2011-03-14 18:30:08 +0000
commit86559fb594b8a9c9c99575d4915caa4937b14311 (patch)
tree6d552e9ccb4e2dec941af45132147220d92d2af6 /src/testing/testing_group.c
parent2ebe944c1ef77807610668fefd716e2adf9a2e9a (diff)
downloadgnunet-86559fb594b8a9c9c99575d4915caa4937b14311.tar.gz
gnunet-86559fb594b8a9c9c99575d4915caa4937b14311.zip
code not to be used by anyone, ever
Diffstat (limited to 'src/testing/testing_group.c')
-rw-r--r--src/testing/testing_group.c262
1 files changed, 190 insertions, 72 deletions
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c
index 14bf31bbc..083e67750 100644
--- a/src/testing/testing_group.c
+++ b/src/testing/testing_group.c
@@ -36,8 +36,11 @@
36 36
37#define DEBUG_CHURN GNUNET_NO 37#define DEBUG_CHURN GNUNET_NO
38 38
39#define USE_START_HELPER GNUNET_YES
40
39#define OLD 1 41#define OLD 1
40 42
43/* Before connecting peers, send all of the HELLOs */
41#define USE_SEND_HELLOS GNUNET_NO 44#define USE_SEND_HELLOS GNUNET_NO
42 45
43#define TOPOLOGY_HACK GNUNET_YES 46#define TOPOLOGY_HACK GNUNET_YES
@@ -3474,12 +3477,9 @@ static void schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskC
3474 if (send_hello_context->peer->daemon->th == NULL) 3477 if (send_hello_context->peer->daemon->th == NULL)
3475 { 3478 {
3476 pg->outstanding_connects++; /* Actual TRANSPORT, CORE connections! */ 3479 pg->outstanding_connects++; /* Actual TRANSPORT, CORE connections! */
3477 send_hello_context->peer->daemon->th = GNUNET_TRANSPORT_connect(send_hello_context->peer->cfg, 3480 send_hello_context->peer->daemon->th
3478 NULL, 3481 = GNUNET_TRANSPORT_connect (send_hello_context->peer->cfg, NULL,
3479 send_hello_context, 3482 send_hello_context, NULL, NULL, NULL);
3480 NULL,
3481 NULL,
3482 NULL);
3483 } 3483 }
3484#if DEBUG_TESTING 3484#if DEBUG_TESTING
3485 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3485 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -3606,7 +3606,7 @@ schedule_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3606 connect_context->ct_ctx->connect_timeout, 3606 connect_context->ct_ctx->connect_timeout,
3607 connect_context->ct_ctx->connect_attempts, 3607 connect_context->ct_ctx->connect_attempts,
3608#if USE_SEND_HELLOS 3608#if USE_SEND_HELLOS
3609 GNUNET_NO, 3609 GNUNET_NO,
3610#else 3610#else
3611 GNUNET_YES, 3611 GNUNET_YES,
3612#endif 3612#endif
@@ -3741,7 +3741,7 @@ connect_topology(struct GNUNET_TESTING_PeerGroup *pg,
3741 struct PeerConnection *connection_iter; 3741 struct PeerConnection *connection_iter;
3742#endif 3742#endif
3743#if USE_SEND_HELLOS 3743#if USE_SEND_HELLOS
3744 struct SendHelloContext *send_hello_context 3744 struct SendHelloContext *send_hello_context;
3745#endif 3745#endif
3746 3746
3747 total = 0; 3747 total = 0;
@@ -5532,6 +5532,7 @@ schedule_churn_restart(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5532 } 5532 }
5533} 5533}
5534 5534
5535
5535static void 5536static void
5536internal_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 5537internal_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5537{ 5538{
@@ -5556,6 +5557,7 @@ internal_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5556 internal_context->peer->daemon 5557 internal_context->peer->daemon
5557 = GNUNET_TESTING_daemon_start (internal_context->peer->cfg, 5558 = GNUNET_TESTING_daemon_start (internal_context->peer->cfg,
5558 internal_context->timeout, 5559 internal_context->timeout,
5560 GNUNET_NO,
5559 internal_context->hostname, 5561 internal_context->hostname,
5560 internal_context->username, 5562 internal_context->username,
5561 internal_context->sshport, 5563 internal_context->sshport,
@@ -5574,6 +5576,66 @@ internal_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5574 &internal_start, internal_context); 5576 &internal_start, internal_context);
5575 } 5577 }
5576} 5578}
5579#if USE_START_HELPER
5580
5581struct PeerStartHelperContext
5582{
5583 struct GNUNET_TESTING_PeerGroup *pg;
5584
5585 struct HostData *host;
5586};
5587
5588static void
5589start_peer_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5590{
5591 struct PeerStartHelperContext *helper = cls;
5592 char *baseservicehome;
5593 char *tempdir;
5594 struct GNUNET_OS_Process *proc;
5595 unsigned int i;
5596 char *arg;
5597 GNUNET_TESTING_NotifyDaemonRunning cb;
5598 /* ssh user@host peerStartHelper /path/to/basedirectory */
5599
5600 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (helper->pg->cfg, "PATHS", "SERVICEHOME",
5601 &baseservicehome));
5602 GNUNET_asprintf(&tempdir, "%s/%s/", baseservicehome, helper->host->hostname);
5603 if (NULL != helper->host->username)
5604 GNUNET_asprintf (&arg, "%s@%s", helper->host->username, helper->host->hostname);
5605 else
5606 GNUNET_asprintf (&arg, "%s", helper->host->hostname);
5607
5608 /* FIXME: Doesn't support ssh_port option! */
5609 proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg,
5610 "peerStartHelper.pl", tempdir, NULL);
5611
5612 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "starting peers with cmd ssh %s %s %s\n", arg, "peerStartHelper.pl", tempdir);
5613
5614 GNUNET_OS_process_wait (proc);
5615 GNUNET_OS_process_close(proc);
5616 GNUNET_free (tempdir);
5617 GNUNET_free (baseservicehome);
5618 GNUNET_free (arg);
5619
5620 helper->pg->starting--;
5621 if (helper->pg->starting == 0) /* All peers have finished starting! */
5622 {
5623 /* Call the peer started callback for each peer, set proper FSM state (?) */
5624 for (i = 0; i < helper->pg->total; i++)
5625 {
5626 cb = helper->pg->peers[i].daemon->cb;
5627 helper->pg->peers[i].daemon->cb = NULL;
5628 if (NULL != cb)
5629 cb (helper->pg->peers[i].daemon->cb_cls,
5630 &helper->pg->peers[i].daemon->id,
5631 helper->pg->peers[i].daemon->cfg, helper->pg->peers[i].daemon,
5632 NULL);
5633
5634 }
5635 }
5636
5637}
5638#endif
5577 5639
5578/** 5640/**
5579 * Function which continues a peer group starting up 5641 * Function which continues a peer group starting up
@@ -5587,14 +5649,57 @@ GNUNET_TESTING_daemons_continue_startup(struct GNUNET_TESTING_PeerGroup *pg)
5587{ 5649{
5588 unsigned int i; 5650 unsigned int i;
5589 5651
5652#if USE_START_HELPER
5653 if ((pg->num_hosts > 0) && (pg->hostkey_data != NULL))
5654 {
5655 struct PeerStartHelperContext *helper;
5656 pg->starting = pg->num_hosts;
5657 for (i = 0; i < pg->num_hosts; i++)
5658 {
5659 helper = GNUNET_malloc(sizeof(struct PeerStartHelperContext));
5660 helper->pg = pg;
5661 helper->host = &pg->hosts[i];
5662 GNUNET_SCHEDULER_add_now(&start_peer_helper, helper);
5663 }
5664 }
5665 else
5666 {
5667 pg->starting = 0;
5668 for (i = 0; i < pg->total; i++)
5669 {
5670 GNUNET_SCHEDULER_add_now (&internal_continue_startup,
5671 &pg->peers[i].internal_context);
5672 }
5673 }
5674#else
5590 pg->starting = 0; 5675 pg->starting = 0;
5591 for (i = 0; i < pg->total; i++) 5676 for (i = 0; i < pg->total; i++)
5592 { 5677 {
5593 GNUNET_SCHEDULER_add_now (&internal_continue_startup, 5678 GNUNET_SCHEDULER_add_now (&internal_continue_startup,
5594 &pg->peers[i].internal_context); 5679 &pg->peers[i].internal_context);
5595 //GNUNET_TESTING_daemon_continue_startup(pg->peers[i].daemon);
5596 } 5680 }
5681#endif
5682}
5683
5684#if USE_START_HELPER
5685static void
5686call_hostkey_callbacks (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5687{
5688 struct GNUNET_TESTING_PeerGroup *pg = cls;
5689 unsigned int i;
5690 for (i = 0; i < pg->total; i++)
5691 {
5692 if (pg->peers[i].internal_context.hostkey_callback != NULL)
5693 pg->peers[i].internal_context.hostkey_callback (pg->peers[i].internal_context.hostkey_cls,
5694 &pg->peers[i].daemon->id,
5695 pg->peers[i].daemon,
5696 NULL);
5697 }
5698
5699 if (pg->peers[0].internal_context.hostkey_callback == NULL)
5700 GNUNET_TESTING_daemons_continue_startup (pg);
5597} 5701}
5702#endif
5598 5703
5599/** 5704/**
5600 * Start count gnunet instances with the same set of transports and 5705 * Start count gnunet instances with the same set of transports and
@@ -5624,8 +5729,7 @@ GNUNET_TESTING_daemons_continue_startup(struct GNUNET_TESTING_PeerGroup *pg)
5624 * @return NULL on error, otherwise handle to control peer group 5729 * @return NULL on error, otherwise handle to control peer group
5625 */ 5730 */
5626struct GNUNET_TESTING_PeerGroup * 5731struct GNUNET_TESTING_PeerGroup *
5627GNUNET_TESTING_daemons_start( 5732GNUNET_TESTING_daemons_start(const struct GNUNET_CONFIGURATION_Handle *cfg,
5628 const struct GNUNET_CONFIGURATION_Handle *cfg,
5629 unsigned int total, 5733 unsigned int total,
5630 unsigned int max_concurrent_connections, 5734 unsigned int max_concurrent_connections,
5631 unsigned int max_concurrent_ssh, 5735 unsigned int max_concurrent_ssh,
@@ -5640,11 +5744,6 @@ GNUNET_TESTING_daemons_start(
5640{ 5744{
5641 struct GNUNET_TESTING_PeerGroup *pg; 5745 struct GNUNET_TESTING_PeerGroup *pg;
5642 const struct GNUNET_TESTING_Host *hostpos; 5746 const struct GNUNET_TESTING_Host *hostpos;
5643#if 0
5644 char *pos;
5645 const char *rpos;
5646 char *start;
5647#endif
5648 const char *hostname; 5747 const char *hostname;
5649 const char *username; 5748 const char *username;
5650 char *baseservicehome; 5749 char *baseservicehome;
@@ -5715,51 +5814,6 @@ GNUNET_TESTING_daemons_start(
5715 hostcnt = off; 5814 hostcnt = off;
5716 minport = 0; 5815 minport = 0;
5717 pg->num_hosts = off; 5816 pg->num_hosts = off;
5718
5719#if NO_LL
5720 off = 2;
5721 /* skip leading spaces */
5722 while ((0 != *hostnames) && (isspace ((unsigned char) *hostnames)))
5723 hostnames++;
5724 rpos = hostnames;
5725 while ('\0' != *rpos)
5726 {
5727 if (isspace ((unsigned char) *rpos))
5728 off++;
5729 rpos++;
5730 }
5731 pg->hosts = GNUNET_malloc (off * sizeof (struct HostData));
5732 off = 0;
5733 start = GNUNET_strdup (hostnames);
5734 pos = start;
5735 while ('\0' != *pos)
5736 {
5737 if (isspace ((unsigned char) *pos))
5738 {
5739 *pos = '\0';
5740 if (strlen (start) > 0)
5741 {
5742 pg->hosts[off].minport = LOW_PORT;
5743 pg->hosts[off++].hostname = start;
5744 }
5745 start = pos + 1;
5746 }
5747 pos++;
5748 }
5749 if (strlen (start) > 0)
5750 {
5751 pg->hosts[off].minport = LOW_PORT;
5752 pg->hosts[off++].hostname = start;
5753 }
5754 if (off == 0)
5755 {
5756 GNUNET_free (start);
5757 GNUNET_free (pg->hosts);
5758 pg->hosts = NULL;
5759 }
5760 hostcnt = off;
5761 minport = 0; /* make gcc happy */
5762#endif
5763 } 5817 }
5764 else 5818 else
5765 { 5819 {
@@ -5885,7 +5939,9 @@ GNUNET_TESTING_daemons_start(
5885 GNUNET_asprintf (&newservicehome, "%s/%s/%d/", baseservicehome, hostname, off); 5939 GNUNET_asprintf (&newservicehome, "%s/%s/%d/", baseservicehome, hostname, off);
5886 else 5940 else
5887 GNUNET_asprintf (&newservicehome, "%s/%d/", baseservicehome, off); 5941 GNUNET_asprintf (&newservicehome, "%s/%d/", baseservicehome, off);
5942#if !USE_START_HELPER
5888 GNUNET_free (baseservicehome); 5943 GNUNET_free (baseservicehome);
5944#endif
5889 } 5945 }
5890 else 5946 else
5891 { 5947 {
@@ -5902,16 +5958,6 @@ GNUNET_TESTING_daemons_start(
5902 newservicehome); 5958 newservicehome);
5903 GNUNET_free (newservicehome); 5959 GNUNET_free (newservicehome);
5904 pg->peers[off].cfg = pcfg; 5960 pg->peers[off].cfg = pcfg;
5905#if DEFER
5906 /* Can we do this later? */
5907 pg->peers[off].allowed_peers =
5908 GNUNET_CONTAINER_multihashmap_create (total);
5909 pg->peers[off].connect_peers =
5910 GNUNET_CONTAINER_multihashmap_create (total);
5911 pg->peers[off].blacklisted_peers =
5912 GNUNET_CONTAINER_multihashmap_create (total);
5913
5914#endif
5915 pg->peers[off].pg = pg; 5961 pg->peers[off].pg = pg;
5916 pg->peers[off].internal_context.peer = &pg->peers[off]; 5962 pg->peers[off].internal_context.peer = &pg->peers[off];
5917 pg->peers[off].internal_context.timeout = timeout; 5963 pg->peers[off].internal_context.timeout = timeout;
@@ -5925,11 +5971,83 @@ GNUNET_TESTING_daemons_start(
5925 pg->peers[off].internal_context.hostkey_cls = hostkey_cls; 5971 pg->peers[off].internal_context.hostkey_cls = hostkey_cls;
5926 pg->peers[off].internal_context.start_cb = cb; 5972 pg->peers[off].internal_context.start_cb = cb;
5927 pg->peers[off].internal_context.start_cb_cls = cb_cls; 5973 pg->peers[off].internal_context.start_cb_cls = cb_cls;
5928 5974#if !USE_START_HELPER
5929 GNUNET_SCHEDULER_add_now (&internal_start, 5975 GNUNET_SCHEDULER_add_now (&internal_start,
5930 &pg->peers[off].internal_context); 5976 &pg->peers[off].internal_context);
5977#else
5978 if ((pg->hostkey_data != NULL) && (hostcnt > 0))
5979 {
5980 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Have hostkey data and running on remote hosts!\n");
5981 GNUNET_TESTING_daemon_start (pcfg,
5982 timeout,
5983 GNUNET_YES,
5984 hostname,
5985 username,
5986 sshport,
5987 pg->peers[off].internal_context.hostkey,
5988 &internal_hostkey_callback,
5989 &pg->peers[off].internal_context,
5990 &internal_startup_callback,
5991 &pg->peers[off].internal_context);
5992 /**
5993 * At this point, given that we had a hostkeyfile,
5994 * we can call the hostkey callback!
5995 * But first, we should copy (rsync) all of the configs
5996 * and hostkeys to the remote peers. Then let topology
5997 * creation happen, then call the peer start helper processes,
5998 * then set pg->whatever_phase for each peer and let them
5999 * enter the fsm to get the HELLO's for peers and start connecting.
6000 */
6001 }
6002 else
6003 {
6004 GNUNET_SCHEDULER_add_now (&internal_start,
6005 &pg->peers[off].internal_context);
6006 }
6007
6008#endif
6009 }
6010
6011#if USE_START_HELPER /* Now the peergroup has been set up, hostkeys and configs written to files. */
6012 if ((pg->hostkey_data != NULL) && (hostcnt > 0))
6013 {
6014 for (off = 0; off < hostcnt; off++)
6015 {
6016 GNUNET_asprintf(&newservicehome, "%s/%s/", baseservicehome, pg->hosts[off].hostname);
6017
6018 if (NULL != username)
6019 GNUNET_asprintf (&arg, "%s@%s:%s", username, pg->hosts[off].hostname, newservicehome);
6020 else
6021 GNUNET_asprintf (&arg, "%s:%s", pg->hosts[off].hostname, newservicehome);
6022
6023 /* FIXME: Doesn't support ssh_port option! */
6024 proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", "-r",
6025#if !DEBUG_TESTING
6026 "-q",
6027#endif
6028 newservicehome, arg, NULL);
6029
6030 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "copying directory with command scp -r %s %s\n", newservicehome, arg);
5931 6031
6032
6033 GNUNET_free (arg);
6034 if (NULL == proc)
6035 {
6036 GNUNET_log (
6037 GNUNET_ERROR_TYPE_ERROR,
6038 _
6039 ("Could not start `%s' process to copy configuration directory.\n"),
6040 "scp");
6041 GNUNET_assert(0);
6042 }
6043 GNUNET_OS_process_wait (proc);
6044 GNUNET_OS_process_close (proc);
6045 }
6046 /* Now all the configuration files and hostkeys are copied to the remote host. Call the hostkey callback for each peer! */
6047 GNUNET_SCHEDULER_add_now(&call_hostkey_callbacks, pg);
5932 } 6048 }
6049 GNUNET_free (baseservicehome);
6050#endif
5933 return pg; 6051 return pg;
5934} 6052}
5935 6053