b9a62698c815d86dfe96ad9e685923b6f427b8fa
[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 #ifndef NEW_TESTING_API_HOSTS_H
27 #define NEW_TESTING_API_HOSTS_H
28
29 #include "gnunet_testbed_service.h"
30 #include "gnunet_helper_lib.h"
31
32
33 /**
34  * Wrapper around
35  */
36 struct GNUNET_TESTBED_HelperHandle
37 {
38   /**
39    * The process handle
40    */
41   struct GNUNET_OS_Process *process;
42
43   /**
44    * Pipe connecting to stdin of the process.
45    */
46   struct GNUNET_DISK_PipeHandle *cpipe_in;
47
48   /**
49    * Pipe from the stdout of the process.
50    */
51   struct GNUNET_DISK_PipeHandle *cpipe_out;
52
53   /**
54    * The port number for ssh; used for helpers starting ssh
55    */
56   char *port;
57
58   /**
59    * The ssh destination string; used for helpers starting ssh
60    */
61   char *dst; 
62 };
63
64
65 /**
66  * Lookup a host by ID.
67  * 
68  * @param id global host ID assigned to the host; 0 is
69  *        reserved to always mean 'localhost'
70  * @return handle to the host, NULL on error
71  */
72 struct GNUNET_TESTBED_Host *
73 GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id);
74
75
76 /**
77  * Create a host by ID; given this host handle, we could not
78  * run peers at the host, but we can talk about the host
79  * internally.
80  * 
81  * @param id global host ID assigned to the host; 0 is
82  *        reserved to always mean 'localhost'
83  * @return handle to the host, NULL on error
84  */
85 struct GNUNET_TESTBED_Host *
86 GNUNET_TESTBED_host_create_by_id_ (uint32_t id);
87
88
89 /**
90  * Obtain a host's unique global ID.
91  * 
92  * @param host handle to the host, NULL means 'localhost'
93  * @return id global host ID assigned to the host (0 is
94  *         'localhost', but then obviously not globally unique)
95  */
96 uint32_t
97 GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host);
98
99
100 /**
101  * Obtain the host's hostname.
102  * 
103  * @param host handle to the host, NULL means 'localhost'
104  * @return hostname of the host
105  */
106 const char *
107 GNUNET_TESTBED_host_get_hostname_ (const struct GNUNET_TESTBED_Host *host);
108
109
110 /**
111  * Obtain the host's username
112  * 
113  * @param host handle to the host, NULL means 'localhost'
114  * @return username to login to the host
115  */
116 const char *
117 GNUNET_TESTBED_host_get_username_ (const struct GNUNET_TESTBED_Host *host);
118
119
120 /**
121  * Obtain the host's ssh port
122  * 
123  * @param host handle to the host, NULL means 'localhost'
124  * @return username to login to the host
125  */
126 uint16_t
127 GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host);
128
129
130 /**
131  * Opaque wrapper around GNUNET_HELPER_Handle
132  */
133 struct GNUNET_TESTBED_HelperHandle;
134
135
136 /**
137  * Run a given helper process at the given host.  Communication
138  * with the helper will be via GNUnet messages on stdin/stdout.
139  * Runs the process via 'ssh' at the specified host, or locally.
140  * Essentially an SSH-wrapper around the 'gnunet_helper_lib.h' API.
141  * 
142  * @param host host to use, use "NULL" for localhost
143  * @param binary_argv binary name and command-line arguments to give to the binary
144  * @return handle to terminate the command, NULL on error
145  */
146 struct GNUNET_TESTBED_HelperHandle *
147 GNUNET_TESTBED_host_run_ (const struct GNUNET_TESTBED_Host *host,
148                           char *const binary_argv[]);
149
150
151 /**
152  * Stops a helper in the HelperHandle using GNUNET_HELPER_stop
153  *
154  * @param handle the handle returned from GNUNET_TESTBED_host_start_
155  */
156 void
157 GNUNET_TESTBED_host_stop_ (struct GNUNET_TESTBED_HelperHandle *handle);
158
159
160 /**
161  * Marks a host as registered with a controller
162  *
163  * @param host the host to mark
164  * @param controller the controller at which this host is registered
165  */
166 void
167 GNUNET_TESTBED_mark_host_registered_at_ (struct GNUNET_TESTBED_Host *host,
168                                          const struct GNUNET_TESTBED_Controller
169                                          *controller);
170
171
172 /**
173  * Checks whether a host has been registered with the given controller
174  *
175  * @param host the host to check
176  * @param controller the controller at which host's registration is checked
177  * @return GNUNET_YES if registered; GNUNET_NO if not
178  */
179 int
180 GNUNET_TESTBED_is_host_registered_ (const struct GNUNET_TESTBED_Host *host,
181                                     const struct GNUNET_TESTBED_Controller
182                                          *controller);
183
184 #endif
185 /* end of testbed_api_hosts.h */