GNUnet  0.10.x
gnunet_testing_lib.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2008, 2009, 2012 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your 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  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
41 #ifndef GNUNET_TESTING_LIB_H
42 #define GNUNET_TESTING_LIB_H
43 
44 #include "gnunet_util_lib.h"
46 #include "gnunet_arm_service.h"
47 
48 #ifdef __cplusplus
49 extern "C"
50 {
51 #if 0 /* keep Emacsens' auto-indent happy */
52 }
53 #endif
54 #endif
55 
59 #define GNUNET_TESTING_HOSTKEYFILESIZE sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)
60 
65 #define GNUNET_TESTING_PREFIX "GNUNET_TESTING_PREFIX"
66 
67 
73 
74 
78 struct GNUNET_TESTING_Peer;
79 
80 
85 {
89  const char *service;
90 
95 
100  unsigned int share;
101 };
102 
103 
124 struct GNUNET_TESTING_System *
125 GNUNET_TESTING_system_create (const char *testdir,
126  const char *trusted_ip,
127  const char *hostname,
128  const struct GNUNET_TESTING_SharedService *
130 
131 
156 struct GNUNET_TESTING_System *
158  const char *trusted_ip,
159  const char *hostname,
161  uint16_t lowport,
162  uint16_t highport);
163 
164 
172 void
174  int remove_paths);
175 
176 
196  uint32_t key_number,
197  struct GNUNET_PeerIdentity *id);
198 
199 
206 uint16_t
208 
209 
217 void
219  uint16_t port);
220 
221 
239 int
242 // FIXME: add dual to 'release' ports again...
243 
244 
258 struct GNUNET_TESTING_Peer *
261  uint32_t key_number,
262  struct GNUNET_PeerIdentity *id,
263  char **emsg);
264 
265 
272 void
274  struct GNUNET_PeerIdentity *id);
275 
276 
284 int
286 
287 
297 int
299 
300 
308 void
310 
311 
319 int
321 
322 
330 int
332 
333 
342 typedef void
344  struct GNUNET_TESTING_Peer *peer,
345  int success);
346 
347 
359 int
362  void *cb_cls);
363 
364 
374 void
376 
377 
386 typedef void
388  const struct GNUNET_CONFIGURATION_Handle *cfg,
389  struct GNUNET_TESTING_Peer *peer);
390 
391 
408 int
409 GNUNET_TESTING_peer_run (const char *testdir,
410  const char *cfgfilename,
412  void *tm_cls);
413 
414 
436 int
437 GNUNET_TESTING_service_run (const char *testdir,
438  const char *service_name,
439  const char *cfgfilename,
441  void *tm_cls);
442 
443 
457 char *
459 
460 
461 #if 0 /* keep Emacsens' auto-indent happy */
462 {
463 #endif
464 #ifdef __cplusplus
465 }
466 #endif
467 
468 #endif
469  /* end of group */
int GNUNET_TESTING_peer_stop_async(struct GNUNET_TESTING_Peer *peer, GNUNET_TESTING_PeerStopCallback cb, void *cb_cls)
Stop a peer asynchronously using ARM API.
Definition: testing.c:1470
uint16_t lowport
Lowest port we are allowed to use.
Definition: testing.c:163
Specification of a service that is to be shared among peers.
int GNUNET_TESTING_peer_start(struct GNUNET_TESTING_Peer *peer)
Start the peer.
Definition: testing.c:1315
Handle for a GNUnet peer controlled by testing.
Definition: testing.c:175
int GNUNET_TESTING_peer_run(const char *testdir, const char *cfgfilename, GNUNET_TESTING_TestMain tm, void *tm_cls)
Start a single peer and run a test using the testing library.
Definition: testing.c:1553
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_TESTING_hostkey_get(const struct GNUNET_TESTING_System *system, uint32_t key_number, struct GNUNET_PeerIdentity *id)
Testing includes a number of pre-created hostkeys for faster peer startup.
Definition: testing.c:704
int GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer)
Stop the peer.
Definition: testing.c:1418
int GNUNET_TESTING_configuration_create(struct GNUNET_TESTING_System *system, struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new configuration using the given configuration as a template; ports and paths will be modif...
Definition: testing.c:1113
struct GNUNET_TESTING_Peer * GNUNET_TESTING_peer_configure(struct GNUNET_TESTING_System *system, struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t key_number, struct GNUNET_PeerIdentity *id, char **emsg)
Configure a GNUnet peer.
Definition: testing.c:1134
int GNUNET_TESTING_peer_kill(struct GNUNET_TESTING_Peer *peer)
Sends SIGTERM to the peer&#39;s main process.
Definition: testing.c:1363
int GNUNET_TESTING_service_run(const char *testdir, const char *service_name, const char *cfgfilename, GNUNET_TESTING_TestMain tm, void *tm_cls)
Start a single service (no ARM, except of course if the given service name is &#39;arm&#39;) and run a test u...
Definition: testing.c:1626
struct GNUNET_TESTING_System * system
The TESTING system associated with this peer.
Definition: testing.c:180
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
void * cb_cls
The closure for the above callback.
Definition: testing.c:220
unsigned int share
The number of peers which share an instance of the service.
struct GNUNET_TESTING_System * GNUNET_TESTING_system_create(const char *testdir, const char *trusted_ip, const char *hostname, const struct GNUNET_TESTING_SharedService *shared_services)
Create a system handle.
Definition: testing.c:449
void GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, int remove_paths)
Free system resources.
Definition: testing.c:527
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct SharedService ** shared_services
Definition: testing.c:131
const char * service
The name of the service.
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testing.c:102
void GNUNET_TESTING_peer_stop_async_cancel(struct GNUNET_TESTING_Peer *peer)
Cancel a previous asynchronous peer stop request.
Definition: testing.c:1495
struct GNUNET_TESTING_System * GNUNET_TESTING_system_create_with_portrange(const char *testdir, const char *trusted_ip, const char *hostname, const struct GNUNET_TESTING_SharedService *shared_services, uint16_t lowport, uint16_t highport)
Create a system handle.
Definition: testing.c:370
Private ECC key encoded for transmission.
char * GNUNET_TESTING_get_testname_from_underscore(const char *argv0)
Sometimes we use the binary name to determine which specific test to run.
Definition: testing.c:1718
The identity of the host (wraps the signing key of the peer).
uint16_t highport
Highest port we are allowed to use.
Definition: testing.c:168
static char * hostname
Our hostname; we give this to all the peers we start.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:79
configuration data
Definition: configuration.c:85
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration template for the service.
uint16_t GNUNET_TESTING_reserve_port(struct GNUNET_TESTING_System *system)
Reserve a port for a peer.
Definition: testing.c:569
void GNUNET_TESTING_peer_get_identity(struct GNUNET_TESTING_Peer *peer, struct GNUNET_PeerIdentity *id)
Obtain the peer identity from a peer handle.
Definition: testing.c:1292
uint32_t key_number
The keynumber of this peer&#39;s hostkey.
Definition: testing.c:245
GNUNET_TESTING_PeerStopCallback cb
The callback to call asynchronously when a peer is stopped.
Definition: testing.c:215
void GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer)
Destroy the peer.
Definition: testing.c:1511
void GNUNET_TESTING_release_port(struct GNUNET_TESTING_System *system, uint16_t port)
Release reservation of a TCP or UDP port for a peer (used during GNUNET_TESTING_peer_destroy).
Definition: testing.c:666
void(* GNUNET_TESTING_TestMain)(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer)
Signature of the &#39;main&#39; function for a (single-peer) testcase that is run using GNUNET_TESTING_peer_r...
int GNUNET_TESTING_peer_wait(struct GNUNET_TESTING_Peer *peer)
Waits for a peer to terminate.
Definition: testing.c:1395
char * trusted_ip
The trusted ip.
Definition: testing.c:114
void(* GNUNET_TESTING_PeerStopCallback)(void *cls, struct GNUNET_TESTING_Peer *peer, int success)
Callback to inform whether the peer is running or stopped.