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 testbed/testbed_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 "testbed_api_peers.h"
29 #include "testbed_api.h"
31 #include "testbed_api_hosts.h"
34 * Details about a peer; kept in a separate struct to avoid bloating
35 * memory consumption everywhere...
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
44 struct GNUNET_CONFIGURATION_Handle *cfg;
47 * If this process has started this peer's ARM process, this is the handle
48 * to the 'gnunet-service-arm' process of the peer.
50 struct GNUNET_OS_Process *arm;
58 * A peer controlled by the testing framework. A peer runs
59 * at a particular host.
61 struct GNUNET_TESTBED_Peer
64 * Our controller context (not necessarily the controller
65 * that is responsible for starting/running the peer!).
67 struct GNUNET_TESTBED_Controller *controller;
70 * Which host does this peer run on?
72 struct GNUNET_TESTBED_Host *host;
75 * Globally unique ID of the peer.
80 * Internals of the peer for the controlling process; NULL if
81 * this process is not controlling this peer.
83 struct PeerDetails *details;
89 * Lookup a peer by ID.
91 * @param id global peer ID assigned to the peer
92 * @return handle to the host, NULL on error
94 struct GNUNET_TESTBED_Peer *
95 GNUNET_TESTBED_peer_lookup_by_id_ (uint32_t id)
103 * Create the given peer at the specified host using the given
104 * controller. If the given controller is not running on the target
105 * host, it should find or create a controller at the target host and
106 * delegate creating the peer. Explicit delegation paths can be setup
107 * using 'GNUNET_TESTBED_controller_link'. If no explicit delegation
108 * path exists, a direct link with a subordinate controller is setup
109 * for the first delegated peer to a particular host; the subordinate
110 * controller is then destroyed once the last peer that was delegated
111 * to the remote host is stopped. This function is used in particular
112 * if some other controller has already assigned a unique ID to the
115 * Creating the peer only creates the handle to manipulate and further
116 * configure the peer; use "GNUNET_TESTBED_peer_start" and
117 * "GNUNET_TESTBED_peer_stop" to actually start/stop the peer's
120 * Note that the given configuration will be adjusted by the
121 * controller to avoid port/path conflicts with other peers.
122 * The "final" configuration can be obtained using
123 * 'GNUNET_TESTBED_peer_get_information'.
125 * @param unique_id unique ID for this peer
126 * @param controller controller process to use
127 * @param host host to run the peer on
128 * @param cfg configuration to use for the peer
129 * @return handle to the peer (actual startup will happen asynchronously)
131 struct GNUNET_TESTBED_Peer *
132 GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
133 struct GNUNET_TESTBED_Controller *controller,
134 struct GNUNET_TESTBED_Host *host,
135 const struct GNUNET_CONFIGURATION_Handle *cfg)
137 struct GNUNET_TESTBED_Peer *peer;
138 struct GNUNET_TESTBED_PeerCreateMessage *msg;
145 peer = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer));
146 peer->controller = controller;
148 peer->unique_id = unique_id;
149 config = GNUNET_CONFIGURATION_serialize (cfg, &c_size);
150 xc_size = GNUNET_TESTBED_compress_config (config, c_size, &xconfig);
151 GNUNET_free (config);
152 msize = xc_size + sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
153 msg = GNUNET_realloc (xconfig, msize);
154 memmove (&msg[1], msg, sizeof (struct GNUNET_TESTBED_PeerCreateMessage));
155 msg->header.size = htons (msize);
156 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER);
157 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (peer->host));
158 msg->peer_id = htonl (peer->unique_id);
159 GNUNET_TESTBED_queue_message (controller,
160 (struct GNUNET_MessageHeader *) msg);
166 * Create the given peer at the specified host using the given
167 * controller. If the given controller is not running on the target
168 * host, it should find or create a controller at the target host and
169 * delegate creating the peer. Explicit delegation paths can be setup
170 * using 'GNUNET_TESTBED_controller_link'. If no explicit delegation
171 * path exists, a direct link with a subordinate controller is setup
172 * for the first delegated peer to a particular host; the subordinate
173 * controller is then destroyed once the last peer that was delegated
174 * to the remote host is stopped.
176 * Creating the peer only creates the handle to manipulate and further
177 * configure the peer; use "GNUNET_TESTBED_peer_start" and
178 * "GNUNET_TESTBED_peer_stop" to actually start/stop the peer's
181 * Note that the given configuration will be adjusted by the
182 * controller to avoid port/path conflicts with other peers.
183 * The "final" configuration can be obtained using
184 * 'GNUNET_TESTBED_peer_get_information'.
186 * @param controller controller process to use
187 * @param host host to run the peer on
188 * @param cfg configuration to use for the peer
189 * @return handle to the peer (actual startup will happen asynchronously)
191 struct GNUNET_TESTBED_Peer *
192 GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
193 struct GNUNET_TESTBED_Host *host,
194 const struct GNUNET_CONFIGURATION_Handle *cfg)
196 static uint32_t id_gen;
198 return GNUNET_TESTBED_peer_create_with_id_ (++id_gen,
206 * Start the given peer.
208 * @param peer peer to start
209 * @return handle to the operation
211 struct GNUNET_TESTBED_Operation *
212 GNUNET_TESTBED_peer_start (struct GNUNET_TESTBED_Peer *peer)
214 // FIXME: start locally or delegate...
221 * Stop the given peer. The handle remains valid (use
222 * "GNUNET_TESTBED_peer_destroy" to fully clean up the
223 * state of the peer).
225 * @param peer peer to stop
226 * @return handle to the operation
228 struct GNUNET_TESTBED_Operation *
229 GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer)
231 // FIXME: stop locally or delegate...
238 * Request information about a peer.
240 * @param peer peer to request information about
241 * @param pit desired information
242 * @return handle to the operation
244 struct GNUNET_TESTBED_Operation *
245 GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
246 enum GNUNET_TESTBED_PeerInformationType pit)
248 // FIXME: handle locally or delegate...
255 * Change peer configuration. Must only be called while the
256 * peer is stopped. Ports and paths cannot be changed this
259 * @param peer peer to change configuration for
260 * @param cfg new configuration (differences to existing
261 * configuration only)
262 * @return handle to the operation
264 struct GNUNET_TESTBED_Operation *
265 GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
266 const struct GNUNET_CONFIGURATION_Handle *cfg)
268 // FIXME: handle locally or delegate...
275 * Manipulate the P2P underlay topology by configuring a link
278 * @param op_cls closure argument to give with the operation event
279 * @param p1 first peer
280 * @param p2 second peer
281 * @param co option to change
282 * @param ... option-specific values
283 * @return handle to the operation, NULL if configuring the link at this
284 * time is not allowed
286 struct GNUNET_TESTBED_Operation *
287 GNUNET_TESTBED_underlay_configure_link (void *op_cls,
288 struct GNUNET_TESTBED_Peer *p1,
289 struct GNUNET_TESTBED_Peer *p2,
290 enum GNUNET_TESTBED_ConnectOption co, ...)
299 * Both peers must have been started before calling this function.
300 * This function then obtains a HELLO from 'p1', gives it to 'p2'
301 * and asks 'p2' to connect to 'p1'.
303 * @param op_cls closure argument to give with the operation event
304 * @param p1 first peer
305 * @param p2 second peer
306 * @return handle to the operation, NULL if connecting these two
307 * peers is fundamentally not possible at this time (peers
308 * not running or underlay disallows)
310 struct GNUNET_TESTBED_Operation *
311 GNUNET_TESTBED_overlay_connect (void *op_cls,
312 struct GNUNET_TESTBED_Peer *p1,
313 struct GNUNET_TESTBED_Peer *p2)
321 /* end of testbed_api_peers.c */