- fallback to using ip addresses for hosts
[oweals/gnunet.git] / src / testbed / testbed_api_hosts.h
1 /*
2       This file is part of GNUnet
3       (C) 2008--2013 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 testbed/testbed_api_hosts.h
23  * @brief internal API to access the 'hosts' subsystem
24  * @author Christian Grothoff
25  */
26
27 #ifndef NEW_TESTING_API_HOSTS_H
28 #define NEW_TESTING_API_HOSTS_H
29
30 //#include "gnunet_testbed_service.h"
31 //#include "testbed_helper.h"
32 #include "testbed.h"
33
34
35 /**
36  * Lookup a host by ID.
37  *
38  * @param id global host ID assigned to the host; 0 is
39  *        reserved to always mean 'localhost'
40  * @return handle to the host, NULL on error
41  */
42 struct GNUNET_TESTBED_Host *
43 GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id);
44
45
46 /**
47  * Create a host by ID; given this host handle, we could not
48  * run peers at the host, but we can talk about the host
49  * internally.
50  *
51  * @param id global host ID assigned to the host; 0 is
52  *        reserved to always mean 'localhost'
53  * @param cfg the configuration to use as a template while starting a controller
54  *          on this host.  Operation queue sizes specific to a host are also
55  *          read from this configuration handle
56  * @return handle to the host, NULL on error
57  */
58 struct GNUNET_TESTBED_Host *
59 GNUNET_TESTBED_host_create_by_id_ (uint32_t id,
60                                    const struct GNUNET_CONFIGURATION_Handle
61                                    *cfg);
62
63
64 /**
65  * Obtain a host's unique global ID.
66  *
67  * @param host handle to the host, NULL means 'localhost'
68  * @return id global host ID assigned to the host (0 is
69  *         'localhost', but then obviously not globally unique)
70  */
71 uint32_t
72 GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host);
73
74
75 /**
76  * Obtain the host's username
77  *
78  * @param host handle to the host, NULL means 'localhost'
79  * @return username to login to the host
80  */
81 const char *
82 GNUNET_TESTBED_host_get_username_ (const struct GNUNET_TESTBED_Host *host);
83
84
85 /**
86  * Obtain the host's ssh port
87  *
88  * @param host handle to the host, NULL means 'localhost'
89  * @return username to login to the host
90  */
91 uint16_t
92 GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host);
93
94
95 /**
96  * Obtain the host's configuration template
97  *
98  * @param host handle to the host
99  * @return the host's configuration template
100  */
101 const struct GNUNET_CONFIGURATION_Handle *
102 GNUNET_TESTBED_host_get_cfg_ (const struct GNUNET_TESTBED_Host *host);
103
104
105 /**
106  * Function to replace host's configuration
107  *
108  * @param host the host handle
109  * @param new_cfg the new configuration to replace the old one
110  */
111 void
112 GNUNET_TESTBED_host_replace_cfg_ (struct GNUNET_TESTBED_Host *host,
113                                   const struct GNUNET_CONFIGURATION_Handle *new_cfg);
114
115
116 /**
117  * Marks a host as registered with a controller
118  *
119  * @param host the host to mark
120  * @param controller the controller at which this host is registered
121  */
122 void
123 GNUNET_TESTBED_mark_host_registered_at_ (struct GNUNET_TESTBED_Host *host,
124                                          const struct GNUNET_TESTBED_Controller
125                                          *controller);
126
127
128 /**
129  * Unmarks a host registered at a controller
130  *
131  * @param host the host to unmark
132  * @param controller the controller at which this host has to be unmarked
133  */
134 void
135 GNUNET_TESTBED_deregister_host_at_ (struct GNUNET_TESTBED_Host *host,
136                                     const struct GNUNET_TESTBED_Controller
137                                     *const controller);
138
139
140 /**
141  * Checks whether a host has been registered with the given controller
142  *
143  * @param host the host to check
144  * @param controller the controller at which host's registration is checked
145  * @return GNUNET_YES if registered; GNUNET_NO if not
146  */
147 int
148 GNUNET_TESTBED_is_host_registered_ (const struct GNUNET_TESTBED_Host *host,
149                                     const struct GNUNET_TESTBED_Controller
150                                     *controller);
151
152
153 /**
154  * (re)sets the operation queue for parallel overlay connects
155  *
156  * @param h the host handle
157  * @param npoc the number of parallel overlay connects - the queue size
158  */
159 void
160 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (struct
161                                                    GNUNET_TESTBED_Host *h,
162                                                    unsigned int npoc);
163
164
165 /**
166  * Releases a time slot thus making it available for be used again
167  *
168  * @param h the host handle
169  * @param index the index of the the time slot
170  * @param key the key to prove ownership of the timeslot
171  * @return GNUNET_YES if the time slot is successfully removed; GNUNET_NO if the
172  *           time slot cannot be removed - this could be because of the index
173  *           greater than existing number of time slots or `key' being different
174  */
175 int
176 GNUNET_TESTBED_release_time_slot_ (struct GNUNET_TESTBED_Host *h,
177                                    unsigned int index, void *key);
178
179
180 /**
181  * Function to update a time slot
182  *
183  * @param h the host handle
184  * @param index the index of the time slot to update
185  * @param key the key to identify ownership of the slot
186  * @param time the new time
187  * @param failed should this reading be treated as coming from a fail event
188  */
189 void
190 GNUNET_TESTBED_update_time_slot_ (struct GNUNET_TESTBED_Host *h,
191                                   unsigned int index, void *key,
192                                   struct GNUNET_TIME_Relative time, int failed);
193
194
195 /**
196  * Returns a timing slot which will be exclusively locked
197  *
198  * @param h the host handle
199  * @param key a pointer which is associated to the returned slot; should not be
200  *          NULL. It serves as a key to determine the correct owner of the slot
201  * @return the time slot index in the array of time slots in the controller
202  *           handle
203  */
204 unsigned int
205 GNUNET_TESTBED_get_tslot_ (struct GNUNET_TESTBED_Host *h, void *key);
206
207
208 /**
209  * Queues the given operation in the queue for parallel overlay connects of the
210  * given host
211  *
212  * @param h the host handle
213  * @param op the operation to queue in the given host's parally overlay connect
214  *          queue 
215  */
216 void
217 GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h, 
218                                struct GNUNET_TESTBED_Operation *op);
219
220
221 /**
222  * Handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from
223  * controller (testbed service)
224  *
225  * @param c the controller handler
226  * @param msg message received
227  * @return GNUNET_YES if we can continue receiving from service; GNUNET_NO if
228  *           not
229  */
230 int
231 GNUNET_TESTBED_host_handle_addhostconfirm_ (struct GNUNET_TESTBED_Controller *c,
232                                             const struct
233                                             GNUNET_TESTBED_HostConfirmedMessage
234                                             *msg);
235
236
237 /**
238  * Sends termination signal to the controller's helper process
239  *
240  * @param cproc the handle to the controller's helper process
241  */
242 void
243 GNUNET_TESTBED_controller_kill_ (struct GNUNET_TESTBED_ControllerProc *cproc);
244
245
246 /**
247  * Cleans-up the controller's helper process handle
248  *
249  * @param cproc the handle to the controller's helper process
250  */
251 void
252 GNUNET_TESTBED_controller_destroy_ (struct GNUNET_TESTBED_ControllerProc
253                                     *cproc);
254
255
256 /**
257  * Resolves the hostname of the host to an ip address
258  *
259  * @param host the host whose hostname is to be resolved
260  */
261 void
262 GNUNET_TESTBED_host_resolve_ (struct GNUNET_TESTBED_Host *host);
263
264
265 #endif
266 /* end of testbed_api_hosts.h */