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 msg->config_size = htonl (c_size);
160 GNUNET_TESTBED_queue_message (controller,
161 (struct GNUNET_MessageHeader *) msg);
167 * Create the given peer at the specified host using the given
168 * controller. If the given controller is not running on the target
169 * host, it should find or create a controller at the target host and
170 * delegate creating the peer. Explicit delegation paths can be setup
171 * using 'GNUNET_TESTBED_controller_link'. If no explicit delegation
172 * path exists, a direct link with a subordinate controller is setup
173 * for the first delegated peer to a particular host; the subordinate
174 * controller is then destroyed once the last peer that was delegated
175 * to the remote host is stopped.
177 * Creating the peer only creates the handle to manipulate and further
178 * configure the peer; use "GNUNET_TESTBED_peer_start" and
179 * "GNUNET_TESTBED_peer_stop" to actually start/stop the peer's
182 * Note that the given configuration will be adjusted by the
183 * controller to avoid port/path conflicts with other peers.
184 * The "final" configuration can be obtained using
185 * 'GNUNET_TESTBED_peer_get_information'.
187 * @param controller controller process to use
188 * @param host host to run the peer on
189 * @param cfg configuration to use for the peer
190 * @return handle to the peer (actual startup will happen asynchronously)
192 struct GNUNET_TESTBED_Peer *
193 GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
194 struct GNUNET_TESTBED_Host *host,
195 const struct GNUNET_CONFIGURATION_Handle *cfg)
197 static uint32_t id_gen;
199 return GNUNET_TESTBED_peer_create_with_id_ (++id_gen,
207 * Start the given peer.
209 * @param peer peer to start
210 * @return handle to the operation
212 struct GNUNET_TESTBED_Operation *
213 GNUNET_TESTBED_peer_start (struct GNUNET_TESTBED_Peer *peer)
215 // FIXME: start locally or delegate...
222 * Stop the given peer. The handle remains valid (use
223 * "GNUNET_TESTBED_peer_destroy" to fully clean up the
224 * state of the peer).
226 * @param peer peer to stop
227 * @return handle to the operation
229 struct GNUNET_TESTBED_Operation *
230 GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer)
232 // FIXME: stop locally or delegate...
239 * Request information about a peer.
241 * @param peer peer to request information about
242 * @param pit desired information
243 * @return handle to the operation
245 struct GNUNET_TESTBED_Operation *
246 GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
247 enum GNUNET_TESTBED_PeerInformationType pit)
249 // FIXME: handle locally or delegate...
256 * Change peer configuration. Must only be called while the
257 * peer is stopped. Ports and paths cannot be changed this
260 * @param peer peer to change configuration for
261 * @param cfg new configuration (differences to existing
262 * configuration only)
263 * @return handle to the operation
265 struct GNUNET_TESTBED_Operation *
266 GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
267 const struct GNUNET_CONFIGURATION_Handle *cfg)
269 // FIXME: handle locally or delegate...
276 * Manipulate the P2P underlay topology by configuring a link
279 * @param op_cls closure argument to give with the operation event
280 * @param p1 first peer
281 * @param p2 second peer
282 * @param co option to change
283 * @param ... option-specific values
284 * @return handle to the operation, NULL if configuring the link at this
285 * time is not allowed
287 struct GNUNET_TESTBED_Operation *
288 GNUNET_TESTBED_underlay_configure_link (void *op_cls,
289 struct GNUNET_TESTBED_Peer *p1,
290 struct GNUNET_TESTBED_Peer *p2,
291 enum GNUNET_TESTBED_ConnectOption co, ...)
300 * Both peers must have been started before calling this function.
301 * This function then obtains a HELLO from 'p1', gives it to 'p2'
302 * and asks 'p2' to connect to 'p1'.
304 * @param op_cls closure argument to give with the operation event
305 * @param p1 first peer
306 * @param p2 second peer
307 * @return handle to the operation, NULL if connecting these two
308 * peers is fundamentally not possible at this time (peers
309 * not running or underlay disallows)
311 struct GNUNET_TESTBED_Operation *
312 GNUNET_TESTBED_overlay_connect (void *op_cls,
313 struct GNUNET_TESTBED_Peer *p1,
314 struct GNUNET_TESTBED_Peer *p2)
322 /* end of testbed_api_peers.c */