2 This file is part of GNUnet
3 (C) 2008--2012 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file testing/new_testing_api_peers.c
23 * @brief management of the knowledge about peers in this library
24 * (we know the peer ID, its host, pending operations, etc.)
25 * @author Christian Grothoff
28 #include "new_testing_api_peers.h"
32 * Details about a peer; kept in a separate struct to avoid bloating
33 * memory consumption everywhere...
38 * Configuration of the peer; NULL if we are not sure what the peer's correct
39 * configuration actually is; non-NULL if this peer is controlled by this
42 struct GNUNET_CONFIGURATION_Handle *cfg;
45 * If this process has started this peer's ARM process, this is the handle
46 * to the 'gnunet-service-arm' process of the peer.
48 struct GNUNET_OS_Process *arm;
56 * A peer controlled by the testing framework. A peer runs
57 * at a particular host.
59 struct GNUNET_TESTING_Peer
62 * Our controller context (not necessarily the controller
63 * that is responsible for starting/running the peer!).
65 struct GNUNET_TESTING_Controller *controller;
68 * Which host does this peer run on?
70 struct GNUENT_TESTING_Host *host;
73 * Globally unique ID of the peer.
78 * Internals of the peer for the controlling process; NULL if
79 * this process is not controlling this peer.
81 struct PeerDetails *details;
87 * Lookup a peer by ID.
89 * @param id global peer ID assigned to the peer
90 * @return handle to the host, NULL on error
92 struct GNUNET_TESTING_Peer *
93 GNUNET_TESTING_peer_lookup_by_id_ (uint32_t id)
101 * Create the given peer at the specified host using the given
102 * controller. If the given controller is not running on the target
103 * host, it should find or create a controller at the target host and
104 * delegate creating the peer. Explicit delegation paths can be setup
105 * using 'GNUNET_TESTING_controller_link'. If no explicit delegation
106 * path exists, a direct link with a subordinate controller is setup
107 * for the first delegated peer to a particular host; the subordinate
108 * controller is then destroyed once the last peer that was delegated
109 * to the remote host is stopped. This function is used in particular
110 * if some other controller has already assigned a unique ID to the
113 * Creating the peer only creates the handle to manipulate and further
114 * configure the peer; use "GNUNET_TESTING_peer_start" and
115 * "GNUNET_TESTING_peer_stop" to actually start/stop the peer's
118 * Note that the given configuration will be adjusted by the
119 * controller to avoid port/path conflicts with other peers.
120 * The "final" configuration can be obtained using
121 * 'GNUNET_TESTING_peer_get_information'.
123 * @param unique_id unique ID for this peer
124 * @param controller controller process to use
125 * @param host host to run the peer on
126 * @param cfg configuration to use for the peer
127 * @return handle to the peer (actual startup will happen asynchronously)
129 struct GNUNET_TESTING_Peer *
130 GNUNET_TESTING_peer_create_with_id_ (uint32_t unique_id,
131 struct GNUNET_TESTING_Controller *controller,
132 struct GNUNET_TESTING_Host *host,
133 const struct GNUNET_CONFIGURATION_Handle *cfg)
135 // FIXME: create locally or delegate...
142 * Create the given peer at the specified host using the given
143 * controller. If the given controller is not running on the target
144 * host, it should find or create a controller at the target host and
145 * delegate creating the peer. Explicit delegation paths can be setup
146 * using 'GNUNET_TESTING_controller_link'. If no explicit delegation
147 * path exists, a direct link with a subordinate controller is setup
148 * for the first delegated peer to a particular host; the subordinate
149 * controller is then destroyed once the last peer that was delegated
150 * to the remote host is stopped.
152 * Creating the peer only creates the handle to manipulate and further
153 * configure the peer; use "GNUNET_TESTING_peer_start" and
154 * "GNUNET_TESTING_peer_stop" to actually start/stop the peer's
157 * Note that the given configuration will be adjusted by the
158 * controller to avoid port/path conflicts with other peers.
159 * The "final" configuration can be obtained using
160 * 'GNUNET_TESTING_peer_get_information'.
162 * @param controller controller process to use
163 * @param host host to run the peer on
164 * @param cfg configuration to use for the peer
165 * @return handle to the peer (actual startup will happen asynchronously)
167 struct GNUNET_TESTING_Peer *
168 GNUNET_TESTING_peer_create (struct GNUNET_TESTING_Controller *controller,
169 struct GNUNET_TESTING_Host *host,
170 const struct GNUNET_CONFIGURATION_Handle *cfg)
172 static uint32_t id_gen;
174 return GNUNET_TESTING_peer_create_with_id_ (++id_gen,
182 * Start the given peer.
184 * @param peer peer to start
185 * @return handle to the operation
187 struct GNUNET_TESTING_Operation *
188 GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer)
190 // FIXME: start locally or delegate...
197 * Stop the given peer. The handle remains valid (use
198 * "GNUNET_TESTING_peer_destroy" to fully clean up the
199 * state of the peer).
201 * @param peer peer to stop
202 * @return handle to the operation
204 struct GNUNET_TESTING_Operation *
205 GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer)
207 // FIXME: stop locally or delegate...
214 * Request information about a peer.
216 * @param peer peer to request information about
217 * @param pit desired information
218 * @return handle to the operation
220 struct GNUNET_TESTING_Operation *
221 GNUNET_TESTING_peer_get_information (struct GNUNET_TESTING_Peer *peer,
222 enum GNUNET_TESTING_PeerInformationType pit)
224 // FIXME: handle locally or delegate...
231 * Change peer configuration. Must only be called while the
232 * peer is stopped. Ports and paths cannot be changed this
235 * @param peer peer to change configuration for
236 * @param cfg new configuration (differences to existing
237 * configuration only)
238 * @return handle to the operation
240 struct GNUNET_TESTING_Operation *
241 GNUNET_TESTING_peer_update_configuration (struct GNUNET_TESTING_Peer *peer,
242 const struct GNUNET_CONFIGURATION_Handle *cfg)
244 // FIXME: handle locally or delegate...
251 * Manipulate the P2P underlay topology by configuring a link
254 * @param op_cls closure argument to give with the operation event
255 * @param p1 first peer
256 * @param p2 second peer
257 * @param co option to change
258 * @param ... option-specific values
259 * @return handle to the operation, NULL if configuring the link at this
260 * time is not allowed
262 struct GNUNET_TESTING_Operation *
263 GNUNET_TESTING_underlay_configure_link (void *op_cls,
264 struct GNUNET_TESTING_Peer *p1,
265 struct GNUNET_TESTING_Peer *p2,
266 enum GNUNET_TESTING_ConnectOption co, ...)
275 * Both peers must have been started before calling this function.
276 * This function then obtains a HELLO from 'p1', gives it to 'p2'
277 * and asks 'p2' to connect to 'p1'.
279 * @param op_cls closure argument to give with the operation event
280 * @param p1 first peer
281 * @param p2 second peer
282 * @return handle to the operation, NULL if connecting these two
283 * peers is fundamentally not possible at this time (peers
284 * not running or underlay disallows)
286 struct GNUNET_TESTING_Operation *
287 GNUNET_TESTING_overlay_connect (void *op_cls,
288 struct GNUNET_TESTING_Peer *p1,
289 struct GNUNET_TESTING_Peer *p2)
297 /* end of new_testing_api_peers.c */