-doxygen
[oweals/gnunet.git] / src / testing / new_testing_api_hosts.c
1 /*
2       This file is part of GNUnet
3       (C) 2008--2012 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19  */
20
21 /**
22  * @file testing/new_testing_api_hosts.c
23  * @brief API for manipulating 'hosts' controlled by the GNUnet testing service;
24  *        allows parsing hosts files, starting, stopping and communicating (via
25  *        SSH/stdin/stdout) with the remote (or local) processes
26  * @author Christian Grothoff
27  */
28 #include "platform.h"
29 #include "gnunet_testing_service.h"
30 #include "gnunet_core_service.h"
31 #include "gnunet_constants.h"
32 #include "gnunet_transport_service.h"
33 #include "gnunet_hello_lib.h"
34
35
36
37 /**
38  * Opaque handle to a host running experiments managed by the testing framework.
39  * The master process must be able to SSH to this host without password (via
40  * ssh-agent).
41  */
42 struct GNUNET_TESTING_Host
43 {
44
45
46   const char *hostname;
47
48   const char *username;
49
50   /**
51    * Global ID we use to refer to a host on the network
52    */
53   uint32_t unique_id;
54
55   uint16_t port;
56 };
57
58
59 /**
60  * Lookup a host by ID.
61  * 
62  * @param id global host ID assigned to the host; 0 is
63  *        reserved to always mean 'localhost'
64  * @return handle to the host, NULL on error
65  */
66 struct GNUNET_TESTING_Host *
67 GNUNET_TESTING_host_lookup_by_id_ (uint32_t id)
68 {
69   GNUNET_break (0);
70   return NULL;
71 }
72
73
74 /**
75  * Create a host by ID; given this host handle, we could not
76  * run peers at the host, but we can talk about the host
77  * internally.
78  * 
79  * @param id global host ID assigned to the host; 0 is
80  *        reserved to always mean 'localhost'
81  * @return handle to the host, NULL on error
82  */
83 struct GNUNET_TESTING_Host *
84 GNUNET_TESTING_host_create_by_id_ (uint32_t id)
85 {
86   return NULL;
87 }
88
89
90 /**
91  * Obtain a host's unique global ID.
92  * 
93  * @param host handle to the host, NULL means 'localhost'
94  * @return id global host ID assigned to the host (0 is
95  *         'localhost', but then obviously not globally unique)
96  */
97 uint32_t
98 GNUNET_TESTING_host_get_id_ (struct GNUNET_TESTING_Host *host)
99 {
100   GNUNET_break (0);
101   return 0;
102 }
103
104
105 /**
106  * Create a host to run peers and controllers on.
107  * 
108  * @param id global host ID assigned to the host; 0 is
109  *        reserved to always mean 'localhost'
110  * @param hostname name of the host, use "NULL" for localhost
111  * @param username username to use for the login; may be NULL
112  * @param port port number to use for ssh; use 0 to let ssh decide
113  * @return handle to the host, NULL on error
114  */
115 struct GNUNET_TESTING_Host *
116 GNUNET_TESTING_host_create_with_id_ (uint32_t id,
117                                      const char *hostname,
118                                      const char *username,
119                                      uint16_t port)
120 {
121   GNUNET_break (0);
122   return NULL;
123 }
124
125
126 /**
127  * Create a host to run peers and controllers on.
128  * 
129  * @param hostname name of the host, use "NULL" for localhost
130  * @param username username to use for the login; may be NULL
131  * @param port port number to use for ssh; use 0 to let ssh decide
132  * @return handle to the host, NULL on error
133  */
134 struct GNUNET_TESTING_Host *
135 GNUNET_TESTING_host_create (const char *hostname,
136                             const char *username,
137                             uint16_t port)
138 {
139   static uint32_t uid_generator;
140
141   return GNUNET_TESTING_host_create_with_id_ (++uid_generator, 
142                                               hostname, username,
143                                               port);
144 }
145
146
147 /**
148  * Load a set of hosts from a configuration file.
149  *
150  * @param filename file with the host specification
151  * @param hosts set to the hosts found in the file
152  * @return number of hosts returned in 'hosts', 0 on error
153  */
154 unsigned int
155 GNUNET_TESTING_hosts_load_from_file (const char *filename,
156                                      struct GNUNET_TESTING_Host **hosts)
157 {
158   GNUNET_break (0);
159   return 0;
160 }
161
162
163 /**
164  * Destroy a host handle.  Must only be called once everything
165  * running on that host has been stopped.
166  *
167  * @param host handle to destroy
168  */
169 void
170 GNUNET_TESTING_host_destroy (struct GNUNET_TESTING_Host *host)
171 {
172   GNUNET_break (0);
173 }
174
175
176 /**
177  * Run a given helper process at the given host.  Communication
178  * with the helper will be via GNUnet messages on stdin/stdout.
179  * Runs the process via 'ssh' at the specified host, or locally.
180  * Essentially an SSH-wrapper around the 'gnunet_helper_lib.h' API.
181  * 
182  * @param host host to use, use "NULL" for localhost
183  * @param binary_arg binary name and command-line arguments to give to the binary
184  * @param cb function to call for messages received from the binary
185  * @param cb_cls closure for cb
186  * @return handle to terminate the command, NULL on error
187  */
188 struct GNUNET_HELPER_Handle *
189 GNUNET_TESTING_host_run_ (struct GNUNET_TESTING_Host *host,
190                           char *const binary_argv[],
191                           GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls)
192 {
193   /* FIXME: decide on the SSH command line, prepend it and
194      run GNUNET_HELPER_start with the modified binary_name and binary_argv! */
195   GNUNET_break (0);
196   return NULL;
197 }
198
199
200 /* end of new_testing_api_hosts.c */