fixes
[oweals/gnunet.git] / src / testbed / testbed_api_peers.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_peers.h
23  * @brief internal API to access the 'peers' subsystem
24  * @author Christian Grothoff
25  */
26 #ifndef NEW_TESTING_API_PEERS_H
27 #define NEW_TESTING_API_PEERS_H
28
29 #include "gnunet_testbed_service.h"
30 #include "gnunet_helper_lib.h"
31
32
33 /**
34  * Details about a peer; kept in a separate struct to avoid bloating
35  * memory consumption everywhere...
36  */
37 struct PeerDetails
38 {
39   /**
40    * Configuration of the peer; NULL if we are not sure what the peer's correct
41    * configuration actually is; non-NULL if this peer is controlled by this
42    * process.
43    */
44   struct GNUNET_CONFIGURATION_Handle *cfg;
45
46   //PEER_DETAILS
47 };
48
49
50 /**
51  * Enumeration of possible states a peer could be in
52  */
53 enum PeerState 
54   {
55     /**
56      * State to signify that this peer is invalid
57      */
58     PS_INVALID,
59
60     /**
61      * The peer has been created
62      */
63     PS_CREATED,
64     
65     /**
66      * The peer is running
67      */
68     PS_STARTED,
69
70     /**
71      * The peer is stopped
72      */
73     PS_STOPPED,    
74   };
75
76
77 /**
78  * A peer controlled by the testing framework.  A peer runs
79  * at a particular host.
80  */ 
81 struct GNUNET_TESTBED_Peer
82 {
83   /**
84    * Our controller context (not necessarily the controller
85    * that is responsible for starting/running the peer!).
86    */
87   struct GNUNET_TESTBED_Controller *controller;
88                            
89   /**
90    * Which host does this peer run on?
91    */
92   struct GNUNET_TESTBED_Host *host;
93
94   /**
95    * Internals of the peer for the controlling process; NULL if 
96    * this process is not controlling this peer.
97    */
98   struct PeerDetails *details;
99
100   /**
101    * Globally unique ID of the peer.
102    */
103   uint32_t unique_id;
104
105   /**
106    * Peer's state
107    */
108   enum PeerState state;
109 };
110
111
112 /**
113  * Data for the OperationType OP_PEER_CREATE
114  */
115 struct PeerCreateData
116 {
117   /**
118    * THe call back to call when we receive peer create success message
119    */
120   GNUNET_TESTBED_PeerCreateCallback cb;
121   
122   /**
123    * The closure for the above callback
124    */
125   void *cls;
126
127   /**
128    * The peer structure to return when we get success message
129    */
130   struct GNUNET_TESTBED_Peer *peer;
131
132 };
133
134
135 /**
136  * Data for the OperationType OP_PEER_DESTROY;
137  */
138 struct PeerDestroyData
139 {
140   /**
141    * The peer structure
142    */
143   struct GNUNET_TESTBED_Peer *peer;
144
145   //PEERDESTROYDATA
146 };
147
148
149 /**
150  * Data for the OperationType OP_PEER_INFO
151  */
152 struct PeerInfoData
153 {
154   /**
155    * The peer whose information has been requested
156    */
157   struct GNUNET_TESTBED_Peer *peer;
158   
159   /**
160    * The type of peer information requested
161    */
162   enum GNUNET_TESTBED_PeerInformationType pit;
163 };
164
165
166 /**
167  * Data for the OperationType OP_PEER_INFO
168  */
169 struct PeerInfoData2
170 {
171   /**
172    * The type of peer information requested
173    */
174   enum GNUNET_TESTBED_PeerInformationType pit;
175
176   /**
177    * The data from reply
178    */
179   union
180   {
181     /**
182      * Configuration handle
183      */
184     struct GNUNET_CONFIGURATION_Handle *cfg;
185
186     /**
187      * Peer Identity
188      */
189     struct GNUNET_PeerIdentity *peer_identity;
190   } details;
191 };
192
193
194 /**
195  * Data structure for OperationType OP_OVERLAY_CONNECT
196  */
197 struct OverlayConnectData
198 {
199   /**
200    * Peer A to connect to peer B
201    */
202   struct GNUNET_TESTBED_Peer *p1;
203
204   /**
205    * Peer B
206    */
207   struct GNUNET_TESTBED_Peer *p2;
208
209 };
210
211
212
213 /**
214  * Create the given peer at the specified host using the given
215  * controller.  If the given controller is not running on the target
216  * host, it should find or create a controller at the target host and
217  * delegate creating the peer.  Explicit delegation paths can be setup
218  * using 'GNUNET_TESTBED_controller_link'.  If no explicit delegation
219  * path exists, a direct link with a subordinate controller is setup
220  * for the first delegated peer to a particular host; the subordinate
221  * controller is then destroyed once the last peer that was delegated
222  * to the remote host is stopped.  This function is used in particular
223  * if some other controller has already assigned a unique ID to the
224  * peer.
225  *
226  * Creating the peer only creates the handle to manipulate and further
227  * configure the peer; use "GNUNET_TESTBED_peer_start" and
228  * "GNUNET_TESTBED_peer_stop" to actually start/stop the peer's
229  * processes.
230  *
231  * Note that the given configuration will be adjusted by the
232  * controller to avoid port/path conflicts with other peers.
233  * The "final" configuration can be obtained using
234  * 'GNUNET_TESTBED_peer_get_information'.
235  *
236  * @param unique_id unique ID for this peer
237  * @param controller controller process to use
238  * @param host host to run the peer on
239  * @param cfg configuration to use for the peer
240  * @param cb the callback to call when the peer has been created
241  * @param cls the closure to the above callback
242  * @return the operation handle
243  */
244 struct GNUNET_TESTBED_Operation *
245 GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
246                                      struct GNUNET_TESTBED_Controller *controller,
247                                      struct GNUNET_TESTBED_Host *host,
248                                      const struct GNUNET_CONFIGURATION_Handle *cfg,
249                                      GNUNET_TESTBED_PeerCreateCallback cb,
250                                      void *cls);
251
252
253
254 #endif
255 /* end of testbed_api_peers.h */