2d25fd596f337cb90f39b6ee8e305bcc8d56a2f8
[oweals/gnunet.git] / src / testbed / testbed_api_hosts.h
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 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
33
34 /**
35  * Lookup a host by ID.
36  *
37  * @param id global host ID assigned to the host; 0 is
38  *        reserved to always mean 'localhost'
39  * @return handle to the host, NULL on error
40  */
41 struct GNUNET_TESTBED_Host *
42 GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id);
43
44
45 /**
46  * Create a host by ID; given this host handle, we could not
47  * run peers at the host, but we can talk about the host
48  * internally.
49  *
50  * @param id global host ID assigned to the host; 0 is
51  *        reserved to always mean 'localhost'
52  * @param cfg the configuration to use as a template while starting a controller
53  *          on this host.  Operation queue sizes specific to a host are also
54  *          read from this configuration handle
55  * @return handle to the host, NULL on error
56  */
57 struct GNUNET_TESTBED_Host *
58 GNUNET_TESTBED_host_create_by_id_ (uint32_t id,
59                                    const struct GNUNET_CONFIGURATION_Handle
60                                    *cfg);
61
62
63 /**
64  * Obtain a host's unique global ID.
65  *
66  * @param host handle to the host, NULL means 'localhost'
67  * @return id global host ID assigned to the host (0 is
68  *         'localhost', but then obviously not globally unique)
69  */
70 uint32_t
71 GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host);
72
73
74 /**
75  * Obtain the host's username
76  *
77  * @param host handle to the host, NULL means 'localhost'
78  * @return username to login to the host
79  */
80 const char *
81 GNUNET_TESTBED_host_get_username_ (const struct GNUNET_TESTBED_Host *host);
82
83
84 /**
85  * Obtain the host's ssh port
86  *
87  * @param host handle to the host, NULL means 'localhost'
88  * @return username to login to the host
89  */
90 uint16_t
91 GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host);
92
93
94 /**
95  * Obtain the host's configuration template
96  *
97  * @param host handle to the host
98  * @return the host's configuration template
99  */
100 const struct GNUNET_CONFIGURATION_Handle *
101 GNUNET_TESTBED_host_get_cfg_ (const struct GNUNET_TESTBED_Host *host);
102
103
104 /**
105  * Marks a host as registered with a controller
106  *
107  * @param host the host to mark
108  * @param controller the controller at which this host is registered
109  */
110 void
111 GNUNET_TESTBED_mark_host_registered_at_ (struct GNUNET_TESTBED_Host *host,
112                                          const struct GNUNET_TESTBED_Controller
113                                          *controller);
114
115
116 /**
117  * Checks whether a host has been registered with the given controller
118  *
119  * @param host the host to check
120  * @param controller the controller at which host's registration is checked
121  * @return GNUNET_YES if registered; GNUNET_NO if not
122  */
123 int
124 GNUNET_TESTBED_is_host_registered_ (const struct GNUNET_TESTBED_Host *host,
125                                     const struct GNUNET_TESTBED_Controller
126                                     *controller);
127
128
129 /**
130  * (re)sets the operation queue for parallel overlay connects
131  *
132  * @param h the host handle
133  * @param npoc the number of parallel overlay connects - the queue size
134  */
135 void
136 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (struct
137                                                    GNUNET_TESTBED_Host *h,
138                                                    unsigned int npoc);
139
140
141 /**
142  * Releases a time slot thus making it available for be used again
143  *
144  * @param h the host handle
145  * @param index the index of the the time slot
146  * @param key the key to prove ownership of the timeslot
147  * @return GNUNET_YES if the time slot is successfully removed; GNUNET_NO if the
148  *           time slot cannot be removed - this could be because of the index
149  *           greater than existing number of time slots or `key' being different
150  */
151 int
152 GNUNET_TESTBED_release_time_slot_ (struct GNUNET_TESTBED_Host *h,
153                                    unsigned int index, void *key);
154
155
156 /**
157  * Function to update a time slot
158  *
159  * @param h the host handle
160  * @param index the index of the time slot to update
161  * @param key the key to identify ownership of the slot
162  * @param time the new time
163  * @param failed should this reading be treated as coming from a fail event
164  */
165 void
166 GNUNET_TESTBED_update_time_slot_ (struct GNUNET_TESTBED_Host *h,
167                                   unsigned int index, void *key,
168                                   struct GNUNET_TIME_Relative time, int failed);
169
170
171 /**
172  * Returns a timing slot which will be exclusively locked
173  *
174  * @param h the host handle
175  * @param key a pointer which is associated to the returned slot; should not be
176  *          NULL. It serves as a key to determine the correct owner of the slot
177  * @return the time slot index in the array of time slots in the controller
178  *           handle
179  */
180 unsigned int
181 GNUNET_TESTBED_get_tslot_ (struct GNUNET_TESTBED_Host *h, void *key);
182
183
184 /**
185  * Queues the given operation in the queue for parallel overlay connects of the
186  * given host
187  *
188  * @param h the host handle
189  * @param op the operation to queue in the given host's parally overlay connect
190  *          queue 
191  */
192 void
193 GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h, 
194                                struct GNUNET_TESTBED_Operation *op);
195
196 #endif
197 /* end of testbed_api_hosts.h */